Skip to content

Commit

Permalink
Move set_nan_defaults to be a stand-alone function (#1497)
Browse files Browse the repository at this point in the history
  • Loading branch information
dachengx authored Dec 16, 2024
1 parent f765c10 commit 5704361
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 19 deletions.
12 changes: 1 addition & 11 deletions straxen/plugins/events/event_basics_vanilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,19 +207,9 @@ def _get_posrec_dtypes(self):

return posrec_dtpye

@staticmethod
def set_nan_defaults(buffer):
"""When constructing the dtype, take extra care to set values to np.Nan / -1 (for ints) as 0
might have a meaning."""
for field in buffer.dtype.names:
if np.issubdtype(buffer.dtype[field], np.integer):
buffer[field][:] = -1
else:
buffer[field][:] = np.nan

def compute(self, events, peaks):
result = np.zeros(len(events), dtype=self.dtype)
self.set_nan_defaults(result)
strax.set_nan_defaults(result)

split_peaks = strax.split_by_containment(peaks, events)

Expand Down
3 changes: 1 addition & 2 deletions straxen/plugins/events/event_nearest_triggering.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import numpy as np
import strax
import straxen

export, __all__ = strax.exporter()

Expand Down Expand Up @@ -77,7 +76,7 @@ def compute(self, events, peaks):
split_peaks = strax.split_by_containment(peaks, events)
result = np.zeros(len(events), self.dtype)

straxen.EventBasicsVanilla.set_nan_defaults(result)
strax.set_nan_defaults(result)

# 1. Assign peaks features to main S1 and main S2 in the event
for event_i, (event, sp) in enumerate(zip(events, split_peaks)):
Expand Down
4 changes: 1 addition & 3 deletions straxen/plugins/events/event_shadow.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import numpy as np
import strax

import straxen

export, __all__ = strax.exporter()


Expand Down Expand Up @@ -108,7 +106,7 @@ def compute(self, events, peaks):
split_peaks = strax.split_by_containment(peaks, events)
result = np.zeros(len(events), self.dtype)

straxen.EventBasicsVanilla.set_nan_defaults(result)
strax.set_nan_defaults(result)

# 1. Assign peaks features to main S1 and main S2 in the event
for event_i, (event, sp) in enumerate(zip(events, split_peaks)):
Expand Down
2 changes: 1 addition & 1 deletion straxen/plugins/peaks/peak_nearest_triggering.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def compute_triggering(self, peaks, current_peak):
_peaks = _peaks[_is_triggering]
# init result
result = np.zeros(len(current_peak), self.dtype)
straxen.EventBasicsVanilla.set_nan_defaults(result)
strax.set_nan_defaults(result)

# use center_time as the anchor of things
things = np.zeros(len(_peaks), dtype=strax.time_fields)
Expand Down
3 changes: 1 addition & 2 deletions straxen/plugins/peaks/peak_per_event.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import numpy as np
import strax
import straxen

export, __all__ = strax.exporter()

Expand Down Expand Up @@ -30,7 +29,7 @@ def compute(self, events, peaks):
split_peaks = strax.split_by_containment(peaks, events)
split_peaks_ind = strax.fully_contained_in(peaks, events)
result = np.zeros(len(peaks), self.dtype)
straxen.EventBasicsVanilla.set_nan_defaults(result)
strax.set_nan_defaults(result)

# Assign peaks features to main S1 and main S2 in the event
for event_i, (event, sp) in enumerate(zip(events, split_peaks)):
Expand Down

0 comments on commit 5704361

Please sign in to comment.