Skip to content

Commit

Permalink
parse_azfp now parses AZFP pressure data according to given matlab …
Browse files Browse the repository at this point in the history
…code (#1189)

* added support for parsing azfp pressure data

* fixed failing ci tests

* Revert "fixed failing ci tests"

This reverts commit c378dc0.

* minor changes to tests

* Update test_convert_azfp.py

* Update echopype/tests/convert/test_convert_azfp.py

---------

Co-authored-by: Emilio Mayorga <emiliomayorga@gmail.com>
  • Loading branch information
praneethratna and emiliom authored Oct 23, 2023
1 parent 206be67 commit 9dfe5ba
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
24 changes: 24 additions & 0 deletions echopype/convert/parse_azfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,25 @@ def _compute_battery(self, ping_num, battery_type):

return N * USL5_BAT_CONSTANT

def _compute_pressure(self, ping_num, is_valid):
"""
Compute pressure in decibar
Parameters
----------
ping_num
ping number
is_valid
whether the associated parameters have valid values
"""
if not is_valid or self.parameters["sensors_flag_pressure_sensor_installed"] == "no":
return np.nan

counts = self.unpacked_data["ancillary"][ping_num][3]
v_in = 2.5 * (counts / 65535)
P = v_in * self.parameters["a1"] + self.parameters["a0"] - 10.125
return P

def parse_raw(self):
"""
Parse raw data file from AZFP echosounder.
Expand All @@ -214,6 +233,7 @@ def _test_valid_params(params):
return True

temperature_is_valid = _test_valid_params(["ka", "kb", "kc"])
pressure_is_valid = _test_valid_params(["a0", "a1"])
tilt_x_is_valid = _test_valid_params(["X_a", "X_b", "X_c"])
tilt_y_is_valid = _test_valid_params(["Y_a", "Y_b", "Y_c"])

Expand All @@ -235,6 +255,10 @@ def _test_valid_params(params):
self.unpacked_data["temperature"].append(
self._compute_temperature(ping_num, temperature_is_valid)
)
# Compute pressure from unpacked_data[ii]['ancillary'][3]
self.unpacked_data["pressure"].append(
self._compute_pressure(ping_num, pressure_is_valid)
)
# compute x tilt from unpacked_data[ii]['ancillary][0]
self.unpacked_data["tilt_x"].append(
self._compute_tilt(ping_num, "X", tilt_x_is_valid)
Expand Down
11 changes: 10 additions & 1 deletion echopype/convert/set_groups_azfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,16 @@ def set_env(self) -> xr.Dataset:
"standard_name": "sea_water_temperature",
"units": "deg_C",
},
)
),
"pressure": (
["time1"],
self.parser_obj.unpacked_data["pressure"],
{
"long_name": "Sea water pressure",
"standard_name": "sea_water_pressure_due_to_sea_water",
"units": "dbar",
},
),
},
coords={
"time1": (
Expand Down
26 changes: 24 additions & 2 deletions echopype/tests/convert/test_convert_azfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ def test_convert_azfp_01a_different_ranges(azfp_path):
check_platform_required_scalar_vars(echodata)


def test_convert_azfp_01a_notemperature_notilt(azfp_path):
"""Test converting file with no valid temperature or tilt data."""
def test_convert_azfp_01a_no_temperature_pressure_tilt(azfp_path):
"""Test converting file with no valid temperature, pressure and tilt data."""
azfp_01a_path = azfp_path / 'rutgers_glider_notemperature/22052500.01A'
azfp_xml_path = azfp_path / 'rutgers_glider_notemperature/22052501.XML'

Expand All @@ -169,13 +169,35 @@ def test_convert_azfp_01a_notemperature_notilt(azfp_path):
assert "temperature" in echodata["Environment"]
assert echodata["Environment"]["temperature"].isnull().all()

# Pressure variable is present in the Environment group and its values are all nan
assert "pressure" in echodata["Environment"]
assert echodata["Environment"]["pressure"].isnull().all()

# Tilt variables are present in the Platform group and their values are all nan
assert "tilt_x" in echodata["Platform"]
assert "tilt_y" in echodata["Platform"]
assert echodata["Platform"]["tilt_x"].isnull().all()
assert echodata["Platform"]["tilt_y"].isnull().all()


def test_convert_azfp_01a_pressure_temperature(azfp_path):
"""Test converting file with valid pressure and temperature data."""
azfp_01a_path = azfp_path / 'pressure' / '22042221.01A'
azfp_xml_path = azfp_path / 'pressure' / '22042220.XML'

echodata = open_raw(
raw_file=azfp_01a_path, sonar_model='AZFP', xml_path=azfp_xml_path
)

# Pressure variable is present in the Environment group and its values are not all nan
assert "pressure" in echodata["Environment"]
assert not echodata["Environment"]["pressure"].isnull().all()

# Temperature variable is present in the Environment group and its values are not all nan
assert "temperature" in echodata["Environment"]
assert not echodata["Environment"]["temperature"].isnull().all()


def test_load_parse_azfp_xml(azfp_path):

azfp_xml_path = azfp_path / '23081211.XML'
Expand Down

0 comments on commit 9dfe5ba

Please sign in to comment.