コード例 #1
0
ファイル: main.py プロジェクト: crawfordsm/ir-reduce
 def wavecal(self):
     if not self.linelist:
         popup = WarningDialog(text="Please select a line list first.")
         popup.open()
         return
     calfile = self.paths['cal'] + self.speclist[self.spec_index]
     if self.ids.lampcal.state == 'down':
         calfile += '-lamp.fits'
     else:
         calfile += '-sky.fits'
     try:
         calib = ExtractedSpectrum(calfile)
     except:
         popup = WarningDialog(text="You don't have a calibration of this type...")
         popup.open()
         return
     niter = self.ids.numiter.text
     if self.linelist in self.linelists:
         #lldb = shelve.open('storage/linelists')
         #linelist_path = ird.deserialize(linelistdb[self.lineslist])
         linelist_path = linelistdb[self.linelist]
         #lldb.close()
     else:
         linelist_path = self.linelist
     self.calibration = calibrate_wavelength(calib, linelist_path, (self.wmin, self.wmax), niter)
     for i, w in self.calibration.parameters:
         self.current_spectrum.header['WAVECAL%i'%i] = (w, 'Wavelength calibration coefficient')
     self.current_spectrum.wav = self.calibration(range(len(self.current_spectrum.spec)))
     self.wmin = self.current_spectrum.wav.min()
     self.wmax = self.current_spectrum.wav.max()
     self.current_spectrum.plot.points = zip(self.current_spectrum.wav, self.current_spectrum.spec)
コード例 #2
0
ファイル: main.py プロジェクト: crawfordsm/ir-reduce
 def fix_distort(self):
     if not (self.fit_params.get('pmodel',False) or \
         self.fit_params.get('nmodel',False)):
         popup = WarningDialog(text='Make sure you fit the trace centers first!')
         popup.open()
         return
     pdistort, ndistort = draw_trace(self.extractregion, self.xx, self.fit_params['pmodel'], \
         self.fit_params['nmodel'], fixdistort = True, fitdegree = self.fit_params['deg'])
     
     im1, im2 = [x for x in copy.deepcopy(self.theapp.extract_pairs[self.pair_index])]
     im1.load(); im2.load()
     #if self.current_flats:
     #    im1 = im_divide(im1, self.current_flats)
     #    im2 = im_divide(im2, self.current_flats)
     im1.data_array = undistort_imagearray(im1.data_array, pdistort)
     im2.data_array = undistort_imagearray(im2.data_array, ndistort)
     im_subtract(im1, im2, outputfile=self.current_impair.fitsfile)
     tmp = self.current_impair
     self.current_impair = FitsImage(self.current_impair.fitsfile)
     self.current_impair.header['EXREGX1'] = (tmp.get_header_keyword('EXREGX1'), 'extraction region coordinate X1')
     self.current_impair.header['EXREGY1'] = (tmp.get_header_keyword('EXREGY1'), 'extraction region coordinate Y1')
     self.current_impair.header['EXREGX2'] = (tmp.get_header_keyword('EXREGX2'), 'extraction region coordinate X2')
     self.current_impair.header['EXREGY2'] = (tmp.get_header_keyword('EXREGY2'), 'extraction region coordinate Y2')
     self.current_impair.update_fits(header_only = True)
     self.set_imagepair(self.pairstrings[self.pair_index])
     self.fit_params['nmodel'] = None
     self.fit_params['pmodel'] = None
コード例 #3
0
ファイル: main.py プロジェクト: crawfordsm/ir-reduce
 def check_filestub(self, stub):
     placeholder = '#'
     reg = placeholder+'+'
     if len(re.findall(reg, stub)) != 1:
         popup = WarningDialog(text = "File format is not valid; must use '#' as placeholder only")
         popup.open()
         return
     self.current_obsnight = self.current_obsnight._replace(filestub=stub) 
コード例 #4
0
ファイル: main.py プロジェクト: crawfordsm/ir-reduce
 def extract_spectrum(self):
     if not (self.fit_params.get('pmodel',False) or \
         self.fit_params.get('nmodel',False)):
         popup = WarningDialog(text='Make sure you fit the trace centers first!')
         popup.open()
         return
     
     #need a calibration, too
     self.lamp = None
     if theapp.current_night.cals:
         self.lamp = theapp.current_night.cals.data_array if not self.current_flats \
             else im_divide(theapp.current_night.cals, self.current_flats).data_array
         self.lamp = self.lamp[self.region[1]:self.region[3]+1,self.region[0]:self.region[2]+1]
     im1, im2 = [x for x in copy.deepcopy(the_app.extract_pairs[self.pair_index])]
     im1.load(); im2.load()
     #if self.current_flats:
     #    im1 = im_divide(im1, self.current_flats)
     #    im2 = im_divide(im2, self.current_flats)
     im1.data_array = undistort_imagearray(im1.data_array, pdistort)
     im2.data_array = undistort_imagearray(im2.data_array, ndistort)
     self.tell = make_region(im1, im2, self.region, flat=self.current_flats, telluric=True)
     #tmp, self.tell = im_minimum(im1.data_array, im2.data_array)
     #self.tell = self.tell[self.region[1]:self.region[3]+1,self.region[0]:self.region[2]+1]
     self.pextract = extract(self.fit_params['pmodel'], self.extractregion, self.tell, 'pos', lamp = self.lamp)
     self.nextract = extract(self.fit_params['nmodel'], self.extractregion, self.tell, 'neg', lamp = self.lamp)
     
     #write uncalibrated spectra to fits files (will update after calibration)
     pstub = self.paths['out'] + re.sub('.fits','-ap%i',im1.fitsfile)
     ext = ('.fits','-sky.fits','-lamp.fits')
     h = im1.header
     for i, p_ap in enumerate(self.pextract):
         for j in range(p_ap.shape[1]):
             spec = p_ap[:,j]
             write_fits((pstub + ext[i]) % j, h, spec)
     
     nstub = self.paths['out'] + re.sub('.fits','-ap%i',im2.fitsfile)
     h = im2.header
     for i, n_ap in enumerate(self.nextract):
         for j in range(n_ap.shape[1]):
             spec = n_ap[:,j]
             write_fits((nstub + ext[i]) % j, h, spec)
コード例 #5
0
ファイル: main.py プロジェクト: crawfordsm/ir-reduce
 def set_spectrum(self, spec):
     self.spec_index = self.speclist.index(spec)
     try:
         tmp = ExtractedSpectrum(self.paths['out']+self.speclist[self.spec_index] + '.fits')
     except:
         popup = WarningDialog(text="You haven't extracted that spectrum yet!")
         popup.open()
         return
     if self.current_spectrum:
         self.ids.specdisplay.remove_plot(self.current_spectrum.plot)
     self.current_spectrum = tmp
     self.current_spectrum.plot = MeshLinePlot(color=[.9,1,1,1])
     if not self.current_spectrum.wav:
         self.wmin = 0
         self.wmax = len(self.current_spectrum.spec)-1
         self.current_spectrum.wav = range(self.wmax)
     else:
         self.wmin = self.current_spectrum.wav.min()
         self.wmax = self.current_spectrum.wav.max()
     self.dmin, self.dmax = minmax(self.current_spectrum.spec)
     self.current_spectrum.plot.points = zip(self.current_spectrum.wav, self.current_spectrum.spec)
     self.ids.specdisplay.add_plot(self.current_spectrum.plot)
コード例 #6
0
ファイル: main.py プロジェクト: crawfordsm/ir-reduce
 def fit_trace(self):
     if not self.fit_params or self.fit_params['shape'] not in ('Gaussian','Lorentzian'):
         popup = WarningDialog(text='Make sure you set up your fit parameters!')
         popup.open()
         return
     pos = {'pos':[x.slider.value for x in self.apertures['pos']], \
         'neg':[x.slider.value for x in self.apertures['neg']]}
     for x in self.trace_lines:
         if x in self.ids.the_graph.plots:
             self.ids.the_graph.remove_plot(x)
     if self.fit_params.get('man',False):
         popup = DefineTrace(npos=len(self.apertures['pos']), \
             nneg=len(self.apertures['neg']), imtexture = self.iregion)
         popup.bind(on_dismiss = self.manual_trace(popup.tracepoints))
         popup.open()
         return
     self.xx, self.fit_params['pmodel'], self.fit_params['nmodel'] = \
         fit_multipeak(self.tracepoints, pos = pos, wid = self.fit_params['wid'], \
         ptype = self.fit_params['shape'])
     self.trace_lines[0].points = zip(self.xx, self.fit_params['pmodel'](self.xx))
     self.trace_lines[1].points = zip(self.xx, self.fit_params['nmodel'](self.xx))
     self.ids.the_graph.add_plot(self.trace_lines[0])
     self.ids.the_graph.add_plot(self.trace_lines[1])
コード例 #7
0
ファイル: main.py プロジェクト: crawfordsm/ir-reduce
 def set_imagepair(self, val):
     if not self.theapp.current_target:
         popup = WarningDialog(text='You need to select a target (on the Observing Screen) before proceeding!')
         popup.open()
         return
     pair_index = self.pairstrings.index(val)
     fitsfile = self.paths['out']+re.sub(' ','',re.sub('.fits','',val))+'.fits'
     if not path.isfile(fitsfile):
         im1, im2 = [x for x in copy.deepcopy(self.extract_pairs[pair_index])]
         im1.load(); im2.load()
         #if self.current_flats:
         #    tmp = im_divide(im1, self.current_flats)
         #    im1.header, im1.data_array = tmp
         #    tmp = im_divide(im2, self.current_flats)
         #    im2.header, im2.data_array = tmp
         im_subtract(im1, im2, outputfile=path.join(self.paths['out'],fitsfile))
     self.current_impair = FitsImage(path.join(self.paths['out'],fitsfile), load=True)
     self.ids.ipane.load_data(self.current_impair)
     self.imwid, self.imht = self.current_impair.dimensions
     if self.current_impair.get_header_keyword('EXREGX1'):
         for x in ['x1', 'y1', 'x2', 'y2']:
             tmp = self.current_impair.get_header_keyword('EXREG'+x.upper())
             if tmp[0] is not None:
                 self.set_coord(x, tmp[0])
コード例 #8
0
ファイル: main.py プロジェクト: crawfordsm/ir-reduce
 def set_imagepair(self, val):
     if not self.theapp.current_target:
         popup = WarningDialog(text='You need to select a target (on the Observing Screen) before proceeding!')
         popup.open()
         return
     self.pair_index = self.pairstrings.index(val)
     fitsfile = self.paths['out']+re.sub(' ','',re.sub('.fits','',val))+'.fits'
     if not path.isfile(fitsfile):
         popup = WarningDialog(text='You have to select an extraction'\
             'region for this image pair \nbefore you can move on to this step.')
         popup.open()
         return
     self.current_impair = FitsImage(fitsfile)
     self.region = self.current_impair.get_header_keyword(*('EXREG' + x for x in ['X1','Y1','X2','Y2']))
     if not any(self.region):
         popup = WarningDialog(text='You have to select an extraction'\
             'region for this image pair \nbefore you can move on to this step.')
         popup.open()
         return
     self.current_impair.load()
     idata = ''.join(map(chr,self.current_impair.scaled))
     self.itexture.blit_buffer(idata, colorfmt='luminance', bufferfmt='ubyte', \
         size = self.current_impair.dimensions)
     self.trace_axis = 0 if get_tracedir(self.current_target.instrument_id) == 'vertical' else 1
     #tmp = self.current_impair.data_array[self.region[1]:self.region[3]+1,self.region[0]:self.region[2]+1]
     #self.extractregion = med_normal(tmp)
     tmp = self.theapp.extract_pairs[self.pair_index]
     if self.trace_axis:
         #self.trace_axis = 1
         reg = [self.region[x] for x in [1, 0, 3, 2]]
         self.extractregion = make_region(tmp[0], tmp[1], reg, self.current_flats)#.transpose()
     else:
         self.extractregion = make_region(tmp[0], tmp[1], self.region, self.current_flats).transpose()
     reg = self.region[:]
     reg[2] = reg[2] - reg[0]
     reg[3] = reg[3] - reg[1]
     self.iregion = self.itexture.get_region(*reg)
     dims = [[0,0],list(self.extractregion.shape)]
     dims[0][self.trace_axis] = 0.4 * self.extractregion.shape[self.trace_axis]
     dims[1][self.trace_axis] = 0.6 * self.extractregion.shape[self.trace_axis]
     self.tracepoints = robm(self.extractregion[dims[0][0]:dims[1][0]+1,\
         dims[0][1]:dims[1][1]+1], axis = self.trace_axis)
     self.tplot.points = interp_nan(list(enumerate(self.tracepoints)))
     pxs, self.tracepoints = zip(*self.tplot.points)
     self.drange = minmax(self.tracepoints)
     self.ids.the_graph.add_plot(self.tplot)