Skip to content

Commit

Permalink
Replaced print with logging in contexts.py (#125)
Browse files Browse the repository at this point in the history
* log instead of print

* fixed docstr

* better annotation
  • Loading branch information
FaroutYLq authored Apr 23, 2024
1 parent 170e374 commit dfdf4b0
Showing 3 changed files with 20 additions and 18 deletions.
10 changes: 6 additions & 4 deletions jobs/job.py
Original file line number Diff line number Diff line change
@@ -175,15 +175,16 @@ def main():
print_versions()
_, runid = sys.argv
runid = int(runid)
settings = load_config()


# Process the saltax desired mode
logging.info("Loading context...")
settings = load_config()
st = create_context(settings, runid)
data_types = get_data_types(settings)
process_data_types(st, str(runid).zfill(6), data_types)

# Process data-only mode if required
if settings["process_data"]:
if settings["process_data"] and settings["saltax_mode"] == "salt":
logging.info("====================")
logging.info("Now starting data-only context for run %d" % runid)
settings_temp = settings.copy()
@@ -192,7 +193,8 @@ def main():
process_data_types(st_data, str(runid).zfill(6), data_types)
logging.info("Finished processing for data-only mode.")

if settings["process_simu"]:
# Process simu-only mode if required
if settings["process_simu"] and settings["saltax_mode"] == "salt":
logging.info("====================")
logging.info("Now starting simu-only context for run %d" % runid)
settings_temp = settings.copy()
26 changes: 13 additions & 13 deletions saltax/contexts.py
Original file line number Diff line number Diff line change
@@ -223,7 +223,7 @@ def xenonnt_salted_fuse(
if processing_config in st.config:
st.config[mc_config] = st.config[processing_config]
else:
print(f"Warning! {processing_config} not in context config, skipping...")
log.warning(f"Warning! {processing_config} not in context config, skipping...")

# No blinding in simulations
st.config["event_info_function"] = "disabled"
@@ -252,12 +252,12 @@ def xenonnt_salted_fuse(
# Try to load instruction from file and generate if not found
try:
instr = pd.read_csv(instr_file_name)
print("Loaded instructions from file", instr_file_name)
log.info("Loaded instructions from file", instr_file_name)
except:
print(f"Instruction file {instr_file_name} not found. Generating instructions...")
log.info(f"Instruction file {instr_file_name} not found. Generating instructions...")
instr = generator_func(runid=runid, **kwargs)
pd.DataFrame(instr).to_csv(instr_file_name, index=False)
print(f"Instructions saved to {instr_file_name}")
log.info(f"Instructions saved to {instr_file_name}")

# Load instructions into config
st.set_config(
@@ -324,12 +324,12 @@ def xenonnt_salted_wfsim(
if runid is not None:
try:
instr = pd.read_csv(instr_file_name)
print("Loaded instructions from file", instr_file_name)
log.info("Loaded instructions from file", instr_file_name)
except:
print(f"Instruction file {instr_file_name} not found. Generating instructions...")
log.info(f"Instruction file {instr_file_name} not found. Generating instructions...")
instr = generator_func(runid=runid, **kwargs)
pd.DataFrame(instr).to_csv(instr_file_name, index=False)
print(f"Instructions saved to {instr_file_name}")
log.info(f"Instructions saved to {instr_file_name}")

# Based on cutax.xenonnt_sim_base()
fax_conf = "fax_config_nt_{:s}.json".format(simu_config_version)
@@ -470,12 +470,12 @@ def fxenonnt(
"""
assert saltax_mode in SALTAX_MODES, "saltax_mode must be one of %s" % (SALTAX_MODES)
if runid is None:
print(
log.warning(
"Since you specified runid=None, this context will not be able to compute raw_records_simu."
)
print("Welcome to data-loading only mode!")
log.warning("Welcome to data-loading only mode!")
else:
print("Welcome to computation mode which only works for run %s!" % (runid))
log.warning("Welcome to computation mode which only works for run %s!" % (runid))

return xenonnt_salted_fuse(
runid=runid,
@@ -539,12 +539,12 @@ def sxenonnt(
"""
assert saltax_mode in SALTAX_MODES, "saltax_mode must be one of %s" % (SALTAX_MODES)
if runid is None:
print(
log.warning(
"Since you specified runid=None, this context will not be able to compute raw_records_simu."
)
print("Welcome to data-loading only mode!")
log.warning("Welcome to data-loading only mode!")
else:
print("Welcome to computation mode which only works for run %s!" % (runid))
log.warning("Welcome to computation mode which only works for run %s!" % (runid))

return xenonnt_salted_wfsim(
runid=runid,
2 changes: 1 addition & 1 deletion saltax/instructions/generator.py
Original file line number Diff line number Diff line change
@@ -385,7 +385,7 @@ def generator_flat(
"""Generate instructions for a run with flat energy spectrum.
:param runid: run number in integer
:param en_range: (en_min, en_max) in keV, default: (0, 30.0)
:param en_range: (en_min, en_max) in keV, default: (0.2, 15.0)
:param recoil: NEST recoil type, default: 8 (beta ER)
:param n_tot: total number of events to generate, default: None i.e.
generate events until end_time

0 comments on commit dfdf4b0

Please sign in to comment.