Open ctuguinay opened 2 weeks ago
Ok so the problem happens here:
spreading_loss = 20 * np.log10(ds_Sv["echo_range"].where(ds_Sv["echo_range"] >= 1, other=1))
absorption_loss = 2 * ds_Sv["sound_absorption"] * ds_Sv["echo_range"]
# Compute power binned averages
power_cal = _log2lin(ds_Sv["Sv"] - spreading_loss - absorption_loss)
power_cal_binned_avg = 10 * np.log10(
power_cal.coarsen(
ping_time=ping_num,
range_sample=range_sample_num,
boundary="pad",
).mean()
)
# Compute noise
noise = power_cal_binned_avg.min(dim="range_sample", skipna=True)
# Align noise `ping_time` to the first index of each coarsened `ping_time` bin
noise = noise.assign_coords(ping_time=ping_num * np.arange(len(noise["ping_time"])))
# Limit max noise level
noise = noise.where(noise < noise_max, noise_max) if noise_max is not None else noise
# Upsample noise to original ping time dimension
Sv_noise = (
noise.reindex({"ping_time": power_cal["ping_time"]}, method="ffill")
+ spreading_loss
+ absorption_loss
)
When printing out the ping time indices for noise
after the reassignment of coordinates I get this:
And when printing out the original ping time indices for power_cal
I get this:
That being the case, the reindex errors out since there's a comparison between integers and datetime objects being doing within that function.
The reason that the remove background noise test passes is because the ping time index for the mock Sv DataArray is consisting of integers and not datetime objects:
def test_remove_background_noise():
"""Test remove_background_noise on toy data"""
# Parameters for fake data
nchan, npings, nrange_samples = 1, 10, 100
chan = np.arange(nchan).astype(str)
ping_index = np.arange(npings)
range_sample = np.arange(nrange_samples)
data = np.ones(nrange_samples)
# Insert noise points
np.put(data, 30, -30)
np.put(data, 60, -30)
# Add more pings
data = np.array([data] * npings)
# Make DataArray
Sv = xr.DataArray(
[data],
coords=[
('channel', chan),
('ping_time', ping_index),
('range_sample', range_sample),
],
)
Found in PR #1331, background noise removal fails at during
test_raw_to_mvbs
in the test fileechopype/tests/utils/test_processinglevels_integration.py
. Not quite sure what the problem is but I'll get to it later since it is out of the scope of #1331.