diff --git a/winterdrp/pipelines/sedmv2/blocks.py b/winterdrp/pipelines/sedmv2/blocks.py index b87364007..84d74cd82 100644 --- a/winterdrp/pipelines/sedmv2/blocks.py +++ b/winterdrp/pipelines/sedmv2/blocks.py @@ -21,7 +21,10 @@ sedmv2_reference_psfex, sedmv2_reference_sextractor, ) -from winterdrp.pipelines.sedmv2.load_sedmv2_image import load_raw_sedmv2_image +from winterdrp.pipelines.sedmv2.load_sedmv2_image import ( + load_proc_sedmv2_image, + load_raw_sedmv2_image, +) from winterdrp.processors import BiasCalibrator, FlatCalibrator from winterdrp.processors.anet import AstrometryNet from winterdrp.processors.astromatic import PSFex, Sextractor, Swarp @@ -57,6 +60,10 @@ ImageLoader(load_image=load_raw_sedmv2_image), ] +load_proc = [ + ImageLoader(load_image=load_proc_sedmv2_image), +] + cal_hunter = [ CalHunter(load_image=load_raw_sedmv2_image, requirements=sedmv2_cal_requirements), ] @@ -193,18 +200,22 @@ ), Sextractor( output_sub_dir="subtract", - cache=False, + cache=True, write_regions_bool=True, **sextractor_photometry_config ), PSFex(config_path=psfex_config_path, output_sub_dir="subtract", norm_fits=True), - ImageSaver(output_dir_name="ref"), + # ImageSaver(output_dir_name="ref"), ZOGYPrepare( output_sub_dir="subtract", sci_zp_header_key="ZP_AUTO", catalog_purifier=default_sedmv2_catalog_purifier, + write_region_bool=True, + ), + ZOGY( + output_sub_dir="subtract", + sci_zp_header_key="ZP_AUTO", ), - ZOGY(output_sub_dir="subtract"), ] imsub = subtract # + export_diff_to_db + extract_candidates diff --git a/winterdrp/pipelines/sedmv2/generator.py b/winterdrp/pipelines/sedmv2/generator.py index e77ac5b95..bca0f8def 100644 --- a/winterdrp/pipelines/sedmv2/generator.py +++ b/winterdrp/pipelines/sedmv2/generator.py @@ -125,6 +125,7 @@ def sedmv2_reference_sextractor(output_sub_dir: str, gain: float) -> Sextractor: gain=gain, output_sub_dir=output_sub_dir, cache=True, + write_regions_bool=True, **sextractor_photometry_config, ) diff --git a/winterdrp/pipelines/sedmv2/load_sedmv2_image.py b/winterdrp/pipelines/sedmv2/load_sedmv2_image.py index f1eeea246..9059ed372 100644 --- a/winterdrp/pipelines/sedmv2/load_sedmv2_image.py +++ b/winterdrp/pipelines/sedmv2/load_sedmv2_image.py @@ -86,6 +86,67 @@ def load_raw_sedmv2_image(path: str) -> tuple[np.array, astropy.io.fits.Header]: return data[0].data, data[0].header # pylint: disable=no-member +def load_proc_sedmv2_image(path: str) -> tuple[np.array, astropy.io.fits.Header]: + """ + Function to load a raw SEDMv2 image + + :param path:- path of file + :return: data and header of image + """ + + with fits.open(path) as data: + header = data[0].header # pylint: disable=no-member + + if "PREPTAG" not in header.keys(): + if "IMGTYPE" in header.keys(): + path_new = prepare_science(path) + else: # IMGTYPE not in cal; may change w updated cal files + path_new = prepare_cal(path) + data = fits.open(path_new) + header = data[0].header # pylint: disable=no-member + + header["TARGET"] = header["OBSTYPE"].lower() + data[0].data = data[0].data * 1.0 # pylint: disable=no-member + header.append(("GAIN", 1.0, "Gain in electrons / ADU"), end=True) + + # positions + header["RA"] = header["RAD"] + header["DEC"] = header["DECD"] + header["TELRA"] = header["TELRAD"] + header["TELDEC"] = header["TELDECD"] + + # keys, IDs + base_name = os.path.basename(path) + header[BASE_NAME_KEY] = base_name + header[LATEST_SAVE_KEY] = path + header[RAW_IMG_KEY] = path + header[PROC_HISTORY_KEY] = "" + header[PROC_FAIL_KEY] = "" + pipeline_version = __version__ + pipeline_version_padded_str = "".join( + [x.rjust(2, "0") for x in pipeline_version.split(".")] + ) + header["PROCID"] = int(str(header["EXPID"]) + str(pipeline_version_padded_str)) + header["OBSID"] = 0 + header["PROGID"] = int(3) # sedmv2's ID + header["FIELDID"] = 999999999 + header["COADDS"] = 1 + header["BZERO"] = 0 + + header["UTC"] = "20221223_00:00:00" + header["UTCTIME"] = header["UTC"] + header["TIMEUTC"] = header["UTCTIME"] + header["OBSDATE"] = int(header["UTC"].split("_")[0]) + header["NIGHT"] = int(Time(header["DATE"], format="isot").jd) - int( + Time("2018-01-01", format="iso").jd + ) # integer value, night 1, night 2... + header["EXPMJD"] = header["OBSDATE"] + + image_data = data[0].data + image_data[image_data == 0] = np.nan + return image_data, data[0].header # pylint: disable=no-member + + def prepare_science(filepath: str) -> str: """ Additional steps to get sedmv2 science files into working order diff --git a/winterdrp/pipelines/sedmv2/sedmv2_pipeline.py b/winterdrp/pipelines/sedmv2/sedmv2_pipeline.py index b6b79eb56..56ea66276 100644 --- a/winterdrp/pipelines/sedmv2/sedmv2_pipeline.py +++ b/winterdrp/pipelines/sedmv2/sedmv2_pipeline.py @@ -11,6 +11,8 @@ from winterdrp.pipelines.base_pipeline import Pipeline from winterdrp.pipelines.sedmv2.blocks import ( cal_hunter, + imsub, + load_proc, load_raw, process, process_stellar, @@ -37,6 +39,7 @@ class SEDMv2Pipeline(Pipeline): "default": load_raw + cal_hunter + process, "default_stellar": load_raw + cal_hunter + process_stellar, # +image_photometry "default_transient": load_raw + cal_hunter + process_transient, # +imsub, + "imsub": load_proc + imsub, } @staticmethod diff --git a/winterdrp/processors/zogy/zogy.py b/winterdrp/processors/zogy/zogy.py index 3782b49b3..b1e6840d0 100644 --- a/winterdrp/processors/zogy/zogy.py +++ b/winterdrp/processors/zogy/zogy.py @@ -270,6 +270,7 @@ def _apply_to_images(self, batch: ImageBatch) -> ImageBatch: sci_catalog_path = image["SRCCAT"] # convert to key sci_mask_path = image[LATEST_WEIGHT_SAVE_KEY] + logger.debug(f"{self.get_path(sci_mask_path)}") ref_weight_data = self.open_fits(self.get_path(ref_mask_path)) sci_weight_data = self.open_fits(self.get_path(sci_mask_path)) @@ -291,6 +292,8 @@ def _apply_to_images(self, batch: ImageBatch) -> ImageBatch: scorr_weight_path = sci_img_path.replace(".fits", ".scorr.weight.fits") self.save_fits(scorr_weight_img, path=self.get_path(scorr_weight_path)) + logger.info(f"{sci_weight_data.get_data()}") + ast_unc_x, ast_unc_y, flux_scale = self.get_ast_fluxscale( ref_catalog_path, sci_catalog_path ) @@ -298,7 +301,6 @@ def _apply_to_images(self, batch: ImageBatch) -> ImageBatch: # Scale reference image ref_data *= flux_scale ref_img.set_data(ref_data) - ref_unscaled_zp = ref_img["ZP"] ref_img["ZP"] = float(ref_img["ZP"]) + 2.5 * np.log10(flux_scale) @@ -329,6 +331,14 @@ def _apply_to_images(self, batch: ImageBatch) -> ImageBatch: sci_rms_image = self.get_rms_image(image, sci_rms) ref_rms_image = self.get_rms_image(ref_img, ref_rms) + sci_rms_data = sci_rms_image.get_data() + sci_rms_data[image_mask] = 0 + sci_rms_image.set_data(sci_rms_data) + + ref_rms_data = ref_rms_image.get_data() + ref_rms_data[image_mask] = 0 + ref_rms_image.set_data(ref_rms_data) + sci_rms_path = sci_img_path + ".unc" ref_rms_path = ref_img_path + ".unc"