def arcstraight(data, xarr, istart, function='poly', order=3, rstep=1, y1=None, y2=None, sigma=5, sections=3, niter=5, log=None, verbose=True): """For a given image, assume that the line given by istart is the fiducial and then calculate the transformation between each line and that line in order to straighten the arc returns Wavlenght solution """ #set up the edges if y1 is None: y1=0 if y2 is None: y2=data.shape[0] # extract the central row ys, xs = data.shape farr = data[istart,:] xp, xf = st.findpoints(xarr, farr, sigma, niter, sections=sections) #short function to return closest peak def get_closest_x(y_arr, i): y = np.arange(len(y_arr)) j = (abs(y[y_arr >0] - i)).argmin() return y_arr[y[y_arr >0][j]] #loop through all lines and rows to trace the lines line_dict = {} yc = int(ys/2.0) xdiff = 5 for x in xp: y_arr = np.zeros(ys) y_arr[yc] = x for i in range(1, yc): if yc+i < y2: y_arr[yc+i] = st.mcentroid(xarr, data[yc+i,:], kern=st.default_kernal, xdiff=xdiff, xc=get_closest_x(y_arr, yc+i)) if yc+i > y1: y_arr[yc-i] = st.mcentroid(xarr, data[yc-i,:], kern=st.default_kernal, xdiff=xdiff, xc=get_closest_x(y_arr, yc-i)) line_dict[x] = y_arr #find the solution for each row iws={} xp = np.array(line_dict.keys()) for i in range(y1, y2): wp = [line_dict[x][i] for x in xp] ws = WavelengthSolution.WavelengthSolution(np.array(wp), xp, order=3, function='polynomial') ws.fit() exit() iws[i] = ws return iws
def addclosestline(self, x): """Find the closes line to the centroided position and add it """ cx = st.mcentroid(self.xarr, self.farr, xc=x, xdiff=self.mdiff) w = self.ws.value(cx) d = abs(self.slines - w) w = self.slines[d.argmin()] self.xp.append(x) self.wp.append(w) self.plotFeatures() self.redraw_canvas()
def onKeyPress(self, event): """Emit signal on key press""" if event.key=='?': #return the help file self.help() elif event.key=='q': #exit the task self.emit(QtCore.SIGNAL("quit()")) elif event.key=='c': #return the centroid if event.xdata: self.log.message(str(event.xdata), with_header=False) cx=st.mcentroid(self.xarr, self.farr, xc=event.xdata, xdiff=self.mdiff) self.emit(QtCore.SIGNAL("updatex(float)"), cx) elif event.key=='x': #return the x position if event.xdata: self.log.message(str(event.xdata), with_header=False) self.emit(QtCore.SIGNAL("updatex(float)"), event.xdata) elif event.key=='R': #reset the fit self.reset() elif event.key=='f': #find the fit self.findfit() self.emit(QtCore.SIGNAL("fitUpdate()")) elif event.key=='b': #auto-idenitfy features self.isFeature=True self.findfeatures() elif event.key=='z': #Assume the solution is correct and find the zeropoint #that best matches it from cross correllation self.findzp() elif event.key=='Z': #Assume the solution is correct and find the zeropoint #that best matches it from cross correllation self.findzpd() elif event.key=='e': #find closest feature from existing fit and line list #and match it pass elif event.key=='i': #reset identified features pass elif event.key=='t': #reset identified features self.isFeature=True self.testfeatures() elif event.key=='l': #plot the features from existing list if self.isFeature: self.isFeature=False self.redraw_canvas() else: self.isFeature=True self.plotFeatures() self.redraw_canvas() elif event.key=='p': #print information about features for i in range(len(self.xp)): print self.xp[i], self.wp[i] elif event.key=='P': #print information about features print self.ws.coef elif event.key=='r': #redraw graph self.redraw_canvas() elif event.key=='a': #draw artificial spectrum self.isArt= not self.isArt self.redraw_canvas() elif event.key=='d': #Delete feature save=False y=None if event.canvas==self.errfigure: y=event.ydata save=True self.deletepoints(event.xdata, y=y, save=save) self.redraw_canvas(keepzoom=True) elif event.key=='u': #undelete self.undeletepoints(event.xdata, y=event.ydata) self.redraw_canvas(keepzoom=True) elif event.key: self.emit(QtCore.SIGNAL("keyPressEvent(string)"), event.key)