Skip to content

Commit c36c2a6

Browse files
tibaldojlenain
andcommitted
Fix bug in ChargeDistributionFilter for pedestal maker (cta-observatory#213)
* Only fill charges container if waveforms are available * Cleanup commented stuff from some previous PR * Pin `persistent` (dependency for `ZODB`) version to fix CI --------- Co-authored-by: Jean-Philippe Lenain <[email protected]> # Conflicts: # src/nectarchain/makers/component/pedestal_component.py
1 parent 21cbe16 commit c36c2a6

File tree

4 files changed

+26
-39
lines changed

4 files changed

+26
-39
lines changed

environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ dependencies:
2424
- pip:
2525
- zeo
2626
- zodb
27+
- persistent<6.2
2728
- mechanize
2829
- browser-cookie3
2930
- pyqtgraph

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ dependencies = [
2626
"iminuit",
2727
"matplotlib",
2828
"pandas",
29+
"persistent<6.2",
2930
"scipy",
3031
"zodb",
3132
"zeo",

src/nectarchain/dqm/bokeh_app/tests/test_app_hooks.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import numpy as np
2-
from bokeh.io import output_file, save
32

43
# bokeh imports
4+
from bokeh.io import output_file, save
55
from bokeh.layouts import layout
66
from bokeh.models import Select
77
from bokeh.plotting import curdoc
8+
9+
# ctapipe imports
810
from ctapipe.coordinates import EngineeringCameraFrame
911
from ctapipe.instrument import CameraGeometry
1012
from ZODB import DB

src/nectarchain/makers/component/pedestal_component.py

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -202,50 +202,38 @@ def __init__(self, subarray, config=None, parent=None, *args, **kwargs):
202202
)
203203

204204
@staticmethod
205-
def calculate_stats(container, mask, statistics):
205+
def calculate_stats(waveformsContainers, wfs_mask, statistics):
206206
"""Calculate statistics for the pedestals from a waveforms container.
207207
208208
Parameters
209209
----------
210-
containers : `~nectarchain.data.container`
211-
Waveforms or Charges container
212-
mask : `numpy.ndarray`
213-
Mask to apply to exclude outliers with shape (n_events,n_pixels,n_samples)
210+
waveformsContainers : `~nectarchain.data.container.WaveformsContainer`
211+
Waveforms container
212+
wfs_mask : `numpy.ndarray`
213+
Mask to apply to exclude outliers with shape (n_pixels,n_samples)
214214
statistics : `list`
215215
Names of the statistics (numpy.ma attributes) to compute
216216
217217
Returns
218218
-------
219219
ped_stats : `dict`
220-
A dictionary containing 3D (n_chan,n_pixels,n_samples)
221-
or 2D (n_chan,n_pixels) arrays for each statistic.
220+
A dictionary containing 3D (n_chan,n_pixels,n_samples) arrays for each
221+
statistic.
222222
"""
223223

224-
# Detect container type by attribute name
225-
if hasattr(container, "wfs_hg"):
226-
data_hg = container.wfs_hg
227-
data_lg = container.wfs_lg
228-
is_waveform = True
229-
else:
230-
data_hg = container.charges_hg
231-
data_lg = container.charges_lg
232-
is_waveform = False
233-
234-
# Adapt mask shape
235-
# Waveforms: (n_events, n_pixels, n_samples)
236-
# Charges: (n_events, n_pixels)
237-
if not is_waveform:
238-
mask = mask[:, :, 0]
239-
240224
ped_stats = {}
241225

242226
for stat in statistics:
243227
# Calculate the statistic along axis = 0, that is over events
244-
ped_stat_hg = getattr(ma, stat)(ma.masked_array(data_hg, mask), axis=0)
245-
ped_stat_lg = getattr(ma, stat)(ma.masked_array(data_lg, mask), axis=0)
228+
ped_stat_hg = getattr(ma, stat)(
229+
ma.masked_array(waveformsContainers.wfs_hg, wfs_mask), axis=0
230+
)
231+
ped_stat_lg = getattr(ma, stat)(
232+
ma.masked_array(waveformsContainers.wfs_lg, wfs_mask), axis=0
233+
)
246234

247235
# Create a 3D array for the statistic
248-
array_shape = np.append([N_GAINS], np.shape(data_hg[0]))
236+
array_shape = np.append([N_GAINS], np.shape(waveformsContainers.wfs_hg[0]))
249237
ped_stat = np.zeros(array_shape)
250238
ped_stat[HIGH_GAIN] = ped_stat_hg
251239
ped_stat[LOW_GAIN] = ped_stat_lg
@@ -318,7 +306,7 @@ def flag_bad_pixels(self, ped_stats, nevents):
318306
# Flag on standard deviation per pixel
319307
# Standard deviation of pedestal in channel/pixel above threshold
320308
log.info(
321-
f"Flag pixels with pedestal standard deviation in a channel/pixel above "
309+
f"Flag pixels with pedestal standard deviation in a chennel/pixel above "
322310
f"the maximum acceptable value {self.pixel_mask_std_pixel_max}"
323311
)
324312
flag_pixel_std = np.int8(
@@ -508,8 +496,6 @@ def finish(self, *args, **kwargs):
508496
self._waveformsContainers = waveformsContainers.containers[
509497
EventType.SKY_PEDESTAL
510498
]
511-
# log.info('JPL: waveformsContainers=',waveformsContainers.containers[
512-
# EventType.SKY_PEDESTAL].nsamples)
513499

514500
# Check if waveforms container is empty
515501
if self._waveformsContainers is None:
@@ -524,8 +510,12 @@ def finish(self, *args, **kwargs):
524510
# container with no results
525511
return None
526512
else:
527-
# Make sure that the charge distribution container is filled
528-
if self._chargesContainers is None:
513+
# If we want to filter based on charges distribution
514+
# make sure that the charge distribution container is filled
515+
if (
516+
self.filter_method == "ChargeDistributionFilter"
517+
and self._chargesContainers is None
518+
):
529519
log.debug("Compute charges from waveforms")
530520
chargesComponent_kwargs = {}
531521
chargesComponent_configurable_traits = (
@@ -585,9 +575,6 @@ def finish(self, *args, **kwargs):
585575
self._ped_stats = self.calculate_stats(
586576
self._waveformsContainers, self._wfs_mask, statistics
587577
)
588-
self._charge_stats = self.calculate_stats(
589-
self._chargesContainers, self._wfs_mask, statistics
590-
)
591578

592579
# calculate the number of events per pixel used to compute the quantitites
593580
# start wit total number of events
@@ -612,10 +599,6 @@ def finish(self, *args, **kwargs):
612599
pedestal_mean_lg=self._ped_stats["mean"][LOW_GAIN],
613600
pedestal_std_hg=self._ped_stats["std"][HIGH_GAIN],
614601
pedestal_std_lg=self._ped_stats["std"][LOW_GAIN],
615-
pedestal_charge_mean_hg=self._charge_stats["mean"][HIGH_GAIN],
616-
pedestal_charge_mean_lg=self._charge_stats["mean"][LOW_GAIN],
617-
pedestal_charge_std_hg=self._charge_stats["std"][HIGH_GAIN],
618-
pedestal_charge_std_lg=self._charge_stats["std"][LOW_GAIN],
619602
pixel_mask=pixel_mask,
620603
)
621604

0 commit comments

Comments
 (0)