Skip to content

Commit 2fc8527

Browse files
committed
modifiy to avoid inplace overwrite
1 parent 5417cfe commit 2fc8527

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

mhkit/acoustics/base.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def apply_calibration(
180180
181181
Returns
182182
-------
183-
spsd: xarray.DataArray (time, freq)
183+
spsd_calibrated: xarray.DataArray (time, freq)
184184
Spectral density in Pa^2/Hz, indexed by time and frequency.
185185
"""
186186

@@ -199,22 +199,25 @@ def apply_calibration(
199199
"'sensitivity_curve' must have 'freq' as one of its dimensions."
200200
)
201201

202+
# Create a copy of spsd to avoid in-place modification
203+
spsd_calibrated = spsd.copy()
204+
202205
# Read calibration curve
203206
freq = sensitivity_curve.dims[0]
204207
# Interpolate calibration curve to desired value
205-
calibration = sensitivity_curve.interp({freq: spsd["freq"]}, method="linear").drop(
206-
freq
207-
)
208+
calibration = sensitivity_curve.interp(
209+
{freq: spsd_calibrated["freq"]}, method="linear"
210+
).drop(freq)
208211
# Fill missing with provided value
209212
calibration = calibration.fillna(fill_value)
210213

211214
# Subtract from sound pressure spectral density
212215
sensitivity_ratio = 10 ** (calibration / 10) # V^2/uPa^2
213-
spsd /= sensitivity_ratio # uPa^2/Hz
214-
spsd /= 1e12 # Pa^2/Hz
215-
spsd.attrs["units"] = "Pa^2/Hz"
216+
spsd_calibrated /= sensitivity_ratio # uPa^2/Hz
217+
spsd_calibrated /= 1e12 # Pa^2/Hz
218+
spsd_calibrated.attrs["units"] = "Pa^2/Hz"
216219

217-
return spsd
220+
return spsd_calibrated
218221

219222

220223
def sound_pressure_spectral_density_level(spsd: xr.DataArray) -> xr.DataArray:

0 commit comments

Comments
 (0)