Skip to content

Commit

Permalink
simplify get_imgid
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiopasra committed May 18, 2020
1 parent fdfbd38 commit 4938026
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 35 deletions.
18 changes: 9 additions & 9 deletions megaradrp/datamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,6 @@ def __init__(self):
instrument_mappings
)

def get_imgid(self, img):
hdr = self.get_header(img)
if 'UUID' in hdr:
return 'uuid:{}'.format(hdr['UUID'])
elif 'DATE-OBS' in hdr:
return 'dateobs:{}'.format(hdr['DATE-OBS'])
else:
return super(MegaraDataModel, self).get_imgid(img)

def get_fiberconf(self, img):
"""Obtain FiberConf from image"""
return get_fiberconf(img)
Expand Down Expand Up @@ -258,6 +249,15 @@ def fibers_to_table(self):
result['y'].unit = self.funit
return result

def scale_unit(self, unit=False):
if self.funit == "arcsec":
scale = 1
else:
scale = cons.GTC_FC_A_PLATESCALE.value
if unit:
return (scale, self.funit)
else:
return scale

class TargetType(enum.Enum):
"""Possible targest in a fiber bundle"""
Expand Down
29 changes: 3 additions & 26 deletions megaradrp/processing/wavecalibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import astropy.wcs
import astropy.io.fits as fits

import numina.datamodel as dm
import numina.array.utils as utils
from numina.frame.utils import copy_img
from numina.processing import Corrector
Expand Down Expand Up @@ -48,30 +49,6 @@ def create_internal_wcs_(self):
return w


def get_imgid(img, prefix=True):
# FIXME: duplicated with datamodel
hdr = img[0].header
base = "{}"
if 'UUID' in hdr:
pre = 'uuid:{}'
value = hdr['UUID']
elif 'DATE-OBS' in hdr:
pre = 'dateobs:{}'
value = hdr['DATE-OBS']
elif 'checksum' in hdr:
pre = 'checksum:{}'
value = hdr['checksum']
elif 'filename' in hdr:
pre = 'file:{}'
value = hdr['filename']
else:
raise ValueError('no method to identity image')
if prefix:
return pre.format(value)
else:
return base.format(value)


class WavelengthCalibrator(Corrector):
"""A Node that applies wavelength calibration."""

Expand Down Expand Up @@ -116,7 +93,7 @@ def calibrate_wl_rss_megara(rss, solutionwl, dtype='float32', span=0, inplace=Fa
A Row stacked Spectra MEGARA image, WL calibrated
"""

imgid = get_imgid(rss)
imgid = dm.get_imgid(rss)
_logger.debug('wavelength calibration in image %s', imgid)
_logger.debug('with wavecalib %s', solutionwl.calibid)
_logger.debug('offsets are %s', solutionwl.global_offset.coef)
Expand Down Expand Up @@ -177,7 +154,7 @@ def calibrate_wl_rss(rss, solutionwl, npix, targetwcs, dtype='float32', span=0,
# This is a new HDUList
rss = copy_img(rss)

imgid = get_imgid(rss)
imgid = dm.get_imgid(rss)
_logger.debug('wavelength calibration in image %s', imgid)
_logger.debug('with wavecalib %s', solutionwl.calibid)
_logger.debug('offsets are %s', solutionwl.global_offset.coef)
Expand Down

0 comments on commit 4938026

Please sign in to comment.