Commit 4c5b4072 authored by Andrea Bignamini's avatar Andrea Bignamini
Browse files

Fix corrupted pair error and logging to STDOUT

Corrupted pairs with missing A or B SLIT resulted in unhandled
exception and premature exit. Now if is fixed, and it reports
in log that the pair is corrupted, but it go on with reduction
of following data.
In addition, previously the logger wrote to STDERR. Now it writes
to STDOUT.
parent bf5fc311
...@@ -206,7 +206,7 @@ class GBFlats(): ...@@ -206,7 +206,7 @@ class GBFlats():
db.insert_dbfile(self.dbconn,'shiftY',shiftY) db.insert_dbfile(self.dbconn,'shiftY',shiftY)
# Since masterflat has been copied from calibration database # Since masterflat has been copied from calibration database
# also str and nor will be copied ETTORE # also str and nor will be copied
self.copy_straighten() self.copy_straighten()
return False return False
......
...@@ -5,6 +5,7 @@ Implemented in the GIANOB DRS by Monica Rainer ...@@ -5,6 +5,7 @@ Implemented in the GIANOB DRS by Monica Rainer
import logging import logging
from drslib.config import CONFIG as CFG from drslib.config import CONFIG as CFG
from sys import stdout
class DrsLogger(): class DrsLogger():
def __init__(self): def __init__(self):
...@@ -29,7 +30,7 @@ class DrsLogger(): ...@@ -29,7 +30,7 @@ class DrsLogger():
def addconsolelogger(self): def addconsolelogger(self):
"""The logger to the terminal is defined""" """The logger to the terminal is defined"""
console_handler = logging.StreamHandler() console_handler = logging.StreamHandler(stream=stdout)
formatter = logging.Formatter(fmt=self.conslogfmt) formatter = logging.Formatter(fmt=self.conslogfmt)
console_handler.setFormatter(formatter) console_handler.setFormatter(formatter)
self.logger.addHandler(console_handler) self.logger.addHandler(console_handler)
......
...@@ -85,14 +85,10 @@ class GBNodding(): ...@@ -85,14 +85,10 @@ class GBNodding():
return True return True
def createAB(self): def create_nodcorr(self):
""" """
Create nodding images A-B and save them in temporary directory if Create nodcorr
the keyword SPEXTMODE is set to GRPAVG_EXT.
""" """
hea = self.nodlist[0].header
badpix = ccdproc.CCDData.read(CONFIG['BADPIX_MASK'], unit=u.adu) badpix = ccdproc.CCDData.read(CONFIG['BADPIX_MASK'], unit=u.adu)
bad_mask=badpix.data bad_mask=badpix.data
inverse_mask=np.logical_not(bad_mask) inverse_mask=np.logical_not(bad_mask)
...@@ -109,6 +105,46 @@ class GBNodding(): ...@@ -109,6 +105,46 @@ class GBNodding():
self.nodcorr[nod.header[CONFIG['KEYS']['SLIT']]] = nod_corr self.nodcorr[nod.header[CONFIG['KEYS']['SLIT']]] = nod_corr
nod = None nod = None
return
def check_nodcorr(self):
"""
Check if nodcorr is not corrupted
"""
try:
nodA = self.nodcorr[CONFIG['A']]
except Exception as e:
nodA = None
try:
nodB = self.nodcorr[CONFIG['B']]
except Exception as e:
nodB = None
if not nodA and not nodB:
self.messages.append('The nodding pair is corrupted. Both slits A and B are missing. Skipping pair processing.')
return False
else:
if not nodA:
self.messages.append('The nodding pair is corrupted. Slit A is missing. Skipping pair processing.')
return False
if not nodB:
self.messages.append('The nodding pair is corrupted. Slit B is missing. Skipping pair processing.')
return False
return True
def createAB(self):
"""
Create nodding images A-B and save them in temporary directory if
the keyword SPEXTMODE is set to GRPAVG_EXT.
"""
hea = self.nodlist[0].header
# Create A-B image # Create A-B image
nodA = self.nodcorr[CONFIG['A']] nodA = self.nodcorr[CONFIG['A']]
...@@ -882,6 +918,10 @@ class GBNodding(): ...@@ -882,6 +918,10 @@ class GBNodding():
warnings.simplefilter('ignore', category=AstropyWarning) warnings.simplefilter('ignore', category=AstropyWarning)
if self.qualitycheck(): if self.qualitycheck():
#t1 = time.time() #t1 = time.time()
# Create and check nodcorr
self.create_nodcorr()
if not self.check_nodcorr():
return
ab, heaA, heaB = self.createAB() ab, heaA, heaB = self.createAB()
#t2 = time.time() #t2 = time.time()
#print 'Bad pixels, create nodding: %s s' % str(t2-t1) #print 'Bad pixels, create nodding: %s s' % str(t2-t1)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment