Skip to content

Commit

Permalink
Add decidecade levels
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcvey3 committed Aug 26, 2024
1 parent 4ecaa66 commit 1fd72f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
14 changes: 10 additions & 4 deletions mhkit/acoustics/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def sound_pressure_spectral_density(P, fs, window=1):
return out


def apply_calibration(spsd, sensitivity_curve, fill_nan):
def apply_calibration(spsd, sensitivity_curve, fill_value):
"""
Applies custom calibration to spectral density values
Expand All @@ -83,7 +83,7 @@ def apply_calibration(spsd, sensitivity_curve, fill_nan):
Mean square sound pressure spectral density in V^2/Hz.
sensitivity_curve: xarray.DataArray (freq)
Calibrated sensitivity curve in units of dB rel 1 V^2/uPa^2.
fill_nan: numeric
fill_value: numeric
Value with which to fill values missing from calibration curve,
in units of dB rel 1 V^2/uPa^2.
Expand All @@ -96,9 +96,11 @@ def apply_calibration(spsd, sensitivity_curve, fill_nan):
# Read calibration curve
freq = sensitivity_curve.dims[0]
# Interpolate calibration curve to desired value
calibration = sensitivity_curve.interp({freq: spsd["freq"]}).drop(freq)
calibration = sensitivity_curve.interp({freq: spsd["freq"]}, method="linear").drop(
freq
)
# Fill missing with provided value
calibration = calibration.fillna(fill_nan)
calibration = calibration.fillna(fill_value)

# Subtract from sound pressure spectral density
Sf_ratio = 10 ** (calibration / 10) # V^2/uPa^2
Expand Down Expand Up @@ -248,6 +250,10 @@ def time_average(spsdl, window=60, method="median", method_arg=None):
out.attrs["units"] = spsdl.units
out.attrs["comment"] = f"Time average {method}"

# This coordinate hangs on for some reason
if method == "quantile":
out = out.drop_vars("quantile")

return out


Expand Down
6 changes: 1 addition & 5 deletions mhkit/acoustics/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def read_hydrophone(
"valid_min": -max_sat,
"valid_max": max_sat,
"fs": fs,
"filename": filename.replace("\\", "/").split("/")[-1],
"filename": str(filename).replace("\\", "/").split("/")[-1],
},
)

Expand Down Expand Up @@ -272,10 +272,6 @@ def read_iclisten(filename, sensitivity=None, use_metadata=True):
Sf = int(hphone_sensitivity.split(" ")[0])
if use_metadata:
sensitivity = Sf
# else:
# warnings.warn(
# f"Overriding manufacturer sensitivity {Sf} with user-defined sensitivity {sensitivity}."
# )

out = read_hydrophone(
filename,
Expand Down

0 comments on commit 1fd72f0

Please sign in to comment.