tasks — Tasks#

This module provide all the high-level simulation and analysis tasks of the package, each implemented as a single function with a precise signature, as well as the default values for their arguments.

More specifically, the following tasks are provided:

Module documentation#

Basic simulation, reconstruction and analysis tasks.

hexsample.tasks.current_call() Tuple[str, dict][source]#

Return the name and arguments of the current function call.

class hexsample.tasks.SimulationDefaults(num_events: int = 10000, output_file_path: str = PosixPath('/home/runner/hexsampledata/simulation.h5'), random_seed: int = None)[source]#

Default parameters for the simulation task.

This is a small helper dataclass to help ensure consistency between the main task definition in this Python module and the command-line interface.

num_events: int = 10000#
output_file_path: str = PosixPath('/home/runner/hexsampledata/simulation.h5')#
random_seed: int = None#
hexsample.tasks.simulate(source: Source, sensor: Sensor, readout: AbstractReadout, num_events: int = 10000, output_file_path: str = PosixPath('/home/runner/hexsampledata/simulation.h5'), random_seed: int = None, header_kwargs: dict = None) str[source]#

Run a simulation.

Warning

The last header_kwargs argument is a temporary workaround to allow passing some metadata to be stored in the output file header. This will go away once we have a proper mechanism to handle metadata.

Arguments#

sourceSource

The X-ray source.

sensorSensor

The sensor.

readoutAbstractReadout

The readout chip.

num_eventsint

The number of events to simulate.

output_file_pathstr

The path to the output file.

random_seedint

The random seed to use.

Returns#

str

The path to the output file that the task has created.

class hexsample.tasks.ReconstructionDefaults(suffix: str = 'recon', zero_sup_threshold: int = 0, num_neighbors: int = 2, max_neighbors: int = -1, pos_recon_algorithm: str = 'centroid', gain_map: ndarray | None = None, eta_2pix_rad: float = 0.127, eta_2pix_pivot: float = 0.04, eta_3pix_rad0: float = 0.513, eta_3pix_rad1: float = 0.141, eta_3pix_rad_pivot: float = 0.05, eta_3pix_theta0: float = 0.104)[source]#

Default parameters for the reconstruction task.

This is a small helper dataclass to help ensure consistency between the main task definition in this Python module and the command-line interface.

suffix: str = 'recon'#
zero_sup_threshold: int = 0#
num_neighbors: int = 2#
max_neighbors: int = -1#
pos_recon_algorithm: str = 'centroid'#
gain_map: ndarray | None = None#
eta_2pix_rad: float = 0.127#
eta_2pix_pivot: float = 0.04#
eta_3pix_rad0: float = 0.513#
eta_3pix_rad1: float = 0.141#
eta_3pix_rad_pivot: float = 0.05#
eta_3pix_theta0: float = 0.104#
hexsample.tasks.reconstruct(input_file_path: str, suffix: str = 'recon', zero_sup_threshold: int = 0, num_neighbors: int = 2, max_neighbors: int = -1, pos_recon_algorithm: str = 'centroid', gain_map: ndarray | None = None, eta_2pix_rad: float = 0.127, eta_2pix_pivot: float = 0.04, eta_3pix_rad0: float = 0.513, eta_3pix_rad1: float = 0.141, eta_3pix_rad_pivot: float = 0.05, eta_3pix_theta0: float = 0.104, header_kwargs: dict = None) str[source]#

Run the reconstruction.

Warning

The last header_kwargs argument is a temporary workaround to allow passing some metadata to be stored in the output file header. This will go away once we have a proper mechanism to handle metadata.

Arguments#

input_file_pathstr

The path to the input file.

suffixstr

The suffix to append to the output file name.

zero_sup_thresholdint

The zero-suppression threshold.

num_neighborsint

The number of neighbor pixels to be used for the clustering.

max_neighborsint

The maximum number of neighbor pixels to be used for the clustering. If max_neighbors is specified (i.e. different from -1), it has priority over num_neighbors.

pos_recon_algorithmstr

The position reconstruction algorithm to use.

gain_mapnp.ndarray or None

The gain map to use for the reconstruction. If None, no gain correction is applied.

eta_indexfloat

The eta index to use.

class hexsample.tasks.CalibrationDefaults(num_events: int = 50000, zero_sup_threshold: float = 20.0, default_gain: float = None, default_noise: float = None)[source]#

Default parameters for the calibrate task.

This is a small helper dataclass to help ensure consistency between the main task definition in this Python module and the command-line interface.

num_events: int = 50000#
zero_sup_threshold: float = 20.0#
default_gain: float = None#
default_noise: float = None#
hexsample.tasks.calibrate(input_file_path: str, energy: float, num_events: int, zero_sup_threshold: float = 20.0, default_gain: float = None, default_noise: float = None) None[source]#

Calibrate the gain and noise response of the readout chip using the events from a digi file. The results are stored as a matrix in two separate HDF5 files, one for the gain and one for the noise.

Arguments#

input_file_pathstr

The path to the input file.

energyfloat

The energy of the X-ray photons in eV. This is used to convert the charge collected in each pixel to the number of electron, which is necessary for the gain calibration.

num_eventsint

The number of events to simulate to find the bias correction.

zero_sup_thresholdfloat

The zero-suppression threshold to use for the clustering in the gain calibration.

default_gainfloat

The default gain value to use for the gain calibration. If None, it will be set to the mean value of the gain matrix after processing all the events.

default_noisefloat

The default noise value to use for the noise calibration. If None, it will be set to the mean value of the noise matrix after processing all the events.

class hexsample.tasks.DisplayDefaults[source]#

Default parameters for the display task.

This is a small helper dataclass to help ensure consistency between the main task definition in this Python module and the command-line interface.

zero_sup_threshold: int = 30#
num_neighbors: int = 6#
event_id: int = None#
hexsample.tasks.display(input_file_path: str, zero_sup_threshold: int = 30) None[source]#

Display events from a digi file.

Arguments#

file_pathstr

The path to the digi file.

zero_sup_thresholdint

The zero-suppression threshold to use when displaying the digi event.

event_idint

The ID of the event to display. If None, display all events.

class hexsample.tasks.QuickLookDefaults[source]#

Default parameters for the quicklook task.

This is a small helper dataclass to help ensure consistency between the main task definition in this Python module and the command-line interface.

hexsample.tasks.quicklook(input_file_path: str) None[source]#

Quicklook at events from a recon file.

Warning

This needs to be rebuilt from the ground up, but the intent is a good one, I think.

Arguments#

file_pathstr

The path to the input recon file.