From d77500dd22544200b0be75d35ed8a7c45436bc5a Mon Sep 17 00:00:00 2001 From: Emilio Mayorga Date: Mon, 22 May 2023 13:35:37 -0700 Subject: [PATCH 1/3] Define backscatter_r and backscatter_i long_name in the convention yaml file, then use it consistently everywhere --- echopype/convert/set_groups_azfp.py | 7 ++++++- echopype/convert/set_groups_base.py | 15 ++++++++++++--- echopype/convert/set_groups_ek60.py | 7 ++++++- echopype/convert/set_groups_ek80.py | 21 ++++++++++++++++++--- echopype/echodata/convention/1.0.yml | 5 +++++ 5 files changed, 47 insertions(+), 8 deletions(-) diff --git a/echopype/convert/set_groups_azfp.py b/echopype/convert/set_groups_azfp.py index 2ab734b85..ad7e2668d 100644 --- a/echopype/convert/set_groups_azfp.py +++ b/echopype/convert/set_groups_azfp.py @@ -261,7 +261,12 @@ def set_beam(self) -> List[xr.Dataset]: "backscatter_r": ( ["channel", "ping_time", "range_sample"], N, - {"long_name": "Backscatter power", "units": "dB"}, + { + "long_name": self._varattrs["beam_var_default"]["backscatter_r"][ + "long_name" + ], # noqa + "units": "dB", + }, ), "equivalent_beam_angle": ( ["channel"], diff --git a/echopype/convert/set_groups_base.py b/echopype/convert/set_groups_base.py index 60ef3f5fd..e2a48f2be 100644 --- a/echopype/convert/set_groups_base.py +++ b/echopype/convert/set_groups_base.py @@ -403,7 +403,10 @@ def _get_power_dataarray(self, zarr_path: str) -> xr.DataArray: ), }, name="backscatter_r", - attrs={"long_name": "Backscatter power", "units": "dB"}, + attrs={ + "long_name": self._varattrs["beam_var_default"]["backscatter_r"]["long_name"], + "units": "dB", + }, ) return backscatter_r @@ -537,14 +540,20 @@ def _get_complex_dataarrays(self, zarr_path: str) -> Tuple[xr.DataArray, xr.Data data=complex_r, coords=array_coords, name="backscatter_r", - attrs={"long_name": "Real part of backscatter power", "units": "V"}, + attrs={ + "long_name": self._varattrs["beam_var_default"]["backscatter_r"]["long_name"], + "units": "V", + }, ) backscatter_i = xr.DataArray( data=complex_i, coords=array_coords, name="backscatter_i", - attrs={"long_name": "Imaginary part of backscatter power", "units": "V"}, + attrs={ + "long_name": self._varattrs["beam_var_default"]["backscatter_i"]["long_name"], + "units": "V", + }, ) return backscatter_r, backscatter_i diff --git a/echopype/convert/set_groups_ek60.py b/echopype/convert/set_groups_ek60.py index 80aab2758..8b07dae4c 100644 --- a/echopype/convert/set_groups_ek60.py +++ b/echopype/convert/set_groups_ek60.py @@ -681,7 +681,12 @@ def set_beam(self) -> List[xr.Dataset]: var_dict["backscatter_r"] = ( ["ping_time", "range_sample"], self.parser_obj.ping_data_dict["power"][ch], - {"long_name": "Backscatter power", "units": "dB"}, + { + "long_name": self._varattrs["beam_var_default"]["backscatter_r"][ + "long_name" + ], # noqa + "units": "dB", + }, ) ds_tmp = xr.Dataset( diff --git a/echopype/convert/set_groups_ek80.py b/echopype/convert/set_groups_ek80.py index af2c05a5b..c8a77c830 100644 --- a/echopype/convert/set_groups_ek80.py +++ b/echopype/convert/set_groups_ek80.py @@ -724,12 +724,22 @@ def _assemble_ds_complex(self, ch): "backscatter_r": ( ["ping_time", "range_sample", "beam"], np.real(data), - {"long_name": "Real part of backscatter power", "units": "V"}, + { + "long_name": self._varattrs["beam_var_default"]["backscatter_r"][ + "long_name" + ], # noqa + "units": "V", + }, ), "backscatter_i": ( ["ping_time", "range_sample", "beam"], np.imag(data), - {"long_name": "Imaginary part of backscatter power", "units": "V"}, + { + "long_name": self._varattrs["beam_var_default"]["backscatter_i"][ + "long_name" + ], + "units": "V", + }, ), }, coords={ @@ -823,7 +833,12 @@ def _assemble_ds_power(self, ch): "backscatter_r": ( ["ping_time", "range_sample"], self.parser_obj.ping_data_dict["power"][ch], - {"long_name": "Backscatter power", "units": "dB"}, + { + "long_name": self._varattrs["beam_var_default"]["backscatter_r"][ + "long_name" + ], + "units": "dB", + }, ), }, coords={ diff --git a/echopype/echodata/convention/1.0.yml b/echopype/echodata/convention/1.0.yml index 7b8110b27..6d4aed785 100644 --- a/echopype/echodata/convention/1.0.yml +++ b/echopype/echodata/convention/1.0.yml @@ -70,6 +70,11 @@ variable_and_varattributes: long_name: Along-range sample number, base 0 beam: long_name: Beam name + beam_var_default: + backscatter_r: + long_name: Raw backscatter measurements (real part) + backscatter_i: + long_name: Raw backscatter measurements (imaginary part) platform_coord_default: time1: axis: T From 9237e798df94ecd901c85048db058e3bec6d96b6 Mon Sep 17 00:00:00 2001 From: Emilio Mayorga Date: Mon, 22 May 2023 13:42:39 -0700 Subject: [PATCH 2/3] Correct backscatter_r and backscatter_i units for AZFP (count, not dB) and EK80 (dB, not V in some cases) --- echopype/convert/set_groups_azfp.py | 2 +- echopype/convert/set_groups_base.py | 4 ++-- echopype/convert/set_groups_ek80.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/echopype/convert/set_groups_azfp.py b/echopype/convert/set_groups_azfp.py index ad7e2668d..defe701ba 100644 --- a/echopype/convert/set_groups_azfp.py +++ b/echopype/convert/set_groups_azfp.py @@ -265,7 +265,7 @@ def set_beam(self) -> List[xr.Dataset]: "long_name": self._varattrs["beam_var_default"]["backscatter_r"][ "long_name" ], # noqa - "units": "dB", + "units": "count", }, ), "equivalent_beam_angle": ( diff --git a/echopype/convert/set_groups_base.py b/echopype/convert/set_groups_base.py index e2a48f2be..5c4808412 100644 --- a/echopype/convert/set_groups_base.py +++ b/echopype/convert/set_groups_base.py @@ -542,7 +542,7 @@ def _get_complex_dataarrays(self, zarr_path: str) -> Tuple[xr.DataArray, xr.Data name="backscatter_r", attrs={ "long_name": self._varattrs["beam_var_default"]["backscatter_r"]["long_name"], - "units": "V", + "units": "dB", }, ) @@ -552,7 +552,7 @@ def _get_complex_dataarrays(self, zarr_path: str) -> Tuple[xr.DataArray, xr.Data name="backscatter_i", attrs={ "long_name": self._varattrs["beam_var_default"]["backscatter_i"]["long_name"], - "units": "V", + "units": "dB", }, ) diff --git a/echopype/convert/set_groups_ek80.py b/echopype/convert/set_groups_ek80.py index c8a77c830..1e4ee68a0 100644 --- a/echopype/convert/set_groups_ek80.py +++ b/echopype/convert/set_groups_ek80.py @@ -728,7 +728,7 @@ def _assemble_ds_complex(self, ch): "long_name": self._varattrs["beam_var_default"]["backscatter_r"][ "long_name" ], # noqa - "units": "V", + "units": "dB", }, ), "backscatter_i": ( @@ -738,7 +738,7 @@ def _assemble_ds_complex(self, ch): "long_name": self._varattrs["beam_var_default"]["backscatter_i"][ "long_name" ], - "units": "V", + "units": "dB", }, ), }, From d23428e29df5bb641777925202fb72d8c318ab0c Mon Sep 17 00:00:00 2001 From: Emilio Mayorga Date: Wed, 24 May 2023 09:32:52 -0700 Subject: [PATCH 3/3] Remove some non-operational # noqa flags added recently to set_groups_ modules --- echopype/convert/set_groups_azfp.py | 2 +- echopype/convert/set_groups_ek60.py | 2 +- echopype/convert/set_groups_ek80.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/echopype/convert/set_groups_azfp.py b/echopype/convert/set_groups_azfp.py index defe701ba..15cb95197 100644 --- a/echopype/convert/set_groups_azfp.py +++ b/echopype/convert/set_groups_azfp.py @@ -264,7 +264,7 @@ def set_beam(self) -> List[xr.Dataset]: { "long_name": self._varattrs["beam_var_default"]["backscatter_r"][ "long_name" - ], # noqa + ], "units": "count", }, ), diff --git a/echopype/convert/set_groups_ek60.py b/echopype/convert/set_groups_ek60.py index 8b07dae4c..e2c248282 100644 --- a/echopype/convert/set_groups_ek60.py +++ b/echopype/convert/set_groups_ek60.py @@ -684,7 +684,7 @@ def set_beam(self) -> List[xr.Dataset]: { "long_name": self._varattrs["beam_var_default"]["backscatter_r"][ "long_name" - ], # noqa + ], "units": "dB", }, ) diff --git a/echopype/convert/set_groups_ek80.py b/echopype/convert/set_groups_ek80.py index 1e4ee68a0..b4c48d79a 100644 --- a/echopype/convert/set_groups_ek80.py +++ b/echopype/convert/set_groups_ek80.py @@ -727,7 +727,7 @@ def _assemble_ds_complex(self, ch): { "long_name": self._varattrs["beam_var_default"]["backscatter_r"][ "long_name" - ], # noqa + ], "units": "dB", }, ),