43 lines
1.7 KiB
Python
43 lines
1.7 KiB
Python
import numpy as np
|
|
import pandas as pd
|
|
from sp2xr.calibration import calibrate_particle_data
|
|
from sp2xr.flag_single_particle_data import define_flags, add_thin_thick_flags
|
|
|
|
|
|
def calibrate_single_particle(ddf_raw, instr_config, run_config):
|
|
meta_cal = ddf_raw._meta.copy()
|
|
meta_cal["BC mass"] = pd.Series([], dtype="float64")
|
|
meta_cal["Opt diam"] = pd.Series([], dtype="float64")
|
|
meta_cal["time_lag"] = pd.Series([], dtype="int8")
|
|
meta_cal["date"] = pd.Series([], dtype="datetime64[ns]")
|
|
meta_cal["hour"] = pd.Series([], dtype="int8")
|
|
|
|
ddf_cal = ddf_raw.map_partitions(
|
|
calibrate_particle_data, config=run_config, meta=meta_cal
|
|
)
|
|
ddf_cal["time_lag"] = ddf_cal["Incand Peak Time"] - ddf_cal["Scatter Peak Time"]
|
|
ddf_cal["ratio_inc_scatt"] = np.log10(ddf_cal["Incand relPeak"]) / np.log10(
|
|
ddf_cal["Scatter relPeak"]
|
|
)
|
|
|
|
ddf_cal = define_flags(ddf_cal, instr_config, run_config)
|
|
|
|
meta_cnts = add_thin_thick_flags(ddf_cal._meta) # builds empty columns for meta
|
|
ddf_cal = ddf_cal.map_partitions(add_thin_thick_flags, meta=meta_cnts)
|
|
|
|
# Create two new columns where the particles out of range are changed to np.nan (!! do not change them to 0, otherwise below where we resample and count, the 0s would be counted being a not null value!!)
|
|
ddf_cal["BC mass within range"] = ddf_cal["BC mass"].where(
|
|
ddf_cal["flag_valid_inc_signal_in_range"], np.nan
|
|
)
|
|
ddf_cal["Opt diam scatt only within range"] = ddf_cal["Opt diam scatt only"].where(
|
|
(
|
|
ddf_cal["flag_valid_scatt_signal_in_range"]
|
|
& ~ddf_cal["flag_valid_inc_signal"]
|
|
),
|
|
np.nan,
|
|
)
|
|
|
|
ddf_cal["temporary_col"] = 1
|
|
|
|
return ddf_cal
|