Skip to content

Commit

Permalink
Merge pull request #248 from cta-observatory/fix-telid
Browse files Browse the repository at this point in the history
use tel id from config.yaml
  • Loading branch information
jsitarek authored Aug 13, 2024
2 parents 959868e + c744bdc commit 8f93fd2
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
logger.setLevel(logging.INFO)


def configfile_coincidence(target_dir, source_name, config_gen):
def configfile_coincidence(target_dir, source_name, config_file):

"""
This function creates the configuration file needed for the event coincidence step
Expand All @@ -49,10 +49,10 @@ def configfile_coincidence(target_dir, source_name, config_gen):
Path to the working directory
source_name : str
Name of the target source
config_gen : dict
Dictionary of the entries of the general configuration file
config_file : str
Path to MCP configuration file (e.g., resources/config.yaml)
"""
config_file = config_gen["general"]["base_config_file"]

if config_file == "":
config_file = resource_file("config.yaml")

Expand All @@ -62,7 +62,7 @@ def configfile_coincidence(target_dir, source_name, config_gen):
config_dict = yaml.safe_load(fc)

conf = {
"mc_tel_ids": config_gen["mc_tel_ids"],
"mc_tel_ids": config_dict["mc_tel_ids"],
"event_coincidence": config_dict["event_coincidence"],
}

Expand Down Expand Up @@ -193,6 +193,7 @@ def main():

env_name = config["general"]["env_name"]
LST_version = config["general"]["LST_version"]
config_file = config["general"]["base_config_file"]

source_in = config["data_selection"]["source_name_database"]
source = config["data_selection"]["source_name_output"]
Expand All @@ -209,7 +210,7 @@ def main():
for source_name in source_list:

print("***** Generating file config_coincidence.yaml...")
configfile_coincidence(target_dir, source_name, config)
configfile_coincidence(target_dir, source_name, config_file)

LST_runs_and_dates = f"{source_name}_LST_runs.txt"
LST_runs = np.genfromtxt(LST_runs_and_dates, dtype=str, delimiter=",", ndmin=2)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
mc_tel_ids:
LST-1: 1
LST-2: 0
LST-3: 0
LST-4: 0
MAGIC-I: 2
MAGIC-II: 3

directories:
workspace_dir : "/fefs/aswg/workspace/elisa.visentin/auto_MCP_PR/" # Output directory where all the data products will be saved.
# MC paths below are ignored if you set NSB_matching = true.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def main():
"-c",
dest="config_file",
type=str,
default="./config_auto_MCP.yaml",
default="../config_auto_MCP.yaml",
help="Path to a configuration file",
)
parser.add_argument(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def main():
"-c",
dest="config_file",
type=str,
default="./config_auto_MCP.yaml",
default="../config_auto_MCP.yaml",
help="Path to a configuration file",
)
parser.add_argument(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
logger.setLevel(logging.INFO)


def config_file_gen(target_dir, noise_value, NSB_match, source_name, config_gen):
def config_file_gen(target_dir, noise_value, NSB_match, source_name, config_file):

"""
Here we create the configuration file needed for transforming DL0 into DL1
Expand All @@ -58,25 +58,27 @@ def config_file_gen(target_dir, noise_value, NSB_match, source_name, config_gen)
If real data are matched to pre-processed MCs or not
source_name : str
Name of the target source
config_gen : dict
Dictionary of the entries of the general configuration file
config_file : str
Path to MCP configuration file (e.g., resources/config.yaml)
"""
config_file = config_gen["general"]["base_config_file"]

if config_file == "":
config_file = resource_file("config.yaml")
with open(
config_file, "rb"
) as fc: # "rb" mode opens the file in binary format for reading
config_dict = yaml.safe_load(fc)

LST_config = config_dict["LST"]
MAGIC_config = config_dict["MAGIC"]

if not NSB_match:
LST_config["increase_nsb"]["extra_noise_in_dim_pixels"] = noise_value[0]
LST_config["increase_nsb"]["extra_bias_in_dim_pixels"] = noise_value[2]
LST_config["increase_nsb"]["extra_noise_in_bright_pixels"] = noise_value[1]

conf = {
"mc_tel_ids": config_gen["mc_tel_ids"],
"mc_tel_ids": config_dict["mc_tel_ids"],
"LST": LST_config,
"MAGIC": MAGIC_config,
}
Expand Down Expand Up @@ -435,8 +437,8 @@ def main():
telescope_ids = list(config["mc_tel_ids"].values())
env_name = config["general"]["env_name"]
NSB_match = config["general"]["NSB_matching"]
config_file = config["general"]["base_config_file"]

# LST_runs_and_dates = config["general"]["LST_runs"]
MC_gammas = config["directories"]["MC_gammas"]
MC_electrons = config["directories"]["MC_electrons"]
MC_helium = config["directories"]["MC_helium"]
Expand All @@ -455,6 +457,7 @@ def main():
if source is None:
source = source_in
source_list = [source]

noise_value = [0, 0, 0]
if not NSB_match:
nsb = config["general"]["NSB_MC"]
Expand All @@ -469,9 +472,7 @@ def main():
directories_generator_MC(
str(target_dir), telescope_ids
) # Here we create all the necessary directories in the given workspace and collect the main directory of the target
config_file_gen(
target_dir, noise_value, NSB_match, "MC", config
) # TODO: fix here
config_file_gen(target_dir, noise_value, NSB_match, "MC", config_file)
to_process = {
"gammas": MC_gammas,
"electrons": MC_electrons,
Expand Down Expand Up @@ -521,9 +522,8 @@ def main():
str(target_dir), telescope_ids, MAGIC_runs, NSB_match, source_name
) # Here we create all the necessary directories in the given workspace and collect the main directory of the target
config_file_gen(
target_dir, noise_value, NSB_match, source_name, config
) # TODO: fix here

target_dir, noise_value, NSB_match, source_name, config_file
)
# Below we run the analysis on the MAGIC data

lists_and_bash_gen_MAGIC(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
logger.setLevel(logging.INFO)


def configfile_stereo(target_dir, source_name, config_gen):
def configfile_stereo(target_dir, source_name, config_file):

"""
This function creates the configuration file needed for the stereo reconstruction step
Expand All @@ -51,11 +51,10 @@ def configfile_stereo(target_dir, source_name, config_gen):
Path to the working directory
source_name : str
Name of the target source
config_gen : dict
Dictionary of the entries of the general configuration file
config_file : str
Path to MCP configuration file (e.g., resources/config.yaml)
"""

config_file = config_gen["general"]["base_config_file"]
if config_file == "":
config_file = resource_file("config.yaml")

Expand All @@ -64,7 +63,7 @@ def configfile_stereo(target_dir, source_name, config_gen):
) as fc: # "rb" mode opens the file in binary format for reading
config_dict = yaml.safe_load(fc)
conf = {
"mc_tel_ids": config_gen["mc_tel_ids"],
"mc_tel_ids": config_dict["mc_tel_ids"],
"stereo_reco": config_dict["stereo_reco"],
}
if source_name == "MC":
Expand Down Expand Up @@ -234,6 +233,7 @@ def main():
target_dir = Path(config["directories"]["workspace_dir"])

env_name = config["general"]["env_name"]
config_file = config["general"]["base_config_file"]

NSB_match = config["general"]["NSB_matching"]
source_in = config["data_selection"]["source_name_database"]
Expand All @@ -253,7 +253,7 @@ def main():
or (args.analysis_type == "doEverything")
and not NSB_match
):
configfile_stereo(target_dir, "MC", config)
configfile_stereo(target_dir, "MC", config_file)
print("***** Generating the bashscript for MCs...")
for part in [
"gammadiffuse",
Expand Down Expand Up @@ -284,7 +284,7 @@ def main():
or (NSB_match)
):
print("***** Generating file config_stereo.yaml...")
configfile_stereo(target_dir, source_name, config)
configfile_stereo(target_dir, source_name, config_file)

# Below we run the analysis on the real data

Expand Down

0 comments on commit 8f93fd2

Please sign in to comment.