From 6f70e5f59953940187cb4ebc35041232ca7b4d6c Mon Sep 17 00:00:00 2001 From: Mike McCann Date: Wed, 26 Mar 2025 12:13:53 -0700 Subject: [PATCH] Revert back to original hs2_calc_bb() - the translation from the Sackmann Matlab code. --- .vscode/launch.json | 4 ++-- src/data/hs2_proc.py | 36 +++++++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 61943baa..8e337122 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -226,7 +226,7 @@ //"args": ["-v", "1", "--last_n_days", "30", "--start_year", "2022", "--end_year", "2022", "--resample", "--noinput"] //"args": ["-v", "1", "--last_n_days", "30", "--start_year", "2022", "--end_year", "2022", "--archive", "--noinput"] //"args": ["-v", "1", "--start_year", "2021", "--end_year", "2022", "--noinput"] - //"args": ["-v", "1", "--mission", "2022.201.00", "--clobber", "--noinput", "--no_cleanup"] + "args": ["-v", "1", "--mission", "2022.201.00", "--clobber", "--noinput", "--no_cleanup"] //"args": ["-v", "1", "--mission", "2009.084.00", "--clobber", "--noinput"] //"args": ["-v", "1", "--mission", "2022.243.00", "--calibrate", "--clobber", "--noinput"] //"args": ["-v", "1", "--start_year", "2004", "--end_year", "2004", "--start_yd", "168", "--use_portal", "--clobber", "--noinput"] @@ -265,7 +265,7 @@ //"args": ["-v", "1", "--noinput", "--num_cores", "8"] //"args": ["-v", "1", "--noinput", "--no_cleanup", "--mission", "2011.256.02", "--clobber"] //"args": ["-v", "1", "--noinput", "--no_cleanup", "--mission", "2010.341.00", "--download_process", "--local"] - "args": ["-v", "1", "--noinput", "--no_cleanup", "--mission", "2020.337.00", "--local"] + //"args": ["-v", "1", "--noinput", "--no_cleanup", "--mission", "2020.337.00", "--local"] }, ] } diff --git a/src/data/hs2_proc.py b/src/data/hs2_proc.py index 029a7d6d..f2869bb8 100644 --- a/src/data/hs2_proc.py +++ b/src/data/hs2_proc.py @@ -1,7 +1,7 @@ # noqa: INP001 from collections import defaultdict -from math import exp +from math import exp, pi from pathlib import Path import numpy as np @@ -164,15 +164,30 @@ def hs2_calc_bb(orig_nc, cals): (_int_signer(orig_nc[f"Snorm{chan}"]) * float(cals[f"Ch{chan}"]["Mu"])), denom, ) - # Replaces "RawTempValue" as the name, helpful when looking at things in the debugger - beta_uncorr.name = f"beta_uncorr_Ch{chan}" wavelength = int(cals[f"Ch{chan}"]["Name"][2:]) + beta_w, b_bw = purewater_scatter(wavelength) - # Use compute_backscatter - same as used for ecopucks - to calculate bbp - _, bbp = compute_backscatter(wavelength, 35.2, beta_uncorr) - setattr(hs2, f"bbp{wavelength}", bbp) + chi = 1.08 + b_b_uncorr = ((2 * pi * chi) * (beta_uncorr - beta_w)) + b_bw + + globals()[f"bb{wavelength}_uncorr"] = b_b_uncorr + globals()[f"bbp{wavelength}_uncorr"] = b_b_uncorr - b_bw + + # ESTIMATION OF KBB AND SIGMA FUNCTION + a = typ_absorption(wavelength) + b_b_tilde = 0.015 + b = (b_b_uncorr - b_bw) / b_b_tilde + + K_bb = a + 0.4 * b + k_1 = 1.0 + k_exp = float(cals[f"Ch{chan}"]["SigmaExp"]) + sigma = k_1 * np.exp(k_exp * K_bb) + + b_b_corr = sigma * b_b_uncorr + + setattr(hs2, f"bb{wavelength}", b_b_corr) + setattr(hs2, f"bbp{wavelength}", b_b_corr - b_bw) - # Fluorescence # -% 'hs2.fl700_uncorr = (hs2.Snorm3.*50)./((1 + str2num(CAL.Ch(3).TempCoeff).*(hs2.Temp-str2num(CAL.General.CalTemp))).*hs2.Gain3.*str2num(CAL.Ch(3).RNominal));' # noqa: E501 denom = ( ( @@ -186,8 +201,11 @@ def hs2_calc_bb(orig_nc, cals): snorm3 = _int_signer(orig_nc["Snorm3"]) setattr(hs2, f"fl{wavelength}", np.divide(snorm3 * 50, denom)) - hs2.caldepth = float(cals["General"]["DepthCal"]) * orig_nc["RawDepthValue"] - float( - cals["General"]["DepthOff"] + setattr( # noqa: B010 + hs2, + "caldepth", + float(cals["General"]["DepthCal"]) * orig_nc["RawDepthValue"] + - float(cals["General"]["DepthOff"]), ) return hs2