Skip to content

Commit

Permalink
Merge branch 'master' into remove_cmt_urls
Browse files Browse the repository at this point in the history
  • Loading branch information
GiovanniVolta authored Jan 10, 2025
2 parents cc8cd60 + f993f0b commit 8fa19e3
Show file tree
Hide file tree
Showing 28 changed files with 193 additions and 198 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 3.0.0
current_version = 3.0.1
files = straxen/__init__.py
commit = True
tag = True
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,6 @@ docs/source/reference/data_kinds*
docs/source/reference/release_notes.rst

test_dict.json

*.pkl
*.pkl.gz
39 changes: 39 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
3.0.1 / 2024-12-27
-------------------
* Fix run_doc for led plugin by @GiovanniVolta in https://github.com/XENONnT/straxen/pull/1462
* Check RSE in `_find` method of `RucioRemoteFrontend` by @dachengx in https://github.com/XENONnT/straxen/pull/1464
* Garbage collection after calculated each chunk in `peak_positions_mlp` by @dachengx in https://github.com/XENONnT/straxen/pull/1467
* Enforce stable sorting in `np.sort` and `np.argsort` by @dachengx in https://github.com/XENONnT/straxen/pull/1468
* Clean `deprecate_kwarg` by @dachengx in https://github.com/XENONnT/straxen/pull/1470
* Update strax version to v2.0.1 by @dachengx in https://github.com/XENONnT/straxen/pull/1473
* Remove expedients plugins because SOM will be default by @dachengx in https://github.com/XENONnT/straxen/pull/1472
* Remove 1T related codes by @dachengx in https://github.com/XENONnT/straxen/pull/1476
* Use SOM peaklets classification by default by @dachengx in https://github.com/XENONnT/straxen/pull/1471
* Fix theta uncertainty bug by @napoliion in https://github.com/XENONnT/straxen/pull/1466
* Remove URLConfig warning about sorting by @dachengx in https://github.com/XENONnT/straxen/pull/1477
* Merge branch 'sr1_leftovers' into master by @dachengx in https://github.com/XENONnT/straxen/pull/1478
* Fix small bug in CNF by @dachengx in https://github.com/XENONnT/straxen/pull/1479
* Remove GCN & CNN S2 pos-rec by @dachengx in https://github.com/XENONnT/straxen/pull/1484
* Set CNF as the default S2 (x, y) position-reconstruction by @dachengx in https://github.com/XENONnT/straxen/pull/1486
* Prototype of peaklets-level (x, y) S2 position reconstruction by @dachengx in https://github.com/XENONnT/straxen/pull/1482
* Rename old `PeakletClassification` as `PeakletClassificationVanilla` by @dachengx in https://github.com/XENONnT/straxen/pull/1487
* Remove Bayes models by @dachengx in https://github.com/XENONnT/straxen/pull/1488
* Rename `defualt_run_comments` -> `default_run_comments` by @dachengx in https://github.com/XENONnT/straxen/pull/1489
* Accelerate Euclidean distance by numba by @dachengx in https://github.com/XENONnT/straxen/pull/1493
* Move `set_nan_defaults` to be a stand-alone function by @dachengx in https://github.com/XENONnT/straxen/pull/1497
* Set CNF as the default S2 (x, y) position-reconstruction by @dachengx in https://github.com/XENONnT/straxen/pull/1494
* Back to fixed window in LED calibration by @GiovanniVolta in https://github.com/XENONnT/straxen/pull/1499
* Move `compute_center_times` from straxen to strax by @dachengx in https://github.com/XENONnT/straxen/pull/1501
* Use numpy and strax native dtypes, not `"<i8"` or `"<f4"` by @dachengx in https://github.com/XENONnT/straxen/pull/1502
* Inherit `area_fraction_top`, `center_time` and `median_time` from peaklets by @dachengx in https://github.com/XENONnT/straxen/pull/1503
* Bump version of changed plugins in #1503 by @dachengx in https://github.com/XENONnT/straxen/pull/1504
* Clean unnecessary codes by @dachengx in https://github.com/XENONnT/straxen/pull/1507
* Clean chunk after computing `records` by @dachengx in https://github.com/XENONnT/straxen/pull/1508
* Add a line of comment about memory optimization by @dachengx in https://github.com/XENONnT/straxen/pull/1509

New Contributors
* @napoliion made their first contribution in https://github.com/XENONnT/straxen/pull/1466

**Full Changelog**: https://github.com/XENONnT/straxen/compare/v3.0.0...v3.0.1


3.0.0 / 2024-10-24
-------------------
* Inherit `DEFAULT_CHUNK_SPLIT_NS` from strax by @dachengx in https://github.com/XENONnT/straxen/pull/1405
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool]
[tool.poetry]
name = "straxen"
version = "3.0.0"
version = "3.0.1"
description = "Streaming analysis for XENON"
readme = "README.md"
authors = [
Expand Down Expand Up @@ -30,7 +30,7 @@ straxer = "straxen.scripts.straxer:main"

[tool.poetry.dependencies]
python = ">=3.9,<3.13"
strax = ">=2.0.1"
strax = ">=2.0.3"
bokeh = "*"
commentjson = "*"
gitpython = "*"
Expand Down
2 changes: 1 addition & 1 deletion straxen/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# mypy: disable-error-code="no-redef"
__version__ = "3.0.0"
__version__ = "3.0.1"

from utilix import uconfig
from .common import *
Expand Down
4 changes: 2 additions & 2 deletions straxen/analyses/bokeh_waveform_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def event_display_interactive(
raise ValueError("Found an event without peaks this should not had have happened.")

# Select main/alt S1/S2s based on time and endtime in event:
m_other_peaks = np.ones(len(peaks), dtype=np.bool_) # To select non-event peaks
m_other_peaks = np.ones(len(peaks), dtype=bool) # To select non-event peaks
endtime = strax.endtime(peaks)

signal = {}
Expand Down Expand Up @@ -570,7 +570,7 @@ def plot_pmt_array(
# Plotting PMTs:
pmts = straxen.pmt_positions()
if plot_all_pmts:
mask_pmts = np.zeros(len(pmts), dtype=np.bool_)
mask_pmts = np.zeros(len(pmts), dtype=bool)
else:
mask_pmts = to_pe == 0
pmts_on = pmts[~mask_pmts]
Expand Down
2 changes: 1 addition & 1 deletion straxen/analyses/waveform_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def plot_records_matrix(
# labels in the case of strings.
# Make a dict that converts the label to an int
int_labels = {h: i for i, h in enumerate(set(ylabs))}
mask = np.ones(len(ylabs), dtype=np.bool_)
mask = np.ones(len(ylabs), dtype=bool)
# If the label (int) is different wrt. its neighbour, show it
mask[1:] = np.abs(np.diff([int_labels[y] for y in ylabs])) > 0
# Only label the selection
Expand Down
2 changes: 2 additions & 0 deletions straxen/config/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def read_json(content: str, **kwargs):
@URLConfig.register("take")
def get_key(container: Container, take=None, **kwargs):
"""Return a single element of a container."""
if not isinstance(container, dict):
raise ValueError(f"Container is not a dict but a {type(container)}")
if take is None:
return container
if not isinstance(take, list):
Expand Down
28 changes: 12 additions & 16 deletions straxen/plugins/afterpulses/afterpulse_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,45 +421,41 @@ def dtype_afterpulses():
- The afterpulse datatype
"""
dtype_ap = [
(("Channel/PMT number", "channel"), "<i2"),
(("Time resolution in ns", "dt"), "<i2"),
(("Start time of the interval (ns since unix epoch)", "time"), "<i8"),
(("Length of the interval in samples", "length"), "<i4"),
(("Integral in ADC x samples", "area"), "<i4"),
(("Pulse area in PE", "area_pe"), "<f4"),
(("Sample index in which hit starts", "left"), "<i2"),
dtype_ap = strax.interval_dtype + [
(("Integral in ADC x samples", "area"), np.int32),
(("Pulse area in PE", "area_pe"), np.float32),
(("Sample index in which hit starts", "left"), np.int16),
(
(
"Sample index in which hit area succeeds 10% of total area",
"sample_10pc_area",
),
"<i2",
np.int16,
),
(
(
"Sample index in which hit area succeeds 50% of total area",
"sample_50pc_area",
),
"<i2",
np.int16,
),
(("Sample index of hit maximum", "max"), "<i2"),
(("Sample index of hit maximum", "max"), np.int16),
(
(
"Index of first sample in record just beyond hit (exclusive bound)",
"right",
),
"<i2",
np.int16,
),
(("Height of hit in ADC counts", "height"), "<i4"),
(("Height of hit in PE", "height_pe"), "<f4"),
(("Delay of hit w.r.t. LED hit in same WF, in samples", "tdelay"), "<i2"),
(("Height of hit in ADC counts", "height"), np.int32),
(("Height of hit in PE", "height_pe"), np.float32),
(("Delay of hit w.r.t. LED hit in same WF, in samples", "tdelay"), np.int16),
(
(
"Internal (temporary) index of fragment in which hit was found",
"record_i",
),
"<i4",
np.int32,
),
(
("Index of sample in record where integration starts", "left_integration"),
Expand Down
16 changes: 2 additions & 14 deletions straxen/plugins/events/event_basics_som.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import strax
import numpy as np

from straxen.plugins.events.event_basics_vanilla import EventBasicsVanilla
from straxen.plugins.peaklets.peaklet_classification_som import som_additional_fields

export, __all__ = strax.exporter()

Expand All @@ -17,15 +16,4 @@ def _set_dtype_requirements(self):
# Properties to store for each peak (main and alternate S1 and S2)
# Add here SOM types:
super()._set_dtype_requirements()
self.peak_properties = list(self.peak_properties)
self.peak_properties += [
("som_sub_type", np.int32, "SOM subtype of the peak(let)"),
("old_type", np.int8, "Old type of the peak(let)"),
("loc_x_som", np.int16, "x location of the peak(let) in the SOM"),
("loc_y_som", np.int16, "y location of the peak(let) in the SOM"),
]
self.peak_properties = tuple(self.peak_properties)

def compute(self, events, peaks):
result = super().compute(events, peaks)
return result
self.peak_properties += tuple(som_additional_fields)
22 changes: 10 additions & 12 deletions straxen/plugins/events/event_basics_vanilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class EventBasicsVanilla(strax.Plugin):
"""

__version__ = "1.3.3"
__version__ = "1.3.4"

depends_on = ("events", "peak_basics", "peak_positions", "peak_proximity")
provides = "event_basics"
Expand Down Expand Up @@ -66,9 +66,7 @@ def infer_dtype(self):
# Basic event properties
self._set_posrec_save()
self._set_dtype_requirements()
dtype = []
dtype += strax.time_fields
dtype += [
dtype = strax.time_fields + [
("n_peaks", np.int32, "Number of peaks in the event"),
("drift_time", np.float32, "Drift time between main S1 and S2 in ns"),
("event_number", np.int64, "Event number in this dataset"),
Expand Down Expand Up @@ -116,7 +114,8 @@ def _set_dtype_requirements(self):
# Properties to store for each peak (main and alternate S1 and S2)
self.peak_properties = (
("time", np.int64, "start time since unix epoch [ns]"),
("center_time", np.int64, "weighted center time since unix epoch [ns]"),
("center_time", np.int64, "weighted average center time since unix epoch [ns]"),
("median_time", np.float32, "weighted relative median time of the peak [ns]"),
("endtime", np.int64, "end time since unix epoch [ns]"),
("area", np.float32, "area, uncorrected [PE]"),
("n_channels", np.int16, "count of contributing PMTs"),
Expand All @@ -128,8 +127,8 @@ def _set_dtype_requirements(self):
("range_90p_area", np.float32, "width, 90% area [ns]"),
("rise_time", np.float32, "time between 10% and 50% area quantiles [ns]"),
("area_fraction_top", np.float32, "fraction of area seen by the top PMT array"),
("tight_coincidence", np.int16, "Channel within tight range of mean"),
("n_saturated_channels", np.int16, "Total number of saturated channels"),
("tight_coincidence", np.int16, "channel within tight range of mean"),
("n_saturated_channels", np.int16, "total number of saturated channels"),
)

def setup(self):
Expand Down Expand Up @@ -217,19 +216,18 @@ def compute(self, events, peaks):
result["endtime"] = events["endtime"]
result["event_number"] = events["event_number"]

self.fill_events(result, events, split_peaks)
self.fill_events(result, split_peaks)
return result

# If copy_largest_peaks_into_event is ever numbafied, also numbafy this function
def fill_events(self, result_buffer, events, split_peaks):
def fill_events(self, result_buffer, split_peaks):
"""Loop over the events and peaks within that event."""
for event_i, _ in enumerate(events):
peaks_in_event_i = split_peaks[event_i]
for event_i, peaks_in_event_i in enumerate(split_peaks):
n_peaks = len(peaks_in_event_i)
result_buffer[event_i]["n_peaks"] = n_peaks

if not n_peaks:
raise ValueError(f"No peaks within event?\n{events[event_i]}")
raise ValueError(f"No peaks within event {event_i}?")

self.fill_result_i(result_buffer[event_i], peaks_in_event_i)

Expand Down
15 changes: 8 additions & 7 deletions straxen/plugins/events/event_top_bottom_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class EventTopBottomParams(strax.Plugin):

depends_on = ("event_info", "event_waveform")
provides = "event_top_bottom_params"
__version__ = "0.0.0"
__version__ = "0.0.1"

def infer_dtype(self):
# Populating data type information
Expand Down Expand Up @@ -91,6 +91,9 @@ def infer_dtype(self):

def compute(self, events):
result = np.zeros(events.shape, dtype=self.dtype)
if not len(events):
return result

result["time"], result["endtime"] = events["time"], strax.endtime(events)
peak_dtype = strax.peak_dtype(n_channels=straxen.n_tpc_pmts, store_data_top=False)
for type_ in self.ptypes:
Expand Down Expand Up @@ -129,15 +132,13 @@ def compute(self, events):
result[f"{type_}_center_time_{arr_}"][mask] += recalc_ctime[mask].astype(int)
# computing widths ##
# zero or undefined area peaks should have nans
strax.compute_widths(fpeaks_)
_, width, area_decile_from_midpoint = strax.compute_widths(fpeaks_)
result[f"{type_}_rise_time_{arr_}"][:] = np.nan
result[f"{type_}_rise_time_{arr_}"][mask] = -fpeaks_["area_decile_from_midpoint"][
mask
][:, 1]
result[f"{type_}_rise_time_{arr_}"][mask] = -area_decile_from_midpoint[mask][:, 1]
result[f"{type_}_range_50p_area_{arr_}"][:] = np.nan
result[f"{type_}_range_50p_area_{arr_}"][mask] = fpeaks_["width"][mask][:, 5]
result[f"{type_}_range_50p_area_{arr_}"][mask] = width[mask][:, 5]
result[f"{type_}_range_90p_area_{arr_}"][:] = np.nan
result[f"{type_}_range_90p_area_{arr_}"][mask] = fpeaks_["width"][mask][:, 9]
result[f"{type_}_range_90p_area_{arr_}"][mask] = width[mask][:, 9]
# Difference between center times of top and bottom arrays
result[f"{type_}_center_time_diff_top_bot"] = (
result[f"{type_}_center_time_top"] - result[f"{type_}_center_time_bot"]
Expand Down
10 changes: 5 additions & 5 deletions straxen/plugins/events_nv/event_waveform_nv.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class nVETOEventWaveform(strax.Plugin):
"""Plugin which computes the summed waveform as well as some shape properties of the NV
events."""

__version__ = "0.0.1"
__version__ = "0.0.2"

depends_on = "events_nv", "records_nv"
provides = "event_waveform_nv"
Expand Down Expand Up @@ -61,7 +61,7 @@ def compute(self, events_nv, records_nv, start, end):
_tmp_events["length"] = (events_nv["endtime"] - events_nv["time"]) // 2
_tmp_events["dt"] = 2
strax.simple_summed_waveform(records_nv, _tmp_events, self.to_pe)
strax.compute_widths(_tmp_events)
strax.compute_properties(_tmp_events)

strax.copy_to_buffer(_tmp_events, events_waveform, "_temp_nv_evts_cpy")
events_waveform["range_50p_area"] = _tmp_events["width"][:, 5]
Expand All @@ -75,9 +75,7 @@ def compute(self, events_nv, records_nv, start, end):
def veto_event_waveform_dtype(
n_samples_wf: int = 200,
) -> list:
dtype = []
dtype += strax.time_dt_fields # because mutable
dtype += [
dtype = strax.time_dt_fields + [
(("Waveform data in PE/sample (not PE/ns!)", "data"), np.float32, n_samples_wf),
(("Width (in ns) of the central 50% area of the peak", "range_50p_area"), np.float32),
(("Width (in ns) of the central 90% area of the peak", "range_90p_area"), np.float32),
Expand Down Expand Up @@ -109,6 +107,8 @@ def _temp_event_data_type(n_samples_wf: int = 150, n_widths: int = 11) -> list:
np.float32,
n_samples_wf,
),
(("Weighted average center time of the peak [ns]", "center_time"), np.int64),
(("Weighted relative median time of the peak [ns]", "median_time"), np.float32),
(("Peak widths in range of central area fraction [ns]", "width"), np.float32, n_widths),
(
("Peak widths: time between nth and 5th area decile [ns]", "area_decile_from_midpoint"),
Expand Down
Loading

0 comments on commit 8fa19e3

Please sign in to comment.