Skip to content

Commit

Permalink
Generalize assignment of coordinate var attributes for ek60, ek80, az…
Browse files Browse the repository at this point in the history
…fp. Add range_bin long_name
  • Loading branch information
emiliom committed Nov 6, 2021
1 parent 4c77300 commit ac998f9
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 53 deletions.
20 changes: 12 additions & 8 deletions echopype/convert/set_groups_azfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
import xarray as xr

from .set_groups_base import SetGroupsBase, set_encodings
from .set_groups_base import DEFAULT_BEAM_COORD_ATTRS, SetGroupsBase, set_encodings


class SetGroupsAZFP(SetGroupsBase):
Expand Down Expand Up @@ -157,17 +157,21 @@ def set_beam(self) -> xr.Dataset:
),
},
coords={
"frequency": (["frequency"], freq, {"units": "Hz", "valid_min": 0.0}),
"frequency": (
["frequency"],
freq,
DEFAULT_BEAM_COORD_ATTRS["frequency"],
),
"ping_time": (
["ping_time"],
ping_time,
{
"axis": "T",
"long_name": "Timestamp of each ping",
"standard_name": "time",
},
DEFAULT_BEAM_COORD_ATTRS["ping_time"],
),
"range_bin": (
["range_bin"],
range_bin,
DEFAULT_BEAM_COORD_ATTRS["range_bin"],
),
"range_bin": (["range_bin"], range_bin),
},
attrs={
"beam_mode": "",
Expand Down
17 changes: 17 additions & 0 deletions echopype/convert/set_groups_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@

DEFAULT_CHUNK_SIZE = {"range_bin": 25000, "ping_time": 2500}

DEFAULT_BEAM_COORD_ATTRS = {
"frequency": {
"long_name": "Transducer frequency",
# TODO: is there an appropriate standard_name for frequency?
"units": "Hz",
"valid_min": 0.0,
},
"ping_time": {
"long_name": "Timestamp of each ping",
"standard_name": "time",
"axis": "T",
},
"range_bin": {
"long_name": "Along-range bin (sample) number, base 0"
}
}

DEFAULT_TIME_ENCODING = {
"units": "seconds since 1900-01-01T00:00:00+00:00",
"calendar": "gregorian",
Expand Down
22 changes: 10 additions & 12 deletions echopype/convert/set_groups_ek60.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import xarray as xr
from _echopype_version import version as ECHOPYPE_VERSION

from .set_groups_base import DEFAULT_CHUNK_SIZE, SetGroupsBase, set_encodings
from .set_groups_base import (
DEFAULT_CHUNK_SIZE, DEFAULT_BEAM_COORD_ATTRS, SetGroupsBase, set_encodings
)


class SetGroupsEK60(SetGroupsBase):
Expand Down Expand Up @@ -514,11 +516,7 @@ def set_beam(self) -> xr.Dataset:
"frequency": (
["frequency"],
freq,
{
"units": "Hz",
"long_name": "Transducer frequency",
"valid_min": 0.0,
},
DEFAULT_BEAM_COORD_ATTRS["frequency"],
)
},
attrs={"beam_mode": "vertical", "conversion_equation_t": "type_3"},
Expand Down Expand Up @@ -600,13 +598,13 @@ def set_beam(self) -> xr.Dataset:
"ping_time": (
["ping_time"],
self.parser_obj.ping_time[ch],
{
"axis": "T",
"long_name": "Timestamp of each ping",
"standard_name": "time",
},
DEFAULT_BEAM_COORD_ATTRS["ping_time"],
),
"range_bin": (
["range_bin"],
np.arange(data_shape[1]),
DEFAULT_BEAM_COORD_ATTRS["range_bin"],
),
"range_bin": (["range_bin"], np.arange(data_shape[1])),
},
)

Expand Down
59 changes: 26 additions & 33 deletions echopype/convert/set_groups_ek80.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
import xarray as xr

from .set_groups_base import SetGroupsBase, set_encodings
from .set_groups_base import DEFAULT_BEAM_COORD_ATTRS, SetGroupsBase, set_encodings


class SetGroupsEK80(SetGroupsBase):
Expand Down Expand Up @@ -347,11 +347,7 @@ def _assemble_ds_ping_invariant(self, params, data_type):
"frequency": (
["frequency"],
freq,
{
"units": "Hz",
"long_name": "Transducer frequency",
"valid_min": 0.0,
},
DEFAULT_BEAM_COORD_ATTRS["frequency"],
),
},
attrs={"beam_mode": "vertical", "conversion_equation_t": "type_3"},
Expand Down Expand Up @@ -394,14 +390,17 @@ def _assemble_ds_complex(self, ch):
"ping_time": (
["ping_time"],
self.parser_obj.ping_time[ch],
{
"axis": "T",
"long_name": "Timestamp of each ping",
"standard_name": "time",
},
DEFAULT_BEAM_COORD_ATTRS["ping_time"],
),
"range_bin": (
["range_bin"],
np.arange(data_shape[1]),
DEFAULT_BEAM_COORD_ATTRS["range_bin"],
),
"quadrant": (
["quadrant"],
np.arange(num_transducer_sectors)
),
"range_bin": (["range_bin"], np.arange(data_shape[1])),
"quadrant": (["quadrant"], np.arange(num_transducer_sectors)),
},
)

Expand Down Expand Up @@ -469,13 +468,13 @@ def _assemble_ds_power(self, ch):
"ping_time": (
["ping_time"],
self.parser_obj.ping_time[ch],
{
"axis": "T",
"long_name": "Timestamp of each ping",
"standard_name": "time",
},
DEFAULT_BEAM_COORD_ATTRS["ping_time"],
),
"range_bin": (
["range_bin"],
np.arange(data_shape[1]),
DEFAULT_BEAM_COORD_ATTRS["range_bin"],
),
"range_bin": (["range_bin"], np.arange(data_shape[1])),
},
)

Expand Down Expand Up @@ -548,13 +547,13 @@ def _assemble_ds_common(self, ch, range_bin_size):
"ping_time": (
["ping_time"],
self.parser_obj.ping_time[ch],
{
"axis": "T",
"long_name": "Timestamp of each ping",
"standard_name": "time",
},
DEFAULT_BEAM_COORD_ATTRS["ping_time"],
),
"range_bin": (
["range_bin"],
np.arange(range_bin_size),
DEFAULT_BEAM_COORD_ATTRS["range_bin"],
),
"range_bin": (["range_bin"], np.arange(range_bin_size)),
},
)
return set_encodings(ds_common)
Expand Down Expand Up @@ -630,9 +629,7 @@ def merge_save(ds_combine, ds_type, group_name):
}
)
ds_data["frequency"] = ds_data["frequency"].assign_attrs(
units="Hz",
long_name="Transducer frequency",
valid_min=0.0,
**DEFAULT_BEAM_COORD_ATTRS["frequency"]
)
if ch in self.parser_obj.ch_ids["complex"]:
ds_complex.append(ds_data)
Expand Down Expand Up @@ -698,11 +695,7 @@ def set_vendor(self) -> xr.Dataset:
"frequency": (
["frequency"],
param_dict["transducer_frequency"],
{
"units": "Hz",
"long_name": "Transducer frequency",
"valid_min": 0.0,
},
DEFAULT_BEAM_COORD_ATTRS["frequency"],
),
"pulse_length_bin": (
["pulse_length_bin"],
Expand Down

0 comments on commit ac998f9

Please sign in to comment.