Skip to content

Commit

Permalink
updating to release
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver committed Jun 28, 2022
2 parents 043d105 + 3e3f92b commit d5ce2f0
Show file tree
Hide file tree
Showing 17 changed files with 107 additions and 11 deletions.
2 changes: 1 addition & 1 deletion geminidr/core/primitives_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def _create_wcs_from_offsets(adinput, adref, center_of_rotation=None):

if center_of_rotation is None:
if 'GNIRS' in adref.tags:
center_of_rotation = (629.0, 519.0) # (x, y; 0-indexed)
center_of_rotation = (519.0, 629.0) # (y, x; 0-indexed)
else:
try:
for m in adref[0].wcs.forward_transform:
Expand Down
20 changes: 20 additions & 0 deletions geminidr/gmos/parameters_gmos.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@
from geminidr.core import parameters_visualize, parameters_ccd
from geminidr.gemini import parameters_qa

def badamps_check(value):
try:
badamps = [int(x) for x in value.split(',')]
except AttributeError: # not a str, must be int
if value is None:
return True
return value > 0
except ValueError: # items are not int-able
return False
else:
return len(badamps) >= 1 and min(badamps) > 0

class displayConfig(parameters_visualize.displayConfig):
remove_bias = config.Field("Remove estimated bias level before displaying?", bool, True)

Expand All @@ -13,6 +25,14 @@ class measureBGConfig(parameters_qa.measureBGConfig):
class measureIQConfig(parameters_qa.measureIQConfig):
remove_bias = config.Field("Remove estimated bias level before displaying?", bool, True)

class maskFaultyAmpConfig(config.Config):
suffix = config.Field("Filename suffix", str, "_badAmpMasked", optional=True)
instrument = config.Field("Applicable instrument", str, None, optional=True)
bad_amps = config.Field("Amps to mask as a list", (int, str), None,
optional=True, check=badamps_check)
valid_from = config.Field("Mask data taken after this date (YYYYMMDD)", str, None, optional=True)
valid_to = config.Field("Mask data taken before this date (YYYYMMDD)", str, None, optional=True)

class subtractOverscanConfig(parameters_ccd.subtractOverscanConfig):
nbiascontam = config.RangeField("Number of columns to exclude from averaging",
int, None, min=0, optional=True)
Expand Down
78 changes: 68 additions & 10 deletions geminidr/gmos/primitives_gmos.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import os
from importlib import import_module

import numpy as np

from datetime import datetime

import astrodata
import gemini_instruments

Expand All @@ -22,6 +26,8 @@
from gemini_instruments.gmos.pixel_functions import get_bias_level

from recipe_system.utils.decorators import parameter_override


# ------------------------------------------------------------------------------
@parameter_override
class GMOS(Gemini, CCD):
Expand All @@ -37,6 +43,54 @@ def __init__(self, adinputs, **kwargs):
self.inst_lookups = 'geminidr.gmos.lookups'
self._param_update(parameters_gmos)

def maskFaultyAmp(self, adinputs=None, **params):
log = self.log

log.debug(gt.log_message("primitive", self.myself(), "starting"))
timestamp_key = 'MASKAMP5'

suffix = params["suffix"]
instrument = params["instrument"]
badamps = params["bad_amps"]
validfromstr = params["valid_from"]
validtostr = params["valid_to"]

if badamps is None or instrument is None:
return adinputs
elif badamps:
try:
badamplist = [int(x) for x in badamps.split(',')]
except AttributeError: # not a str, must be int
badamplist = [badamps]

if validfromstr:
validfrom = datetime.strptime(validfromstr, '%Y%m%d')
else:
validfrom = datetime(1900, 1, 1)

if validtostr:
validto = datetime.strptime(validtostr, '%Y%m%d')
else:
validto = datetime(2200, 1, 1)

for ad in adinputs:
if instrument == ad.instrument() and \
validfrom.date() <= ad.ut_date() <= validto.date():

ampsstr = ', '.join([str(i) for i in badamplist])
plural = 's' if len(ampsstr) > 1 else ''
log.status(f'Masking amp{plural} {ampsstr}')

for amp in badamplist:
ext = amp - 1
mask = np.ones(ad[ext].mask.shape, dtype=ad[ext].mask.dtype)
ad[ext].mask = mask

gt.mark_history(ad, primname=self.myself(), keyword=timestamp_key)
ad.update_filename(suffix=suffix, strip=True)

return adinputs

def standardizeInstrumentHeaders(self, adinputs=None, suffix=None):
"""
This primitive is used to make the changes and additions to the
Expand Down Expand Up @@ -91,7 +145,7 @@ def standardizeInstrumentHeaders(self, adinputs=None, suffix=None):
# Update keywords in the image extensions. The descriptors return
# the true values on unprepared data.
descriptors = ['pixel_scale', 'read_noise', 'gain_setting',
'gain', 'saturation_level']
'gain', 'saturation_level']
for desc in descriptors:
keyword = ad._keyword_for(desc)
comment = self.keyword_comments[keyword]
Expand Down Expand Up @@ -180,9 +234,10 @@ def subtractOverscan(self, adinputs=None, **params):
dsec_list = ad.data_section()
osec_list = ad.overscan_section()
for ext, dsec, osec in zip(ad, dsec_list, osec_list):
ext.hdr['BIASSEC'] = '[{}:{},{}:{}]'.format(osec.x1+1,
osec.x2, y1+1, osec.y2)
#ext.hdr['DATASEC'] = '[{}:{},{}:{}]'.format(dsec.x1+1,
ext.hdr['BIASSEC'] = '[{}:{},{}:{}]'.format(osec.x1 + 1,
osec.x2, y1 + 1,
osec.y2)
# ext.hdr['DATASEC'] = '[{}:{},{}:{}]'.format(dsec.x1+1,
# dsec.x2, y1+1, dsec.y2)

adinputs = super().subtractOverscan(adinputs, **params)
Expand Down Expand Up @@ -210,7 +265,8 @@ def _get_bpm_filename(self, ad):
det = ad.detector_name(pretty=True)[:3]
amps = '{}amp'.format(3 * ad.phu['NAMPS'])
mos = '_mosaic' if (ad.phu.get(self.timestamp_keys['mosaicDetectors'])
or ad.phu.get(self.timestamp_keys['tileArrays'])) else ''
or ad.phu.get(
self.timestamp_keys['tileArrays'])) else ''
mode_key = '{}_{}_{}{}_{}'.format(inst, det, xbin, ybin, amps)

db_matches = sorted((k, v) for k, v in maskdb.bpm_dict.items() \
Expand All @@ -224,8 +280,8 @@ def _get_bpm_filename(self, ad):
return None

# Prepend standard path if the filename doesn't start with '/'
return bpm if bpm.startswith(os.path.sep) else os.path.join(bpm_dir, bpm)

return bpm if bpm.startswith(os.path.sep) else os.path.join(bpm_dir,
bpm)

def _get_illum_mask_filename(self, ad):
"""
Expand All @@ -251,7 +307,8 @@ def _get_illum_mask_filename(self, ad):
if mode:
mode = mode.pop()
else: # DARK/BIAS (only F2 K-band darks for flats should get here)
log.fullinfo("{} not IMAGE or SPECT: no illumination mask".format(ad.filename))
log.fullinfo("{} not IMAGE or SPECT: no illumination mask".format(
ad.filename))
return None

try:
Expand All @@ -263,7 +320,7 @@ def _get_illum_mask_filename(self, ad):

# illumMask_dict is loaded.
bpm_dir = os.path.join(os.path.dirname(masks.__file__), 'BPM')
key= '{}_{}_{}{}_{}'.format(inst, det, xbin, ybin, amps)
key = '{}_{}_{}{}_{}'.format(inst, det, xbin, ybin, amps)

for illumkey in illum_dict.keys():
if illumkey.startswith(key):
Expand All @@ -275,4 +332,5 @@ def _get_illum_mask_filename(self, ad):

log.stdinfo("Retrieved mask: {}".format(mask))
# Prepend standard path if the filename doesn't start with '/'
return mask if mask.startswith(os.path.sep) else os.path.join(bpm_dir, mask)
return mask if mask.startswith(os.path.sep) else os.path.join(bpm_dir,
mask)
1 change: 1 addition & 0 deletions geminidr/gmos/recipes/qa/recipes_ARC_LS_SPECT.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
def makeProcessedArc(p):
p.prepare()
p.addDQ()
p.maskFaultyAmp(instrument='GMOS-S', bad_amps=5, valid_from='20220128')
p.addVAR(read_noise=True)
p.overscanCorrect()
p.ADUToElectrons()
Expand Down
1 change: 1 addition & 0 deletions geminidr/gmos/recipes/qa/recipes_BIAS.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def makeProcessedBias(p):

p.prepare()
p.addDQ()
p.maskFaultyAmp(instrument='GMOS-S', bad_amps=5, valid_from='20220128')
p.addVAR(read_noise=True)
p.overscanCorrect()
p.addToList(purpose="forStack")
Expand Down
1 change: 1 addition & 0 deletions geminidr/gmos/recipes/qa/recipes_FLAT_IMAGE.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def makeProcessedFlat(p):

p.prepare()
p.addDQ()
p.maskFaultyAmp(instrument='GMOS-S', bad_amps=5, valid_from='20220128')
p.addVAR(read_noise=True)
p.overscanCorrect()
p.biasCorrect()
Expand Down
1 change: 1 addition & 0 deletions geminidr/gmos/recipes/qa/recipes_FLAT_LS_SPECT.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
def makeProcessedFlat(p):
p.prepare()
p.addDQ()
p.maskFaultyAmp(instrument='GMOS-S', bad_amps=5, valid_from='20220128')
p.addVAR(read_noise=True)
p.overscanCorrect()
p.biasCorrect()
Expand Down
1 change: 1 addition & 0 deletions geminidr/gmos/recipes/qa/recipes_IMAGE.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def reduce(p):

p.prepare()
p.addDQ()
p.maskFaultyAmp(instrument='GMOS-S', bad_amps=5, valid_from='20220128')
#p.addIllumMaskToDQ()
p.addVAR(read_noise=True)
p.detectSources()
Expand Down
1 change: 1 addition & 0 deletions geminidr/gmos/recipes/qa/recipes_LS_IMAGE.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def reduce(p):

p.prepare(attach_mdf=True)
p.addDQ()
p.maskFaultyAmp(instrument='GMOS-S', bad_amps=5, valid_from='20220128')
#p.addIllumMaskToDQ()
p.subtractOverscan()
p.ADUToElectrons()
Expand Down
2 changes: 2 additions & 0 deletions geminidr/gmos/recipes/qa/recipes_LS_SPECT.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def reduceScience(p):
"""
p.prepare()
p.addDQ()
p.maskFaultyAmp(instrument='GMOS-S', bad_amps=5, valid_from='20220128')
p.addVAR(read_noise=True)
p.overscanCorrect()
p.measureIQ(display=True)
Expand Down Expand Up @@ -73,6 +74,7 @@ def reduceStandard(p):
"""
p.prepare()
p.addDQ()
p.maskFaultyAmp(instrument='GMOS-S', bad_amps=5, valid_from='20220128')
p.addVAR(read_noise=True)
p.overscanCorrect()
p.measureIQ(display=True)
Expand Down
1 change: 1 addition & 0 deletions geminidr/gmos/recipes/qa/recipes_NS.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def reduce(p):
"""
p.prepare()
p.addDQ(static_bpm=None)
p.maskFaultyAmp(instrument='GMOS-S', bad_amps=5, valid_from='20220128')
p.addVAR(read_noise=True)
p.overscanCorrect()
p.biasCorrect()
Expand Down
1 change: 1 addition & 0 deletions geminidr/gmos/recipes/ql/recipes_ARC_LS_SPECT.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
def makeProcessedArc(p):
p.prepare()
p.addDQ()
p.maskFaultyAmp(instrument='GMOS-S', bad_amps=5, valid_from='20220128')
p.addVAR(read_noise=True)
p.overscanCorrect()
p.ADUToElectrons()
Expand Down
2 changes: 2 additions & 0 deletions geminidr/gmos/recipes/ql/recipes_FLAT_LS_SPECT.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
def makeProcessedFlatNoStack(p):
p.prepare()
p.addDQ()
p.maskFaultyAmp(instrument='GMOS-S', bad_amps=5, valid_from='20220128')
p.addVAR(read_noise=True)
p.overscanCorrect()
p.getProcessedBias()
Expand All @@ -28,6 +29,7 @@ def makeProcessedFlatNoStack(p):
def makeProcessedFlatStack(p):
p.prepare()
p.addDQ()
p.maskFaultyAmp(instrument='GMOS-S', bad_amps=5, valid_from='20220128')
p.addVAR(read_noise=True)
p.overscanCorrect()
p.getProcessedBias()
Expand Down
2 changes: 2 additions & 0 deletions geminidr/gmos/recipes/ql/recipes_LS_SPECT.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def reduceScience(p):
"""
p.prepare()
p.addDQ()
p.maskFaultyAmp(instrument='GMOS-S', bad_amps=5, valid_from='20220128')
p.addVAR(read_noise=True)
p.overscanCorrect()
p.getProcessedBias()
Expand Down Expand Up @@ -55,6 +56,7 @@ def reduceStandard(p):
"""
p.prepare()
p.addDQ()
p.maskFaultyAmp(instrument='GMOS-S', bad_amps=5, valid_from='20220128')
p.addVAR(read_noise=True)
p.overscanCorrect()
p.getProcessedBias()
Expand Down
1 change: 1 addition & 0 deletions geminidr/gmos/recipes/sq/recipes_BIAS.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def makeProcessedBias(p):

p.prepare()
p.addDQ(static_bpm=None)
p.maskFaultyAmp(instrument='GMOS-S', bad_amps=5, valid_from='20220128')
p.addVAR(read_noise=True)
p.overscanCorrect()
p.stackFrames(zero=False)
Expand Down
1 change: 1 addition & 0 deletions geminidr/gmos/recipes/sq/recipes_FLAT_IMAGE.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def makeProcessedFlat(p):
"""
p.prepare()
p.addDQ()
p.maskFaultyAmp(instrument='GMOS-S', bad_amps=5, valid_from='20220128')
p.addVAR(read_noise=True)
p.overscanCorrect()
p.getProcessedBias()
Expand Down
2 changes: 2 additions & 0 deletions geminidr/gmos/recipes/sq/recipes_IMAGE.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def reduce(p):

p.prepare()
p.addDQ()
p.maskAmp5()
p.addVAR(read_noise=True)
p.overscanCorrect()
p.getProcessedBias()
Expand Down Expand Up @@ -57,6 +58,7 @@ def makeProcessedFringe(p):
"""
p.prepare()
p.addDQ()
p.maskFaultyAmp(instrument='GMOS-S', bad_amps=5, valid_from='20220128')
#p.addIllumMaskToDQ()
p.addVAR(read_noise=True)
p.overscanCorrect()
Expand Down

0 comments on commit d5ce2f0

Please sign in to comment.