Commit 09dd850f authored by Monica Rainer's avatar Monica Rainer
Browse files

Add U-Ne frames quality check

parent bf2b3f2d
......@@ -35,11 +35,14 @@ class GBWls():
self.messages = []
self.wllist = []
self.wlcorr = []
self.mlamp = ''
def qualitycheck(self,unefp):
"""
Quality check for UNe and FP lamps still to be defined.
--> It will be done after the default wavelength calibration,
here everything is defined as ok.
"""
for frame in self.wls:
......@@ -128,7 +131,7 @@ class GBWls():
#wlname = hea[CONFIG['KEYS']['IMANAME']].replace('.fts','_LFC.fits')
#wlname = wlname.replace(' ', '').replace('-', '_')
nome = os.path.join(CONFIG['CALIB_DIR'],wlname)
self.mlamp = os.path.join(CONFIG['CALIB_DIR'],wlname)
mwl.header = hea
mwl.header[CONFIG['KEYS']['FILENAME']] = wlname
......@@ -140,18 +143,20 @@ class GBWls():
hdu = fits.PrimaryHDU(data=mwl.data,header=mwl.header)
masterwl = fits.HDUList([hdu])
masterwl.writeto(nome,clobber=True)
masterwl.writeto(self.mlamp,clobber=True)
mwl = None
db.insert_dbfile(self.dbconn,unefp,nome)
self.messages.append('%s masterlamp %s was created and inserted in the calibration database.' % (unefp,str(os.path.basename(nome))))
#db.insert_dbfile(self.dbconn,unefp,self.mlamp)
#self.messages.append('%s masterlamp %s was created and inserted in the calibration database.' % (unefp,str(os.path.basename(self.mlamp))))
else:
self.messages.append('There are no available %s lamps. The reference lamp will be taken from the calibration database.' % (unefp))
self.messages.append('There are no useful %s lamps. The reference lamp will be taken from the calibration database.' % (unefp))
if db.check_dbfile(self.dbconn,unefp):
try:
db.copy_dbfile(self.dbconn,unefp)
self.mlamp = db.extract_dbfile(self.dbconn,unefp)
except:
self.messages.append('There are no %s lamps in the calibration database.' %(unefp))
return False
......@@ -160,7 +165,8 @@ class GBWls():
def extract(self,unefp):
# straighten the lamp's orders
lamp = db.extract_dbfile(self.dbconn,unefp)
# lamp = db.extract_dbfile(self.dbconn,unefp)
lamp = self.mlamp
#print lamp
straight = lamp.replace('.fits','_str.fits')
......@@ -188,11 +194,11 @@ class GBWls():
mflat = ccdproc.CCDData.read(cal_flat, unit=u.adu)
shift = varie.shiftY(mflat.data)
db.insert_dbfile(self.dbconn,'shiftY',shift)
else:
except:
db.copy_dbfile(self.dbconn,'shiftY')
shift = db.extract_dbfile(self.dbconn,'shiftY')
if not shift:
shift = CONFIG['SHIFT_Y']
if not shift:
shift = CONFIG['SHIFT_Y']
shiftY = [''.join(('DY=',str(shift - CONFIG['SHIFT_Y'])))]
#print shiftY
......@@ -205,9 +211,9 @@ class GBWls():
#self.messages.append('%s: orders straightened.' % (str(os.path.basename(lamp))))
strname = '_'.join((unefp,'str'))
db.insert_dbfile(self.dbconn,strname,straight)
self.messages.append('Straightened %s masterlamp %s was created and inserted in the calibration database.' % (unefp,str(os.path.basename(straight))))
#strname = '_'.join((unefp,'str'))
#db.insert_dbfile(self.dbconn,strname,straight)
#self.messages.append('Straightened %s masterlamp %s was created and inserted in the calibration database.' % (unefp,str(os.path.basename(straight))))
wl = ccdproc.CCDData.read(straight, unit=u.adu)
......@@ -234,6 +240,12 @@ class GBWls():
keyfail = ''.join((CONFIG['CAL_FAILED'][0],str(x+32)))
if calib_failed:
if self.quality[0] == 'OK':
self.quality = ['FAILED' for q in self.quality]
#db.remove_dbfile(CONFIG['DATE'],'UNE')
#return
wl.header[keyfail] = (False,CONFIG['CAL_FAILED'][1])
self.messages.append(' *** WARNING ***')
self.messages.append('The default wavelength calibration for the order %s will be taken from the database and as such it will not be optimal for the night.' % str(x+32))
......@@ -300,9 +312,24 @@ class GBWls():
red_extr = os.path.join(CONFIG['RED_CALIB'],os.path.basename(extracted))
shutil.copyfile(extracted,red_extr)
calname = '_'.join((unefp,'calib'))
db.insert_dbfile(self.dbconn,calname,extracted)
self.messages.append('%s wavelength calibration %s was created and inserted in the calibration database.' % (unefp,str(os.path.basename(extracted))))
if self.quality[0] == 'OK':
db.insert_dbfile(self.dbconn,unefp,self.mlamp)
self.messages.append('%s masterlamp %s was created and inserted in the calibration database.' % (unefp,str(os.path.basename(self.mlamp))))
strname = '_'.join((unefp,'str'))
db.insert_dbfile(self.dbconn,strname,straight)
self.messages.append('Straightened %s masterlamp %s was created and inserted in the calibration database.' % (unefp,str(os.path.basename(straight))))
calname = '_'.join((unefp,'calib'))
db.insert_dbfile(self.dbconn,calname,extracted)
self.messages.append('%s wavelength calibration %s was created and inserted in the calibration database.' % (unefp,str(os.path.basename(extracted))))
else:
os.remove(self.mlamp)
os.remove(straight)
os.remove(extracted)
wlextract = None
ordini = None
......
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