def main(): print(f"\n--> Start calculating DRS4 pedestals from run {run}\n") try: # verify input file file_list = sorted(Path(f"{base_dir}/R0").rglob(f'*{run}.0000*')) if len(file_list) == 0: print(f">>> Error: Run {run} not found\n") raise NameError() else: input_file = f"{file_list[0]}" # find date input_dir, name = os.path.split(os.path.abspath(input_file)) path, date = input_dir.rsplit('/', 1) # verify and make output dir output_dir = f"{base_dir}/calibration/{date}/{prod_id}" if not os.path.exists(output_dir): print(f"--> Create directory {output_dir}") os.makedirs(output_dir, exist_ok=True) # make log dir log_dir = f"{output_dir}/log" if not os.path.exists(log_dir): print(f"--> Create directory {log_dir}") os.makedirs(log_dir, exist_ok=True) # define output file output_file = f"{output_dir}/drs4_pedestal.Run{run}.0000.fits" if os.path.exists(output_file): print(f">>> Output file {output_file} exists already. ") if query_yes_no("Do you want to remove it?"): os.remove(output_file) else: print(f">>> Exit") exit(1) # run lstchain script cmd = f"lstchain_data_create_drs4_pedestal_file --input_file {input_file} " \ f"--output_file {output_file} --max_events {max_events}" os.system(cmd) # plot and save some results plot_file = f"{output_dir}/log/drs4_pedestal.Run{run}.0000.pdf" print(f"\n--> PRODUCING PLOTS in {plot_file} ...") drs4.plot_pedestals(input_file, output_file, run, plot_file, tel_id=1, offset_value=300) print("\n--> END") except Exception as e: print(f"\n >>> Exception: {e}")
def test_plot_drs4(temp_dir_observed_files): pdf_filename = temp_dir_observed_files / "drs4_pedestal.Run2005.0000.pdf" plot_drs4.plot_pedestals( test_drs4_r0_path, test_drs4_pedestal_path, run=2005, plot_file=pdf_filename, tel_id=1, offset_value=400, sample_size=100, ) assert pdf_filename.is_file()
def main(): args = parser.parse_args() run = args.run_number prod_id = args.prod_version max_events = args.max_events base_dir = args.base_dir tel_id = args.tel_id yes = args.yes pro_symlink = not args.no_pro_symlink print(f"\n--> Start calculating DRS4 pedestals from run {run}\n") # verify input file r0_dir = args.r0_dir or Path(args.base_dir) / 'R0' input_file = find_r0_subrun(run, sub_run=0, r0_dir=r0_dir) date = input_file.parent.name # verify and make output dir calib_dir = base_dir / LEVEL_A_PIXEL_DIR output_dir = calib_dir / "drs4_baseline" / 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: create_pro_symlink(output_dir) # make log dir log_dir = output_dir / "log" if not log_dir.exists(): print(f"--> Create directory {log_dir}") os.makedirs(log_dir, exist_ok=True) # define output file output_file = output_dir / f"drs4_pedestal.Run{run:05d}.0000.h5" 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) else: print("\n--> Output file exists already. Stop") exit(1) # run lstchain script cmd = [ "lstchain_create_drs4_pedestal_file", f"--input={input_file}", f"--output={output_file}", f"--max-events={max_events}", ] if args.no_progress: cmd.append("--no-progress") subprocess.run(cmd, check=True) # plot and save some results plot_file = f"{output_dir}/log/drs4_pedestal.Run{run:05d}.0000.pdf" print(f"\n--> PRODUCING PLOTS in {plot_file} ...") drs4.plot_pedestals(input_file, output_file, run, plot_file, tel_id=tel_id, offset_value=400) print("\n--> END")