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])
def add_negtrace(self, val=None): tp = np.ascontiguousarray(self.tracepoints) peaks = findpeaks1d(tp, pn='neg') new_peak = float(peaks) peakheight = interp(tp, np.arange(tp.size, dtype=np.float64), np.array([new_peak])) plot = MeshLinePlot(color=[1,0,0,1], points=[(new_peak, 0), (new_peak, peakheight)]) self.ids.the_graph.add_plot(plot) newspin = ApertureSlider(aperture_line = plot, tfscreen = self) newspin.slider.range = [0, len(self.tracepoints)-1] newspin.slider.step = 0.1 newspin.slider.value = val or new_peak newspin.trash.bind(on_press = lambda x: self.remtrace('neg',newspin)) self.ids.negtrace.add_widget(newspin) self.apertures['neg'].append(newspin)
def fix_line(self, val): x, y = zip(*self.plot_points) top_y = interp(np.array(y, dtype=np.float64), np.array(x, dtype=np.float64), np.array([val])) self.aperture_line.points = [(val, 0), (val, top_y)]