GithubHelp home page GithubHelp logo

hover2pi / pysynphot2d Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 255 KB

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

License: MIT License

Python 6.80% Jupyter Notebook 93.20%
python3 pysynphot stsci astronomy astropy

pysynphot2d's Introduction

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!

pysynphot2d's People

Contributors

hover2pi avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.