def _updateFITSfiles(self): """ Updates the FITS files that were given in the configuration file with the derived flux factor. Interpolates the fitted ratio function if the wavelength scale of the file to be updated is different. """ #must interpolate the fitted function to right wavelength scale interp = interpolate.interp1d(self.fitting['obsWavelengths'], self.fitting['fit']) #loop over the files to be updated. for file in self.fitting['update']: fh = pf.open(file) hdu = fh[0].header data = fh[0].data ft = interp(basics.getWavelengths(file, len(data[0, :]))) for i, line in enumerate(data): data[i, :] = line / ft new = file.split('.fits')[0] + 'senscalib.fits' hdu.add_history('Original File: %s' % file) hdu.add_history( 'Pixel values modified by fluxCalibrateToSDSS.py (SMN)') hdu.add_history( 'Updated: %s' % datetime.datetime.isoformat(datetime.datetime.now())) if os.path.isfile(new): os.remove(new) fh.writeto(new, output_verify='ignore') fh.close() if self.debug: print '\nFile %s updated and saved as %s' % (file, new)
def _updateFITSfiles(self): """ Updates the FITS files that were given in the configuration file with the derived flux factor. Interpolates the fitted ratio function if the wavelength scale of the file to be updated is different. """ #must interpolate the fitted function to right wavelength scale interp = interpolate.interp1d(self.fitting['obsWavelengths'], self.fitting['fit']) #loop over the files to be updated. for file in self.fitting['update']: fh = pf.open(file) hdu = fh[0].header data = fh[0].data ft = interp(basics.getWavelengths(file, len(data[0,:]))) for i, line in enumerate(data): data[i, :] = line / ft new = file.split('.fits')[0] + 'senscalib.fits' hdu.add_history('Original File: %s' % file) hdu.add_history('Pixel values modified by fluxCalibrateToSDSS.py (SMN)') hdu.add_history('Updated: %s' % datetime.datetime.isoformat(datetime.datetime.now())) if os.path.isfile(new): os.remove(new) fh.writeto(new, output_verify='ignore') fh.close() if self.debug: print '\nFile %s updated and saved as %s' % (file, new)
def _deriveObservedSpectra(self): """ Derives a 1D spectrum from the 2D input data. Sums the pixels around the centre of the continuum that match to the SDSS fiber size. Multiplies the flux in the pixels next to the last full ones to include with the fractional flux we would otherwise be "missing". """ #y center and how many full pixels on either side we can include that would still #be within the SDSS fiber y = self.fitting['ycenter'] ymod = self.fitting['slitPix2'] #modify the lines of the fractional pixel information self.fitting['obsData'][y + ymod + 1, :] *= (self.fitting['slitPixFractional'] / 2.) self.fitting['obsData'][y - ymod - 1, :] *= (self.fitting['slitPixFractional'] / 2.) #sum the flux self.fitting['obsSpectrum'] = np.sum(self.fitting['obsData'][y-ymod-1:y+ymod+2, :], axis=0) / \ self.fitting['boosting'] #match the resolution, i.e. convolve the observed spectrum with a Gaussian self.fitting['obsSpectraConvolved'] = filt.gaussian_filter1d( self.fitting['obsSpectrum'], self.fitting['sigma']) #get a wavelength scale self.fitting['obsWavelengths'] = basics.getWavelengths( self.fitting['observed'], len(self.fitting['obsSpectraConvolved']))
def _deriveObservedSpectra(self): """ Derives a 1D spectrum from the 2D input data. Sums the pixels around the centre of the continuum that match to the SDSS fiber size. Multiplies the flux in the pixels next to the last full ones to include with the fractional flux we would otherwise be "missing". """ #y center and how many full pixels on either side we can include that would still #be within the SDSS fiber y = self.fitting['ycenter'] ymod = self.fitting['slitPix2'] #modify the lines of the fractional pixel information self.fitting['obsData'][y+ymod+1, :] *= (self.fitting['slitPixFractional'] / 2.) self.fitting['obsData'][y-ymod-1, :] *= (self.fitting['slitPixFractional'] / 2.) #sum the flux self.fitting['obsSpectrum'] = np.sum(self.fitting['obsData'][y-ymod-1:y+ymod+2, :], axis=0) / \ self.fitting['boosting'] #match the resolution, i.e. convolve the observed spectrum with a Gaussian self.fitting['obsSpectraConvolved'] = filt.gaussian_filter1d(self.fitting['obsSpectrum'], self.fitting['sigma']) #get a wavelength scale self.fitting['obsWavelengths'] = basics.getWavelengths(self.fitting['observed'], len(self.fitting['obsSpectraConvolved']))