From be009b3cbed8034429a7340fbb849ffe1c5cdcc8 Mon Sep 17 00:00:00 2001 From: leewujung Date: Mon, 20 Jun 2022 21:27:58 -0700 Subject: [PATCH 1/4] minor docstring change --- echopype/preprocess/api.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/echopype/preprocess/api.py b/echopype/preprocess/api.py index 4a1bcac64..a3e891cdc 100644 --- a/echopype/preprocess/api.py +++ b/echopype/preprocess/api.py @@ -10,7 +10,9 @@ def _check_range_uniqueness(ds): - """Check if range (``echo_range``) changes across ping in a given frequency channel.""" + """ + Check if range (``echo_range``) changes across ping in a given frequency channel. + """ return ( ds["echo_range"].isel(ping_time=0).dropna(dim="range_sample") == ds["echo_range"].dropna(dim="range_sample") @@ -18,7 +20,8 @@ def _check_range_uniqueness(ds): def _set_MVBS_attrs(ds): - """Attach common attributes + """ + Attach common attributes. Parameters ---------- @@ -42,7 +45,8 @@ def _set_MVBS_attrs(ds): def compute_MVBS(ds_Sv, range_meter_bin=20, ping_time_bin="20S"): - """Compute Mean Volume Backscattering Strength (MVBS) + """ + Compute Mean Volume Backscattering Strength (MVBS) based on intervals of range (``echo_range``) and ``ping_time`` specified in physical units. Output of this function differs from that of ``compute_MVBS_index_binning``, which computes @@ -161,7 +165,8 @@ def _freq_MVBS(ds, rint, pbin): def compute_MVBS_index_binning(ds_Sv, range_sample_num=100, ping_num=100): - """Compute Mean Volume Backscattering Strength (MVBS) + """ + Compute Mean Volume Backscattering Strength (MVBS) based on intervals of ``range_sample`` and ping number (``ping_num``) specified in index number. Output of this function differs from that of ``compute_MVBS``, which computes From a8261a5f8c0fda5a1b0332c608524655b81d786c Mon Sep 17 00:00:00 2001 From: leewujung Date: Mon, 20 Jun 2022 23:12:50 -0700 Subject: [PATCH 2/4] fix bug from the process of converting freq to ch --- echopype/preprocess/api.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/echopype/preprocess/api.py b/echopype/preprocess/api.py index a3e891cdc..d5039adfc 100644 --- a/echopype/preprocess/api.py +++ b/echopype/preprocess/api.py @@ -72,30 +72,24 @@ def compute_MVBS(ds_Sv, range_meter_bin=20, ping_time_bin="20S"): "echo_range variable changes across pings in at least one of the frequency channels." ) - # TODO: right now this computation is brittle as it takes echo_range - # from only the lowest frequency to make it the range for all channels. - # This should be implemented different to allow non-uniform echo_range. - - # get indices of sorted frequency_nominal values. This is necessary - # because the frequency_nominal values are not always in ascending order. - sorted_freq_ind = np.argsort(ds_Sv.frequency_nominal) - def _freq_MVBS(ds, rint, pbin): sv = 10 ** (ds["Sv"] / 10) # average should be done in linear domain - sv.coords["range_meter"] = ( + sv.coords["echo_range"] = ( ["range_sample"], - ds_Sv["echo_range"].isel(channel=sorted_freq_ind[0], ping_time=0).data, + ds["echo_range"].isel(ping_time=0).squeeze().drop("channel").data, ) - sv = sv.swap_dims({"range_sample": "range_meter"}) + sv = sv.swap_dims({"range_sample": "echo_range"}) sv_groupby_bins = ( - sv.groupby_bins("range_meter", bins=rint, right=False, include_lowest=True) + sv.groupby_bins("echo_range", bins=rint, right=False, include_lowest=True) .mean() .resample(ping_time=pbin, skipna=True) .mean() ) - sv_groupby_bins.coords["echo_range"] = (["range_meter_bins"], rint[:-1]) - sv_groupby_bins = sv_groupby_bins.swap_dims({"range_meter_bins": "echo_range"}) - sv_groupby_bins = sv_groupby_bins.drop_vars("range_meter_bins") + sv_groupby_bins.coords["echo_range"] = (["echo_range_bins"], rint[:-1]) + sv_groupby_bins = ( + sv_groupby_bins.swap_dims({"echo_range_bins": "echo_range"}) + .drop_vars("echo_range_bins") + ) return 10 * np.log10(sv_groupby_bins) # Groupby freq in case of different echo_range (from different sampling intervals) From 77086ff629a4b1b6a64fa99d8ed19a2f30a6f82b Mon Sep 17 00:00:00 2001 From: leewujung Date: Mon, 20 Jun 2022 23:21:52 -0700 Subject: [PATCH 3/4] reorder dimensions for AZFP Sv echo_range to be identical with Sv --- echopype/calibrate/calibrate_azfp.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/echopype/calibrate/calibrate_azfp.py b/echopype/calibrate/calibrate_azfp.py index 30afb6660..825e744cb 100644 --- a/echopype/calibrate/calibrate_azfp.py +++ b/echopype/calibrate/calibrate_azfp.py @@ -154,6 +154,9 @@ def _cal_power(self, cal_type, **kwargs): # Add env and cal parameters out = self._add_params_to_output(out) + # Order the dimensions + out["echo_range"] = out["echo_range"].transpose("channel", "ping_time", "range_sample") + # Squeeze out the beam dim # doing it here because both out and self.cal_params["equivalent_beam_angle"] has beam dim return out.squeeze("beam", drop=True) From b6205e57a13fea2e50801f099ea4cea4c38855da Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 21 Jun 2022 06:23:43 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- echopype/preprocess/api.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/echopype/preprocess/api.py b/echopype/preprocess/api.py index d5039adfc..55fbbfcf7 100644 --- a/echopype/preprocess/api.py +++ b/echopype/preprocess/api.py @@ -86,9 +86,8 @@ def _freq_MVBS(ds, rint, pbin): .mean() ) sv_groupby_bins.coords["echo_range"] = (["echo_range_bins"], rint[:-1]) - sv_groupby_bins = ( - sv_groupby_bins.swap_dims({"echo_range_bins": "echo_range"}) - .drop_vars("echo_range_bins") + sv_groupby_bins = sv_groupby_bins.swap_dims({"echo_range_bins": "echo_range"}).drop_vars( + "echo_range_bins" ) return 10 * np.log10(sv_groupby_bins)