Remove warnings for log10(0) in histograms calcualtion
This commit is contained in:
@@ -228,14 +228,20 @@ def calibrate_single_particle(
|
||||
)
|
||||
ddf_cal["time_lag"] = ddf_cal["Incand Peak Time"] - ddf_cal["Scatter Peak Time"]
|
||||
|
||||
# Suppress divide by zero warning for log10(0) - expected for particles with no signal
|
||||
import warnings
|
||||
# Calculate ratio using map_partitions to properly suppress warnings in Dask workers
|
||||
def calculate_ratio_with_suppression(df):
|
||||
"""Calculate log10 ratio with warning suppression for zero values."""
|
||||
with np.errstate(divide="ignore", invalid="ignore"):
|
||||
df["ratio_inc_scatt"] = np.log10(df["Incand relPeak"]) / np.log10(
|
||||
df["Scatter relPeak"]
|
||||
)
|
||||
return df
|
||||
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings("ignore", message="divide by zero encountered in log10")
|
||||
ddf_cal["ratio_inc_scatt"] = np.log10(ddf_cal["Incand relPeak"]) / np.log10(
|
||||
ddf_cal["Scatter relPeak"]
|
||||
)
|
||||
meta_with_ratio = ddf_cal._meta.copy()
|
||||
meta_with_ratio["ratio_inc_scatt"] = pd.Series([], dtype="float64")
|
||||
ddf_cal = ddf_cal.map_partitions(
|
||||
calculate_ratio_with_suppression, meta=meta_with_ratio
|
||||
)
|
||||
|
||||
ddf_cal = define_flags(ddf_cal, instr_config, run_config)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user