Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/data/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,14 +744,14 @@ def add_biolume_proxies( # noqa: PLR0913, PLR0915

return fluo, sunsets, sunrises

def correct_biolume_proxies( # noqa: PLR0913, PLR0915
def correct_biolume_proxies( # noqa: C901, PLR0912, PLR0913, PLR0915
self,
biolume_fluo: pd.Series, # from add_biolume_proxies
biolume_sunsets: list[datetime], # from add_biolume_proxies
biolume_sunrises: list[datetime], # from add_biolume_proxies
adinos_threshold: float = 0.1,
correction_threshold: int = 3,
fluo_bl_threshold: float = 0.35, # use 0.45 for pearson corr
fluo_bl_threshold: float = 0.35,
corr_type: str = "pearson", # "spearman" or "pearson"
depth_threshold: float = 2.0,
minutes_from_surface_threshold: int = 5,
Expand All @@ -768,6 +768,11 @@ def correct_biolume_proxies( # noqa: PLR0913, PLR0915
# We didn't add biolum proxies this round...
return

# Save the attrs for later as the correction process will drop them
saved_attrs = defaultdict(list)
for var in variables:
saved_attrs[var] = self.df_r[var].attrs

df_p["biolume_fluo"] = biolume_fluo
df_p["fluoBL_corr"] = np.full_like(df_p.biolume_fluo, np.nan)

Expand Down Expand Up @@ -975,6 +980,13 @@ def _interval_contains_sunevent(
"profile=%d skipped for proxy correction",
iprofil_,
)
# Copy the attrs back to self.df_r[] as they were lost in the processing
# Also add the fluo_bl_threshold value to the comment attribute
for var in saved_attrs:
self.df_r[var].attrs = saved_attrs[var]
self.df_r[var].attrs["comment"] += (
f"; corrected with fluo_bl_threshold={fluo_bl_threshold}"
)

def resample_variable( # noqa: PLR0913
self,
Expand Down