exosim.tasks.detector.addCosmicRays#
Classes#
Task to simulate the addition of cosmic rays to sub-exposures in a detector. |
Module Contents#
- class AddCosmicRays[source]#
Bases:
exosim.tasks.task.TaskTask to simulate the addition of cosmic rays to sub-exposures in a detector.
This task models the impact of cosmic rays on a detector during the exposure time. The model assumes that the cosmic rays can interact with the detector pixels in various predefined shapes like a cross, horizontal rectangle, and vertical rectangle. The number of cosmic ray events and their impact on the detector pixels are calculated based on the given cosmic ray flux, detector characteristics, and integration times for the sub-exposures.
Notes
This task assumes that the cosmic ray events saturate the affected pixels, setting their value to the full well depth.
The probabilities for the interaction shapes are configurable. The task issues a warning if the sum of provided probabilities is not 1.
The cosmic ray flux is specified in ct/s/cm^2 and is scaled based on the pixel size and detector dimensions.
This is a default class with standardised inputs and outputs. The user can load this class and overwrite the “model” method to implement a custom Task to replace this.
- execute()[source]#
Class execution. It runs on call and executes all the task actions returning the outputs. It requires the input with correct keywords
- model(subexposures, parameters, integration_times, output=None)[source]#
Default model to simulate the addition of cosmic rays to the sub-exposures.
This method saturates the hit pixels in the sub-exposure data based on the cosmic ray rate, detector properties, and the given integration times. The cosmic ray interactions could be in various shapes like single pixel, lines, squares, etc., which are defined in the configuration.
- Parameters:
subexposures (Signal) – The sub-exposures’ cached signal.
parameters (dict) – The channel parameters dictionary containing detector information.
integration_times (ArrayType) – The integration times for the sub-exposures.
output (Output, optional) – The output file where the cosmic ray events will be stored.
- Return type:
None
Notes
The method assumes multiple possible shapes for the interaction: - Single pixel - Vertical line: Saturates two pixels vertically aligned. - Horizontal line: Saturates two pixels horizontally aligned. - Square: Saturates four pixels in a square. - Cross: Saturates five pixels in a cross shape. - Horizontal rectangle: Saturates six pixels in a horizontal rectangle shape. - Vertical rectangle: Saturates six pixels in a vertical rectangle shape.
- count_events(rate, pixel_size, spatial_pix, spectral_pix, integration_times, saturation_rate, randomise)[source]#
Calculate the number of cosmic ray events in each sub-exposure, randomly distributing them while keeping the probability proportional to the exposure time.
- Parameters:
rate (float) – Cosmic rays flux rate in ct/s/cm^2.
pixel_size (float) – Size of a detector pixel in cm^2.
spatial_pix (int) – Number of spatial pixels in the detector.
spectral_pix (int) – Number of spectral pixels in the detector.
integration_times (
Quantity) – Sub-exposure integration times.saturation_rate (float) – Saturation rate for the detector.
randomise (bool) – A flag to randomize the total number of events
- Returns:
events_counter_i – An array containing the number of events for each sub-exposure, rounded to the nearest integer.
- Return type:
np.ndarray
- shapes_and_probs(parameters)[source]#
Generate cosmic ray interaction shapes and their corresponding probabilities.
- Parameters:
parameters (dict) – A dictionary containing optional ‘interaction_shapes’ which is a sub-dictionary specifying shapes and their probabilities.
- Returns:
shapes (list of tuples) – A list of tuples representing shapes of cosmic ray interactions.
probs (list of float) – A list of probabilities corresponding to the shapes.
- Raises:
ValueError – If the sum of provided probabilities for all shapes is greater than 1.
- Return type:
Tuple[List, List]
Examples
>>> shapes, probs = AddCosmicRays.shapes_and_probs({"interaction_shapes": {"single": 0.5, "line_h": 0.3, "line_v": 0.2}}) >>> print(shapes) [([0], [0]), ([0, 1], [0, 0]), ([0, 0], [0, 1]), ([0, 0, 1, 1], [0, 1, 0, 1]), ([0, 0, 0, -1, 1], [0, 1, -1, 0, 0])] >>> print(probs) [0.5, 0.3, 0.2, 0.1, 0.1]
>>> shapes, probs = AddCosmicRays.shapes_and_probs({"interaction_shapes": {"single": 0.5, "line_h": 0.3, "line_v": 0.2}}) >>> print(shapes)
Warning
A warning is issued if the sum of provided probabilities for all shapes is not 1.