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
CONFIG['YCCD'] = 2048
CONFIG['N_ORD'] = 50 # number of echelle orders
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
......
......@@ -215,6 +215,20 @@ class GBFlats():
nor = flat.replace('.fits','_nor.fits')
#extracted = flat.replace('.fits','_ext.fits')
args = [CONFIG['STRAIGHT'],flat,straight]
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:
dy = opt.rindex('DY=')
ypos = int(opt[dy-2:])
shift = CONFIG['SHIFT_Y'] + ypos
dy = False
except:
pass
if dy:
shift = db.extract_dbfile(self.dbconn,'shiftY')
if not shift:
cal_flat = db.extract_dbfile(self.dbconn,'flat')
......@@ -222,14 +236,11 @@ class GBFlats():
shift = varie.shiftY(mflat.data)
db.insert_dbfile(self.dbconn,'shiftY',shift)
shiftY = ''.join(('DY=',str(shift - CONFIG['SHIFT_Y'])))
shiftY = [''.join(('DY=',str(shift - CONFIG['SHIFT_Y'])))]
#print shiftY
#args = [CONFIG['STRAIGHT'],flat,straight,CONFIG['STRAIGHT_OPT']]
args = [CONFIG['STRAIGHT'],flat,straight]
args.extend(CONFIG['STRAIGHT_OPT'])
args.extend(shiftY)
#print args
subprocess.call(args)
red_straight = os.path.join(CONFIG['RED_CALIB'],os.path.basename(straight))
......
......@@ -178,27 +178,35 @@ class GBNodding():
straight = fitsfile.replace('.fits','_str.fits')
args = [CONFIG['STRAIGHT'],fitsfile,straight]
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:
dy = opt.rindex('DY=')
ypos = int(opt[dy-2:])
shift = CONFIG['SHIFT_Y'] + ypos
dy = False
except:
pass
if dy:
shift = db.extract_dbfile(self.dbconn,'shiftY')
if not shift:
try:
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)
except:
try:
else:
db.copy_dbfile(self.dbconn,'shiftY')
shift = db.extract_dbfile(self.dbconn,'shiftY')
if not shift:
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
args = [CONFIG['STRAIGHT'],fitsfile,straight]
args.extend(CONFIG['STRAIGHT_OPT'])
args.extend(shiftY)
subprocess.call(args)
......
......@@ -326,27 +326,35 @@ class GBStare():
straight = fitsfile.replace('.fits','_str.fits')
args = [CONFIG['STRAIGHT'],fitsfile,straight]
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:
dy = opt.rindex('DY=')
ypos = int(opt[dy-2:])
shift = CONFIG['SHIFT_Y'] + ypos
dy = False
except:
pass
if dy:
shift = db.extract_dbfile(self.dbconn,'shiftY')
if not shift:
try:
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)
except:
try:
else:
db.copy_dbfile(self.dbconn,'shiftY')
shift = db.extract_dbfile(self.dbconn,'shiftY')
if not shift:
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
args = [CONFIG['STRAIGHT'],fitsfile,straight]
args.extend(CONFIG['STRAIGHT_OPT'])
args.extend(shiftY)
subprocess.call(args)
......
......@@ -93,15 +93,15 @@ def stdcombine(x,axis):
#-------------- Define straighten option vertical shift -------------------
def shiftY(fdata):
# search for shift defined in the straighten options in config.py
try:
for opt in CONFIG['STRAIGHT_OPT']:
try:
dy = opt.rindex('DY=')
ypos = int(opt[dy-1:])
shift = CONFIG['SHIFT_Y'] + ypos
return shift
#for opt in CONFIG['STRAIGHT_OPT']:
# try:
# dy = opt.rindex('DY=')
# ypos = int(opt[dy-2:])
# shift = CONFIG['SHIFT_Y'] + ypos
# return shift
# except:
# pass
# 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
background = np.sort(column)[20] # value of the 20th pixel after arranging them in ascending order
#print column
......@@ -335,6 +335,7 @@ def optExtract(data,gain,ron,slit_pos,ordine):
OptFlux[OptFlux==-np.inf] = 0
OptFlux = np.nan_to_num(OptFlux)
OptFlux[OptFlux<0] = 0
#t5 = time.time()
#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):
OptFlux[OptFlux==-np.inf] = 0
OptFlux = np.nan_to_num(OptFlux)
OptFlux[OptFlux<0] = 0
# update the model and its variance
model = OptFlux*profile
#model[rworst,cworst] = 0
......@@ -1170,13 +1173,14 @@ def create_s1d(spectrum, header):
wave_old[o] = wave_old[o]*(1+(berv/c))
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)
#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)
except:
#shift = 1
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))
end[o] = round(start[o]+(nstep*wstep),3)
......@@ -1190,6 +1194,7 @@ def create_s1d(spectrum, header):
select_wave = wave_new[o][wave_old[o][0]<=wave_new[o]<=wave_old[o][-1]]
flux_new = spl(select_wave)
start[o] = select_wave[0]
#shift = int((start[o]-end[o+1])/wstep)+1
end[o] = select_wave[-1]
flux_new[abs(flux_new)<1e-04] = 0
......@@ -1200,6 +1205,17 @@ def create_s1d(spectrum, header):
ngap = max(int(round(gap/wstep,0)),0)
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)
#t2 = time.time()
......
......@@ -164,27 +164,35 @@ class GBWls():
straight = lamp.replace('.fits','_str.fits')
extracted = lamp.replace('.fits','_ext.fits')
args = [CONFIG['STRAIGHT'],lamp,straight]
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:
dy = opt.rindex('DY=')
ypos = int(opt[dy-2:])
shift = CONFIG['SHIFT_Y'] + ypos
dy = False
except:
pass
if dy:
shift = db.extract_dbfile(self.dbconn,'shiftY')
if not shift:
try:
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)
except:
try:
else:
db.copy_dbfile(self.dbconn,'shiftY')
shift = db.extract_dbfile(self.dbconn,'shiftY')
if not shift:
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
args = [CONFIG['STRAIGHT'],lamp,straight]
args.extend(CONFIG['STRAIGHT_OPT'])
args.extend(shiftY)
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