Skip to content

Commit

Permalink
refactored ek80 xml parser
Browse files Browse the repository at this point in the history
  • Loading branch information
praneethratna committed Oct 2, 2023
1 parent ce1e614 commit a8bc113
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 272 deletions.
2 changes: 1 addition & 1 deletion echopype/convert/parse_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def _read_datagrams(self, fid):
'water_level_draft': 0.0,
'water_level_draft_is_manual': 0,
'transducer_name': 'Unknown',
'transducer_sound_speed': 1490.0},
'sound_speed': 1490.0},
'xml': '<?xml version="1.0" encoding="utf-8"?>\r\n<Environment Depth="240" ... />\r\n</Environment>'}
""" # noqa
num_datagrams_parsed = 0
Expand Down
21 changes: 11 additions & 10 deletions echopype/convert/set_groups_ek80.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def set_env(self) -> xr.Dataset:
},
)

varnames = ["sound_velocity_source", "transducer_name", "transducer_sound_speed"]
varnames = ["sound_velocity_source", "transducer_name", "sound_speed"]
for vn in varnames:
if vn in self.parser_obj.environment:
dict_env[vn] = (
Expand Down Expand Up @@ -193,12 +193,12 @@ def set_env(self) -> xr.Dataset:
def set_sonar(self, beam_group_type: list = ["power", None]) -> xr.Dataset:
# Collect unique variables
params = [
"transducer_frequency",
"frequency",
"serial_number",
"transducer_name",
"transducer_serial_number",
"application_name",
"application_version",
"version",
"channel_id_short",
]
var = defaultdict(list)
Expand Down Expand Up @@ -231,7 +231,7 @@ def set_sonar(self, beam_group_type: list = ["power", None]) -> xr.Dataset:
sonar_vars = {
"frequency_nominal": (
["channel"],
var["transducer_frequency"],
var["frequency"],
{
"units": "Hz",
"long_name": "Transducer frequency",
Expand Down Expand Up @@ -282,7 +282,7 @@ def set_sonar(self, beam_group_type: list = ["power", None]) -> xr.Dataset:
# will not try to populate sonar_serial_number from the raw datagrams
"sonar_serial_number": "",
"sonar_software_name": var["application_name"][0],
"sonar_software_version": var["application_version"][0],
"sonar_software_version": var["version"][0],
"sonar_type": "echosounder",
}
ds = ds.assign_attrs(sonar_attr_dict)
Expand All @@ -294,7 +294,7 @@ def set_platform(self) -> xr.Dataset:

freq = np.array(
[
self.parser_obj.config_datagram["configuration"][ch]["transducer_frequency"]
self.parser_obj.config_datagram["configuration"][ch]["frequency"]
for ch in self.sorted_channel["power_complex"]
]
)
Expand Down Expand Up @@ -455,7 +455,7 @@ def _assemble_ds_ping_invariant(self, params, data_type):

freq = np.array(
[
self.parser_obj.config_datagram["configuration"][ch]["transducer_frequency"]
self.parser_obj.config_datagram["configuration"][ch]["frequency"]
for ch in self.sorted_channel[data_type]
]
)
Expand Down Expand Up @@ -678,7 +678,7 @@ def _add_freq_start_end_ds(self, ds_tmp: xr.Dataset, ch: str) -> xr.Dataset:
freq_start = np.array(self.parser_obj.ping_data_dict["frequency_start"][ch])
freq_stop = np.array(self.parser_obj.ping_data_dict["frequency_end"][ch])
elif not self.sorted_channel["power"]:
freq = self.parser_obj.config_datagram["configuration"][ch]["transducer_frequency"]
freq = self.parser_obj.config_datagram["configuration"][ch]["frequency"]
freq_start = np.full(len(self.parser_obj.ping_time[ch]), freq)
freq_stop = freq_start
else:
Expand Down Expand Up @@ -1239,7 +1239,7 @@ def set_vendor(self) -> xr.Dataset:
# - receiver sampling frequency
# - transceiver type
table_params = [
"transducer_frequency",
"frequency",
"impedance", # transceiver impedance (z_er), different from transducer impedance (z_et)
"rx_sample_frequency", # receiver sampling frequency
"transceiver_type",
Expand Down Expand Up @@ -1272,7 +1272,7 @@ def set_vendor(self) -> xr.Dataset:
{
"frequency_nominal": (
["channel"],
param_dict["transducer_frequency"],
param_dict["frequency"],
{
"units": "Hz",
"long_name": "Transducer frequency",
Expand Down Expand Up @@ -1361,6 +1361,7 @@ def set_vendor(self) -> xr.Dataset:
for p in cal_params:
if p in config[ch_id]["calibration"]: # only for parameters that exist in dict
param_dict[p] = (["cal_frequency"], config[ch_id]["calibration"][p])
print(config[ch_id]["calibration"]["frequency"])
ds_ch = xr.Dataset(
data_vars=param_dict,
coords={
Expand Down
Loading

0 comments on commit a8bc113

Please sign in to comment.