def fix_distort(self): if not (self.fit_params.get('pmodel',False) or \ self.fit_params.get('nmodel',False)): popup = WarningDialog(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']) im1, im2 = [x for x in copy.deepcopy(self.theapp.extract_pairs[self.pair_index])] im1.load(); im2.load() #if self.current_flats: # im1 = im_divide(im1, self.current_flats) # im2 = im_divide(im2, self.current_flats) im1.data_array = undistort_imagearray(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 extract_spectrum(self): if not (self.fit_params.get('pmodel',False) or \ self.fit_params.get('nmodel',False)): popup = WarningDialog(text='Make sure you fit the trace centers first!') popup.open() return #need a calibration, too self.lamp = None if theapp.current_night.cals: self.lamp = theapp.current_night.cals.data_array if not self.current_flats \ else im_divide(theapp.current_night.cals, self.current_flats).data_array self.lamp = self.lamp[self.region[1]:self.region[3]+1,self.region[0]:self.region[2]+1] im1, im2 = [x for x in copy.deepcopy(the_app.extract_pairs[self.pair_index])] im1.load(); im2.load() #if self.current_flats: # im1 = im_divide(im1, self.current_flats) # im2 = im_divide(im2, self.current_flats) im1.data_array = undistort_imagearray(im1.data_array, pdistort) im2.data_array = undistort_imagearray(im2.data_array, ndistort) self.tell = make_region(im1, im2, self.region, flat=self.current_flats, telluric=True) #tmp, self.tell = im_minimum(im1.data_array, im2.data_array) #self.tell = self.tell[self.region[1]:self.region[3]+1,self.region[0]:self.region[2]+1] self.pextract = extract(self.fit_params['pmodel'], self.extractregion, self.tell, 'pos', lamp = self.lamp) self.nextract = extract(self.fit_params['nmodel'], self.extractregion, self.tell, 'neg', lamp = self.lamp) #write uncalibrated spectra to fits files (will update after calibration) pstub = self.paths['out'] + re.sub('.fits','-ap%i',im1.fitsfile) ext = ('.fits','-sky.fits','-lamp.fits') h = im1.header for i, p_ap in enumerate(self.pextract): for j in range(p_ap.shape[1]): spec = p_ap[:,j] write_fits((pstub + ext[i]) % j, h, spec) nstub = self.paths['out'] + re.sub('.fits','-ap%i',im2.fitsfile) h = im2.header for i, n_ap in enumerate(self.nextract): for j in range(n_ap.shape[1]): spec = n_ap[:,j] write_fits((nstub + ext[i]) % j, h, spec)