def set_aperture(self,new_ind): self.ids.fitdisplay.remove_plot(self.thetrace) self.ids.fitdisplay.remove_plot(self.thefit) self.ids.pointlist.clear_widgets() self.ap_index = new_ind x1, y1 = zip(*self.tracepoints[self.ap_index]) x2, y2 = x1, self.polyfits[self.ap_index](x1) self.thetrace = MeshLinePlot(color=(1,0,0,1), points = [x for (i, x) in \ self.tracepoints[self.ap_index] if self.traceselectors[self.ap_index][i]]) self.thetrace.mode = 'points' self.ids.fitdisplay.add_plot(self.thetrace) self.thefit = MeshLinePlot(color=(0,1,0,1), points = izip(x2, y2)) self.ids.fitdisplay.add_plot(self.thefit) x2, y2 = zip(*self.fitpoints[self.ap_index]) self.xmin, self.xmax = minmax(x1+x2) self.ymin, self.ymax = minmax(y1+y2) self.point_buttons = [] for i, p in enumerate(self.tracepoints[self.ap_index]): tmp = ToggleButton(text='X: {0:7.2d}, Y: {1:7.2d}'.format(*p), \ on_press=self.toggle_point(i, tmp.state)) tmp.state = 'down' if self.traceselectors[self.ap_index][i] else 'normal' self.point_buttons.append(tmp) self.ids.pointlist.add_widget(tmp)
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)
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)