ctlearn_manager.utils.utils


class ctlearn_manager.utils.utils.DefaultCuts(*values)[source]

Bases: Enum

NO_CUTS = <ctlearn_manager.utils.utils.Cuts object>
EFF_40 = <ctlearn_manager.utils.utils.Cuts object>
EFF_70 = <ctlearn_manager.utils.utils.Cuts object>
EFF_90 = <ctlearn_manager.utils.utils.Cuts object>
GH_0_9 = <ctlearn_manager.utils.utils.Cuts object>
ctlearn_manager.utils.utils.remove_table_from_h5(file_path, table_path)[source]
Parameters:
  • file_path (str)

  • table_path (str)

ctlearn_manager.utils.utils.plot_pointing_on_ax(ax, zenith, azimuth)[source]
ctlearn_manager.utils.utils.remove_row_from_table_utils(index_file, table_path, row_index)[source]
Parameters:
  • table_path (str)

  • row_index (int)

class ctlearn_manager.utils.utils.Cuts(cut_type=CutType.GLOBAL, gammaness_cut=0.0, theta_cut=None, efficiency_gammaness=0.7, efficiency_theta=None)[source]

Bases: object

Parameters:
  • cut_type (CutType)

  • gammaness_cut (float)

  • theta_cut (float)

  • efficiency_gammaness (float)

  • efficiency_theta (float)

plot_cuts_info_plt(ax, text_color=None, background_color=None, alpha=0.2)[source]
get_label()[source]
get_directory_name()[source]

Get the directory name for the cuts based on their type and parameters. :return: Directory name as a string.

class ctlearn_manager.utils.utils.CutType(*values)[source]

Bases: Enum

GLOBAL = 'global'
EFFICIENCY_OPTIMIZED = 'energy_dependent_efficiency'
SENSITIVITY_OPTIMIZED = 'sensitivity_optimized'
ctlearn_manager.utils.utils.get_irf_type_from_config(config)[source]

Get the IRF type from the configuration. :param config: The configuration object. :type config: object :return: The IRF type. :rtype: IRFType

class ctlearn_manager.utils.utils.IRFType(*values)[source]

Bases: Enum

EFFICIENCY_OPTIMIZED = 'energy_dependent_efficiency'
SENSITIVITY_OPTIMIZED = 'sensitivity_optimized'
ctlearn_manager.utils.utils.set_mpl_style(mplstyle_file='CTLearnStyleLight.mplstyle')[source]
Parameters:

mplstyle_file (str)

ctlearn_manager.utils.utils.angular_distance(ze1, az1, ze2, az2)[source]
ctlearn_manager.utils.utils.get_dates_from_runs(runs)[source]
ctlearn_manager.utils.utils.get_files_LST_cluster(run, DL1_data_dir='/fefs/aswg/data/real/DL1/')[source]
Parameters:

run (int)

ctlearn_manager.utils.utils.get_files_cscs(run, DL1_data_dir='/pnfs/cta.cscs.ch/lst/DL1/')[source]
Parameters:

run (int)

ctlearn_manager.utils.utils.get_avg_pointing(input_file, pointing_table='/dl1/event/telescope/parameters/LST_LSTCam', alt_key='alt_tel', az_key='az_tel')[source]
ctlearn_manager.utils.utils.get_predict_data_sbatch_script(cluster, command, job_name, sbatch_scripts_dir, account, env_name, time, partition, nodes=1, memory_mb=None, use_gpu_cscs=True)[source]
ctlearn_manager.utils.utils.remove_model_from_index(model_nickname, MODEL_INDEX_FILE)[source]
class ctlearn_manager.utils.utils.ClusterConfiguration(account=None, environment=None, use_cluster=True, partition=None, time=None, nodes=1, memory_mb=None)[source]

Bases: object

info()[source]
get_cluster()[source]
write_sbatch_script(job_name, cmd, sbatch_scripts_dir, use_gpu_cscs=True)[source]
ctlearn_manager.utils.utils.calc_flux_for_N_sigma(N_sigma, cumul_excess, cumul_off, min_signi, min_exc, min_off_events, alpha, target_obs_time, actual_obs_time, cond=True)[source]
ctlearn_manager.utils.utils.find_68_percent_range(bin_heights, bin_edges, a=0.68)[source]
class ctlearn_manager.utils.utils.ParticleType(*values)[source]

Bases: Enum

GAMMA_POINT = 'gamma_point'
GAMMA_DIFFUSE = 'gamma_diffuse'
PROTON = 'proton'
ELECTRON = 'electron'
ctlearn_manager.utils.utils.get_current_env()[source]
class ctlearn_manager.utils.utils.DataSample(directory, pattern, particle_type=None, zenith_distance=<Quantity nan deg>, azimuth=<Quantity nan deg>, energy_range=<Quantity [nan, nan] TeV>, nsb_range=<Quantity [nan, nan] Hz>)[source]

Bases: object

A class to represent a training sample for CTLearn. :param directory: The directory where training data is stored. :type directory: str :param pattern: The pattern to match training files. :type pattern: str :param zenith_distance: The zenith distance of the training sample. :type zenith_distance: astropy.units.Quantity :param azimuth: The azimuth of the training sample. :type azimuth: astropy.units.Quantity :param energy_range: The energy range of the training sample. :type energy_range: list of astropy.units.Quantity :param nsb_range: The NSB (Night Sky Background) range of the training sample. :type nsb_range: list of astropy.units.Quantity

Initialize the ModelManager. :param directory: The directory where training data is stored. :type directory: str :param pattern: The pattern to match training files. :type pattern: str :param zenith_distance: The zenith distance for training data, defaults to NaN degrees. :type zenith_distance: astropy.units.Quantity :param azimuth: The azimuth for training data, defaults to NaN degrees. :type azimuth: astropy.units.Quantity :param energy_range: The energy range for training data, defaults to [NaN, NaN] TeV. :type energy_range: list of astropy.units.Quantity :param nsb_range: The NSB range for training data, defaults to [NaN, NaN] Hz. :type nsb_range: list of astropy.units.Quantity

Parameters:
  • directory (str)

  • pattern (str)

  • particle_type (ParticleType | None)

u = <module 'astropy.units' from '/home/docs/checkouts/readthedocs.org/user_builds/ctlearn-manager/envs/latest/lib/python3.13/site-packages/astropy/units/__init__.py'>
class ctlearn_manager.utils.utils.ExportCurves(file_path, export_mode=True, import_label='')[source]

Bases: object

Initialize the ExportCurves class.

Parameters:
  • curves (dict) – A dictionary containing the curves to export.

  • file_path (str) – The path to the output CSV file.

  • export_mode (bool)

  • import_label (str)

add_curve(x_values, y_values, curve_type, cuts)[source]

Add a curve to the export.

Parameters:
  • x_values (list or np.ndarray) – The x values of the curve.

  • y_values (list or np.ndarray) – The y values of the curve.

  • label (str, optional) – The label for the curve, defaults to None.

  • curve_type (CurveType)

  • cuts (Cuts)

export()[source]
plot_curves(axs, **kwargs)[source]

Plot the curves on the given axes.

Parameters:
  • ax (matplotlib.axes.Axes) – The axes to plot the curves on.

  • kwargs – Additional keyword arguments for plotting.

  • axs (list[axis])

class ctlearn_manager.utils.utils.CurveType(*values)[source]

Bases: Enum

GH_CUTS = 'GH-cuts'
THETA_CUTS = 'theta-cuts'
ANGULAR_RESOLUTION = 'angular-resolution'
ENERGY_RESOLUTION = 'energy-resolution'
ROC = 'ROC'
SENSITIVITY_DATA = 'sensitivity-data'
PSF_DATA = 'PSF-data'
class ctlearn_manager.utils.utils.CTLMDirectories(project_directory, tri_model_nickname)[source]

Bases: object

Parameters:
  • project_directory (str)

  • tri_model_nickname (str)

get_irf_directory(zenith, azimuth, cuts)[source]
Parameters:
  • zenith (float)

  • azimuth (float)

  • cuts (Cuts)

get_irf_files(zenith, azimuth, cuts)[source]
Parameters:
  • zenith (float)

  • azimuth (float)

  • cuts (Cuts)

get_closest_irf_files(zenith, azimuth, cuts=None)[source]

Get the closest IRF files for the given zenith and azimuth. :param zenith: The zenith angle in degrees. :type zenith: float :param azimuth: The azimuth angle in degrees. :type azimuth: float :param cuts: The cuts to apply. :type cuts: Cuts :return: A dictionary with the closest IRF files. :rtype: dict

Parameters:
  • zenith (float)

  • azimuth (float)

  • cuts (Cuts)

get_closest_rf_irf_files(cuts=None)[source]

Get the closest IRF files for the given zenith and azimuth. :param zenith: The zenith angle in degrees. :type zenith: float :param azimuth: The azimuth angle in degrees. :type azimuth: float :param cuts: The cuts to apply. :type cuts: Cuts :return: A dictionary with the closest IRF files. :rtype: dict

Parameters:
  • zenith (float)

  • cuts (Cuts)

get_dl2_mc_directory(particle_type, zenith, azimuth)[source]
Parameters:
  • particle_type (ParticleType)

  • zenith (float)

  • azimuth (float)

get_dl2_mc_merged_directory(particle_type, zenith, azimuth)[source]
Parameters:
  • particle_type (ParticleType)

  • zenith (float)

  • azimuth (float)

get_dl2_mc_files(zenith, azimuth, particle_types=[ParticleType.GAMMA_POINT, ParticleType.PROTON], merged=None)[source]
Parameters:
  • zenith (float)

  • azimuth (float)

  • particle_types (list[ParticleType])

  • merged (bool)

get_available_MC_directions(particle_type)[source]
Parameters:

particle_type (ParticleType)

get_dl2_post_processed_data_directory(run)[source]
Parameters:

run (int)

get_dl2_post_processed_data_rf_directory(run)[source]
Parameters:

run (int)

load_model_from_index(model_nickname, MODEL_INDEX_FILE, cluser_config=<ctlearn_manager.utils.utils.ClusterConfiguration object>)[source]
Parameters:
  • model_nickname (str)

  • MODEL_INDEX_FILE (str)

ctlearn_manager.utils.utils.get_user_confirmation(prompt)[source]
Parameters:

prompt (str)

ctlearn_manager.utils.utils.calc_flux_for_N_sigma_array(N_sigma, on_counts, off_counts, min_signi, min_excess, min_off_events, alpha, target_obs_time, actual_obs_time, cond=True, max_iterations=1000)[source]

Calculates the flux scaling factor needed to reach a target significance.

This function takes arrays of ON and OFF counts and iteratively finds the factor by which the excess counts (and thus the flux) would need to be scaled to reach a significance of N_sigma after a target observation time.

Parameters:
  • N_sigma (float) – The target significance (e.g., 5 for 5 sigma).

  • on_counts (numpy.ndarray) – Array of observed ON counts.

  • off_counts (numpy.ndarray) – Array of observed OFF counts.

  • alpha (float) – The ratio of ON to OFF region exposure (1 / n_off).

  • target_obs_time (astropy.units.Quantity) – The target observation time for the sensitivity calculation.

  • actual_obs_time (astropy.units.Quantity) – The actual observation time of the provided event data.

  • min_signi (float, optional) – Minimum significance required in the original data to perform the calculation.

  • min_excess (float, optional) – Minimum excess counts relative to the ON background (alpha * off_counts)

  • min_off_events (int, optional) – Minimum number of OFF events required.

  • max_iterations (int, optional) – Number of iterations to find the flux scaling factor.

Returns:

  • flux_factor (numpy.ndarray) – The factor by which the flux needs to be multiplied to reach N_sigma. Returns np.nan for bins that do not meet the minimum criteria.

  • final_significance (numpy.ndarray) – The significance calculated with the final flux_factor, which should be close to N_sigma for valid bins.

class ctlearn_manager.utils.utils.ColorTheme(*values)[source]

Bases: Enum

light_theme = <enum 'CTLearnManagerLightTheme'>
dark_theme = <enum 'CTLearnManagerDarkTheme'>
ctlearn_manager.utils.utils.get_color(name)[source]
Parameters:

name (str)

ctlearn_manager.utils.utils.set_global_theme(theme)[source]
Parameters:

theme (ColorTheme)

ctlearn_manager.utils.utils.get_closest_rf_irf_files(zenith, cuts=None)[source]

Get the closest IRF files for the given zenith and azimuth. :param zenith: The zenith angle in degrees. :type zenith: float :param azimuth: The azimuth angle in degrees. :type azimuth: float :param cuts: The cuts to apply. :type cuts: Cuts :return: A dictionary with the closest IRF files. :rtype: dict

Parameters:
  • zenith (float)

  • cuts (Cuts)

ctlearn_manager.utils.utils.convert_irf_format(irf_file, cuts_file, output_file)[source]

Convert IRF file format by reading HDUs from irf and cuts files, renaming them and their columns, and writing to a new FITS file.

Parameters:

irf_filestr

Path to the input IRF file

cuts_filestr

Path to the input cuts file

output_filestr

Path to the output FITS file

ctlearn_manager.utils.utils.produce_dl3(dl2_files, CTLearnTriModelCollection, output_dl3_directory, pointing_table='dl1/monitoring/telescope/pointing/tel_001', source_name='Crab', source_ra=<Quantity 83.633 deg>, source_dec=<Quantity 22.01 deg>, cuts=<ctlearn_manager.utils.utils.Cuts object>, overwrite=False, dl3_file_pattern='LST-1.Run*.dl3.fits', pointing_alt_key='altitude', pointing_az_key='azimuth', cluster_configuration=<ctlearn_manager.utils.utils.ClusterConfiguration object>)[source]
Parameters:
  • dl2_files (list[str])

  • output_dl3_directory (str)

  • source_name (str)

  • source_ra (float)

  • source_dec (float)

  • cuts (Cuts)

  • overwrite (bool)

  • dl3_file_pattern (str)