Skip to content

This is a wrapper for `pysynphot` that vectorizes all methods to operate on 2D spectra

License

Notifications You must be signed in to change notification settings

hover2pi/pysynphot2d

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pysynphot2d Demo

This notebook is a demonstration of the pysynphot2d wrapper which vectorizes the functionality of pysynphot so that it supports 2D spectra.

%matplotlib inline
import numpy as np
import pysynphot as ps
import matplotlib.pyplot as plt
from pysynphot2d import psp2d

ArraySpectrum to ArraySpectra

Just pass a 1D wavelength array and 2D flux array to psp2d.ArraySpectra as you would pass a 1D flux array to pysynphot.ArraySpectrum.

Here's a simple example with some toy data:

# Dummy data
wave = np.linspace(4000,8000,20)
flux = np.arange(100).reshape(5,20)
toy2D = psp2d.ArraySpectra(wave, flux)

# Take a look
for spec in toy2D.spectra:
    plt.plot(spec.wave, spec.flux)

png

Now let's do some method calls as we would for a pysynphot.ArraySpectrum object.

# Sample each spectrum at the given wavelength
sampled_spectra = toy2D.sample(6789)
print('Samples:',sampled_spectra)
Samples: [ 13.24775  33.24775  53.24775  73.24775  93.24775]
# Renormalize each spectrum to the given magnitude
V_band = ps.ObsBandpass('johnson,v')
renormed_spectra = toy2D.renorm(17, 'vegamag', V_band)

# Take a look
for spec in renormed_spectra:
    plt.plot(spec.wave, spec.flux)

png

That's it! Try your favorite pysynphot methods on your new psp2d.ArraySpectra objects (and let me know if it breaks!).

Observation to Observations

Just pass your psp2d.ArraySpectra object to psp2d.Observations along with a pysynphot.ObsBandpass as you would pass pysynphot.ArraySpectrum to pysynphot.Observation:

# Dummy observations
obs2d = psp2d.Observations(toy2D, V_band)

# Take a look
for spec in obs2d.spectra:
    plt.plot(spec.wave, spec.flux)
(/grp/hst/cdbs/comp/nonhst/johnson_v_004_syn.fits) does not have a defined binset in the wavecat table. The waveset of the spectrum will be used instead.
(/grp/hst/cdbs/comp/nonhst/johnson_v_004_syn.fits) does not have a defined binset in the wavecat table. The waveset of the spectrum will be used instead.
(/grp/hst/cdbs/comp/nonhst/johnson_v_004_syn.fits) does not have a defined binset in the wavecat table. The waveset of the spectrum will be used instead.
(/grp/hst/cdbs/comp/nonhst/johnson_v_004_syn.fits) does not have a defined binset in the wavecat table. The waveset of the spectrum will be used instead.
(/grp/hst/cdbs/comp/nonhst/johnson_v_004_syn.fits) does not have a defined binset in the wavecat table. The waveset of the spectrum will be used instead.

png

That's it! Enjoy and let me know when it breaks!

About

This is a wrapper for `pysynphot` that vectorizes all methods to operate on 2D spectra

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published