Commit be3f1d35 authored by Monica Rainer's avatar Monica Rainer
Browse files

Fix bug in shiftY and change settings s1d

parent c6755255
...@@ -263,7 +263,7 @@ CONFIG['XCCD'] = 2048 ...@@ -263,7 +263,7 @@ CONFIG['XCCD'] = 2048
CONFIG['YCCD'] = 2048 CONFIG['YCCD'] = 2048
CONFIG['N_ORD'] = 50 # number of echelle orders CONFIG['N_ORD'] = 50 # number of echelle orders
CONFIG['W_ORD'] = 41 # width of straighten order in pixel CONFIG['W_ORD'] = 41 # width of straighten order in pixel
CONFIG['SHIFT_Y'] = 20 # bottom position of flat signal on the lowest order and the left side of the detector CONFIG['SHIFT_Y'] = 20 # expected bottom position of flat signal on the lowest order and the left side of the detector. DO NOT CHANGE.
# #
# Quality checks # Quality checks
......
...@@ -215,21 +215,32 @@ class GBFlats(): ...@@ -215,21 +215,32 @@ class GBFlats():
nor = flat.replace('.fits','_nor.fits') nor = flat.replace('.fits','_nor.fits')
#extracted = flat.replace('.fits','_ext.fits') #extracted = flat.replace('.fits','_ext.fits')
shift = db.extract_dbfile(self.dbconn,'shiftY') args = [CONFIG['STRAIGHT'],flat,straight]
if not shift: args.extend(CONFIG['STRAIGHT_OPT'])
cal_flat = db.extract_dbfile(self.dbconn,'flat') # search for shift defined in the straighten options in config.py
mflat = ccdproc.CCDData.read(cal_flat, unit=u.adu) dy = True
shift = varie.shiftY(mflat.data) for opt in CONFIG['STRAIGHT_OPT']:
db.insert_dbfile(self.dbconn,'shiftY',shift) try:
dy = opt.rindex('DY=')
ypos = int(opt[dy-2:])
shift = CONFIG['SHIFT_Y'] + ypos
dy = False
except:
pass
shiftY = ''.join(('DY=',str(shift - CONFIG['SHIFT_Y']))) if dy:
#print shiftY shift = db.extract_dbfile(self.dbconn,'shiftY')
if not shift:
cal_flat = db.extract_dbfile(self.dbconn,'flat')
mflat = ccdproc.CCDData.read(cal_flat, unit=u.adu)
shift = varie.shiftY(mflat.data)
db.insert_dbfile(self.dbconn,'shiftY',shift)
shiftY = [''.join(('DY=',str(shift - CONFIG['SHIFT_Y'])))]
#print shiftY
args.extend(shiftY)
#args = [CONFIG['STRAIGHT'],flat,straight,CONFIG['STRAIGHT_OPT']] #print args
args = [CONFIG['STRAIGHT'],flat,straight]
args.extend(CONFIG['STRAIGHT_OPT'])
args.extend(shiftY)
subprocess.call(args) subprocess.call(args)
red_straight = os.path.join(CONFIG['RED_CALIB'],os.path.basename(straight)) red_straight = os.path.join(CONFIG['RED_CALIB'],os.path.basename(straight))
......
...@@ -178,28 +178,36 @@ class GBNodding(): ...@@ -178,28 +178,36 @@ class GBNodding():
straight = fitsfile.replace('.fits','_str.fits') straight = fitsfile.replace('.fits','_str.fits')
shift = db.extract_dbfile(self.dbconn,'shiftY') args = [CONFIG['STRAIGHT'],fitsfile,straight]
if not shift: args.extend(CONFIG['STRAIGHT_OPT'])
# search for shift defined in the straighten options in config.py
dy = True
for opt in CONFIG['STRAIGHT_OPT']:
try: try:
cal_flat = db.extract_dbfile(self.dbconn,'flat') dy = opt.rindex('DY=')
mflat = ccdproc.CCDData.read(cal_flat, unit=u.adu) ypos = int(opt[dy-2:])
shift = varie.shiftY(mflat.data) shift = CONFIG['SHIFT_Y'] + ypos
db.insert_dbfile(self.dbconn,'shiftY',shift) dy = False
except: except:
try: pass
if dy:
shift = db.extract_dbfile(self.dbconn,'shiftY')
if not shift:
cal_flat = db.extract_dbfile(self.dbconn,'flat')
if cal_flat:
mflat = ccdproc.CCDData.read(cal_flat, unit=u.adu)
shift = varie.shiftY(mflat.data)
db.insert_dbfile(self.dbconn,'shiftY',shift)
else:
db.copy_dbfile(self.dbconn,'shiftY') db.copy_dbfile(self.dbconn,'shiftY')
shift = db.extract_dbfile(self.dbconn,'shiftY') shift = db.extract_dbfile(self.dbconn,'shiftY')
if not shift: if not shift:
shift = CONFIG['SHIFT_Y'] shift = CONFIG['SHIFT_Y']
except:
shift = CONFIG['SHIFT_Y']
shiftY = ''.join(('DY=',str(shift - CONFIG['SHIFT_Y'])))
#print shiftY
args = [CONFIG['STRAIGHT'],fitsfile,straight] shiftY = [''.join(('DY=',str(shift - CONFIG['SHIFT_Y'])))]
args.extend(CONFIG['STRAIGHT_OPT']) #print shiftY
args.extend(shiftY) args.extend(shiftY)
subprocess.call(args) subprocess.call(args)
......
...@@ -326,28 +326,36 @@ class GBStare(): ...@@ -326,28 +326,36 @@ class GBStare():
straight = fitsfile.replace('.fits','_str.fits') straight = fitsfile.replace('.fits','_str.fits')
shift = db.extract_dbfile(self.dbconn,'shiftY') args = [CONFIG['STRAIGHT'],fitsfile,straight]
if not shift: args.extend(CONFIG['STRAIGHT_OPT'])
# search for shift defined in the straighten options in config.py
dy = True
for opt in CONFIG['STRAIGHT_OPT']:
try: try:
cal_flat = db.extract_dbfile(self.dbconn,'flat') dy = opt.rindex('DY=')
mflat = ccdproc.CCDData.read(cal_flat, unit=u.adu) ypos = int(opt[dy-2:])
shift = varie.shiftY(mflat.data) shift = CONFIG['SHIFT_Y'] + ypos
db.insert_dbfile(self.dbconn,'shiftY',shift) dy = False
except: except:
try: pass
if dy:
shift = db.extract_dbfile(self.dbconn,'shiftY')
if not shift:
cal_flat = db.extract_dbfile(self.dbconn,'flat')
if cal_flat:
mflat = ccdproc.CCDData.read(cal_flat, unit=u.adu)
shift = varie.shiftY(mflat.data)
db.insert_dbfile(self.dbconn,'shiftY',shift)
else:
db.copy_dbfile(self.dbconn,'shiftY') db.copy_dbfile(self.dbconn,'shiftY')
shift = db.extract_dbfile(self.dbconn,'shiftY') shift = db.extract_dbfile(self.dbconn,'shiftY')
if not shift: if not shift:
shift = CONFIG['SHIFT_Y'] shift = CONFIG['SHIFT_Y']
except:
shift = CONFIG['SHIFT_Y']
shiftY = ''.join(('DY=',str(shift - CONFIG['SHIFT_Y']))) shiftY = [''.join(('DY=',str(shift - CONFIG['SHIFT_Y'])))]
#print shiftY #print shiftY
args.extend(shiftY)
args = [CONFIG['STRAIGHT'],fitsfile,straight]
args.extend(CONFIG['STRAIGHT_OPT'])
args.extend(shiftY)
subprocess.call(args) subprocess.call(args)
str_file = os.path.join(CONFIG['RED_STR'],os.path.basename(straight)) str_file = os.path.join(CONFIG['RED_STR'],os.path.basename(straight))
......
...@@ -93,25 +93,25 @@ def stdcombine(x,axis): ...@@ -93,25 +93,25 @@ def stdcombine(x,axis):
#-------------- Define straighten option vertical shift ------------------- #-------------- Define straighten option vertical shift -------------------
def shiftY(fdata): def shiftY(fdata):
# search for shift defined in the straighten options in config.py # search for shift defined in the straighten options in config.py
try: #for opt in CONFIG['STRAIGHT_OPT']:
for opt in CONFIG['STRAIGHT_OPT']: # try:
try: # dy = opt.rindex('DY=')
dy = opt.rindex('DY=') # ypos = int(opt[dy-2:])
ypos = int(opt[dy-1:]) # shift = CONFIG['SHIFT_Y'] + ypos
shift = CONFIG['SHIFT_Y'] + ypos # return shift
return shift # except:
# pass
# if the shift is not defined, compute it # if the shift is not defined, compute it
except: column = fdata[0:140,0] # the bottom 140 pixel of the first column on the left of the detector
column = fdata[0:140,0] # the bottom 140 pixel of the first column on the left of the detector background = np.sort(column)[20] # value of the 20th pixel after arranging them in ascending order
background = np.sort(column)[20] # value of the 20th pixel after arranging them in ascending order #print column
#print column for i in xrange(len(column)):
for i in xrange(len(column)): if column[i] > 3*background:
if column[i] > 3*background: if np.median(column[i+1:i+6]) > 3*background:
if np.median(column[i+1:i+6]) > 3*background: shift = i
shift = i return shift
return shift # if the shift computation fails, use the default definition
# if the shift computation fails, use the default definition return CONFIG['SHIFT_Y']
return CONFIG['SHIFT_Y']
#--------------------- Build the extraction mask ------------------- #--------------------- Build the extraction mask -------------------
...@@ -335,6 +335,7 @@ def optExtract(data,gain,ron,slit_pos,ordine): ...@@ -335,6 +335,7 @@ def optExtract(data,gain,ron,slit_pos,ordine):
OptFlux[OptFlux==-np.inf] = 0 OptFlux[OptFlux==-np.inf] = 0
OptFlux = np.nan_to_num(OptFlux) OptFlux = np.nan_to_num(OptFlux)
OptFlux[OptFlux<0] = 0
#t5 = time.time() #t5 = time.time()
#print 'First optimal extraction order %s: %s ms' % (str(ordine+32),str((t5-t4)*1000)) #print 'First optimal extraction order %s: %s ms' % (str(ordine+32),str((t5-t4)*1000))
...@@ -372,6 +373,8 @@ def optExtract(data,gain,ron,slit_pos,ordine): ...@@ -372,6 +373,8 @@ def optExtract(data,gain,ron,slit_pos,ordine):
OptFlux[OptFlux==-np.inf] = 0 OptFlux[OptFlux==-np.inf] = 0
OptFlux = np.nan_to_num(OptFlux) OptFlux = np.nan_to_num(OptFlux)
OptFlux[OptFlux<0] = 0
# update the model and its variance # update the model and its variance
model = OptFlux*profile model = OptFlux*profile
#model[rworst,cworst] = 0 #model[rworst,cworst] = 0
...@@ -1170,13 +1173,14 @@ def create_s1d(spectrum, header): ...@@ -1170,13 +1173,14 @@ def create_s1d(spectrum, header):
wave_old[o] = wave_old[o]*(1+(berv/c)) wave_old[o] = wave_old[o]*(1+(berv/c))
try: try:
#shift = int((wave_old[o][0] - end[o+1])/wstep) -1
shift = max(int(round((wave_old[o][0] - end[o+1])/wstep,0)),1) shift = max(int(round((wave_old[o][0] - end[o+1])/wstep,0)),1)
#start[o] = max(end[o+1] + (shift*wstep), end[o+1]+wstep)
#shift = int(round((wave_old[o][0] - end[o+1])/wstep,0))
start[o] = round(end[o+1] + (shift*wstep),3) start[o] = round(end[o+1] + (shift*wstep),3)
except: except:
#shift = 1
start[o] = round(wave_old[o][0],3) start[o] = round(wave_old[o][0],3)
#nstep = int(round(((wave_old[o][-1]-start[o])/wstep),0))+1
nstep = int(round(((wave_old[o][-1]-start[o])/wstep),0)) nstep = int(round(((wave_old[o][-1]-start[o])/wstep),0))
end[o] = round(start[o]+(nstep*wstep),3) end[o] = round(start[o]+(nstep*wstep),3)
...@@ -1190,16 +1194,28 @@ def create_s1d(spectrum, header): ...@@ -1190,16 +1194,28 @@ def create_s1d(spectrum, header):
select_wave = wave_new[o][wave_old[o][0]<=wave_new[o]<=wave_old[o][-1]] select_wave = wave_new[o][wave_old[o][0]<=wave_new[o]<=wave_old[o][-1]]
flux_new = spl(select_wave) flux_new = spl(select_wave)
start[o] = select_wave[0] start[o] = select_wave[0]
#shift = int((start[o]-end[o+1])/wstep)+1
end[o] = select_wave[-1] end[o] = select_wave[-1]
flux_new[abs(flux_new)<1e-04] = 0 flux_new[abs(flux_new)<1e-04] = 0
#print len(flux_new) #print len(flux_new)
if s1d.any(): if s1d.any():
gap = start[o]- (end[o+1]+wstep) gap = start[o]- (end[o+1]+wstep)
ngap = max(int(round(gap/wstep,0)),0) ngap = max(int(round(gap/wstep,0)),0)
s1d = np.append(s1d,np.zeros(ngap)) s1d = np.append(s1d,np.zeros(ngap))
#print shift
#if shift < 1:
# new = flux_new[0:-shift]
# old = s1d[shift:]
# if np.mean(new) > np.mean(old):
# s1d[shift:] = new
# shift = -shift+1
#else:
# shift = 0
#s1d = np.append(s1d,flux_new[shift:])
s1d = np.append(s1d,flux_new) s1d = np.append(s1d,flux_new)
#t2 = time.time() #t2 = time.time()
......
...@@ -164,28 +164,36 @@ class GBWls(): ...@@ -164,28 +164,36 @@ class GBWls():
straight = lamp.replace('.fits','_str.fits') straight = lamp.replace('.fits','_str.fits')
extracted = lamp.replace('.fits','_ext.fits') extracted = lamp.replace('.fits','_ext.fits')
shift = db.extract_dbfile(self.dbconn,'shiftY') args = [CONFIG['STRAIGHT'],lamp,straight]
if not shift: args.extend(CONFIG['STRAIGHT_OPT'])
# search for shift defined in the straighten options in config.py
dy = True
for opt in CONFIG['STRAIGHT_OPT']:
try: try:
cal_flat = db.extract_dbfile(self.dbconn,'flat') dy = opt.rindex('DY=')
mflat = ccdproc.CCDData.read(cal_flat, unit=u.adu) ypos = int(opt[dy-2:])
shift = varie.shiftY(mflat.data) shift = CONFIG['SHIFT_Y'] + ypos
db.insert_dbfile(self.dbconn,'shiftY',shift) dy = False
except: except:
try: pass
if dy:
shift = db.extract_dbfile(self.dbconn,'shiftY')
if not shift:
cal_flat = db.extract_dbfile(self.dbconn,'flat')
if cal_flat:
mflat = ccdproc.CCDData.read(cal_flat, unit=u.adu)
shift = varie.shiftY(mflat.data)
db.insert_dbfile(self.dbconn,'shiftY',shift)
else:
db.copy_dbfile(self.dbconn,'shiftY') db.copy_dbfile(self.dbconn,'shiftY')
shift = db.extract_dbfile(self.dbconn,'shiftY') shift = db.extract_dbfile(self.dbconn,'shiftY')
if not shift: if not shift:
shift = CONFIG['SHIFT_Y'] shift = CONFIG['SHIFT_Y']
except:
shift = CONFIG['SHIFT_Y']
shiftY = ''.join(('DY=',str(shift - CONFIG['SHIFT_Y'])))
#print shiftY
args = [CONFIG['STRAIGHT'],lamp,straight] shiftY = [''.join(('DY=',str(shift - CONFIG['SHIFT_Y'])))]
args.extend(CONFIG['STRAIGHT_OPT']) #print shiftY
args.extend(shiftY) args.extend(shiftY)
subprocess.call(args) subprocess.call(args)
......
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