diff --git a/bin/drp b/bin/drp index e1dac83d..06588b04 100755 --- a/bin/drp +++ b/bin/drp @@ -115,12 +115,13 @@ cli.add_command(metacli) @click.option('-f', '--use-fiducial-master', is_flag=True, default=False, help='use fiducial master calibration frames') @click.option('-s', '--skip-sky-subtraction', is_flag=True, help='skip sky subtraction') @click.option('--sky-weights', type=(float, float), default=None, help='weights (east, west) for the master sky combination') +@click.option('-c', '--skip-flux-calibration', is_flag=True, default=False, help='skip flux calibration') @click.option('-n', '--ncpus', type=int, default=None, help='number of CPUs to use during extraction') @click.option("-a", "--aperture-extraction", is_flag=True, default=False, help="run quick reduction with aperture extraction") def quick_reduction(expnum: int, use_fiducial_master: bool, skip_sky_subtraction: bool, - sky_weights: tuple, ncpus: int, aperture_extraction: bool) -> None: + sky_weights: tuple, skip_flux_calibration: bool, ncpus: int, aperture_extraction: bool) -> None: quick_science_reduction(expnum, use_fiducial_master, skip_sky_subtraction, - sky_weights, ncpus, aperture_extraction) + sky_weights, skip_flux_calibration, ncpus, aperture_extraction) # register quick DRP command diff --git a/python/lvmdrp/functions/fluxCalMethod.py b/python/lvmdrp/functions/fluxCalMethod.py index 4ee7b049..3e6e12ab 100644 --- a/python/lvmdrp/functions/fluxCalMethod.py +++ b/python/lvmdrp/functions/fluxCalMethod.py @@ -66,8 +66,7 @@ "correctTelluric_drp", ] - -def apply_fluxcal(in_rss: str, out_rss: str, display_plots: bool = False): +def apply_fluxcal(in_rss: str, out_rss: str, skip_fluxcal: bool = False, display_plots: bool = False): """applies flux calibration to spectrograph-combined data Parameters @@ -76,6 +75,8 @@ def apply_fluxcal(in_rss: str, out_rss: str, display_plots: bool = False): input RSS file out_rss : str output RSS file + skip_fluxcal : bool, optional + whether to skip flux calibration, by default False display_plots : bool, optional Returns @@ -123,7 +124,7 @@ def apply_fluxcal(in_rss: str, out_rss: str, display_plots: bool = False): sens_ave = biweight_location(sens_arr, axis=1, ignore_nan=True) sens_rms = biweight_scale(sens_arr, axis=1, ignore_nan=True) - # fix all zeros + # fix case of all invalid values if (sens_ave == 0).all() or np.isnan(sens_ave).all(): log.warning( "all sensitivity values are zero or NaN, impossible to flux-calibrate" @@ -168,12 +169,21 @@ def apply_fluxcal(in_rss: str, out_rss: str, display_plots: bool = False): ext = np.interp(rss._wave, lext, ext) sci_secz = rss._header["TESCIAM"] - log.info("flux-calibrating data science and sky spectra") - - rss._data *= sens_ave * 10 ** (0.4 * ext * (sci_secz)) / exptimes[:, None] - rss._error *= sens_ave * 10 ** (0.4 * ext * (sci_secz)) / exptimes[:, None] - rss._sky *= sens_ave * 10 ** (0.4 * ext * (sci_secz)) / exptimes[:, None] - rss._sky_error *= sens_ave * 10 ** (0.4 * ext * (sci_secz)) / exptimes[:, None] + # optionally sky flux calibration + if skip_fluxcal: + log.info("skipping flux calibration") + rss._data /= exptimes[:, None] + rss._error /= exptimes[:, None] + rss._sky /= exptimes[:, None] + rss._sky_error /= exptimes[:, None] + rss.setHdrValue("FLUXCAL", False, "flux-calibrated?") + rss.setHdrValue("BUNIT", "electron/s/A", "flux units") + else: + log.info("flux-calibrating data science and sky spectra") + rss._data *= sens_ave * 10 ** (0.4 * ext * (sci_secz)) / exptimes[:, None] + rss._error *= sens_ave * 10 ** (0.4 * ext * (sci_secz)) / exptimes[:, None] + rss._sky *= sens_ave * 10 ** (0.4 * ext * (sci_secz)) / exptimes[:, None] + rss._sky_error *= sens_ave * 10 ** (0.4 * ext * (sci_secz)) / exptimes[:, None] log.info(f"writing output file in {os.path.basename(out_rss)}") rss.writeFitsData(out_rss) diff --git a/python/lvmdrp/functions/run_quickdrp.py b/python/lvmdrp/functions/run_quickdrp.py index 80021d4f..5cab26cc 100644 --- a/python/lvmdrp/functions/run_quickdrp.py +++ b/python/lvmdrp/functions/run_quickdrp.py @@ -119,6 +119,7 @@ def get_master_mjd(sci_mjd: int) -> int: def quick_science_reduction(expnum: int, use_fiducial_master: bool = False, skip_sky_subtraction: bool = False, sky_weights: Tuple[float, float] = None, + skip_flux_calibration: bool = False, ncpus: int = None, aperture_extraction: bool = False) -> None: """ Run the Quick DRP for a given exposure number. @@ -275,7 +276,7 @@ def quick_science_reduction(expnum: int, use_fiducial_master: bool = False, sci_paths = sorted(drp.path.expand("lvm_anc", drpver=drpver, tileid=sci_tileid, mjd=sci_mjd, kind="", imagetype="object", camera="*", expnum=sci_expnum)) sci_paths = [sci_path for sci_path in sci_paths if "lvm-object-sp" not in sci_path] for sci_path in sci_paths: - flux_tasks.apply_fluxcal(in_rss=sci_path, out_rss=sci_path) + flux_tasks.apply_fluxcal(in_rss=sci_path, out_rss=sci_path, skip_fluxcal=skip_flux_calibration) # combine channels drp.combine_channels(tileid=sci_tileid, mjd=sci_mjd, expnum=sci_expnum)