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

Optimize get vend cal params power #1285

Merged
merged 4 commits into from
Mar 26, 2024
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
14 changes: 7 additions & 7 deletions echopype/calibrate/cal_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def get_vend_cal_params_power(beam: xr.Dataset, vend: xr.Dataset, param: str) ->
raise ValueError(f"{param} does not exist in the Vendor_specific group!")

# Find idx to select the corresponding param value
# by matching beam["transmit_duration_nominal"] with ds_vend["pulse_length"]
# by matching beam["transmit_duration_nominal"] with vend["pulse_length"]
transmit_isnull = beam["transmit_duration_nominal"].isnull()
idxmin = np.abs(beam["transmit_duration_nominal"] - vend["pulse_length"]).idxmin(
dim="pulse_length_bin"
Expand All @@ -297,13 +297,13 @@ def get_vend_cal_params_power(beam: xr.Dataset, vend: xr.Dataset, param: str) ->
idxmin = idxmin.where(~transmit_isnull, 0).astype(int)

# Get param dataarray into correct shape
da_param = (
vend[param]
.expand_dims(dim={"ping_time": idxmin["ping_time"]}) # expand dims for direct indexing
.sortby(idxmin.channel) # sortby in case channel sequence differs in vend and beam
)
da_param = vend[param].transpose("pulse_length_bin", "channel")

if not np.array_equal(da_param.channel.data, idxmin.channel.data):
da_param = da_param.sortby(
da_param.channel, ascending=False
) # sortby because channel sequence differs in vend and beam

# Select corresponding index and clean up the original nan elements
da_param = da_param.sel(pulse_length_bin=idxmin, drop=True)

# Set the nan elements back to nan.
Expand Down
Loading
Loading