@@ -180,7 +180,7 @@ def apply_calibration(
180
180
181
181
Returns
182
182
-------
183
- spsd : xarray.DataArray (time, freq)
183
+ spsd_calibrated : xarray.DataArray (time, freq)
184
184
Spectral density in Pa^2/Hz, indexed by time and frequency.
185
185
"""
186
186
@@ -199,22 +199,25 @@ def apply_calibration(
199
199
"'sensitivity_curve' must have 'freq' as one of its dimensions."
200
200
)
201
201
202
+ # Create a copy of spsd to avoid in-place modification
203
+ spsd_calibrated = spsd .copy ()
204
+
202
205
# Read calibration curve
203
206
freq = sensitivity_curve .dims [0 ]
204
207
# 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 )
208
211
# Fill missing with provided value
209
212
calibration = calibration .fillna (fill_value )
210
213
211
214
# Subtract from sound pressure spectral density
212
215
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"
216
219
217
- return spsd
220
+ return spsd_calibrated
218
221
219
222
220
223
def sound_pressure_spectral_density_level (spsd : xr .DataArray ) -> xr .DataArray :
0 commit comments