Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rcooke-ast committed Oct 11, 2023
1 parent b1d6e1f commit 3ad7d3c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
37 changes: 32 additions & 5 deletions pypeit/coadd3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ class DataCube(datamodel.DataContainer):
Parsed meta from the header
spectrograph (:class:`~pypeit.spectrographs.spectrograph.Spectrograph`):
Build from PYP_SPEC
_ivar (:class:`~pypeit.spectrographs.spectrograph.Spectrograph`):
Build from PYP_SPEC
_wcs (:class:`~pypeit.spectrographs.spectrograph.Spectrograph`):
Build from PYP_SPEC
"""
version = '1.2.0'
Expand All @@ -87,7 +91,9 @@ class DataCube(datamodel.DataContainer):
internals = ['head0',
'filename',
'spectrograph',
'spect_meta'
'spect_meta',
'_ivar', # This is set internally, and should be accessed with self.ivar
'_wcs' # This is set internally, and should be accessed with self.wcs
]

def __init__(self, flux, sig, bpm, wave, PYP_SPEC, blaze_wave, blaze_spec, sensfunc=None,
Expand All @@ -97,6 +103,9 @@ def __init__(self, flux, sig, bpm, wave, PYP_SPEC, blaze_wave, blaze_spec, sensf
_d = dict([(k, values[k]) for k in args[1:]])
# Setup the DataContainer
datamodel.DataContainer.__init__(self, d=_d)
# Initialise the internals
self._ivar = None
self._wcs = None

def _bundle(self):
"""
Expand Down Expand Up @@ -177,21 +186,39 @@ def from_file(cls, ifile):
# Meta
self.spectrograph = load_spectrograph(self.PYP_SPEC)
self.spect_meta = self.spectrograph.parse_spec_header(hdu[0].header)
self._ivar = None
self._wcs = None
return self

@property
def ivar(self):
"""
Utility function to compute the inverse variance cube
Returns
-------
self._ivar : `numpy.ndarray`_
The inverse variance of the datacube. Note that self._ivar should
not be accessed directly, and you should only call self.ivar
"""
return utils.inverse(self.sig**2)
if self._ivar is None:
self._ivar = utils.inverse(self.sig**2)
return self._ivar

@property
def wcs(self):
"""
Utility function to provide the world coordinate system of the datacube
Returns
-------
self._wcs : `astropy.wcs.WCS`_
The WCS based on the stored header information. Note that self._wcs should
not be accessed directly, and you should only call self.wcs
"""
return wcs.WCS(self.head0)
if self._wcs is None:
self._wcs = wcs.WCS(self.head0)
return self._wcs


class DARcorrection:
Expand Down Expand Up @@ -637,7 +664,7 @@ def set_default_skysub(self):
msgs.newline() + self.cubepar['skysub_frame'])
try:
spec2DObj = spec2dobj.Spec2DObj.from_file(self.cubepar['skysub_frame'], self.detname)
skysub_exptime = fits.open(self.cubepar['skysub_frame'])[0].header['EXPTIME']
skysub_exptime = self.spec.get_meta_value([spec2DObj.head0], 'exptime')
except:
msgs.error("Could not load skysub image from spec2d file:" + msgs.newline() + self.cubepar['skysub_frame'])
else:
Expand Down Expand Up @@ -700,7 +727,7 @@ def get_current_skysub(self, spec2DObj, exptime, opts_skysub=None):
msgs.info("Loading skysub frame:" + msgs.newline() + opts_skysub)
try:
spec2DObj_sky = spec2dobj.Spec2DObj.from_file(opts_skysub, self.detname)
skysub_exptime = fits.open(opts_skysub)[0].header['EXPTIME']
skysub_exptime = self.spec.get_meta_value([spec2DObj_sky.head0], 'exptime')
except:
msgs.error("Could not load skysub image from spec2d file:" + msgs.newline() + opts_skysub)
skyImg = spec2DObj_sky.sciimg * exptime / skysub_exptime # Sky counts
Expand Down
2 changes: 1 addition & 1 deletion pypeit/core/datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ def set_voxel_sampling(spatscale, specscale, dspat=None, dwv=None):

def wcs_bounds(all_ra, all_dec, all_wave, ra_min=None, ra_max=None, dec_min=None, dec_max=None, wave_min=None, wave_max=None):
"""
Create a WCS and the expected edges of the voxels, based on user-specified
Calculate the bounds of the WCS and the expected edges of the voxels, based on user-specified
parameters or the extremities of the data. This is a convenience function
that calls the core function in `pypeit.core.datacube`_.
Expand Down
2 changes: 1 addition & 1 deletion pypeit/par/pypeitpar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1593,7 +1593,7 @@ def validate(self):
allowed_skysub_options = ["none", "image", ""] # Note, "None" is treated as None which gets assigned to the default value "image".
if self.data['skysub_frame'] not in allowed_skysub_options:
# Check if the supplied name exists
if not os.path.exists(self.data['method']):
if not os.path.exists(self.data['skysub_frame']):
raise ValueError("The 'skysub_frame' must be one of:\n" + ", ".join(allowed_skysub_options) +
"\nor, the relative path to a spec2d file.")
if len(self.data['whitelight_range']) != 2:
Expand Down

0 comments on commit 3ad7d3c

Please sign in to comment.