Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Ievgen Vovk
ctapipe_io_magic
Commits
0e97a041
Commit
0e97a041
authored
Dec 05, 2019
by
Moritz Huetten
Browse files
tests again pass
parent
71a37510
Pipeline
#65683
canceled with stage
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
ctapipe_io_magic/__init__.py
View file @
0e97a041
# Event source for MAGIC calibrated data files.
# Requires uproot package (https://github.com/scikit-hep/uproot).
import
logging
import
glob
import
re
...
...
@@ -16,6 +17,7 @@ from ctapipe.instrument import TelescopeDescription, SubarrayDescription, Optics
__all__
=
[
'MAGICEventSource'
]
logger
=
logging
.
getLogger
(
__name__
)
class
MAGICEventSource
(
EventSource
):
"""
...
...
@@ -162,7 +164,8 @@ class MAGICEventSource(EventSource):
Returns
-------
MarsDataRun:
The run to use
"""
input_path
=
'/'
.
join
(
self
.
input_url
.
split
(
'/'
)[:
-
1
])
...
...
@@ -218,7 +221,7 @@ class MAGICEventSource(EventSource):
if
'data'
in
self
.
current_run
:
del
self
.
current_run
[
'data'
]
# Setting the new active run
# Setting the new active run
(class MarsDataRun object)
self
.
current_run
=
self
.
_set_active_run
(
run_number
)
# Loop over the events
...
...
@@ -1016,39 +1019,44 @@ class MarsDataRun:
stereo_event_number
=
events
[
b
'MRawEvtHeader.fStereoEvtNumber'
]
# Reading meta information:
meta_info
=
input_file
[
'RunHeaders'
].
arrays
(
metainfo_array_list
)
mars_meta
[
'origin'
]
=
"MAGIC"
mars_meta
[
'input_url'
]
=
file_name
mars_meta
[
'number'
]
=
int
(
meta_info
[
b
'MRawRunHeader.fRunNumber'
][
0
])
#mars_meta['number_subrun'] = int(meta_info[b'MRawRunHeader.fSubRunIndex'][0])
mars_meta
[
'source_ra'
]
=
meta_info
[
b
'MRawRunHeader.fSourceRA'
][
0
]
/
seconds_per_hour
*
degrees_per_hour
*
u
.
deg
mars_meta
[
'source_dec'
]
=
meta_info
[
b
'MRawRunHeader.fSourceDEC'
][
0
]
/
seconds_per_hour
*
u
.
deg
is_simulation
=
int
(
meta_info
[
b
'MRawRunHeader.fRunType'
][
0
])
if
is_simulation
==
0
:
is_simulation
=
False
elif
is_simulation
==
256
:
is_simulation
=
True
else
:
msg
=
"Run type (Data or MC) of MAGIC data file not recognised."
self
.
log
.
error
(
msg
)
raise
mars_meta
[
'is_simulation'
]
=
is_simulation
# Reading the info only contained in real data
if
is_simulation
==
False
:
badpixelinfo
=
input_file
[
'RunHeaders'
][
'MBadPixelsCam.fArray.fInfo'
].
array
(
uproot
.
asjagged
(
uproot
.
asdtype
(
np
.
int32
))).
flatten
().
reshape
((
4
,
1183
),
order
=
'F'
)
# now we have 3 axes:
# 1st axis: Unsuitable pixels
# 2nd axis: Uncalibrated pixels (says why pixel is unsuitable)
# 3rd axis: Bad hardware pixels (says why pixel is unsuitable)
# Each axis cointains a 32bit integer encoding more information about the specific problem, see MARS software, MBADPixelsPix.h
# Here, we however discard this additional information and only grep the "unsuitable" axis.
badpixelinfo
=
badpixelinfo
[
1
].
astype
(
bool
)
else
:
try
:
meta_info
=
input_file
[
'RunHeaders'
].
arrays
(
metainfo_array_list
)
mars_meta
[
'origin'
]
=
"MAGIC"
mars_meta
[
'input_url'
]
=
file_name
mars_meta
[
'number'
]
=
int
(
meta_info
[
b
'MRawRunHeader.fRunNumber'
][
0
])
#mars_meta['number_subrun'] = int(meta_info[b'MRawRunHeader.fSubRunIndex'][0])
mars_meta
[
'source_ra'
]
=
meta_info
[
b
'MRawRunHeader.fSourceRA'
][
0
]
/
seconds_per_hour
*
degrees_per_hour
*
u
.
deg
mars_meta
[
'source_dec'
]
=
meta_info
[
b
'MRawRunHeader.fSourceDEC'
][
0
]
/
seconds_per_hour
*
u
.
deg
is_simulation
=
int
(
meta_info
[
b
'MRawRunHeader.fRunType'
][
0
])
if
is_simulation
==
0
:
is_simulation
=
False
elif
is_simulation
==
256
:
is_simulation
=
True
else
:
msg
=
"Run type (Data or MC) of MAGIC data file not recognised."
self
.
log
.
error
(
msg
)
raise
mars_meta
[
'is_simulation'
]
=
is_simulation
# Reading the info only contained in real data
if
is_simulation
==
False
:
badpixelinfo
=
input_file
[
'RunHeaders'
][
'MBadPixelsCam.fArray.fInfo'
].
array
(
uproot
.
asjagged
(
uproot
.
asdtype
(
np
.
int32
))).
flatten
().
reshape
((
4
,
1183
),
order
=
'F'
)
# now we have 3 axes:
# 1st axis: Unsuitable pixels
# 2nd axis: Uncalibrated pixels (says why pixel is unsuitable)
# 3rd axis: Bad hardware pixels (says why pixel is unsuitable)
# Each axis cointains a 32bit integer encoding more information about the specific problem, see MARS software, MBADPixelsPix.h
# Here, we however discard this additional information and only grep the "unsuitable" axis.
badpixelinfo
=
badpixelinfo
[
1
].
astype
(
bool
)
else
:
badpixelinfo
=
np
.
zeros
(
1183
)
except
KeyError
:
logger
.
warning
(
"RunHeaders tree not present in file. Cannot read meta information and assume it is a real data run."
)
badpixelinfo
=
np
.
zeros
(
1183
)
is_simulation
=
False
# Computing the event arrival time
mjd
=
events
[
b
'MTime.fMjd'
]
...
...
ctapipe_io_magic/tests/test_magic_event_source.py
View file @
0e97a041
...
...
@@ -75,8 +75,8 @@ def test_geom():
with
MAGICEventSource
(
input_url
=
dataset
)
as
source
:
event
=
next
(
source
.
_generator
())
assert
event
.
inst
.
subarray
.
tels
[
1
].
camera
.
pix_x
.
size
==
1039
assert
event
.
inst
.
subarray
.
tels
[
2
].
camera
.
pix_x
.
size
==
1039
assert
source
.
subarray
.
tels
[
1
].
camera
.
pix_x
.
size
==
1039
assert
source
.
subarray
.
tels
[
2
].
camera
.
pix_x
.
size
==
1039
def
test_eventseeker
():
...
...
@@ -87,8 +87,20 @@ def test_eventseeker():
seeker
=
EventSeeker
(
source
)
event
=
seeker
[
0
]
assert
event
.
count
==
0
assert
event
.
dl0
.
event_id
==
29795
.0
assert
event
.
dl0
.
event_id
==
29795
event
=
seeker
[
2
]
assert
event
.
count
==
2
assert
event
.
r1
.
event_id
==
29798.0
assert
event
.
r1
.
event_id
==
29798
def
test_eventcontent
():
dataset
=
get_dataset_path
(
"20131004_M1_05029747.003_Y_MagicCrab-W0.40+035.root"
)
dataset
=
dataset
.
replace
(
'_M1_'
,
'_M*_'
)
with
MAGICEventSource
(
input_url
=
dataset
)
as
source
:
seeker
=
EventSeeker
(
source
)
event
=
seeker
[
0
]
assert
event
.
dl1
.
tel
[
1
].
image
[
0
]
==
-
0.53125
assert
event
.
dl1
.
tel
[
2
].
image
[
0
]
==
2.2265625
assert
event
.
dl1
.
tel
[
1
].
pulse_time
[
0
]
==
49.125
assert
event
.
dl1
.
tel
[
2
].
pulse_time
[
0
]
==
23.5625
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment