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
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':[]}
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
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)