Skip to content

lstautorta.High_Level_analysis

Functions:

Name Description
get_current_obs_info

Retrieve current observation info from the shared observation file.

get_night_timestamp

Get current timestamp (YYYYMMDD) with respect to the night.

main

Initialize current_run_is and quit variables and get the current timestamp with Start_time = now()

now

Returns the current timestamp in seconds, relative to the Unix epoch.

wait_for_directory

Wait for the directory to exist

get_current_obs_info

get_current_obs_info(db_hostname='lst101', obs_target_query_timeout_s=10)

Retrieve current observation info from the shared observation file. Waits until the file is available.

Source code in src/lstautorta/High_Level_analysis.py
def get_current_obs_info(
    db_hostname: str = "lst101",
    obs_target_query_timeout_s: int = 10,
):
    """
    Retrieve current observation info from the shared observation file.
    Waits until the file is available.
    """
    logging.info("Waiting for shared observation file at %s", DEFAULT_SHARED_OBS_PATH)
    return wait_for_shared_obs(DEFAULT_SHARED_OBS_PATH)

get_night_timestamp

get_night_timestamp(today)

Get current timestamp (YYYYMMDD) with respect to the night. It will consider a same night everything run between 08h00 until 07h59 of the next day.

Ex: An observation launched at 04h00 (local time) will refer to the previous day.

:param today: datetime object datetime object with current local time

:return: timestamp: str

Source code in src/lstautorta/High_Level_analysis.py
def get_night_timestamp(today):
    """
    Get current timestamp (YYYYMMDD) with respect to the night.
    It will consider a same night everything run between 08h00 until 07h59 of the next day.

    Ex: An observation launched at 04h00 (local time) will refer to the previous day.

    :param today: datetime object
        datetime object with current local time

    :return:
        timestamp: str
    """
    # TODO check that today is a datetime object ?
    if today.hour < 8:  # script launched between
        yesterday = today - datetime.timedelta(days=1)
        timestamp = f"{yesterday.year:04d}{yesterday.month:02d}{yesterday.day:02d}"
    else:
        timestamp = f"{today.year:04d}{today.month:02d}{today.day:02d}"

    return timestamp

main

main()

Initialize current_run_is and quit variables and get the current timestamp with Start_time = now() Initialize the logging system by setting the log file name and logging level Change the current working directory to /fefs/onsite/pipeline/rta/data Find the current reservations for nodes using the scontrol command and parse the output to find the individual node names Modify a configuration file with sed commands, replacing placeholders with the node names found in step 4 Check if the ib0 network interface is in connected mode for each of the nodes and log the results

Source code in src/lstautorta/High_Level_analysis.py
def main():
    """
    Initialize current_run_is and quit variables and get the current timestamp with Start_time = now()
    Initialize the logging system by setting the log file name and logging level
    Change the current working directory to /fefs/onsite/pipeline/rta/data
    Find the current reservations for nodes using the scontrol command and parse the output to find the individual node names
    Modify a configuration file with sed commands, replacing placeholders with the node names found in step 4
    Check if the ib0 network interface is in connected mode for each of the nodes and log the results
    """
    current_run_is = -1
    quit = False

    Start_time = now()

    # today = str(datetime.datetime.now().year) + str(datetime.datetime.now().month) + str(datetime.datetime.now().day)
    today = get_night_timestamp(datetime.datetime.now())

    wait_for_directory("/fefs/onsite/pipeline/rta/data/" + today_to_directory(today))
    logging.basicConfig(
        filename="/fefs/onsite/pipeline/rta/data/" + today_to_directory(today) + "/log_High_Level_" + today + ".txt",
        level=logging.INFO,
    )
    logging.info("Start RTA High Level for the day " + today)

    RTA_ready = True

    loop_id = 0
    data_directory = "/fefs/onsite/pipeline/rta/data/"
    while quit == False and RTA_ready:
        time.sleep(10)
        obs_info = get_current_obs_info()
        if obs_info is None or obs_info.obs_id is None:
            logging.info("None")
            current_run_is = -1
            continue
        if current_run_is == -1:
            current_run_is = obs_info.obs_id
        if current_run_is != obs_info.obs_id:
            time.sleep(1)
            obs_info = get_current_obs_info()
            if obs_info is None or obs_info.obs_id is None:
                logging.info("None")
                current_run_is = -1
                continue
            current_run_is = obs_info.obs_id
            if current_run_is != -1:
                logging.info("Start RTA check for run " + str(current_run_is))
                time.sleep(2)
                source_ra, source_dec = get_source_ra_dec(obs_info)
                logging.info(
                    # ~ "srun --reservation=rta_one_node ./Theta_square.py -da "
                    "./Theta_square.py -da "
                    + today_to_directory(today)
                    + " -r "
                    + str(current_run_is)
                    + " -RA "
                    + str(source_ra)
                    + " -DEC "
                    + str(source_dec)
                )
                os.system(
                    # ~ "srun --reservation=rta_one_node ./Theta_square.py -da "
                    "./Theta_square.py -da "
                    + today_to_directory(today)
                    + " -r "
                    + str(current_run_is)
                    + " -RA "
                    + str(source_ra)
                    + " -DEC "
                    + str(source_dec)
                )
                logging.info(
                    # ~ "srun --reservation=rta_one_node ./Spectra.py -da "
                    "./Spectra.py -da "
                    + today_to_directory(today)
                    + " -r "
                    + str(current_run_is)
                    + " -RA "
                    + str(source_ra)
                    + " -DEC "
                    + str(source_dec)
                )
                os.system(
                    # ~ "srun --reservation=rta_one_node ./Spectra.py -da "
                    "./Spectra.py -da "
                    + today_to_directory(today)
                    + " -r "
                    + str(current_run_is)
                    + " -RA "
                    + str(source_ra)
                    + " -DEC "
                    + str(source_dec)
                )
                logging.info(
                    # ~ "srun --reservation=rta_one_node ./rta_var.py --dl3_folder "
                    "./rta_var.py --dl3_folder "
                    + data_directory
                    + today_to_directory(today)
                    + "/"
                    + str(current_run_is)
                    + "/DL3 -ra "
                    + str(source_ra)
                    + " -dec "
                    + str(source_dec)
                    + "  --output_dir "
                    + data_directory
                    + today_to_directory(today)
                    + "/"
                    + str(current_run_is)
                    + "/plots --date "
                    + today
                )
                os.system(
                    # ~ "srun --reservation=rta_one_node ./rta_var.py --dl3_folder "
                    "./rta_var.py --dl3_folder "
                    + data_directory
                    + today_to_directory(today)
                    + "/"
                    + str(current_run_is)
                    + "/DL3 -ra "
                    + str(source_ra)
                    + " -dec "
                    + str(source_dec)
                    + "  --output_dir "
                    + data_directory
                    + today_to_directory(today)
                    + "/"
                    + str(current_run_is)
                    + "/plots --date "
                    + today
                )

        if loop_id % 1 == 0:
            logging.info("Start RTA check for run " + str(current_run_is))
            time.sleep(2)
            logging.info(datetime.datetime.now())
            source_ra, source_dec = get_source_ra_dec(obs_info)
            logging.info(
                "./Theta_square.py -da "
                + today_to_directory(today)
                + " -r "
                + str(current_run_is)
                + " -RA "
                + str(source_ra)
                + " -DEC "
                + str(source_dec)
            )
            os.system(
                "./Theta_square.py -da "
                + today_to_directory(today)
                + " -r "
                + str(current_run_is)
                + " -RA "
                + str(source_ra)
                + " -DEC "
                + str(source_dec)
            )
            logging.info(
                "./Spectra.py -da "
                + today_to_directory(today)
                + " -r "
                + str(current_run_is)
                + " -RA "
                + str(source_ra)
                + " -DEC "
                + str(source_dec)
            )
            os.system(
                "./Spectra.py -da "
                + today_to_directory(today)
                + " -r "
                + str(current_run_is)
                + " -RA "
                + str(source_ra)
                + " -DEC "
                + str(source_dec)
            )
            logging.info(
                "./rta_var.py --dl3_folder  "
                + data_directory
                + today_to_directory(today)
                + "/"
                + str(current_run_is)
                + "/DL3 -ra "
                + str(source_ra)
                + " -dec "
                + str(source_dec)
                + "  --output_dir "
                + data_directory
                + today_to_directory(today)
                + "/"
                + str(current_run_is)
                + "/plots --date "
                + today
            )
            os.system(
                "./rta_var.py --dl3_folder  "
                + data_directory
                + today_to_directory(today)
                + "/"
                + str(current_run_is)
                + "/DL3 -ra "
                + str(source_ra)
                + " -dec "
                + str(source_dec)
                + "  --output_dir "
                + data_directory
                + today_to_directory(today)
                + "/"
                + str(current_run_is)
                + "/plots --date "
                + today
            )

        loop_id = loop_id + 1
        if (datetime.datetime.timestamp(datetime.datetime.now()) - Start_time) > 14 * 3600:
            quit = True
            logging.info("End of the night, Stop the RTA check")

now

now()

Returns the current timestamp in seconds, relative to the Unix epoch.

:return: float

Source code in src/lstautorta/High_Level_analysis.py
def now():
    """
    Returns the current timestamp in seconds, relative to the Unix epoch.

    :return: float
    """
    return datetime.datetime.timestamp(datetime.datetime.now())

wait_for_directory

wait_for_directory(directory, interval=5)

Wait for the directory to exist

:param directory: directory path :param interval: Time interval between verification

Source code in src/lstautorta/High_Level_analysis.py
def wait_for_directory(directory, interval=5):
    """
    Wait for the directory to exist

    :param directory: directory path
    :param interval: Time interval between verification
    """
    while not os.path.exists(directory):
        print(f"{directory} does not exist yet. let's wait {interval} seconds...")
        time.sleep(interval)
    print(f"The directory {directory} finally exist !!!")