Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New implementation of the nectarchain module #82

Merged
merged 130 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 127 commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
962dc11
clean commit history :
Jul 12, 2023
517bfc7
test script
Jun 14, 2023
1631a59
add method to sort WaveformsContainer
Jun 15, 2023
cfcb0dc
-waveformContainer contructor from event list
Jun 16, 2023
e8a5e1f
user script for test ggroller
Mar 30, 2023
ec426d2
change values of pp and n in fit parameters file
Apr 11, 2023
7521510
improve test
May 17, 2023
8ca58d8
repare test
May 17, 2023
1f0b255
reduce pvalue digit in label
May 18, 2023
627363c
-add time counter to SPE fit
Jul 9, 2023
482435a
add possibility to freez parameters into minuit
Jul 9, 2023
4fa0f82
begin : redesign of the SPE fit class to speed up
Jul 12, 2023
622b94f
new skeleton for the calibration pipeline :
Sep 4, 2023
55725c0
mothers class for the maker module
Sep 7, 2023
8bb7ca1
mother class for the gain makers
Sep 7, 2023
86161c4
unchanged modeuls for the new structure
Sep 7, 2023
ebd86fc
FlatFieldSPEMaker implementation
Sep 7, 2023
408281a
photostatistic maker (not re-implemented yet)
Sep 7, 2023
2049a7c
implementation of the FFSPE fit for single run
Sep 8, 2023
32b2ba7
implementation of FF SPE gain maker
Sep 9, 2023
9ee64ca
bugfix
Sep 9, 2023
17e800c
update for nominal voltage data FF SPE fit from HHV
Sep 9, 2023
0139b7d
-bugfix
Sep 9, 2023
177e577
put I/O method in mother class
Sep 11, 2023
41c6a92
add low gain in contructor (only high gain before)
Sep 11, 2023
10793f0
typo bugfiox
Sep 11, 2023
090844c
move gain utils in one single folder
Sep 11, 2023
8596d24
bugfix nominal voltage fit
Sep 11, 2023
77f12ab
Photostatistic implementation done
Sep 11, 2023
043601d
cleaning : import, type, etc
Sep 11, 2023
c0e9358
remove old SPE fit implementation
Sep 11, 2023
992e264
makers : core module enhancement
Sep 11, 2023
211ce40
cleaning
Sep 12, 2023
8de8cff
moving container and makers in
Sep 12, 2023
808841a
folder restructuring
Sep 12, 2023
bc65fe5
cleaning after the restructuration
Sep 12, 2023
aacd51b
unit test for chargecontainer
Sep 13, 2023
72da7ad
test extractor utlis
Sep 13, 2023
d89345c
unit test CalibrationMaker and GainMakers
Sep 13, 2023
dbc56ef
unit test flatfieldSPEMakers
Sep 13, 2023
0c428bb
unit test implementation follow up
Sep 13, 2023
7db7034
mv wavefomrs in makers
Sep 13, 2023
7c3b907
code into WavefomContainers split into 2 parts : one for the data for…
Sep 14, 2023
205ac1f
move charge container into makers module
Sep 14, 2023
a43bdab
creation of mother class to charge and waveform container
Sep 14, 2023
b0ae914
follow up : factorisation waveforms and chargs Makers
Sep 14, 2023
a1eee04
display module
Sep 14, 2023
fd0e78a
finalisation of the refactorisation of the waveformsMaker
Sep 14, 2023
f5d0180
ChargesContainers I/O
Sep 15, 2023
f1c3298
update calibration class following COntainers changes
Sep 15, 2023
71976ef
bugfix according to unit tests
Sep 15, 2023
7ba1ab3
docstrings container + unit test
Sep 15, 2023
2ed495c
make container module visible
Sep 15, 2023
973a28c
small bugfix + fix unit test for makers
Sep 15, 2023
9aa08a8
docstrings makers module
Sep 17, 2023
0023b45
follow pre-commit hook
Sep 17, 2023
d0a1963
set Dirac import into methods which need it
Sep 17, 2023
272b0c5
first step to reimplement following ctapipe
Oct 16, 2023
878bb96
-removed the I/O method for containers
Oct 23, 2023
ae0edf5
-adapt charges extraction makers and waveform extraction
Oct 23, 2023
eb6bf07
-creation of the component module, which inherits from ctapipe.component
Oct 23, 2023
ecaa250
-preliminary tuto script to extract charges
Oct 23, 2023
06406f5
renaming code name for gain
Oct 23, 2023
ed9c535
move SPE code in component module
Oct 23, 2023
3a6df9f
move SPE algo in utlis
Oct 24, 2023
24bc852
renaming spe module
Oct 24, 2023
db59c9d
changement yaml parameters spe location
Oct 26, 2023
eac90bc
mv spe algo in component main folder
Oct 30, 2023
2634f76
move utils outside of the sub-modules
Oct 30, 2023
bfe61ac
charge and waveforms extraction with ctapip Tool
Nov 5, 2023
a1cb5d2
container for charges and waveforms
Nov 5, 2023
6c60126
fast eventsource reader (30% faster)
Nov 5, 2023
41e988b
gain container to store interesting values
Nov 5, 2023
12308a8
for spe algorithm Component
Nov 5, 2023
dcf266e
calibration module
Nov 5, 2023
7ecd516
calibration module : SPE fit implementation
Nov 5, 2023
08ad778
add useful method
Nov 5, 2023
1dac369
utils for nectarchain
Nov 5, 2023
ff6545a
script to load waveforms and extract charge updated
Nov 5, 2023
b5ac73f
Merge branch 'master' into new_struct
Nov 8, 2023
71ced47
renaming code name for gain
Oct 23, 2023
3e3444f
move SPE code in component module
Oct 23, 2023
d4e7c53
move SPE algo in utlis
Oct 24, 2023
fef63b7
renaming spe module
Oct 24, 2023
e4c1be5
changement yaml parameters spe location
Oct 26, 2023
8cdb3ff
mv spe algo in component main folder
Oct 30, 2023
a70d9c1
move utils outside of the sub-modules
Oct 30, 2023
ff6ad76
charge and waveforms extraction with ctapip Tool
Nov 5, 2023
8df4f79
container for charges and waveforms
Nov 5, 2023
9ce96e3
fast eventsource reader (30% faster)
Nov 5, 2023
4f2fcac
gain container to store interesting values
Nov 5, 2023
b7c74c9
for spe algorithm Component
Nov 5, 2023
1cf9f5e
calibration module
Nov 5, 2023
5f5b2f0
calibration module : SPE fit implementation
Nov 5, 2023
ed5292b
add useful method
Nov 5, 2023
c2164e6
utils for nectarchain
Nov 5, 2023
550cce6
script to load waveforms and extract charge updated
Nov 5, 2023
9d990fc
Merge branch 'new_structure' into new_struct
Nov 8, 2023
9478a14
cleaning
Nov 8, 2023
7c035a4
container namesape + other
Nov 18, 2023
901f7a9
waveforms from hdf5 method
Nov 18, 2023
c622a42
SPE fit for flatfirld runs implementation
Nov 18, 2023
00f71e6
start of reimplementatuion of phtotstat method
Nov 18, 2023
1ddff8d
follow up photostat implementation
Nov 20, 2023
f223dfa
clean way to manage the work done on reduced
Nov 23, 2023
bd5b5da
forgotten in last commit..
Nov 23, 2023
e371f1a
photostatistic re-implemented
Nov 23, 2023
349ecca
same
Nov 23, 2023
e191d63
typo changes
Nov 23, 2023
4962b73
circular import bugfix
Nov 23, 2023
eac070f
imprve log
Nov 23, 2023
b9bcf55
bugfix output filename
Nov 23, 2023
bab9ce3
bugfix I/O + maxevents read written now in output file
Nov 23, 2023
f100b71
some bugfix
Nov 24, 2023
0d8cd55
cleaning and improvement of the data management
Nov 24, 2023
20dc186
updates of scripts
Nov 24, 2023
6b46c25
remove old unit test
Nov 24, 2023
5942818
update runs of interest
Nov 28, 2023
460171c
bugfix :
Nov 28, 2023
3a881aa
load Containers : now if it is splited in slices,
Nov 28, 2023
d63767f
bugfix computation of convergence rate
Nov 28, 2023
1a44d13
-add classes to perform SPE fit directly
Dec 1, 2023
e198118
-ignore png files
Jan 12, 2024
8403a4b
update scripts
Jan 12, 2024
2f3cbf5
tuto for :
Jan 12, 2024
9035730
-fix issue to access component defined outside
Jan 15, 2024
a233bb9
bugfix : issue mentioned by @jlenain in #82.
Jan 15, 2024
bda2d74
update with pre-commit hooks
Jan 19, 2024
47784b0
ignore notebooks
Jan 19, 2024
4961c02
rm notebook
Jan 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ distribute-*.tar.gz
.ropeproject

# ipython/jupyter notebooks and checkpoints
*.ipynb
#*.ipynb
guillaumegrolleron marked this conversation as resolved.
Show resolved Hide resolved
.ipynb_checkpoints
.cache*
.cache
Expand Down Expand Up @@ -92,6 +92,7 @@ src/nectarchain/user_scripts/**/test
**.log
**.pdf
**.csv
**.png

#VScode
.vscode/
Expand Down
607 changes: 607 additions & 0 deletions notebooks/tool_implementation/tuto_SPE.ipynb

Large diffs are not rendered by default.

1,265 changes: 1,265 additions & 0 deletions notebooks/tool_implementation/tuto_tools.ipynb

Large diffs are not rendered by default.

517 changes: 517 additions & 0 deletions notebooks/tool_implementation/tuto_waveforms_charges_extraction.ipynb

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/nectarchain/data/container/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .chargesContainer import *
from .core import NectarCAMContainer,ArrayDataContainer,TriggerMapContainer,merge_map_ArrayDataContainer,get_array_keys
from .waveformsContainer import *
from .gainContainer import *
from .eventSource import *
40 changes: 40 additions & 0 deletions src/nectarchain/data/container/chargesContainer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import logging

logging.basicConfig(format="%(asctime)s %(name)s %(levelname)s %(message)s")
log = logging.getLogger(__name__)
log.handlers = logging.getLogger("__main__").handlers

import os
from abc import ABC
from pathlib import Path

import numpy as np
from astropy.io import fits
from ctapipe.containers import Field,partial,Map

from .core import ArrayDataContainer,TriggerMapContainer

__all__ = ["ChargesContainer","ChargesContainers"]
class ChargesContainer(ArrayDataContainer):
"""
A container that holds information about charges from a specific run.

Fields:
charges_hg (np.ndarray): An array of high gain charges.
charges_lg (np.ndarray): An array of low gain charges.
peak_hg (np.ndarray): An array of high gain peak time.
peak_lg (np.ndarray): An array of low gain peak time.
method (str): The charge extraction method used.
"""

charges_hg = Field(type=np.ndarray, dtype = np.uint16, ndim = 2, description="The high gain charges")
charges_lg = Field(type=np.ndarray, dtype = np.uint16, ndim = 2, description="The low gain charges")
peak_hg = Field(type=np.ndarray, dtype = np.uint16, ndim = 2, description="The high gain peak time")
peak_lg = Field(type=np.ndarray, dtype = np.uint16, ndim = 2, description="The low gain peak time")
method = Field(type=str, description="The charge extraction method used")


class ChargesContainers(TriggerMapContainer):
containers = Field(default_factory=partial(Map, ChargesContainer),
description = "trigger or slices of data mapping of ChargesContainer"
)
44 changes: 0 additions & 44 deletions src/nectarchain/data/container/charges_container.py

This file was deleted.

143 changes: 131 additions & 12 deletions src/nectarchain/data/container/core.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,43 @@
import logging

import numpy as np
from ctapipe.containers import Container, Field, Map, partial

logging.basicConfig(format="%(asctime)s %(name)s %(levelname)s %(message)s")
log = logging.getLogger(__name__)
log.handlers = logging.getLogger("__main__").handlers

import importlib
import copy
import numpy as np
from pathlib import Path
from ctapipe.containers import Field,Container,partial,Map
from ctapipe.core.container import FieldValidationError
from ctapipe.containers import EventType
from ctapipe.io import HDF5TableReader

__all__ = ["ArrayDataContainer", "TriggerMapContainer"]
from tables.exceptions import NoSuchNodeError


__all__ = ["ArrayDataContainer","TriggerMapContainer","get_array_keys","merge_map_ArrayDataContainer"]
def get_array_keys(container : Container) :
keys = []
for field in container.fields :
if field.type == np.ndarray :
keys.append(field.key)
return keys

Check warning on line 25 in src/nectarchain/data/container/core.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/data/container/core.py#L21-L25

Added lines #L21 - L25 were not covered by tests
class NectarCAMContainer(Container):
"""base class for the NectarCAM containers. This contaner cannot berecursive,
to be directly written with a HDF5TableWriter"""

@staticmethod
def _container_from_hdf5(path,container_class) :
if isinstance(path,str) :
path = Path(path)

Check warning on line 33 in src/nectarchain/data/container/core.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/data/container/core.py#L32-L33

Added lines #L32 - L33 were not covered by tests

container = container_class()
with HDF5TableReader(path) as reader :
tableReader = reader.read(table_name = f"/data/{container_class.__name__}", containers = container_class)
container = next(tableReader)

Check warning on line 38 in src/nectarchain/data/container/core.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/data/container/core.py#L35-L38

Added lines #L35 - L38 were not covered by tests

yield container

Check warning on line 40 in src/nectarchain/data/container/core.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/data/container/core.py#L40

Added line #L40 was not covered by tests


class ArrayDataContainer(NectarCAMContainer):
Expand All @@ -39,15 +63,15 @@
"""

run_number = Field(
type=int,
type=np.uint16,
description="run number associated to the waveforms",
)
nevents = Field(
type=int,
type=np.uint64,
description="number of events",
)
npixels = Field(
type=int,
type=np.uint16,
description="number of effective pixels",
)
pixels_id = Field(type=np.ndarray, dtype=np.uint16, ndim=1, description="pixel ids")
Expand Down Expand Up @@ -85,8 +109,103 @@
)


class TriggerMapContainer(Container):
containers = Field(
default_factory=partial(Map, Container),
description="trigger mapping of Container",
)
@staticmethod
def _container_from_hdf5(path,container_class,slice_index = None) :
if isinstance(path,str) :
path = Path(path)
module = importlib.import_module(f'{container_class.__module__}')
container = eval(f"module.{container_class.__name__}s")()

Check warning on line 117 in src/nectarchain/data/container/core.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/data/container/core.py#L114-L117

Added lines #L114 - L117 were not covered by tests


with HDF5TableReader(path) as reader :
if len(reader._h5file.root.__members__) > 1 and slice_index is None:
log.info(f"reading {container_class.__name__}s containing {len(reader._h5file.root.__members__)} slices, will return a generator")
for data in reader._h5file.root.__members__ :

Check warning on line 123 in src/nectarchain/data/container/core.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/data/container/core.py#L120-L123

Added lines #L120 - L123 were not covered by tests
#container.containers[data] = eval(f"module.{container_class.__name__}s")()
for key,trigger in EventType.__members__.items() :
try :
waveforms_data = eval(f"reader._h5file.root.{data}.__members__")
_mask = [container_class.__name__ in _word for _word in waveforms_data]
_waveforms_data = np.array(waveforms_data)[_mask]
if len(_waveforms_data) == 1 :
tableReader = reader.read(table_name = f"/{data}/{_waveforms_data[0]}/{trigger.name}", containers = container_class)

Check warning on line 131 in src/nectarchain/data/container/core.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/data/container/core.py#L125-L131

Added lines #L125 - L131 were not covered by tests
#container.containers[data].containers[trigger] = next(tableReader)
container.containers[trigger] = next(tableReader)

Check warning on line 133 in src/nectarchain/data/container/core.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/data/container/core.py#L133

Added line #L133 was not covered by tests

else :
log.info(f"there is {len(_waveforms_data)} entry corresponding to a {container_class} table save, unable to load")
except NoSuchNodeError as err:
log.warning(err)
except Exception as err:
log.error(err,exc_info = True)
raise err
yield container

Check warning on line 142 in src/nectarchain/data/container/core.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/data/container/core.py#L136-L142

Added lines #L136 - L142 were not covered by tests
else :
if slice_index is None :
log.info(f"reading {container_class.__name__}s containing a single slice, will return the {container_class.__name__}s instance")
data = "data"

Check warning on line 146 in src/nectarchain/data/container/core.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/data/container/core.py#L144-L146

Added lines #L144 - L146 were not covered by tests
else :
log.info(f"reading slice {slice_index} of {container_class.__name__}s, will return the {container_class.__name__}s instance")
data = f"data_{slice_index}"
for key,trigger in EventType.__members__.items() :
try :
container_data = eval(f"reader._h5file.root.{data}.__members__")
_mask =[container_class.__name__ in _word for _word in container_data]
_container_data = np.array(container_data)[_mask]
if len(_container_data) == 1 :
tableReader = reader.read(table_name = f"/{data}/{_container_data[0]}/{trigger.name}", containers = container_class)
container.containers[trigger] = next(tableReader)

Check warning on line 157 in src/nectarchain/data/container/core.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/data/container/core.py#L148-L157

Added lines #L148 - L157 were not covered by tests
else :
log.info(f"there is {len(_container_data)} entry corresponding to a {container_class} table save, unable to load")
except NoSuchNodeError as err:
log.warning(err)
except Exception as err:
log.error(err,exc_info = True)
raise err
yield container
return container

Check warning on line 166 in src/nectarchain/data/container/core.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/data/container/core.py#L159-L166

Added lines #L159 - L166 were not covered by tests

@classmethod
def from_hdf5(cls,path,slice_index = None) :
return cls._container_from_hdf5(path,slice_index=slice_index,container_class=cls)

Check warning on line 170 in src/nectarchain/data/container/core.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/data/container/core.py#L170

Added line #L170 was not covered by tests





class TriggerMapContainer(Container) :
containers = Field(default_factory=partial(Map, Container),
description = "trigger mapping of Container"
)

def is_empty(self) :
return len(self.containers.keys())==0

Check warning on line 182 in src/nectarchain/data/container/core.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/data/container/core.py#L182

Added line #L182 was not covered by tests

def validate(self) :
super().validate()
for i,container in enumerate(self.containers) :
if i==0 :
container_type = type(container)

Check warning on line 188 in src/nectarchain/data/container/core.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/data/container/core.py#L185-L188

Added lines #L185 - L188 were not covered by tests
else :
if not(isinstance(container,container_type)) :
raise FieldValidationError("all the containers mapped must have the same type to be merged ")

Check warning on line 191 in src/nectarchain/data/container/core.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/data/container/core.py#L190-L191

Added lines #L190 - L191 were not covered by tests

def merge_map_ArrayDataContainer(triggerMapContainer : TriggerMapContainer) :
triggerMapContainer.validate()
keys = list(triggerMapContainer.containers.keys())
output_container = copy.deepcopy(triggerMapContainer.containers[keys[0]])
for key in keys[1:] :
for field in get_array_keys(triggerMapContainer.containers[key]):
output_container[field] = np.concatenate((output_container[field],triggerMapContainer.containers[key][field]),axis = 0)
if "nevents" in output_container.fields :
output_container.nevents += triggerMapContainer.containers[key].nevents
return output_container

Check warning on line 202 in src/nectarchain/data/container/core.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/data/container/core.py#L194-L202

Added lines #L194 - L202 were not covered by tests

#class TriggerMapArrayDataContainer(TriggerMapContainer):
# containers = Field(default_factory=partial(Map, ArrayDataContainer),
# description = "trigger mapping of arrayDataContainer"
# )




Loading