] i=1 for obs in tab: image_file = os.path.join('/Volumes/obiwan/azuri/spectra/IPHAS_GTC/',obs['FName']) hdulist = pyfits.open(image_file) # print 'type(hdulist) = ',type(hdulist) header = hdulist[0].header if header['OBJECT'] != '': obs['OName'] = header['OBJECT'] try: print('airmass = ',header['AIRMASS']) except: """do nothing""" print(obs) if True: wavelength = getWavelength(header) image_data = fits.getdata(image_file) # print 'type(image_data) = ',type(image_data) # print 'type(image_data[1000,1000]) = ',type(image_data[1000,1000]) # print 'len(image_data) = ',len(image_data) # print 'image_data.shape = ',image_data.shape # print 'image_data[1551,',obs['ObjectAreas'][0][0]+1,'] = ',image_data[1551,obs['ObjectAreas'][0][0]+1] imageMinusSky, imageSky = subtractSky(image_data,obs['SkyLeft'],obs['SkyRight']) # print 'imageMinusSky[1551,',obs['ObjectAreas'][0][0]+1,':',obs['ObjectAreas'][0][0]+5,'] = ',imageMinusSky[1551,obs['ObjectAreas'][0][0]+1:obs['ObjectAreas'][0][0]+5] obsCols = populateObjectArray(imageMinusSky,obs['ObjectAreas']) # print 'obsCols[1551,1:5] = ',obsCols[1551,1:5] # print 'obsCols[1000,0] = %.3e' % (obsCols[1000,0]) # print 'sum(obsCols[1551,:]) = ',np.sum(obsCols[1551,:]) obsColsSmoothed = boxCarMedianSmooth(obsCols, 0, 15)
from datetime import datetime as dt import math import numpy as np from matplotlib import pyplot as plt from myUtils import getWavelength, smooth, toYearFraction from Pa30_LBT import readLBTFiles photometry_file = '/Users/azuri/daten/uni/HKU/Pa30/variability/pa30_photometry_visual_1.txt' gtc_file = "/Users/azuri/daten/uni/HKU/Pa30/variability/Pa30_GT080716_cal_sum_cleaned.fits" wiyn_file = "/Users/azuri/daten/uni/HKU/Pa30/variability/Pa30_WN151014_cal_sum_cleaned_t.fits" gvaramadze_file = "/Users/azuri/daten/uni/HKU/Pa30/variability/gvaramadze.fits" gvaramadze_hdulist = pyfits.open(gvaramadze_file) gvaramadze_header = gvaramadze_hdulist[0].header gvaramadze_wavelength = np.array(getWavelength(gvaramadze_header, 1)) * unit['AA'] gvaramadze_spectrum = np.array( pyfits.getdata(gvaramadze_file)) * unit['erg/s/cm**2/AA'] #gvaramadze_wavelength,gvaramadze_spectrum = readGvaramadzeFile() garnavich_wavelength, garnavich_spectrum = readLBTFiles() garnavich_wavelength = np.array(garnavich_wavelength) garnavich_spectrum = np.array(garnavich_spectrum) garnavich_spectrum = garnavich_spectrum[garnavich_wavelength < 5455.] garnavich_wavelength = garnavich_wavelength[ garnavich_wavelength < 5455.] * unit['AA'] #garnavich_spectrum_smoothed = smooth(garnavich_spectrum,9)#scipy.ndimage.mean_filter(garnavich_spectrum, 7)#boxCarMeanSmooth(somme_spectrum, 0, 21) garnavich_spectrum = garnavich_spectrum * unit['erg/s/cm**2/AA'] gtc_hdulist = pyfits.open(gtc_file) wiyn_hdulist = pyfits.open(wiyn_file)
skyOutMedian = '/Users/azuri/daten/uni/HKU/Pa30/sparsepak/spectra/pa30_zdtsEcndr_skyMedian.fits' componentsOutRoot = '/Users/azuri/daten/uni/HKU/Pa30/sparsepak/spectra/pa30_zdtsEcndr_PCA' if standardStar: cubePlusSky = '/Users/azuri/daten/uni/HKU/Pa30/sparsepak/spectra/kwb_141015_114545_ori_zdtsEcn1dr.fits' cubeMinusSkyOut = '/Users/azuri/daten/uni/HKU/Pa30/sparsepak/spectra/kwb_141015_114545_ori_zdtsEcn1dr-skyMean.fits' cubeMinusSkyOutMedian = '/Users/azuri/daten/uni/HKU/Pa30/sparsepak/spectra/kwb_141015_114545_ori_zdtsEcn1dr-skyMedian.fits' skyOutMean = '/Users/azuri/daten/uni/HKU/Pa30/sparsepak/spectra/kwb_141015_114545_ori_zdtsEcn1dr_skyMean.fits' skyOutMedian = '/Users/azuri/daten/uni/HKU/Pa30/sparsepak/spectra/kwb_141015_114545_ori_zdtsEcn1dr_skyMedian.fits' componentsOutRoot = '/Users/azuri/daten/uni/HKU/Pa30/sparsepak/spectra/kwb_141015_114545_ori_zdtsEcn1dr_PCA' hdulistCubePlusSky = pyfits.open(cubePlusSky) wavelength = getWavelength(hdulistCubePlusSky[0].header, 1) print("wavelength = ",wavelength) dataCubePlusSky = hdulistCubePlusSky[0].data # create the PCA instance nComponents = 10 pca = PCA(nComponents) # fit on data pca.fit(dataCubePlusSky) # access values and vectors print('pca.components_ = ',pca.components_.shape,': ',pca.components_) print('pca_explained_variance_ = ',pca.explained_variance_.shape,': ',pca.explained_variance_) # transform data B = pca.transform(dataCubePlusSky) print('B = ',B.shape,': ',B)
from myUtils import getWavelength #execfile("/Users/azuri/entwicklung/python/myUtils.py")# import getDate, findClosestDate,... #ebv = 1.206 ebv = 0.79 # 3D map Bayestar15 #ebv = 0.99 # 3D map Bayestar17 R_V = 3.1 # (Fitzpatrick and Massa 2007) #R_V = 3.1 A_V = 2.4 #Claire ebv = A_V / R_V somme_file = "/Users/azuri/daten/uni/HKU/Pa30/_pa30_somme6_scaled.fits" somme_hdulist = pyfits.open(somme_file) somme_header = somme_hdulist[0].header somme_wavelength = getWavelength(somme_header, 1) somme_spectrum = fits.getdata(somme_file) print('somme_wavelength = ', somme_wavelength) somme_spectrum_smoothed = ndimage.median_filter(somme_spectrum, size=21) somme_spectrum_smoothed_dereddened = pyasl.unred(somme_wavelength, somme_spectrum_smoothed, ebv=ebv, R_V=R_V) plt.plot(somme_wavelength, np.log10(somme_spectrum_smoothed), 'm-', label='Buil scaled and smoothed') plt.plot(somme_wavelength, np.log10(somme_spectrum_smoothed_dereddened), 'm-') #, label='Somme scaled, smoothed, and dereddened') plt.legend()
lines_names = [ 'O VI', 'O VI', 'O VIII', 'O VIII', 'O VIII', 'C V', 'O VI', 'O VI', 'O VII', 'C IV', 'O VIII', 'C VI' ] lines_wave = [ 3811, 3834, 4340, 4501, 4658, 4944, 5270, 5291, 5670, 5808, 6068, 6202 ] leDu_file = "/Users/azuri/daten/uni/HKU/Pa30/variability/_pa30_20181009_941_PLeDu.fits" somme_file = "/Users/azuri/daten/uni/HKU/Pa30/variability/_pa30_somme6.fits" gtc_file = "/Users/azuri/daten/uni/HKU/Pa30/variability/Pa30_GT080716_cal_sum_cleaned.fits" wiyn_file = "/Users/azuri/daten/uni/HKU/Pa30/variability/Pa30_WN151014_cal_sum_cleaned_t.fits" gvaramadze_file = "/Users/azuri/daten/uni/HKU/Pa30/variability/gvaramadze.fits" gvaramadze_hdulist = pyfits.open(gvaramadze_file) gvaramadze_header = gvaramadze_hdulist[0].header gvaramadze_wavelength = getWavelength(gvaramadze_header, 1) gvaramadze_spectrum = fits.getdata(gvaramadze_file) #gvaramadze_wavelength,gvaramadze_spectrum = readGvaramadzeFile() gvaramadze_wavelength = np.array(gvaramadze_wavelength) gvaramadze_spectrum = np.array(gvaramadze_spectrum) garnavich_wavelength, garnavich_spectrum = readLBTFiles() garnavich_wavelength = np.array(garnavich_wavelength) garnavich_spectrum = np.array(garnavich_spectrum) garnavich_spectrum = garnavich_spectrum[garnavich_wavelength < 5455.] garnavich_wavelength = garnavich_wavelength[garnavich_wavelength < 5455.] garnavich_spectrum_smoothed = smooth( garnavich_spectrum, 9 ) #scipy.ndimage.mean_filter(garnavich_spectrum, 7)#boxCarMeanSmooth(somme_spectrum, 0, 21) def plot_lines():
import astropy.io.fits as pyfits import matplotlib.pyplot as plt import numpy as np from myUtils import getWavelength calibratedSpectraFile = '/Users/azuri/daten/uni/HKU/Pa30/sparsepak/spectra/pa30_zdtsEcndr-skyMedian_cal.fits' calibratedSpectraFile = '/Users/azuri/daten/uni/HKU/Pa30/sparsepak/spectra/pa30_zd_Ecmsndr-skyMedian_cal.fits' starSpectra = [0,4,5,6,9,18,20,21,30,33,] hdulist = pyfits.open(calibratedSpectraFile) header = hdulist[0].header wavelength = getWavelength(header,1) spectrum = hdulist[0].data print('spectrum = ',spectrum.shape,': ',spectrum) print('wavelength = ',wavelength.shape,': ',wavelength) coadd = np.zeros(wavelength.shape[0]) nSpec = 0 for iSpec in np.arange(0,spectrum.shape[0],1): specMean = np.mean(spectrum[iSpec,:]) print('mean of spectrum ',iSpec,' = ',specMean) if abs(specMean) < 2.0e-16: print('using spectrum ',iSpec) coadd += spectrum[iSpec,:] nSpec += 1 print('mean of ',nSpec,' spectra in coadd = ',np.mean(coadd)) plt.plot(wavelength,coadd) plt.show()