Skip to content

Commit

Permalink
Add more information to geometry table
Browse files Browse the repository at this point in the history
* module_id
* hardware_pixel_id
* index in module
* DRS4 chip info

Also add functions to create such a mapping from CameraConfiguration
object in data files.
  • Loading branch information
maxnoe committed Jul 23, 2024
1 parent b526efb commit 98fef10
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/ctapipe_io_lst/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from .version import __version__
from .calibration import LSTR0Corrections
from .event_time import EventTimeCalculator, cta_high_res_to_time
from .pixels import get_pixel_table
from .pointing import PointingSource
from .anyarray_dtypes import (
CDTS_AFTER_37201_DTYPE,
Expand Down Expand Up @@ -104,9 +105,8 @@ def get_channel_info(pixel_status):

def load_camera_geometry():
''' Load camera geometry from bundled resources of this repo '''
with as_file(files("ctapipe_io_lst") / "resources/LSTCam.camgeom.fits.gz") as path:
Provenance().add_input_file(path, role="CameraGeometry")
cam = CameraGeometry.from_table(path)
pixel_table = get_pixel_table()
cam = CameraGeometry.from_table(pixel_table)
cam.frame = CameraFrame(focal_length=OPTICS.effective_focal_length)
return cam

Expand Down
12 changes: 3 additions & 9 deletions src/ctapipe_io_lst/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,17 @@
N_GAINS, N_PIXELS, N_MODULES, N_SAMPLES, LOW_GAIN, HIGH_GAIN,
N_PIXELS_MODULE, N_CAPACITORS_PIXEL, N_CAPACITORS_CHANNEL,
CLOCK_FREQUENCY_KHZ,
CHANNEL_ORDER_LOW_GAIN, CHANNEL_ORDER_HIGH_GAIN, N_CHANNELS_MODULE,
N_CHANNELS_MODULE,
PIXEL_INDEX, PixelStatus
)

from .pixels import pixel_channel_indices

__all__ = [
'LSTR0Corrections',
]


@lru_cache()
def pixel_channel_indices(n_modules):
module_index = np.repeat(np.arange(n_modules), 7)
low_gain = module_index * N_CHANNELS_MODULE + np.tile(CHANNEL_ORDER_LOW_GAIN, n_modules)
high_gain = module_index * N_CHANNELS_MODULE + np.tile(CHANNEL_ORDER_HIGH_GAIN, n_modules)
return low_gain, high_gain


def get_first_capacitors_for_pixels(first_capacitor_id, expected_pixel_id=None):
'''
Get the first capacitor for each pixel / gain
Expand Down
70 changes: 70 additions & 0 deletions src/ctapipe_io_lst/pixels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import numpy as np
from functools import lru_cache
from astropy.table import Table
from importlib.resources import files, as_file

from ctapipe.core import Provenance

from .constants import N_PIXELS_MODULE, CHANNEL_ORDER_LOW_GAIN, CHANNEL_ORDER_HIGH_GAIN, N_CHANNELS_MODULE


@lru_cache()
def pixel_channel_indices(n_modules):
"""Get index into first_capacitor_id or each channel, pixel"""
return _pixel_channel_indices(np.arange(n_modules))


def _pixel_channel_indices(module_id_map):
module = np.repeat(module_id_map, N_PIXELS_MODULE)
n_modules = len(module_id_map)
low_gain = module * N_CHANNELS_MODULE + np.tile(CHANNEL_ORDER_LOW_GAIN, n_modules)
high_gain = module * N_CHANNELS_MODULE + np.tile(CHANNEL_ORDER_HIGH_GAIN, n_modules)
return low_gain, high_gain


def get_pixel_table_from_camera_config(config):
"""
Construct a table of pixel / module ids from the mappings in CameraConfiguration
"""
if hasattr(config, "pixel_id_map"):

Check warning on line 29 in src/ctapipe_io_lst/pixels.py

View check run for this annotation

Codecov / codecov/patch

src/ctapipe_io_lst/pixels.py#L29

Added line #L29 was not covered by tests
# new R1v1.CameraConfiguration
pixel_id_map = config.pixel_id_map
module_id_map = config.module_id_map

Check warning on line 32 in src/ctapipe_io_lst/pixels.py

View check run for this annotation

Codecov / codecov/patch

src/ctapipe_io_lst/pixels.py#L31-L32

Added lines #L31 - L32 were not covered by tests
else:
# old ProtoR1.CameraConfiguration
pixel_id_map = config.expected_pixels_id
module_id_map = config.lstcam.expected_modules_id

Check warning on line 36 in src/ctapipe_io_lst/pixels.py

View check run for this annotation

Codecov / codecov/patch

src/ctapipe_io_lst/pixels.py#L35-L36

Added lines #L35 - L36 were not covered by tests

n_modules = len(module_id_map)
n_pixels = len(pixel_id_map)

Check warning on line 39 in src/ctapipe_io_lst/pixels.py

View check run for this annotation

Codecov / codecov/patch

src/ctapipe_io_lst/pixels.py#L38-L39

Added lines #L38 - L39 were not covered by tests

chip_lg, chip_hg = _pixel_channel_indices(module_id_map)

Check warning on line 41 in src/ctapipe_io_lst/pixels.py

View check run for this annotation

Codecov / codecov/patch

src/ctapipe_io_lst/pixels.py#L41

Added line #L41 was not covered by tests

pixel_index = np.arange(n_pixels)

Check warning on line 43 in src/ctapipe_io_lst/pixels.py

View check run for this annotation

Codecov / codecov/patch

src/ctapipe_io_lst/pixels.py#L43

Added line #L43 was not covered by tests
# the pixel data arrives in module groups, the module id of each group
# is in module_id_map. Repeat to have the module_id of each pixel
module_id = np.repeat(module_id_map, N_PIXELS_MODULE)

Check warning on line 46 in src/ctapipe_io_lst/pixels.py

View check run for this annotation

Codecov / codecov/patch

src/ctapipe_io_lst/pixels.py#L46

Added line #L46 was not covered by tests

# pixels inside one module are ordered by module_pixel_index
module_pixel_index = np.tile(np.arange(N_PIXELS_MODULE), n_modules)
hardware_pixel_id = module_id * N_PIXELS_MODULE + module_pixel_index

Check warning on line 50 in src/ctapipe_io_lst/pixels.py

View check run for this annotation

Codecov / codecov/patch

src/ctapipe_io_lst/pixels.py#L49-L50

Added lines #L49 - L50 were not covered by tests

table = Table(dict(

Check warning on line 52 in src/ctapipe_io_lst/pixels.py

View check run for this annotation

Codecov / codecov/patch

src/ctapipe_io_lst/pixels.py#L52

Added line #L52 was not covered by tests
pixel_id=pixel_id_map,
pixel_index=pixel_index,
module_id=module_id,
module_pixel_index=module_pixel_index,
hardware_pixel_id=hardware_pixel_id,
drs4_chip_hg=chip_hg,
drs4_chip_lg=chip_lg,
))

table.sort("pixel_id")
return table

Check warning on line 63 in src/ctapipe_io_lst/pixels.py

View check run for this annotation

Codecov / codecov/patch

src/ctapipe_io_lst/pixels.py#L62-L63

Added lines #L62 - L63 were not covered by tests


def get_pixel_table():
"""Load pixel information from bundled camera geometry file"""
with as_file(files("ctapipe_io_lst") / "resources/LSTCam.camgeom.fits.gz") as path:
Provenance().add_input_file(path, role="CameraGeometry")
return Table.read(path)
Binary file modified src/ctapipe_io_lst/resources/LSTCam.camgeom.fits.gz
Binary file not shown.

0 comments on commit 98fef10

Please sign in to comment.