Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Centralize/generalize declaration of convention attributes #493

Merged
merged 6 commits into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion echopype/convert/set_groups_azfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import numpy as np
import xarray as xr

from ..echodata.convention.attrs import DEFAULT_BEAM_COORD_ATTRS
from ..utils.coding import set_encodings
from .set_groups_base import DEFAULT_BEAM_COORD_ATTRS, SetGroupsBase
from .set_groups_base import SetGroupsBase


class SetGroupsAZFP(SetGroupsBase):
Expand Down
16 changes: 0 additions & 16 deletions echopype/convert/set_groups_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,6 @@

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

# TODO: Move to a new utility module in, say, echodata.convention
DEFAULT_BEAM_COORD_ATTRS = {
"frequency": {
"long_name": "Transducer frequency",
"standard_name": "sound_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"},
}


class SetGroupsBase(abc.ABC):
"""Base class for saving groups to netcdf or zarr from echosounder data files."""
Expand Down
54 changes: 13 additions & 41 deletions echopype/convert/set_groups_ek60.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
import xarray as xr
from _echopype_version import version as ECHOPYPE_VERSION

from ..echodata.convention.attrs import (
DEFAULT_BEAM_COORD_ATTRS,
DEFAULT_PLATFORM_COORD_ATTRS,
DEFAULT_PLATFORM_VAR_ATTRS,
)
from ..utils.coding import set_encodings

# fmt: off
from .set_groups_base import DEFAULT_BEAM_COORD_ATTRS, DEFAULT_CHUNK_SIZE, SetGroupsBase
from .set_groups_base import DEFAULT_CHUNK_SIZE, SetGroupsBase

# fmt: on

Expand Down Expand Up @@ -183,34 +188,20 @@ def set_platform(self, NMEA_only=False) -> xr.Dataset:
"latitude": (
["location_time"],
lat,
{
"long_name": "Platform latitude",
"standard_name": "latitude",
"units": "degrees_north",
"valid_range": (-90.0, 90.0),
},
DEFAULT_PLATFORM_VAR_ATTRS["latitude"],
),
"longitude": (
["location_time"],
lon,
{
"long_name": "Platform longitude",
"standard_name": "longitude",
"units": "degrees_east",
"valid_range": (-180.0, 180.0),
},
DEFAULT_PLATFORM_VAR_ATTRS["longitude"],
),
"sentence_type": (["location_time"], msg_type),
},
coords={
"location_time": (
["location_time"],
location_time,
{
"axis": "T",
"long_name": "Timestamps for NMEA position datagrams",
"standard_name": "time",
},
DEFAULT_PLATFORM_COORD_ATTRS["location_time"],
)
},
)
Expand All @@ -235,41 +226,22 @@ def set_platform(self, NMEA_only=False) -> xr.Dataset:
"pitch": (
["ping_time"],
self.parser_obj.ping_data_dict["pitch"][ch],
{
"long_name": "Platform pitch",
"standard_name": "platform_pitch_angle",
"units": "arc_degree",
"valid_range": (-90.0, 90.0),
},
DEFAULT_PLATFORM_VAR_ATTRS["pitch"],
),
"roll": (
["ping_time"],
self.parser_obj.ping_data_dict["roll"][ch],
{
"long_name": "Platform roll",
"standard_name": "platform_roll_angle",
"units": "arc_degree",
"valid_range": (-90.0, 90.0),
},
DEFAULT_PLATFORM_VAR_ATTRS["roll"],
),
"heave": (
["ping_time"],
self.parser_obj.ping_data_dict["heave"][ch],
{
"long_name": "Platform heave",
"standard_name": "platform_heave_angle",
"units": "arc_degree",
"valid_range": (-90.0, 90.0),
},
DEFAULT_PLATFORM_VAR_ATTRS["heave"],
),
"water_level": (
["ping_time"],
self.parser_obj.ping_data_dict["transducer_depth"][ch],
{
"long_name": "z-axis distance from the platform coordinate system "
"origin to the sonar transducer",
"units": "m",
},
DEFAULT_PLATFORM_VAR_ATTRS["water_level"],
),
},
coords={
Expand Down
3 changes: 2 additions & 1 deletion echopype/convert/set_groups_ek80.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import numpy as np
import xarray as xr

from ..echodata.convention.attrs import DEFAULT_BEAM_COORD_ATTRS
from ..utils.coding import set_encodings
from .set_groups_base import DEFAULT_BEAM_COORD_ATTRS, SetGroupsBase
from .set_groups_base import SetGroupsBase


class SetGroupsEK80(SetGroupsBase):
Expand Down
65 changes: 65 additions & 0 deletions echopype/echodata/convention/attrs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""
Define convention-based global, coordinate and variable attributes
in one place for consistent reuse
"""

DEFAULT_BEAM_COORD_ATTRS = {
"frequency": {
"long_name": "Transducer frequency",
"standard_name": "sound_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_PLATFORM_COORD_ATTRS = {
"location_time": {
"axis": "T",
"long_name": "Timestamps for NMEA datagrams",
"standard_name": "time",
}
}

DEFAULT_PLATFORM_VAR_ATTRS = {
"latitude": {
"long_name": "Platform latitude",
"standard_name": "latitude",
"units": "degrees_north",
"valid_range": (-90.0, 90.0),
},
"longitude": {
"long_name": "Platform longitude",
"standard_name": "longitude",
"units": "degrees_east",
"valid_range": (-180.0, 180.0),
},
"pitch": {
"long_name": "Platform pitch",
"standard_name": "platform_pitch_angle",
"units": "arc_degree",
"valid_range": (-90.0, 90.0),
},
"roll": {
"long_name": "Platform roll",
"standard_name": "platform_roll_angle",
"units": "arc_degree",
"valid_range": (-90.0, 90.0),
},
"heave": {
"long_name": "Platform heave",
"standard_name": "platform_heave_angle",
"units": "arc_degree",
"valid_range": (-90.0, 90.0),
},
"water_level": {
"long_name": "z-axis distance from the platform coordinate system "
"origin to the sonar transducer",
"units": "m",
},
}
10 changes: 1 addition & 9 deletions echopype/echodata/echodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from ..utils.repr import HtmlTemplate
from ..utils.uwa import calc_sound_speed
from .convention import _get_convention
from .convention.attrs import DEFAULT_PLATFORM_COORD_ATTRS

XARRAY_ENGINE_MAP: Dict["FileFormatHint", "EngineHint"] = {
".nc": "netcdf4",
Expand All @@ -30,15 +31,6 @@
"EK80": 0,
}

# TODO: Move to a new utility module in, say, echodata.convention
DEFAULT_PLATFORM_COORD_ATTRS = {
"location_time": {
"axis": "T",
"long_name": "Timestamps for NMEA datagrams",
"standard_name": "time",
}
}


class EchoData:
"""Echo data model class for handling raw converted data,
Expand Down