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 e47fe78
Show file tree
Hide file tree
Showing 4 changed files with 75 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
69 changes: 69 additions & 0 deletions src/ctapipe_io_lst/pixels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
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):
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"):
# new R1v1.CameraConfiguration
pixel_id_map = config.pixel_id_map
module_id_map = config.module_id_map
else:
# old ProtoR1.CameraConfiguration
pixel_id_map = config.expected_pixels_id
module_id_map = config.lstcam.expected_modules_id

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

chip_lg, chip_hg = _pixel_channel_indices(module_id_map)

pixel_index = np.arange(n_pixels)
# 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)

# 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

table = Table(dict(
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


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 e47fe78

Please sign in to comment.