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

Overhaul access pattern [all tests ci] #762

Merged
merged 13 commits into from
Aug 10, 2022
4 changes: 2 additions & 2 deletions echopype/calibrate/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ def add_attrs(cal_type, ds):
prov_dict["processing_function"] = f"calibrate.compute_{cal_type}"
cal_ds = cal_ds.assign_attrs(prov_dict)

if "water_level" in echodata.platform.data_vars.keys():
if "water_level" in echodata["Platform"].data_vars.keys():
# add water_level to the created xr.Dataset
cal_ds["water_level"] = echodata.platform.water_level
cal_ds["water_level"] = echodata["Platform"].water_level

return cal_ds

Expand Down
22 changes: 13 additions & 9 deletions echopype/calibrate/calibrate_azfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ def get_cal_params(self, cal_params):
self.cal_params["equivalent_beam_angle"] = (
cal_params["equivalent_beam_angle"]
if "equivalent_beam_angle" in cal_params
else self.echodata.beam["equivalent_beam_angle"]
else self.echodata["Sonar/Beam_group1"]["equivalent_beam_angle"]
)

# Get params from the Vendor_specific group
for p in ["EL", "DS", "TVR", "VTX", "Sv_offset"]:
# substitute if None in user input
self.cal_params[p] = cal_params[p] if p in cal_params else self.echodata.vendor[p]
self.cal_params[p] = (
cal_params[p] if p in cal_params else self.echodata["Vendor_specific"][p]
)

def get_env_params(self):
"""Get env params using user inputs or values from data file.
Expand All @@ -53,7 +55,7 @@ def get_env_params(self):
self.env_params["temperature"] = (
self.env_params["temperature"]
if "temperature" in self.env_params
else self.echodata.environment["temperature"]
else self.echodata["Environment"]["temperature"]
)

# Salinity and pressure always come from user input
Expand All @@ -71,7 +73,7 @@ def get_env_params(self):
formula_source="AZFP",
)
self.env_params["sound_absorption"] = uwa.calc_absorption(
frequency=self.echodata.beam["frequency_nominal"],
frequency=self.echodata["Sonar/Beam_group1"]["frequency_nominal"],
temperature=self.env_params["temperature"],
salinity=self.env_params["salinity"],
pressure=self.env_params["pressure"],
Expand Down Expand Up @@ -108,10 +110,10 @@ def _cal_power(self, cal_type, **kwargs):
# Compute derived params

# Harmonize time coordinate between Beam_groupX data and env_params
# Use self.echodata.beam because complex sample is always in Beam_group1
# Use self.echodata["Sonar/Beam_group1"] because complex sample is always in Beam_group1
for p in self.env_params.keys():
self.env_params[p] = self.echodata._harmonize_env_param_time(
self.env_params[p], ping_time=self.echodata.beam.ping_time
self.env_params[p], ping_time=self.echodata["Sonar/Beam_group1"].ping_time
)

# TODO: take care of dividing by zero encountered in log10
Expand All @@ -122,7 +124,9 @@ def _cal_power(self, cal_type, **kwargs):
# scaling factor (slope) in Fig.G-1, units Volts/dB], see p.84
a = self.cal_params["DS"]
EL = (
self.cal_params["EL"] - 2.5 / a + self.echodata.beam.backscatter_r / (26214 * a)
self.cal_params["EL"]
- 2.5 / a
+ self.echodata["Sonar/Beam_group1"].backscatter_r / (26214 * a)
) # eq.(5) # has beam dim due to backscatter_r

if cal_type == "Sv":
Expand All @@ -136,7 +140,7 @@ def _cal_power(self, cal_type, **kwargs):
* np.log10(
0.5
* self.env_params["sound_speed"]
* self.echodata.beam["transmit_duration_nominal"]
* self.echodata["Sonar/Beam_group1"]["transmit_duration_nominal"]
* self.cal_params["equivalent_beam_angle"]
)
+ self.cal_params["Sv_offset"]
Expand All @@ -155,7 +159,7 @@ def _cal_power(self, cal_type, **kwargs):
out = out.merge(self.range_meter)

# Add frequency_nominal to data set
out["frequency_nominal"] = self.echodata.beam["frequency_nominal"]
out["frequency_nominal"] = self.echodata["Sonar/Beam_group1"]["frequency_nominal"]

# Add env and cal parameters
out = self._add_params_to_output(out)
Expand Down
Loading