diff --git a/sed/config/default.yaml b/sed/config/default.yaml index 1eca22cc..2972c345 100644 --- a/sed/config/default.yaml +++ b/sed/config/default.yaml @@ -31,8 +31,10 @@ dataframe: tof_binning: 1 # binning factor used for the adc coordinate (2^(adc_binning-1)) adc_binning: 1 - # list of columns to apply jitter to + # list of columns to apply jitter to. jitter_cols: ["@x_column", "@y_column", "@tof_column"] + # Jitter amplitude or list of jitter amplitudes. Should equal half the digitial step size of each jitter_column + jitter_amps: [0.5, 0.5, 0.5] energy: # Number of bins to use for energy calibration traces diff --git a/sed/core/dfops.py b/sed/core/dfops.py index 4bc7c386..13b86a70 100644 --- a/sed/core/dfops.py +++ b/sed/core/dfops.py @@ -29,6 +29,8 @@ def apply_jitter( with added jitter. Defaults to None. amps (Union[float, Sequence[float]], optional): Amplitude scalings for the jittering noise. If one number is given, the same is used for all axes. + For normal noise, the added noise will have sdev [-amp, +amp], for + uniform noise it will cover the inverval [-amp, +amp]. Defaults to 0.5. jitter_type (str, optional): the type of jitter to add. 'uniform' or 'normal' distributed noise. Defaults to "uniform". diff --git a/sed/core/processor.py b/sed/core/processor.py index ef6b041d..997817cb 100644 --- a/sed/core/processor.py +++ b/sed/core/processor.py @@ -1180,13 +1180,22 @@ def calibrate_delay_axis( else: print(self._dataframe) - def add_jitter(self, cols: List[str] = None, **kwds): + def add_jitter( + self, + cols: List[str] = None, + amps: Union[float, Sequence[float]] = None, + **kwds, + ): """Add jitter to the selected dataframe columns. Args: cols (List[str], optional): The colums onto which to apply jitter. Defaults to config["dataframe"]["jitter_cols"]. - **kwds: keyword arguments passed to apply_jitter + amps (Union[float, Sequence[float]], optional): Amplitude scalings for the + jittering noise. If one number is given, the same is used for all axes. + For uniform noise (defualt) it will cover the inverval [-amp, +amp]. + Defaults to config["dataframe"]["jitter_amps"]. + **kwds: additional keyword arguments passed to apply_jitter """ if cols is None: cols = self._config["dataframe"]["jitter_cols"] @@ -1194,10 +1203,14 @@ def add_jitter(self, cols: List[str] = None, **kwds): if col.startswith("@"): cols[loc] = self._config["dataframe"].get(col.strip("@")) + if amps is None: + amps = self._config["dataframe"]["jitter_amps"] + self._dataframe = self._dataframe.map_partitions( apply_jitter, cols=cols, cols_jittered=cols, + amps=amps, **kwds, ) metadata = []