Ejemplo n.º 1
0
    def readSpectrum(self, fileName, colWave=0, colFlux=1, skipRows=0):
        """
        Reading spectrum in text or FITS format
        and update regions and points
        """
        if not ".fits" in fileName:
            self.spectrum = sp.readSpectrum(fileName,\
                                                  colWave=colWave,\
                                                  colFlux=colFlux,\
                                                  skipRows=skipRows)

        else:
            self.spectrum = sp.Spectrum()
            """ Check more at
            http://archive.eso.org/cms/eso-data/help/1dspectra.html
            https://www.hs.uni-hamburg.de/DE/Ins/Per/Czesla/PyA/PyA/pyaslDoc/aslDoc/readFitsSpec.html
            """
            self.spectrum.wave, self.spectrum.flux = pyasl.read1dFitsSpec(
                fileName)
            # self.spectrum.wave = self.spectrum.wave.byteswap().newbyteorder()
            self.spectrum.flux = self.spectrum.flux.byteswap().newbyteorder(
            )  #TODO PyAstronomy bug
            self.spectrum.name = fileName
        self.radialVelocity = 0.0
        self.oryginalWavelength = copy.deepcopy(self.spectrum.wave)

        self.spectrumNote.set_spectrum(fileName)
Ejemplo n.º 2
0
    def readSpectrum(self, fileName, colWave=0, colFlux=1, skipRows=0):
        """
        Reading spectrum in text or FITS format
        and update regions and points
        """
        if not ".fits" in fileName:
            self.spectrum = sp.readSpectrum(fileName,\
                                                  colWave=colWave,\
                                                  colFlux=colFlux,\
                                                  skipRows=skipRows)

        else:
            self.spectrum = sp.Spectrum()
            """ Check more at
            http://archive.eso.org/cms/eso-data/help/1dspectra.html
            https://www.hs.uni-hamburg.de/DE/Ins/Per/Czesla/PyA/PyA/pyaslDoc/aslDoc/readFitsSpec.html
            """
            self.spectrum.wave = None
            self.spectrum.flux = None

            # Search FITS data for Molecfit keywords
            waveKey = "lambda"  # use orignal wavelength not the the molecfit corrected
            fluxKey = "cflux"  # use telluric absorption corrected flux
            dataKeys = [waveKey, fluxKey]
            fitsFile = fits.open(fileName)
            for hdu in fitsFile:
                if hdu.data is None or not hasattr(hdu.data, 'names'):
                    continue
                if all(name in hdu.data.names for name in dataKeys):
                    self.spectrum.wave = hdu.data[waveKey]
                    self.spectrum.flux = hdu.data[fluxKey]
                    self.spectrum.wave = self.spectrum.wave * 1000  # micrometre to nanometre
                    break
            fitsFile.close()

            # If no Molecfit formated data is found, fall back to pyastronomy solution used in main version of HANDY
            if self.spectrum.wave is None or self.spectrum.flux is None:
                self.spectrum.wave, self.spectrum.flux = pyasl.read1dFitsSpec(
                    fileName)
                self.spectrum.flux = self.spectrum.flux.byteswap(
                ).newbyteorder()  # TODO PyAstronomy bug
            self.spectrum.name = fileName
        self.radialVelocity = 0.0
        self.oryginalWavelength = copy.deepcopy(self.spectrum.wave)
Ejemplo n.º 3
0
# print type(image_data), image_data.shape
# print read_data[0].dispersion
# print len(read_data[0].dispersion), len(list(read_data[0]))
# image_hdr2 = fits.getheader('fwcbs_ASASSN14dq-gr7.ms.fits')
# print image_data.shape, len(list(read_data.dispersion))
# init_value = image_hdr['CRVAL1']
# step_size = image_hdr['CD1_1']
# wav_array, flux_array = psl.read1dFitsSpec(fn=file_name, hdu=0)
# plot_data(x_array=wav_data, y_array=flux_data)
# plt.show()
# -------------------------------------------------------------------------------------------------------------------- #

# -------------------------------------------------------------------------------------------------------------------- #
# View 1-D Spectra
# -------------------------------------------------------------------------------------------------------------------- #
wav_array, flux_array = psl.read1dFitsSpec(fn=file_name, hdu=0)
fig, ax = plot_data(x_array=wav_data, y_array=flux_data)
ax2 = ax.twiny()
ax2.set_xticks(numpy.linspace(1, len(wav_data), len(ax.get_xticks())))
plt.show()

pixel_range = raw_input("Enter The Pixel Range For The Line (X, Y): ").split(
    ',')
lower_limit = int(pixel_range[0])
upper_limit = int(pixel_range[1])

usable_flux = flux_data[lower_limit:upper_limit]
usable_wav = wav_data[lower_limit:upper_limit]
length_data = len(usable_wav)

mean = sum(usable_wav) / length_data
Ejemplo n.º 4
0
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
fits_name = pandas.read_table(ifile) 
ifits = fits_name[fits_name.columns[0]]
n_stars = len(ifits)

# Spectra should be rebinned to a common wavelength scale
grid_step  = 0.01
grid_start = 5340. 
grid_end   = 6900.
grid_wavelengths = np.arange(grid_start,grid_end,grid_step) 
grid_nwavelengths = len(grid_wavelengths)
stellar_rebin_flux = np.zeros((grid_nwavelengths, n_stars))

for ii in range(0, n_stars):
   fits_now = spectra_dir + ifits[ii]
   wvl, flx = pyasl.read1dFitsSpec(fits_now)
   inter_flx = griddata(wvl, flx, grid_wavelengths, method='cubic')
   stellar_rebin_flux[:,ii] = inter_flx 

# Smooth the spectra to a lower resolution 
# [A gaussian smooth with sigma = 120 is performed] 
smoothed_flux_matrix = np.zeros((grid_nwavelengths, n_stars))
for ii in range(0, n_stars):
   gaussian_filter(stellar_rebin_flux[:,ii],120, output=smoothed_flux_matrix[:,ii])

# Get all the spectra to the same flux level using a  pseudo continuum centred in the R band
stellar_flux_matrix  = np.zeros((grid_nwavelengths, n_stars))
smoothed_refe_flux = smoothed_flux_matrix[:,0]
R_band_center = 6090
R_band_width  = 20
result = np.where(np.logical_and(grid_wavelengths> R_band_center - (R_band_width/2.0), grid_wavelengths< R_band_center + (R_band_width/2.0)))
Ejemplo n.º 5
0
@author: Jeaic O Cuimin
"""
import matplotlib.pyplot as plt
from astropy.io import fits
from PyAstronomy import pyasl
import os

folder = '/cphys/ugrad/2015-16/JF/CUMMINJ1/zuma/2014_spectra/'

for filename in os.listdir(folder):
    if filename.endswith(".fit"):
        print(filename)
        spectrum_1 = fits.open(str(folder) + '/' + str(filename))
        print('spectrum 1 successful')
        spectrum_2 = pyasl.read1dFitsSpec(str(folder) + '/' + str(filename))
        hdu = spectrum_1[0]
        hdu_2 = spectrum_1[0].data
        start_time = hdu.header['JD-OBS']
        mid_time = hdu.header['JD-MID']
        wl = spectrum_2[0]
        flux = spectrum_2[1]
        plt.style.use('dark_background')
        plt.plot(wl, flux, label=("Julian: " + str(mid_time)))
        plt.title("Spectral data for Z-UMa")
        plt.xlabel("Wavelength [Angstroms]")
        plt.ylabel("Flux [erg/cm2/s/A]")
        plt.xlim(3750, 8000)
        plt.ylim(0, 7e-11)
        plt.legend()
        plt.savefig(
Ejemplo n.º 6
0
from PyAstronomy import pyasl
import os 
import pandas as pd
import numpy as np
import scipy.interpolate as interp
import heapq
#dark background easier on the eyes
plt.style.use('dark_background')

#getting the scaels of the flux to match
scale_factor=6e11
scale_factor_1=5.9e10
#matching the curve positions for reference
translation_factor=0.45
#The spectrum for maximum
spectrum_max=pyasl.read1dFitsSpec('/cphys/ugrad/2015-16/JF/CUMMINJ1/zuma/2014_spectra/_zuma_20140709_946_D_Boyd_flux.fit')
wl_max=spectrum_max[0]
flux_max=spectrum_max[1]

#the spectrum for minimum
spectrum_minimum=pyasl.read1dFitsSpec('/cphys/ugrad/2015-16/JF/CUMMINJ1/zuma/2014_spectra/_zuma_20140401_932_D_Boyd_flux.fit')
wl_min=spectrum_minimum[0]
flux_min=spectrum_minimum[1]
#the m7III reference spectrum
spectrum_m3=pyasl.read1dFitsSpec('/cphys/ugrad/2015-16/JF/CUMMINJ1/zuma/2014_spectra/ref_spectra/m7iii.fits')
wl_m3=spectrum_m3[0]
flux_m3=spectrum_m3[1]
#the m4iii referecne spectrum
spectrum_m4=pyasl.read1dFitsSpec('/cphys/ugrad/2015-16/JF/CUMMINJ1/zuma/2014_spectra/ref_spectra/m4iii.fits')
wl_m4=spectrum_m4[0]
flux_m4=spectrum_m4[1]
Ejemplo n.º 7
0
Created on Mon Oct 15 11:00:40 2018

@author: Jeaic O Cuimin
"""
import matplotlib.pyplot as plt
from astropy.io import fits
from PyAstronomy import pyasl
import os
import pandas as pd

plt.style.use('dark_background')
folder = '/cphys/ugrad/2015-16/JF/CUMMINJ1/zuma/2014_spectra/ref_spectra'

for filename in os.listdir(folder):
    if filename.endswith(".fits"):
        spectrum_2 = pyasl.read1dFitsSpec(str(folder) + '/' + str(filename))
        wl = spectrum_2[0]
        flux = spectrum_2[1]
        print("Fits file " + str(filename) + " successfully read")
        plt.plot(wl, flux, alpha=0.25, label=str(filename[:-4]))
        plt.title("Reference Spectra M(n)III stars for Z-UMa")
        plt.xlabel("Wavelength [Angstroms]")
        plt.ylabel("Flux [erg/cm2/s/A]")
        plt.ylim([0, 14])
        plt.xlim(3750, 8000)
        #plt.show()

#open the file (minimum)
spectrum_1 = fits.open(
    '/cphys/ugrad/2015-16/JF/CUMMINJ1/zuma/2014_spectra/_zuma_20140713_934_D_Boyd_flux.fit'
)