Example #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
        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':[]}
Example #2
0
 def __init__(self, *args, **kw):
     super(AssignLines, self).__init__(*args, **kw)
     if self.spectrum is not None:
         spec = MeshLinePlot(color=[1,1,0,1], 
                             points=zip(self.spectrum.wav, self.spectrum.spec))
         self.ids.graph.add_plot(spec)
     if self.synth:
         ok = np.logical_and(np.greater_equal(self.synth[0], self.exp_lo),
                             np.less_equal(self.synth[0], self.exp_hi))
         self.synth = [x[ok] for x in self.synth]
         normwav = self.synth[1] / replace_nans(self.synth[1]).max()
         syn = MeshLinePlot(color=[1,0,1,1],
                            points=zip(self.synth[0], normwav))
         self.ids.synth.add_plot(syn)
 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)