Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.log.error(f"{err}. Use --help for more info")
exit_status = 2 # wrong cmd line parameter
except KeyboardInterrupt:
self.log.warning("WAS INTERRUPTED BY CTRL-C")
Provenance().finish_activity(activity_name=self.name, status="interrupted")
exit_status = 130 # Script terminated by Control-C
except Exception as err:
self.log.exception(f"Caught unexpected exception: {err}")
Provenance().finish_activity(activity_name=self.name, status="error")
exit_status = 1 # any other error
finally:
for activity in Provenance().finished_activities:
output_str = " ".join([x["url"] for x in activity.output])
self.log.info("Output: %s", output_str)
self.log.debug("PROVENANCE: '%s'", Provenance().as_json(indent=3))
with open("provenance.log", mode="w+") as provlog:
provlog.write(Provenance().as_json(indent=3))
self.exit(exit_status)
def write_subarray_description(self):
sub = self.subarray
ext, args = self._get_file_format_info(self.format, sub.name, "subarray")
tab = sub.to_table(kind="subarray")
tab.meta["SOURCE"] = self.infile
filename = f"{sub.name}.subarray.{ext}"
try:
tab.write(filename, **args)
Provenance().add_output_file(filename, "dl0.sub.svc.subarray")
except IOError as err:
self.log.warning(
"couldn't write subarray description '%s' because: %s", filename, err
)
----------
argv: list(str)
command-line arguments, or None to get them
from sys.argv automatically
"""
# return codes are taken from:
# http://tldp.org/LDP/abs/html/exitcodes.html
exit_status = 0
try:
self.initialize(argv)
self.log.info(f"Starting: {self.name}")
Provenance().start_activity(self.name)
self.setup()
self.is_setup = True
self.log.debug(f"CONFIG: {self.get_current_config()}")
Provenance().add_config(self.get_current_config())
self.start()
self.finish()
self.log.info(f"Finished: {self.name}")
Provenance().finish_activity(activity_name=self.name)
except ToolConfigurationError as err:
self.log.error(f"{err}. Use --help for more info")
exit_status = 2 # wrong cmd line parameter
except KeyboardInterrupt:
self.log.warning("WAS INTERRUPTED BY CTRL-C")
Provenance().finish_activity(activity_name=self.name, status="interrupted")
exit_status = 130 # Script terminated by Control-C
except Exception as err:
def write_optics_descriptions(self):
sub = self.subarray
ext, args = self._get_file_format_info(self.format, sub.name, "optics")
tab = sub.to_table(kind="optics")
tab.meta["SOURCE"] = self.infile
filename = f"{sub.name}.optics.{ext}"
try:
tab.write(filename, **args)
Provenance().add_output_file(filename, "dl0.sub.svc.optics")
except IOError as err:
self.log.warning(
"couldn't write optics description '%s' because: %s", filename, err
)
def _info_system():
# collect system info using the ctapipe provenance system :
print("\n*** ctapipe system environment ***\n")
prov = Provenance()
system_prov = prov.current_activity.provenance["system"]
for section in ["platform", "python"]:
print("\n====== ", section, " ======== \n")
sysinfo = system_prov[section]
for name, val in sysinfo.items():
print("{:>20.20s} -- {:<60.60s}".format(name, str(val)))
Set to None if no configuration to pass.
tool : ctapipe.core.Tool
Tool executable that is calling this component.
Passes the correct logger to the component.
Set to None if no Tool to pass.
kwargs
"""
super().__init__(config=config, parent=parent, input_url=input_url, **kwargs)
self.metadata = dict(is_simulation=False)
self.log.info(f"INPUT PATH = {self.input_url}")
if self.max_events:
self.log.info(f"Max events being read = {self.max_events}")
Provenance().add_input_file(str(self.input_url), role="DL0/Event")
def finish(self):
Provenance().add_output_file(
self.output, role="muon_efficiency_parameters",
)
self.writer.close()
def finish(self):
df_p, df_c = self.calculator.finish()
output_directory = os.path.dirname(self.output_path)
if not os.path.exists(output_directory):
self.log.info(f"Creating directory: {output_directory}")
os.makedirs(output_directory)
with pd.HDFStore(self.output_path, "w") as store:
store["charge_resolution_pixel"] = df_p
store["charge_resolution_camera"] = df_c
self.log.info("Created charge resolution file: {}".format(self.output_path))
Provenance().add_output_file(self.output_path)
from sys.argv automatically
"""
# return codes are taken from:
# http://tldp.org/LDP/abs/html/exitcodes.html
exit_status = 0
try:
self.initialize(argv)
self.log.info(f"Starting: {self.name}")
Provenance().start_activity(self.name)
self.setup()
self.is_setup = True
self.log.debug(f"CONFIG: {self.get_current_config()}")
Provenance().add_config(self.get_current_config())
self.start()
self.finish()
self.log.info(f"Finished: {self.name}")
Provenance().finish_activity(activity_name=self.name)
except ToolConfigurationError as err:
self.log.error(f"{err}. Use --help for more info")
exit_status = 2 # wrong cmd line parameter
except KeyboardInterrupt:
self.log.warning("WAS INTERRUPTED BY CTRL-C")
Provenance().finish_activity(activity_name=self.name, status="interrupted")
exit_status = 130 # Script terminated by Control-C
except Exception as err:
self.log.exception(f"Caught unexpected exception: {err}")
Provenance().finish_activity(activity_name=self.name, status="error")
exit_status = 1 # any other error
finally:
def write_camera_geometries(self):
cam_types = get_camera_types(self.subarray)
self.subarray.info(printer=self.log.info)
for cam_name in cam_types:
ext, args = self._get_file_format_info(self.format, "CAMGEOM", cam_name)
self.log.debug(f"writing {cam_name}")
tel_id = cam_types[cam_name].pop()
geom = self.subarray.tel[tel_id].camera.geometry
table = geom.to_table()
table.meta["SOURCE"] = self.infile
filename = f"{cam_name}.camgeom.{ext}"
try:
table.write(filename, **args)
Provenance().add_output_file(filename, "dl0.tel.svc.camera")
except IOError as err:
self.log.warning(
"couldn't write camera definition '%s' because: %s", filename, err
)