Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update zogy #347

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions winterdrp/pipelines/sedmv2/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
]
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions winterdrp/pipelines/sedmv2/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
61 changes: 61 additions & 0 deletions winterdrp/pipelines/sedmv2/load_sedmv2_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions winterdrp/pipelines/sedmv2/sedmv2_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
12 changes: 11 additions & 1 deletion winterdrp/processors/zogy/zogy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -291,14 +292,15 @@ 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
)

# 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)

Expand Down Expand Up @@ -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"

Expand Down