Skip to content

Commit

Permalink
Added the ability override proposal_id and ra and dec.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmccully committed Feb 12, 2025
1 parent 75ff93a commit b99baa1
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.21.0 (2025-02-12)
-------------------
- Added the ability to change the proposal of a frame before saving
- Refactored how RA and Dec are pulled from the header so that they can be overridden

1.20.2 (2025-02-10)
-------------------
- Bugfix to logging on reduction stopped
Expand Down
31 changes: 30 additions & 1 deletion banzai/frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class ObservationFrame(metaclass=abc.ABCMeta):
def __init__(self, hdu_list: list, file_path: str, frame_id: int = None, hdu_order: list = None):
self._hdus = hdu_list
self._file_path = file_path
self.ra, self.dec = fits_utils.parse_ra_dec(hdu_list[0].meta)
self.instrument = None
self.frame_id = frame_id
self.hdu_order = hdu_order
Expand Down Expand Up @@ -90,6 +89,26 @@ def n_sub_exposures(self, value):
def save_processing_metadata(self, context):
pass

@property
@abc.abstractmethod
def ra(self):
pass

@ra.setter
@abc.abstractmethod
def ra(self, value):
pass

@property
@abc.abstractmethod
def dec(self):
pass

@dec.setter
@abc.abstractmethod
def dec(self, value):
pass

@property
@abc.abstractmethod
def bias_level(self):
Expand Down Expand Up @@ -179,7 +198,17 @@ def proposal(self):
@abc.abstractmethod
def proposal(self, value):
pass

@property
@abc.abstractmethod
def object(self):
pass

@object.setter
@abc.abstractmethod
def object(self, value):
pass

@property
@abc.abstractmethod
def blockid(self):
Expand Down
67 changes: 67 additions & 0 deletions banzai/lco.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from astropy.time import Time
from astropy.table import Table
from astropy.coordinates import Angle
import hashlib

from banzai import dbs
Expand All @@ -22,6 +23,64 @@ def get_output_directory(self, runtime_context) -> str:
return os.path.join(runtime_context.processed_path, self.instrument.site,
self.instrument.camera, self.epoch, 'processed')

@property
def ra(self):
try:
coord = Angle(self.meta.get('CRVAl1'), unit='degree')
except (ValueError, TypeError):
# Fallback to RA and DEC
try:
coord = Angle(self.meta.get('RA'), unit='hourangle')
except (ValueError, TypeError):
# Fallback to Cat-RA and CAT-DEC
try:
coord = Angle(self.meta.get('CAT-RA'), unit='hourangle')
except (ValueError, TypeError) as e:
coord = np.nan
return coord

@ra.setter
def ra(self, value):
if value is None:
coord = 'N/A'
if 'CRVAL1' in self.meta:
self.meta.pop('CRVAL1')
else:
self.meta['CRVAL1'] = float(value)
coord = Angle(value, unit='degree')
coord = coord.to('hourangle').to_string(sep=':', pad=True)
self.meta['RA'] = coord
self.meta['CAT-RA'] = coord

@property
def dec(self):
try:
coord = Angle(self.meta.get('CRVAl2'), unit='degree')
except (ValueError, TypeError):
# Fallback to RA and DEC
try:
coord = Angle(self.meta.get('DEC'), unit='degree')
except (ValueError, TypeError):
# Fallback to Cat-RA and CAT-DEC
try:
coord = Angle(self.meta.get('CAT-DEC'), unit='degree')
except (ValueError, TypeError) as e:
coord = np.nan
return coord

@dec.setter
def dec(self, value):
if value is None:
coord = 'N/A'
if 'CRVAL2' in self.meta:
self.meta.pop('CRVAL2')
else:
self.meta['CRVAL2'] = float(value)
coord = Angle(value, unit='degree')
coord = coord.to_string(sep=':', pad=True)
self.meta['DEC'] = coord
self.meta['CAT-DEC'] = coord

@property
def n_amps(self):
return len(self.ccd_hdus)
Expand Down Expand Up @@ -73,7 +132,15 @@ def proposal(self):
@proposal.setter
def proposal(self, value):
self.primary_hdu.meta['PROPID'] = value

@property
def object(self):
return self.meta['OBJECT']

@object.setter
def object(self, value):
self.meta['OBJECT'] = value

@property
def blockid(self):
id = self.primary_hdu.meta.get('BLKUID')
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ build-backend = 'setuptools.build_meta'

[project]
name = "lco-banzai"
version = "1.20.2"
version = "1.21.0"
description = "Python data reduction package for LCOGT data"
authors = [
{ name="Curtis McCully", email="[email protected]" },
Expand Down

0 comments on commit b99baa1

Please sign in to comment.