def test_find_run_summary(): from lstchain.onsite import find_run_summary # find by run_id path = find_run_summary(date='20200218', base_dir=BASE_DIR) assert path.name == 'RunSummary_20200218.ecsv' path = find_run_summary(date='20201120', base_dir=BASE_DIR) assert path.name == 'RunSummary_20201120.ecsv' with pytest.raises(IOError): find_run_summary(date='20221120', base_dir=BASE_DIR)
def main(): args = parser.parse_args() run = args.run_number prod_id = args.prod_version stat_events = args.statistics time_run = args.time_run sys_date = args.sys_date no_sys_correction = args.no_sys_correction output_base_name = args.output_base_name sub_run = args.sub_run tel_id = args.tel_id config_file = args.config yes = args.yes pro_symlink = not args.no_pro_symlink # looks for the filter values in the database if not given if args.filters is None: filters = search_filter(run, args.mongodb) else: filters = args.filters if filters is None: sys.exit(f"Missing filter value for run {run}. \n") # define the FF selection cuts if args.min_ff is None or args.max_ff is None: min_ff, max_ff = define_FF_selection_range(filters) else: min_ff, max_ff = args.min_ff, args.max_ff print(f"\n--> Start calculating calibration from run {run}, filters {filters}") # verify config file if not config_file.exists(): raise IOError(f"Config file {config_file} does not exists. \n") print(f"\n--> Config file {config_file}") # verify input file r0_dir = args.r0_dir or args.base_dir / 'R0' input_file = find_r0_subrun(run, sub_run, r0_dir) date = input_file.parent.name print(f"\n--> Input file: {input_file}") # verify output dir calib_dir = args.base_dir / LEVEL_A_PIXEL_DIR output_dir = calib_dir / "calibration" / date / prod_id if not output_dir.exists(): print(f"--> Create directory {output_dir}") output_dir.mkdir(parents=True, exist_ok=True) if pro_symlink: pro = "pro" create_pro_symlink(output_dir) else: pro = prod_id # make log dir log_dir = output_dir / "log" if not log_dir.exists(): print(f"--> Create directory {log_dir}") log_dir.mkdir(parents=True, exist_ok=True) # search the summary file info run_summary_path = find_run_summary(date, args.base_dir) print(f"\n--> Use run summary {run_summary_path}") pedestal_file = find_pedestal_file(pro, args.pedestal_run, date=date, base_dir=args.base_dir) print(f"\n--> Pedestal file: {pedestal_file}") # search for time calibration file time_file = find_time_calibration_file(pro, run, time_run, args.base_dir) print(f"\n--> Time calibration file: {time_file}") # define systematic correction file if no_sys_correction: systematics_file = None else: systematics_file = find_systematics_correction_file(pro, date, sys_date, args.base_dir) print(f"\n--> F-factor systematics correction file: {systematics_file}") # define charge file names print("\n***** PRODUCE CHARGE CALIBRATION FILE ***** ") if filters is not None: filter_info = f"_filters_{filters}" else: filter_info = "" # remember there are no systematic corrections prefix = "no_sys_corrected_" if no_sys_correction else "" output_name = f"{prefix}{output_base_name}{filter_info}.Run{run:05d}.{sub_run:04d}" output_file = output_dir / f'{output_name}.h5' print(f"\n--> Output file {output_file}") log_file = log_dir / f"{output_name}.log" print(f"\n--> Log file {log_file}") if output_file.exists(): remove = False if not yes and os.getenv('SLURM_JOB_ID') is None: remove = query_yes_no(">>> Output file exists already. Do you want to remove it?") if yes or remove: os.remove(output_file) os.remove(log_file) else: print("\n--> Output file exists already. Stop") exit(1) # # produce ff calibration file # cmd = [ "lstchain_create_calibration_file", f"--input_file={input_file}", f"--output_file={output_file}", "--LSTEventSource.default_trigger_type=tib", f"--EventSource.min_flatfield_adc={min_ff}", f"--EventSource.max_flatfield_adc={max_ff}", f"--LSTCalibrationCalculator.systematic_correction_path={systematics_file}", f"--LSTEventSource.EventTimeCalculator.run_summary_path={run_summary_path}", f"--LSTEventSource.LSTR0Corrections.drs4_time_calibration_path={time_file}", f"--LSTEventSource.LSTR0Corrections.drs4_pedestal_path={pedestal_file}", f"--LSTEventSource.use_flatfield_heuristic={args.use_flatfield_heuristic}", f"--FlatFieldCalculator.sample_size={stat_events}", f"--PedestalCalculator.sample_size={stat_events}", f"--config={config_file}", f"--log-file={log_file}", "--log-file-level=DEBUG", ] print("\n--> RUNNING...") subprocess.run(cmd, check=True) # plot and save some results plot_file = f"{output_dir}/log/{output_name}.pdf" print(f"\n--> PRODUCING PLOTS in {plot_file} ...") calib.read_file(output_file, tel_id) calib.plot_all(calib.ped_data, calib.ff_data, calib.calib_data, run, plot_file) print("\n--> END")
def main(): args = parser.parse_args() run = args.run_number prod_id = args.prod_version stat_events = args.statistics base_dir = args.base_dir sub_run = args.sub_run config_file = args.config pro_symlink = not args.no_pro_symlink print(f"\n--> Start calculating drs4 time corrections from run {run}") # verify config file if not config_file.exists(): raise IOError(f"Config file {config_file} does not exists. \n") print(f"\n--> Config file {config_file}") # verify input file r0_dir = args.r0_dir or Path(args.base_dir) / 'R0' input_file = find_r0_subrun(run, sub_run, r0_dir) date = input_file.parent.name print(f"\n--> Input file: {input_file}") # verify output dir calib_dir = base_dir / LEVEL_A_PIXEL_DIR output_dir = calib_dir / "drs4_time_sampling_from_FF" / date / prod_id if not output_dir.exists(): print(f"--> Create directory {output_dir}") output_dir.mkdir(parents=True, exist_ok=True) # update the default production directory if pro_symlink: pro = "pro" create_pro_symlink(output_dir) else: pro = prod_id run_summary_path = find_run_summary(date, args.base_dir) print(f"\n--> Use run summary {run_summary_path}") pedestal_file = find_pedestal_file(pro, args.pedestal_run, date=date, base_dir=args.base_dir) print(f"\n--> Pedestal file: {pedestal_file}") time_file = output_dir / f"time_calibration.Run{run:05d}.0000.h5" print(f"\n--> PRODUCING TIME CALIBRATION in {time_file} ...") cmd = [ "lstchain_data_create_time_calibration_file", f"--input-file={input_file}", f"--output-file={time_file}", f"--config={config_file}", f"--run-summary-path={run_summary_path}", f"--pedestal-file={pedestal_file}", f"--max-events={stat_events}", ] if args.no_progress: cmd.append("--no-progress") print("\n--> RUNNING...") subprocess.run(cmd, check=True) print("\n--> END")