def on_enter(self): self.pairstrings = ['{0} - {1}'.format(*[os.path.basename(x.fitsfile) for x in y]) \ for y in self.theapp.extract_pairs] if not self.theapp.current_flats and self.theapp.current_night.flaton: flat = os.path.join(self.paths['cal'],'Flat.fits') try: self.current_flats = FitsImage(flat, load = True) self.theapp.current_flats = self.current_flats except: if self.theapp.current_night.flaton and self.theapp.current_night.flaton[0]: fon = FitsImage(os.path.join(self.paths['cal'], \ self.theapp.current_night.flaton[0]), load=True) if self.theapp.current_night.flatoff and self.theapp.current_night.flatoff[0]: foff = FitsImage(os.path.join(self.paths['cal'], \ self.theapp.current_night.flatoff[0]), load=True) im_subtract(fon, foff, outputfile = flat) else: fits.writeto(flat, fon.data_array, header=fon.header) self.current_flats = FitsImage(flat, load = True) self.theapp.current_flats = self.current_flats else: self.current_flats = self.theapp.current_flats
def fix_distort(self): if not (self.fit_params.get('pmodel',False) or \ self.fit_params.get('nmodel',False)): popup = AlertDialog(text='Make sure you fit the trace centers first!') popup.open() return pdistort, ndistort = draw_trace(self.extractregion, self.xx, self.fit_params['pmodel'], \ self.fit_params['nmodel'], fixdistort = True, fitdegree = self.fit_params['deg'], bin=20) im1, im2 = [x for x in copy.deepcopy(self.theapp.extract_pairs[self.pair_index])] im1.load(); im2.load() im1.data_array = fix_distortion(im1.data_array, pdistort) im2.data_array = undistort_imagearray(im2.data_array, ndistort) im_subtract(im1, im2, outputfile=self.current_impair.fitsfile) tmp = self.current_impair self.current_impair = FitsImage(self.current_impair.fitsfile) self.current_impair.header['EXREGX1'] = (tmp.get_header_keyword('EXREGX1'), 'extraction region coordinate X1') self.current_impair.header['EXREGY1'] = (tmp.get_header_keyword('EXREGY1'), 'extraction region coordinate Y1') self.current_impair.header['EXREGX2'] = (tmp.get_header_keyword('EXREGX2'), 'extraction region coordinate X2') self.current_impair.header['EXREGY2'] = (tmp.get_header_keyword('EXREGY2'), 'extraction region coordinate Y2') self.current_impair.update_fits(header_only = True) self.set_imagepair(self.pairstrings[self.pair_index]) self.fit_params['nmodel'] = None self.fit_params['pmodel'] = None
def make_region(im1, im2, region, flat = None, telluric = False): if not im1.data_array.any(): im1.load() if not im2.data_array.any(): im2.load() reg1 = im1.data_array[region[0]:region[2]+1, region[1]:region[3]+1] reg2 = im2.data_array[region[0]:region[2]+1, region[1]:region[3]+1] if flat: freg = flat.data_array[region[0]:region[2]+1, region[1]:region[3]+1] freg /= np.median(freg) reg1 /= freg reg2 /= freg if telluric: return RobustData(im_minimum(reg1, reg2)).normalized return RobustData(im_subtract(reg1, reg2)).normalized