Package pysynphot
[hide private]
[frames] | no frames]

Source Code for Package pysynphot

  1  """ 
  2  Package:  Astrolib Pysynphot 
  3   
  4  Purpose: 
  5  ======== 
  6   
  7  Object-oriented replacement for STSDAS synphot package. 
  8   
  9  This __init__ file is used to expose the desired elements of the user 
 10  interface for interactive use. 
 11   
 12   
 13  Dependencies: 
 14  ============= 
 15  - numpy 1.0 or greater 
 16  - pyfits 1.1 or greater 
 17  - spark (syntax parser) (included in package tho; really dependency?) 
 18   
 19  Environment: 
 20  ============ 
 21  The environment variable PYSYN_CDBS must be set. 
 22   
 23  Example: 
 24  ======== 
 25   
 26  >>> import pysynphot as S 
 27  >>> print S.__version__ 
 28  0.3d3 
 29  >>> #Read a spectrum from a file 
 30  >>> vega=S.FileSpectrum('alpha_lyr_stis_003.fits') 
 31  >>> print vega 
 32  alpha_lyr_stis_003.fits 
 33  >>> vega.wave 
 34  array([  9.00452026e+02,   9.01354004e+02,   9.02257996e+02, ..., 
 35           2.99353200e+06,   2.99653275e+06,   2.99953700e+06], dtype=float32) 
 36  >>> vega.flux 
 37  array([  1.23810534e-17,   1.67559564e-17,   1.78002369e-17, ..., 
 38           1.40140738e-19,   1.38734357e-19,   1.26490663e-19]) 
 39  >>> bb=S.BlackBody(40000) 
 40  >>> print bb.wave 
 41  [   500.            500.19760122    500.39528054 ...,  25969.1985582 
 42    25979.46164894  25989.72879567] 
 43  >>> print bb.flux 
 44  [ 1.15230179  1.15375888  1.15521646 ...,  0.00141824  0.0014166 
 45    0.00141496] 
 46  >>> print bb 
 47  BlackBody(T=40000) 
 48   
 49  >>> pl=S.PowerLaw(10000,-2) 
 50  >>> print pl 
 51  Power law: refwave 10000.000000, index -2.000000 
 52  >>> print pl.wave 
 53  [   500.            500.19760122    500.39528054 ...,  25969.1985582 
 54    25979.46164894  25989.72879567] 
 55  >>> print pl.flux 
 56  [  4.00000000e+02   3.99684021e+02   3.99368286e+02 ...,   1.48280114e-01 
 57     1.48162976e-01   1.48045942e-01] 
 58   
 59  >>> g1=S.GaussianSource(18.3,18000,2000,fluxunits='abmag') 
 60  >>> print g1 
 61  Gaussian: mu=18000.000000,fwhm=2000.000000,flux=18.300000 abmag 
 62   
 63  >>> unitflux=S.UnitSpectrum(18,fluxunits='abmag') 
 64  >>> print unitflux 
 65  Unit spectrum of 18.000000 abmag 
 66   
 67  >>> bp1=S.ObsBandpass('acs,hrc,f555w') 
 68  >>> print bp1 
 69  acs,hrc,f555w 
 70  >>> print bp1.wave 
 71  [   500.   1000.   1001. ...,  11999.  30000.  30010.] 
 72  >>> print bp1.throughput 
 73  [ 0.  0.  0. ...,  0.  0.  0.] 
 74  >>> bp1.showfiles() 
 75  /data/cdbs1/comp/ota/hst_ota_007_syn.fits 
 76  /data/cdbs1/comp/acs/acs_hrc_m12_005_syn.fits 
 77  /data/cdbs1/comp/acs/acs_hrc_m3_005_syn.fits 
 78  /data/cdbs1/comp/acs/acs_f555w_003_syn.fits 
 79  /data/cdbs1/comp/acs/acs_hrc_win_005_syn.fits 
 80  /data/cdbs1/comp/acs/acs_hrc_ccd_011_syn.fits 
 81  >>> len(bp1) 
 82  6 
 83   
 84  >>> sp1=S.FileSpectrum('/data/cdbs1/calspec/feige66_002.fits') 
 85  >>> print bp1.waveunits 
 86  probably angstroms 
 87  >>> print sp1.waveunits 
 88  angstrom 
 89  >>> obs1=sp1*bp1 
 90  >>> print obs1 
 91  /data/cdbs1/calspec/feige66_002.fits * acs,hrc,f555w 
 92  >>> print obs1.wave 
 93  [   500.   1000.   1001. ...,  11999.  30000.  30010.] 
 94  >>> print obs1.flux.max() 
 95  7.47814099194e-14 
 96  >>> print obs1.flux.argmax() 
 97  6924 
 98   
 99  >>> sp2=S.FileSpectrum('/data/cdbs1/calspec/feige66_002.fits')*S.ObsBandpass('acs,hrc,f555w') 
100  >>> print sp2 
101  /data/cdbs1/calspec/feige66_002.fits * acs,hrc,f555w 
102  >>> print sp2.waveunits 
103  angstrom 
104  >>> print sp2.fluxunits 
105  flam 
106   
107  """ 
108   
109   
110  __version__ = '0.3d4b' 
111  __revstring__  = '$Rev: 256 $' 
112   
113  #UI: 
114  from spectrum import BlackBody, GaussianSource, UnitSpectrum 
115  from spectrum import Powerlaw as PowerLaw 
116  from spectrum import TabularSourceSpectrum as FileSpectrum 
117   
118  from spectrum import TabularSpectralElement as FileBandpass 
119  from observationmode import ObservationMode as Obsmode 
120  from obsbandpass import ObsBandpass 
121   
122  from numpy import arange as Waveset 
123   
124   
125 -def _test():
126 import doctest 127 doctest.testfile('__init__.py')
128 129 if __name__ == '__main__': 130 #WARNING: doctest won't presently work except in the correct directory. 131 _test() 132