Skip to content

Commit

Permalink
Carefully check winter images have all required fields
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdstein committed Jul 11, 2023
1 parent 6834176 commit d662986
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
5 changes: 4 additions & 1 deletion mirar/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,11 @@ def check_image_has_core_fields(img: Image):
"""
for key in core_fields:
if key not in img.keys():
if BASE_NAME_KEY in img.keys():
msg = f"({img[BASE_NAME_KEY]}) "

err = (
f"New image is missing the core field {key}. "
f"New image {msg}is missing the core field {key}. "
f"Available fields are {list(img.keys())}."
)
logger.error(err)
Expand Down
1 change: 1 addition & 0 deletions mirar/pipelines/winter/load_winter_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def load_raw_winter_image(path: str | Path) -> tuple[np.array, astropy.io.fits.H
)
logger.debug(header["UTCTIME"])
header["MJD-OBS"] = Time(header["UTCTIME"]).mjd
header["DATE-OBS"] = Time(header["UTCTIME"]).isot

header["OBSCLASS"] = ["science", "calibration"][
header["OBSTYPE"] in ["DARK", "FLAT"]
Expand Down
8 changes: 4 additions & 4 deletions mirar/processors/astromatic/swarp/swarp.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,9 @@ def _apply_to_images(
except ValueError:
continue

new_image["COADDS"] = np.sum([x["COADDS"] for x in batch])
new_image[EXPTIME_KEY] = np.sum([x[EXPTIME_KEY] for x in batch])
new_image[TIME_KEY] = min([x[TIME_KEY] for x in batch])
new_image["COADDS"] = sum(x["COADDS"] for x in batch)
new_image[EXPTIME_KEY] = sum(x[EXPTIME_KEY] for x in batch)
new_image[TIME_KEY] = min(x[TIME_KEY] for x in batch)

new_image[RAW_IMG_KEY] = ",".join([x[RAW_IMG_KEY] for x in batch])

Expand All @@ -395,7 +395,7 @@ def _apply_to_images(
try:
check_image_has_core_fields(new_image)
except MissingCoreFieldError as err:
raise SwarpError from err
raise SwarpError(err) from err

if not self.cache:
for temp_file in temp_files:
Expand Down
3 changes: 2 additions & 1 deletion mirar/processors/base_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
NoncriticalProcessingError,
ProcessorError,
)
from mirar.io import open_fits, save_to_path
from mirar.io import check_image_has_core_fields, open_fits, save_to_path
from mirar.paths import (
BASE_NAME_KEY,
CAL_OUTPUT_SUB_DIR,
Expand Down Expand Up @@ -317,6 +317,7 @@ def save_fits(
:return: None
"""
path = str(path)
check_image_has_core_fields(image)
data = image.get_data()
header = image.get_header()
if header is not None:
Expand Down
8 changes: 8 additions & 0 deletions mirar/processors/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@ def __init__(
self.ref_image_generator = ref_image_generator
self.output_sub_dir = output_sub_dir

def __str__(self):
output_sub_dir = get_output_dir(
dir_root=self.output_sub_dir, sub_dir=self.night_sub_dir
)
return (
f"Processor to get reference images and " f"save them to {output_sub_dir}"
)

def _apply_to_images(
self,
batch: ImageBatch,
Expand Down
4 changes: 2 additions & 2 deletions mirar/processors/utils/image_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def open_raw_image(self, path: str) -> Image:
try:
check_image_has_core_fields(new_img)
except MissingCoreFieldError as err:
raise BadImageError from err
raise BadImageError(err) from err

return new_img

Expand Down Expand Up @@ -166,7 +166,7 @@ def _apply_to_images(
try:
check_image_has_core_fields(new_image)
except MissingCoreFieldError as err:
raise BadImageError from err
raise BadImageError(err) from err

new_batch.append(new_image)

Expand Down

0 comments on commit d662986

Please sign in to comment.