Skip to content

Commit

Permalink
add amps as argument to add_jitter, and provide better description. A…
Browse files Browse the repository at this point in the history
…lso add jitter_amps to default config
  • Loading branch information
rettigl committed Oct 14, 2023
1 parent 503e9f2 commit fee3844
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 3 additions & 1 deletion sed/config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions sed/core/dfops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand Down
17 changes: 15 additions & 2 deletions sed/core/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1180,24 +1180,37 @@ 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"]
for loc, col in enumerate(cols):
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 = []
Expand Down

0 comments on commit fee3844

Please sign in to comment.