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

Move Beam group to Sonar/Beam_group1 and Beam_power to Sonar/Beam_power #574

Merged
merged 15 commits into from
Mar 12, 2022
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
198 changes: 0 additions & 198 deletions echopype/convert/add_ancillary.py

This file was deleted.

12 changes: 7 additions & 5 deletions echopype/convert/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

NMEA_SENTENCE_DEFAULT = ["GGA", "GLL", "RMC"]

BEAM_SUBGROUP_DEFAULT = "Beam_group1"


def to_file(
echodata: EchoData,
Expand Down Expand Up @@ -132,7 +134,7 @@ def _save_groups_to_file(echodata, output_path, engine, compress=True):
engine=engine,
)

# Beam group
# /Sonar/Beam_groupX group
if echodata.sonar_model == "AD2CP":
io.save_file(
echodata.beam.chunk(
Expand All @@ -143,7 +145,7 @@ def _save_groups_to_file(echodata, output_path, engine, compress=True):
path=output_path,
mode="a",
engine=engine,
group="Beam",
group=f"Sonar/{BEAM_SUBGROUP_DEFAULT}",
compression_settings=COMPRESSION_SETTINGS[engine] if compress else None,
)
else:
Expand All @@ -157,7 +159,7 @@ def _save_groups_to_file(echodata, output_path, engine, compress=True):
path=output_path,
mode="a",
engine=engine,
group="Beam",
group=f"Sonar/{BEAM_SUBGROUP_DEFAULT}",
compression_settings=COMPRESSION_SETTINGS[engine] if compress else None,
)
if echodata.beam_power is not None:
Expand All @@ -171,7 +173,7 @@ def _save_groups_to_file(echodata, output_path, engine, compress=True):
path=output_path,
mode="a",
engine=engine,
group="Beam_power",
group="Sonar/Beam_group2",
compression_settings=COMPRESSION_SETTINGS[engine] if compress else None,
)

Expand Down Expand Up @@ -446,7 +448,7 @@ def open_raw(
echodata.nmea = setgrouper.set_nmea()
echodata.provenance = setgrouper.set_provenance()
echodata.sonar = setgrouper.set_sonar()
# Beam_power group only exist if EK80 has both complex and power/angle data
# Beam_group2 group only exist if EK80 has both complex and power/angle data
if sonar_model in ["EK80", "ES80", "EA640"]:
echodata.beam, echodata.beam_power = setgrouper.set_beam()
else:
Expand Down
10 changes: 5 additions & 5 deletions echopype/convert/convert_combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def perform_combination(sonar_model, input_paths, output_path, engine):
# TODO: there should be compression option for the combined file too...

def coerce_type(ds, group):
if group == "Beam":
if group == "Sonar/Beam_group1":
if sonar_model == "EK80":
ds["transceiver_software_version"] = ds[
"transceiver_software_version"
Expand Down Expand Up @@ -91,15 +91,15 @@ def coerce_type(ds, group):
# with nicely monotonically varying ping_time/location_time/mru_time.
# However we know there are lots of problems with pings going backward in time for EK60/EK80 files,
# and we will need to clean up data before calling merge.
# Combine Beam
# Combine /Sonar/Beam_group1
with xr.open_mfdataset(
input_paths,
group="Beam",
group="Sonar/Beam_group1",
concat_dim="ping_time",
data_vars="minimal",
engine=engine,
) as ds_beam:
coerce_type(ds_beam, "Beam")
coerce_type(ds_beam, "Sonar/Beam_group1")
io.save_file(
ds_beam.chunk(
{
Expand All @@ -110,7 +110,7 @@ def coerce_type(ds, group):
path=output_path,
mode="a",
engine=engine,
group="Beam",
group="Sonar/Beam_group1",
)

# Combine Environment group
Expand Down
15 changes: 13 additions & 2 deletions echopype/convert/set_groups_azfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class SetGroupsAZFP(SetGroupsBase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self._beamgroups = [
{
"name": "Beam_group1",
"descr": "contains backscatter power (uncalibrated) and other beam or channel-specific data.",
}
]

def set_env(self) -> xr.Dataset:
"""Set the Environment group."""
# TODO Look at why this cannot be encoded without the modifications
Expand Down Expand Up @@ -44,6 +51,11 @@ def set_env(self) -> xr.Dataset:

def set_sonar(self) -> xr.Dataset:
"""Set the Sonar group."""

# Add beam_group_name and beam_group_descr variables sharing a common dimension (beam),
# using the information from self._beamgroups
ds = xr.Dataset(self._beam_groups_vars())

# Assemble sonar group dictionary
sonar_dict = {
"sonar_manufacturer": "ASL Environmental Sciences",
Expand All @@ -53,9 +65,8 @@ def set_sonar(self) -> xr.Dataset:
"sonar_software_version": "1.4",
"sonar_type": "echosounder",
}
# Save
ds = xr.Dataset()
ds = ds.assign_attrs(sonar_dict)

return ds

def set_platform(self) -> xr.Dataset:
Expand Down
23 changes: 22 additions & 1 deletion echopype/convert/set_groups_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def __init__(
self.compression_settings = COMPRESSION_SETTINGS[self.engine]

self._varattrs = sonarnetcdf_1.yaml_dict["variable_and_varattributes"]
# self._beamgroups must be a list of dicts, eg:
# [{"name":"Beam_group1", "descr":"contains complex backscatter data and other beam or channel-specific data."}]
self._beamgroups = []

# TODO: change the set_XXX methods to return a dataset to be saved
# in the overarching save method
Expand Down Expand Up @@ -94,7 +97,7 @@ def set_sonar(self) -> xr.Dataset:

@abc.abstractmethod
def set_beam(self) -> xr.Dataset:
"""Set the Beam group."""
"""Set the /Sonar/Beam group."""
raise NotImplementedError

@abc.abstractmethod
Expand Down Expand Up @@ -200,3 +203,21 @@ def _parse_NMEA(self):
)

return location_time, msg_type, lat, lon

def _beam_groups_vars(self):
"""Stage beam_group_name and beam_group_descr variables sharing a common dimension
to be inserted in the Sonar group"""
beam_groups_vars = {
"beam_group_name": (
["beam"],
[di["name"] for di in self._beamgroups],
{"long_name": "Beam group name"},
),
"beam_group_descr": (
["beam"],
[di["descr"] for di in self._beamgroups],
{"long_name": "Beam group description"},
),
}

return beam_groups_vars
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this! :D

Loading