Exemplo n.º 1
0
 def set_imagepair(self, val):
     if not self.theapp.current_target:
         popup = AlertDialog(text='You need to select a target (on the Observing Screen) before proceeding!')
         popup.open()
         return
     header = [[0],[0]]
     pair = self.extract_pairs[self.pairstrings.index(val)]
     self.current_extraction = self.current_target.extractions.get(str(hash(':'.join(pair))), None)
     if not self.current_extraction:
         im1, im2 = [fitsimage(os.path.join(self.paths['raw'], x), header[i]) for i, x in enumerate(pair)]
         if 'EXREGX1' in header[0] or 'EXREGX1' in header[1]:
             for x in ['x1','y1','x2','y2']:
                 tmp = header[0]['EXREG'+x.upper()] or header[1]['EXREG'+x.upper()]
                 if tmp:
                     self.set_coord(x, tmp)
         region = map(int,[self.bx1, self.by1, self.bx2, self.by2])
         td = int(tracedir(self.current_target.instrument_id) == 'horizontal')
         self.current_extraction = extraction(im1, im2, self.current_flats, region,
                                              td, 'Gaussian')
         self.current_extraction.file1 = pair[0]
         self.current_extraction.file2 = pair[1]
         self.current_extraction.flatfile = os.path.join(self.paths['cal'],'Flat.fits')
         self.theapp.current_target.extractions[self.current_extraction.name] = self.current_extraction
     else:
         self.bx1, self.by1, self.bx2, self.by2 = self.current_extraction.region
     im = scalable_image(self.current_extraction.diff)
     self.ids.ipane.load_data(im)
     self.imwid, self.imht = im.dimensions
Exemplo n.º 2
0
 def go_screen(self, idx):
     if (idx > 1 and self.root.ids.sm.screens[1].current_target.targid == ''):
         popup = AlertDialog(text='You need to select a target before proceeding!')
         popup.open()
         return
     self.index = idx
     self.update_screen()
Exemplo n.º 3
0
 def go_next_screen(self): 
     if (self.root.ids.sm.current == 'observing' and 
         self.root.ids.sm.screens[1].current_target.targid == ''):
         popup = AlertDialog(text='You need to select a target before proceeding!')
         popup.open()
         return
     self.index = (self.index + 1) % len(self.screen_names)
     self.update_screen()
Exemplo n.º 4
0
 def check_filestub(self, stub):
     placeholder = '#'
     reg = placeholder+'+'
     if len(re.findall(reg, stub)) != 1:
         popup = AlertDialog(text = "File format is not valid; must use '#' as placeholder only")
         popup.open()
         return
     self.current_obsnight.filestub = stub
Exemplo n.º 5
0
 def wavecal(self):
     if not self.linelist:
         popup = AlertDialog(text="Please select a line list first.")
         popup.open()
         return
     if not self.assignment.assignment:
         popup = AlertDialog(text='Please designate initial line assignments.')
         popup.open()
         return
     calfile = os.path.join(self.paths['cal'],self.speclist[self.spec_index])
     if self.ids.lampcal_toggle.state == 'down':
         calfile += '-lamp.fits'
     else:
         calfile += '-sky.fits'
     try:
         calib = ExtractedSpectrum(str(calfile))
     except IOError:
         popup = AlertDialog(text="You don't have a calibration of this type...")
         popup.open()
         return
     self.calibration = calibrate_wavelength(medfilt(calib.spec), list(self.synthspec), zip(*self.assignment.assignment))
     try:
         for i, w in enumerate(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.ids.specdisplay.xmin = float(floor_round(self.current_spectrum.wav.min(), dec=1))
         self.ids.specdisplay.xmax = float(ceil_round(self.current_spectrum.wav.max(), dec=1))
         self.ids.specdisplay.xlabel = 'Wavelength'
         self.current_spectrum.plot.points = zip(self.current_spectrum.wav, self.current_spectrum.spec)
         self.save_spectrum()
     except Exception as e:
         print e
Exemplo n.º 6
0
 def assign(self):
     if not self.linelist:
         popup = AlertDialog(text="Please select a line list first.")
         popup.open()
         return
     fext = '-lamp.fits' if self.theapp.current_night.cals else '-sky.fits'
     fname = os.path.join(self.paths['cal'], 
                          os.path.basename(self.current_spectrum.filename).replace('.fits', fext))
     cal = ExtractedSpectrum(fname)
     cal.spec = detrend(medfilt(cal.spec, 3))
     srange = [float(self.ids.wmin.text), float(self.ids.wmax.text)]
     self.synthspec = synth_from_range(dict(self.linelist), cal.spec.size, srange)
     self.assignment = AssignLines(spectrum=cal, synth=self.synthspec, exp_lo=srange[0], exp_hi=srange[1])
     self.assignment.open()
Exemplo n.º 7
0
 def fit_trace(self):
     if not self.fit_params or self.fit_params['shape'] not in ('Gaussian','Lorentzian'):
         popup = AlertDialog(text='Make sure you set up your fit parameters!')
         popup.open()
         return
     stripe = np.array(self.tracepoints, dtype=np.float64)
     wid = self.fit_params['wid']
     self.current_extraction.mtype = self.fit_params['shape']
     stripex = np.arange(stripe.size, dtype=float)
     pos = tuple((interp(stripe, stripex.astype(np.float64), np.array([x.slider.value], dtype=np.float64)), 
                  x.slider.value, 
                  wid) for x in self.apertures['pos']) + \
           tuple((interp(stripe, stripex.astype(np.float64), np.array([x.slider.value], dtype=np.float64)), 
                  x.slider.value, 
                  wid) 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
     peaks = fitpeaks1d(stripe, pos, model_type=self.fit_params['shape']).individual()
     self.fit_params['model'] = [p.parameters.tolist() for p in peaks]
     self.fit_params['pmodel'] = [p.parameters.tolist() for p in peaks if p.amplitude > 0]
     self.fit_params['nmodel'] = [p.parameters.tolist() for p in peaks if p.amplitude < 0]
     pmod = CompositeModel(tuple(self.fit_params['pmodel']), self.fit_params['shape'])
     nmod = CompositeModel(tuple(self.fit_params['nmodel']), self.fit_params['shape'])
     self.trace_lines[0].points = zip(stripex, pmod(stripex))
     self.trace_lines[1].points = zip(stripex, nmod(stripex))
     self.ids.the_graph.add_plot(self.trace_lines[0])
     self.ids.the_graph.add_plot(self.trace_lines[1])
Exemplo n.º 8
0
 def extract_spectrum(self):
     if not self.fit_params.get('model',False):
         popup = AlertDialog(text='Make sure you fit the trace centers first!')
         popup.open()
         return
     self.waiting.open()
     self.lamp = np.empty([2,2], dtype=np.float64)
     self.lamps = False
     if self.theapp.current_night.cals:
         self.lamp = self.theapp.current_night.cals if not self.current_flats \
             else im_divide(self.theapp.current_night.cals, self.current_flats)
         self.lamp = self.lamp[self.region[1]:self.region[3]+1,self.region[0]:self.region[2]+1]
         self.lamps = True
     t = Thread(target=self.extract_wrapper)
     t.start()
Exemplo n.º 9
0
 def set_imagepair(self, val):
     if not self.theapp.current_target:
         popup = AlertDialog(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 os.path.isfile(fitsfile):
         im1, im2 = [x for x in copy.deepcopy(self.extract_pairs[pair_index])]
         im1.load(); im2.load()
         im_subtract(im1, im2, outputfile=os.path.join(self.paths['out'],fitsfile))
     self.current_impair = FitsImage(os.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])
Exemplo n.º 10
0
 def fix_distort(self):
     popup = AlertDialog(text='This is not yet functional')
     popup.open()
     return
     if not (self.fit_params.get('model',False)):
         popup = AlertDialog(text='Make sure you fit the trace centers first!')
         popup.open()
         return
     trace = self.current_extraction.fit_trace(self.fit_params['model'], np.empty(0), False)
     #im1, im2 = [x for x in copy.deepcopy(self.theapp.extract_pairs[self.pair_index])]
     #im1.load(); im2.load()
     #dist_reshape = lambda x, y: x.reshape(len(y), x.size/len(y))
     #pdistort = dist_reshape(self.fit_params['pmodel'].parameters, self.apertures['pos'])
     #ndistort = dist_reshape(self.fit_params['nmodel'].parameters, self.apertures['neg'])
     #im1.data_array = self.current_extraction.fix_distortion(self.fit_params['model'])
     #im2.data_array = extract.fix_distortion(im2.data_array, ndistort)
     self.current_extraction.fix_distortion(trace)
     self.theapp.current_target.extractions[self.current_extraction.name] = self.current_extraction
     #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['model'] = None
     self.theapp.current_extraction = self.current_extraction
     self.theapp.save_current()
     #self.fit_params['nmodel'] = None
     #self.fit_params['pmodel'] = None
     pdb.set_trace()
Exemplo n.º 11
0
 def wavecal(self):
     if not self.linelist:
         popup = AlertDialog(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 = AlertDialog(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)
Exemplo n.º 12
0
 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 = AlertDialog(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 = SmoothLinePlot(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)
Exemplo n.º 13
0
 def set_imagepair(self, val):
     if not self.theapp.current_target:
         popup = AlertDialog(text='You need to select a target (on the Observing Screen) before proceeding!')
         popup.open()
         return
     header = [fits.Header()]*2
     pair = self.extract_pairs[self.pairstrings.index(val)]
     #im1, im2 = [FitsImage(os.path.join(self.paths['raw'], x), 
     #                      load=True) for x in pair]
     self.current_extraction = self.current_target.extractions.get(str(hash(':'.join(pair))), None)
     if not self.current_extraction:
         im1, im2 = [fitsimage(os.path.join(self.paths['raw'], x), header[i]) for i, x in enumerate(pair)]
         if 'EXREGX1' in header[0] or 'EXREGX1' in header[1]:
             for x in ['x1','y1','x2','y2']:
                 tmp = header[0]['EXREG'+x.upper()] or header[1]['EXREG'+x.upper()]
                 if tmp:
                     self.set_coord(x, tmp)
         region = map(int,[self.bx1, self.by1, self.bx2, self.by2])
         td = int(tracedir(self.current_target.instrument_id) == 'horizontal')
         #pdb.set_trace()
         self.current_extraction = extraction(im1, im2, self.current_flats, region,
                                              td, 'Gaussian')
         self.current_extraction.file1 = pair[0]
         self.current_extraction.file2 = pair[1]
         self.current_extraction.flatfile = os.path.join(self.paths['cal'],'Flat.fits')
         self.theapp.current_target.extractions[self.current_extraction.name] = self.current_extraction
     else:
         self.bx1, self.by1, self.bx2, self.by2 = self.current_extraction.region
     #fitsfile = self.paths['out']+re.sub(' ','',re.sub('.fits','',val))+'.fits'
     #im1, im2 = [x for x in copy.deepcopy(self.extract_pairs[pair_index])]
     #if not os.path.isfile(fitsfile):
     #    im1, im2 = [x for x in copy.deepcopy(self.extract_pairs[pair_index])]
     #    im1.load(); im2.load()
     #    im_subtract(im1, im2, outputfile=os.path.join(self.paths['out'],fitsfile))
     #self.current_impair = FitsImage(os.path.join(self.paths['out'],fitsfile), load=True)
     #self.ids.ipane.load_data(self.current_impair)
     im = scalable_image(self.current_extraction.diff)
     self.ids.ipane.load_data(im)
     self.imwid, self.imht = im.dimensions
Exemplo n.º 14
0
 def set_spectrum(self, spec):
     self.spec_index = self.speclist.index(spec)
     try:
         tmp = ExtractedSpectrum(str(os.path.join(self.paths['out'],self.speclist[self.spec_index] + '.fits')))
     except IOError:
         popup = AlertDialog(text="You haven't extracted that spectrum yet!")
         popup.open()
         return
     if self.current_spectrum:
         self.ids.specdisplay.remove_plot(self.current_spectrum.plot)
     if not self.theapp.current_night.cals:
         self.ids.lampcal_toggle.state = 'normal'
         self.ids.lampcal_toggle.disabled = True
         self.ids.skycal_toggle.state = 'down'
     self.current_spectrum = tmp
     self.current_spectrum.spec = medfilt(self.current_spectrum.spec, 3)
     self.current_spectrum.plot = MeshLinePlot(color=[.9,1,1,1])
     self.current_spectrum.plot.points = zip(self.current_spectrum.wav, self.current_spectrum.spec)
     self.ids.specdisplay.add_plot(self.current_spectrum.plot)
     self.ids.specdisplay.xmin = float(floor_round(self.current_spectrum.wav.min(), dec=1))
     self.ids.specdisplay.xmax = float(ceil_round(self.current_spectrum.wav.max(), dec=1))
     self.ids.specdisplay.ymin = float(floor_round(self.current_spectrum.spec.min(), dec=1))
     self.ids.specdisplay.ymax = float(ceil_round(self.current_spectrum.spec.max(), dec=1))
     self.ids.specdisplay.xlabel = ['Pixel','Wavelength']['WAVECAL0' in self.current_spectrum.header]
Exemplo n.º 15
0
    def set_imagepair(self, val):
        if not self.theapp.current_target:
            popup = AlertDialog(text='You need to select a target (on the Observing Screen) before proceeding!')
            popup.open()
            return
        if self.pairstrings.index(val) == self.pair_index:
            return
        self.clear_pair()
        self.pair_index = self.pairstrings.index(val)
        pair = self.theapp.extract_pairs[self.pair_index]
        extract_state = self.theapp.current_target.extractions.get(str(hash(':'.join(pair))),None)
        if extract_state:
            self.current_extraction = extract_state #extraction_from_state(extract_state, self.current_flats)
        else:
            popup = AlertDialog(text="You have to select an extraction region for this image pair before you can move on to this step.")
            popup.open()
            return
        self.current_impair = scalable_image(self.current_extraction.diff)
        self.trace_axis = int(tracedir(self.current_target.instrument_id) == 'horizontal')

        idata = ''.join(map(chr,self.current_impair.scaled))
        self.itexture.blit_buffer(idata, colorfmt='luminance', bufferfmt='ubyte', \
            size = self.current_impair.dimensions)
        self.extractregion = self.current_extraction.extract_region
        reg = self.current_extraction.region[:]
        reg[2] = reg[2] - reg[0]
        reg[3] = reg[3] - reg[1]
        #if self.trace_axis:
        #    self.iregion = self.itexture.get_region(*reg)
        #else:
        #    self.iregion = self.itexture.get_region(reg[1],reg[0],reg[3],reg[2])
        self.iregion = self.itexture.get_region(*reg)
        self.rtx = [0.0] + [[0.0, 1.0][self.trace_axis]]*2 + [1.0, 1.0] + [[1.0, 0.0][self.trace_axis]]*2 + [0.0]
        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 = twod_to_oned(self.extractregion[dims[0][0]:dims[1][0]+1,
                                                           dims[0][1]:dims[1][1]+1], axis=self.trace_axis)
        points = replace_nans(np.array(self.tracepoints))
        self.tplot.points = zip(np.arange(points.size), points)
        self.tracepoints = points
        self.drange = [float(points.min()), float(points.max())]
        self.ids.the_graph.add_plot(self.tplot)
        if self.current_extraction.name in self.trace_info:
            info = self.trace_info[self.current_extraction.name]
            for trace in info['ap']['pos']:
                self.add_postrace(val=trace)
            for trace in info['ap']['neg']:
                self.add_negtrace(val=trace)
            self.trace_lines = info['lines']
            self.ids.the_graph.add_plot(self.trace_lines[0])
            self.ids.the_graph.add_plot(self.trace_lines[1])
            self.fit_params = info['par']
        else:
            self.trace_info[self.current_extraction.name] = {'ap':{'pos':[], 'neg':[]}, 'lines':[]}
Exemplo n.º 16
0
 def fix_distort(self):
     popup = AlertDialog(text='This is not yet functional')
     popup.open()
     return
     if not (self.fit_params.get('model',False)):
         popup = AlertDialog(text='Make sure you fit the trace centers first!')
         popup.open()
         return
     trace = self.current_extraction.fit_trace(self.fit_params['model'], np.empty(0), False)
     self.current_extraction.fix_distortion(trace)
     self.theapp.current_target.extractions[self.current_extraction.name] = self.current_extraction
     self.set_imagepair(self.pairstrings[self.pair_index])
     self.fit_params['model'] = None
     self.theapp.current_extraction = self.current_extraction
     self.theapp.save_current()
Exemplo n.º 17
0
 def alert(self, message, button_message="Close"):
     alert = AlertDialog(message, button_message)
     self.beep()
     alert.show()
     alert.exec_()
Exemplo n.º 18
0
 def set_imagepair(self, val):
     if not self.theapp.current_target:
         popup = AlertDialog(text='You need to select a target (on the Observing Screen) before proceeding!')
         popup.open()
         return
     self.pair_index = self.pairstrings.index(val)
     pair = self.theapp.extract_pairs[self.pair_index]
     extract_state = self.theapp.current_target.extractions.get(str(hash(':'.join(pair))),None)
     if extract_state:
         self.current_extraction = extract_state #extraction_from_state(extract_state, self.current_flats)
     else:
         popup = AlertDialog(text='You have to select an extraction'\
             'region for this image pair \nbefore you can move on to this step.')
         popup.open()
         return
     
     #fitsfile = self.paths['out']+re.sub(' ','',re.sub('.fits','',val))+'.fits'
     #if not os.path.isfile(fitsfile):
     #    popup = AlertDialog(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 = AlertDialog(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 = scalable_image(self.current_extraction.diff)
     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 tracedir(self.current_target.instrument_id) == 'vertical' else 1
     self.trace_axis = int(tracedir(self.current_target.instrument_id) == 'horizontal')
     #if self.trace_axis:
         #self.trace_axis = 1
     #    reg = [self.region[x] for x in [1, 0, 3, 2]]
         #self.extractregion = make_region(pair[0], pair[1], reg, self.current_flats)#.transpose()
     #else:
     #    self.extractregion = make_region(pair[0], pair[1], self.region, self.current_flats).transpose()
     #self.current_extraction = extraction(pair[0].data, pair[0].data, self.current_flats.data,
     #                                     self.region, self.trace_axis, 'Gaussian')
     self.extractregion = self.current_extraction.extract_region
     reg = self.current_extraction.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 = Robust2D(self.extractregion[dims[0][0]:dims[1][0]+1,
     #                                               dims[0][1]:dims[1][1]+1]).combine(axis=self.trace_axis)
     self.tracepoints = twod_to_oned(self.extractregion[dims[0][0]:dims[1][0]+1,
                                                        dims[0][1]:dims[1][1]+1], axis=self.trace_axis)
     #points = RobustData(self.tracepoints, index=True)
     #points.replace_nans(inplace=True)
     points = replace_nans(np.array(self.tracepoints))
     self.tplot.points = zip(np.arange(points.size), points)
     self.tracepoints = points
     self.drange = [float(points.min()), float(points.max())]
     self.ids.the_graph.add_plot(self.tplot)
Exemplo n.º 19
0
 def extract_spectrum(self):
     if not self.fit_params.get('model',False):
         popup = AlertDialog(text='Make sure you fit the trace centers first!')
         popup.open()
         return
     
     #need a calibration, too
     self.lamp = np.empty([2,2], dtype=np.float64)
     lamps = False
     if self.theapp.current_night.cals:
         self.lamp = self.theapp.current_night.cals if not self.current_flats \
             else im_divide(self.theapp.current_night.cals, self.current_flats)
         self.lamp = self.lamp[self.region[1]:self.region[3]+1,self.region[0]:self.region[2]+1]
         lamps = True
     
     #im1, im2 = [x for x in copy.deepcopy(self.theapp.extract_pairs[self.pair_index])]
     #im1.load(); im2.load()
     #im1.data_array = extract.fix_distortion(im1.data_array, pdistort)
     #im2.data_array = extract.fix_distortion(im2.data_array, ndistort)
     #self.tell = make_region(im1, im2, self.region, flat=self.current_flats, telluric=True)
     #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)
     self.current_extraction.fit_trace(self.fit_params['model'], self.lamp, lamps=lamps, extract=True)
     #if self.lamp.size > 0:
     #    spectra, tellurics, lamps = self.current_extraction.extract(trace, 
     #                                                                self.lamp, 
     #                                                                False)
     #else:
     #    spectra, telluric = self.current_extraction.extract(trace, self.lamp, True)
     
     #write uncalibrated spectra to fits files (will update after calibration)
     h1, h2 = fits.Header(), fits.Header()
     fitsimage(self.current_extraction.file1, h1)
     #im1 = FitsImage(self.current_extraction.file1, load=False)
     pstub = os.path.join(self.paths['out'], 
                          re.sub('.fits','-ap%i',
                                 os.path.basename(self.current_extraction.file1)))#im1.fitsfile)
     ext = ('.fits','-sky.fits','-lamp.fits')
     #h = im1.header
     h1['EXREGX1'] = (self.current_extraction.region[0], 'extraction region coordinate X1')
     h1['EXREGY1'] = (self.current_extraction.region[1], 'extraction region coordinate Y1')
     h1['EXREGX2'] = (self.current_extraction.region[2], 'extraction region coordinate X2')
     h1['EXREGY2'] = (self.current_extraction.region[3], 'extraction region coordinate Y2')
     fitsimage(self.current_extraction.file2, h2)
     nstub = os.path.join(self.paths['out'], 
                          re.sub('.fits','-ap%i',
                                 os.path.basename(self.current_extraction.file2)))#im2.fitsfile)
     #h = im2.header
     h2['EXREGX1'] = (self.current_extraction.region[0], 'extraction region coordinate X1')
     h2['EXREGY1'] = (self.current_extraction.region[1], 'extraction region coordinate Y1')
     h2['EXREGX2'] = (self.current_extraction.region[2], 'extraction region coordinate X2')
     h2['EXREGY2'] = (self.current_extraction.region[3], 'extraction region coordinate Y2')
     
     for j, typ in enumerate(['spec', 'tell']+['lamp']*lamps):
         specs = self.current_extraction.extracts[typ]
         if len(specs.shape) == 1:
             if self.fit_params['model'][0][0] > 0:
                 fits.writeto((pstub+ext[j])%0, specs, header=h1)
             else:
                 fits.writeto((nstub+ext[j])%0, specs*-1., header=h2)
         else:
             specs = specs.T
             for i, ap in enumerate(specs):
                 if self.fit_params['model'][i][0] > 0:
                     fits.writeto((pstub+ext[j])%i, ap, header=h1)
                 else:
                     fits.writeto((nstub+ext[j])%i, ap*-1., header=h2)
     return
Exemplo n.º 20
0
 def alert_aux(self, alert_text, button_text):
     self.log(alert_text)
     alert = AlertDialog(alert_text, button_text)
     self.beep(message="alert")
     alert.show()
     alert.exec_()