Utilities

Functions to deal with command lines argument and options, dates, production IDs, directories and moving files.

Command line arguments and options

Input arguments and options for LSTOSA scripts are set in osa.utils.cliopts.

Reference/API

Command line argument parser for lstosa scripts.

osa.utils.cliopts.autocloser_cli_parser()

Define the command line parser for the autocloser.

osa.utils.cliopts.calibration_pipeline_argparser()

Command line parser for the calibration pipeline.

osa.utils.cliopts.calibration_pipeline_cliparsing()

Set the global variables and parse the command line arguments for the calibration pipeline

osa.utils.cliopts.closer_argparser()
osa.utils.cliopts.closercliparsing()
osa.utils.cliopts.copy_datacheck_parsing()
osa.utils.cliopts.data_sequence_argparser()
osa.utils.cliopts.data_sequence_cli_parsing()
osa.utils.cliopts.get_calib_prod_id() str

Build calibration production ID.

osa.utils.cliopts.get_dl1_prod_id()

Get the prod ID for the dl1 products provided it is defined in the configuration file.

Returns:
dl1_prod_id: string
osa.utils.cliopts.get_dl2_prod_id()
Returns:
osa.utils.cliopts.get_prod_id()

Get production ID from the configuration file if it is defined. Otherwise, it takes the lstchain version used.

Returns:
prod_id: string
osa.utils.cliopts.provprocessparsing()
osa.utils.cliopts.sequencer_argparser()

Argument parser for sequencer script.

osa.utils.cliopts.sequencer_cli_parsing()
osa.utils.cliopts.sequencer_webmaker_argparser()
osa.utils.cliopts.set_default_date_if_needed()

Check if the date is set, if not set it to yesterday.

osa.utils.cliopts.simprocparsing()
osa.utils.cliopts.valid_date(string)

Check if the string is a valid date and return a datetime object.

Moving files and DB register

Move analysis products (calibration, DL1, data-checks, muons and DL2 files) to their final destinations and register them in the data base (the latter actions is not implemented yet).

Reference/API

Identify files to be moved to their final destination directories

osa.utils.register.register_files(run_str, analysis_dir, prefix, suffix, output_dir) None

Copy files into final data directory destination and register them into the DB (to be implemented).

Parameters:
run_str: str

Run number

analysis_dir: pathlib.Path

analysis directory

suffix: str

suffix of the data file

output_dir: pathlib.Path

final data directory

prefix: str

prefix of the data file

osa.utils.register.register_found_pattern(file_path: Path, seq_list: list, concept: str, destination_path: Path)
Parameters:
file_path: pathlib.Path
seq_list: list
concept: str
destination_path: pathlib.Path
osa.utils.register.register_non_existing_file(file_path, concept, seq_list)
Parameters:
file_path: pathlib.Path
concept: str
seq_list: list
osa.utils.register.register_run_concept_files(run_string, concept)

Prepare files to be moved to final destination directories from the running_analysis original directory.

Parameters:
run_string: str
concept: str

Utility functions

Handling of dates, directories and production IDs.

Reference/API

Functions to deal with dates and prod IDs.

osa.utils.utils.create_lock(lockfile) bool

Create a lock file to prevent multiple instances of the same analysis.

Parameters:
lockfile: pathlib.Path
Returns:
bool
osa.utils.utils.cron_lock(tel) Path

Create a lock file for the cron jobs.

osa.utils.utils.date_to_dir(date: datetime) str

Function to change from YYYY-MM-DD to YYYYMMDD format (used for directories).

osa.utils.utils.date_to_iso(date: datetime) str

Function to change from YYYY-MM-DD to YYYY-MM-DD.

osa.utils.utils.example_seq()

Example sequence table output for testing.

osa.utils.utils.get_calib_prod_id() str

Build calibration production ID.

osa.utils.utils.get_dl1_prod_id()

Get the prod ID for the dl1 products provided it is defined in the configuration file.

Returns:
dl1_prod_id: string
osa.utils.utils.get_dl2_prod_id()
Returns:
osa.utils.utils.get_lstchain_version()

Get the lstchain version.

Returns:
lstchain_version: string
osa.utils.utils.get_prod_id()

Get production ID from the configuration file if it is defined. Otherwise, it takes the lstchain version used.

Returns:
prod_id: string
osa.utils.utils.gettag()

Get the name of the script currently being used.

osa.utils.utils.is_day_closed() bool

Get the name and Check for the existence of the Closer flag file.

osa.utils.utils.is_defined(variable)

Check if a variable is already defined.

osa.utils.utils.is_night_time(hour)

Check if it is nighttime.

osa.utils.utils.night_finished_flag() Path

Create night-is-finished lock file.

Returns:
lockfile: pathlib.Path

Path of the lock file

osa.utils.utils.set_prod_ids()

Set the product IDs.

osa.utils.utils.stringify(args)

Join a list of arguments in a string.

osa.utils.utils.time_to_seconds(timestring)

Transform (D-)HH:MM:SS time format to seconds.

Parameters:
timestring: str or None

Time in format (D-)HH:MM:SS

Returns:
Seconds that correspond to (D-)HH:MM:SS
osa.utils.utils.wait_for_daytime(start=8, end=18)

Check every hour if it is still nighttime to not running jobs while it is still night.

I/O

Reading and writing files.

Reference/API

Handle the writing, reading and appending strings to files.

osa.utils.iofile.append_to_file(file: Path, content: str) None

Check if the file already exists and write the content in it.

Parameters:
file: pathlib.Path

The file to write in.

content: str

The content to write in the file.

osa.utils.iofile.write_to_file(file: Path, content: str)

Check if the file already exists and write the content in it.