Documents the stellar spectrum generator; added mock imports to conf.py
This commit is contained in:
1 parent
2c7719daf0
commit
bbb88f12aa
3 files changed
+69
-9
No files matched your search
+11
-4
@@ -14,10 +14,17 @@ import os
|
||||
import sys
|
||||
sys.path.insert(0, os.path.abspath('../exoplasim'))
|
||||
|
||||
#import mock, sys
|
||||
#MOCK_MODULES = ['exoplasim','exoplasim.gcmt','netCDF4','numpy']
|
||||
#for mod_name in MOCK_MODULES:
|
||||
#sys.modules[mod_name] = mock.Mock()
|
||||
from mock import Mock as MagicMock
|
||||
|
||||
class Mock(MagicMock):
|
||||
@classmethod
|
||||
def __getattr__(cls, name):
|
||||
return MagicMock()
|
||||
|
||||
MOCK_MODULES = ['numpy', 'scipy', 'matplotlib.colors','matplotlib.pyplot','exoplasim',
|
||||
'exoplasim.gcmt','exoplasim.randomcontinents','exoplasim.makestellarspec']
|
||||
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)
|
||||
|
||||
# -- Project information -----------------------------------------------------
|
||||
|
||||
project = 'ExoPlaSim'
|
||||
|
||||
@@ -21,6 +21,15 @@ exoplasim.randomcontinents module
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
|
||||
exoplasim.makestellarspec module
|
||||
--------------------------------
|
||||
|
||||
.. automodule:: exoplasim.makestellarspec
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
Module contents
|
||||
---------------
|
||||
|
||||
|
||||
@@ -3,6 +3,10 @@ import matplotlib.pyplot as plt
|
||||
import sys
|
||||
|
||||
"""
|
||||
========================
|
||||
Stellar Spectrum Utility
|
||||
========================
|
||||
|
||||
Convert spectral files to exoplasim-compliant formats, including resampling
|
||||
to the necessary resolutions.
|
||||
|
||||
@@ -11,12 +15,36 @@ Usage
|
||||
|
||||
python makestellarspec.py spectrum.txt mystarsname
|
||||
|
||||
Yields
|
||||
------
|
||||
mystarsname.dat
|
||||
965 wavelengths
|
||||
mystarsname_hr.dat
|
||||
2048 wavelengths
|
||||
|
||||
"""
|
||||
|
||||
|
||||
cc = 299792458.0 #Speed of light
|
||||
|
||||
def readspec(sfile,cgs=False):
|
||||
"""Read a Phoenix stellar spectrum and return wavelengths, fluxes, and units
|
||||
|
||||
Takes as input a spectrum file generated by the Phoenix stellar spectrum web simulator,
|
||||
https://phoenix.ens-lyon.fr/simulator-jsf22-26.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
sfile : str
|
||||
Path to the spectrum file
|
||||
cgs : bool, optional
|
||||
Whether or not we should try to use CGS units (irrelevant for exoplasim)
|
||||
|
||||
Returns
|
||||
-------
|
||||
numpy.ndarray, numpy.ndarray, str
|
||||
Returns wavelengths, fluxes, and the units
|
||||
"""
|
||||
f=open(sfile,"r")
|
||||
ftxt = f.read()
|
||||
if ftxt[0]=='#':
|
||||
@@ -67,7 +95,7 @@ def readspec(sfile,cgs=False):
|
||||
fluxes[:] = fluxes[:]*10.0 #W/m^2/micron
|
||||
return wvls,fluxes,units
|
||||
|
||||
def coarsen(wvls,fluxes,w1,w2,num=5000):
|
||||
def _coarsen(wvls,fluxes,w1,w2,num=5000):
|
||||
inds = np.arange(len(wvls))
|
||||
nlow = (inds[wvls>w1])[0]
|
||||
nhigh= (inds[wvls>w2])[0]
|
||||
@@ -90,18 +118,34 @@ def coarsen(wvls,fluxes,w1,w2,num=5000):
|
||||
|
||||
return waves,flxs2
|
||||
|
||||
def integrate_trap(x,y):
|
||||
def _integrate_trap(x,y):
|
||||
net = 0
|
||||
for n in range(1,len(y)):
|
||||
net += 0.5*(x[n]-x[n-1])*(y[n]+y[n-1])
|
||||
return net
|
||||
|
||||
def normalize(wvls,fluxes):
|
||||
def _normalize(wvls,fluxes):
|
||||
netf = np.trapz(fluxes,x=wvls)
|
||||
factor = 1366.941858/netf
|
||||
return fluxes*factor
|
||||
|
||||
def writedat(wvls,fluxes,name):
|
||||
"""Write wavelengths and fluxes to a .dat file ExoPlaSim can read.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
wvls : array-like
|
||||
An array-like object containing a monotonic list of wavelengths going from short to long
|
||||
fluxes : array-like
|
||||
An array-like object containing a flux for each wavelength in ``wvls``.
|
||||
name : str
|
||||
A name to use when generating output files.
|
||||
|
||||
Yields
|
||||
------
|
||||
name.dat
|
||||
The provided spectrum in a format ExoPlaSim can read.
|
||||
"""
|
||||
f=open(name+".dat","w")
|
||||
sdat = ' Wavelength Flux \n'
|
||||
for n in range(0,len(wvls)):
|
||||
@@ -128,7 +172,7 @@ if __name__=="__main__":
|
||||
plt.xscale('log')
|
||||
plt.yscale('log')
|
||||
plt.show()
|
||||
#wc,fc = coarsen(w,f,wave0,wave1,num=numw*4)
|
||||
#wc,fc = _coarsen(w,f,wave0,wave1,num=numw*4)
|
||||
#plt.plot(wc,fc)
|
||||
#plt.xscale('log')
|
||||
#plt.yscale('log')
|
||||
@@ -147,7 +191,7 @@ if __name__=="__main__":
|
||||
factor = 1366.941858/E1
|
||||
f2*=factor
|
||||
print(np.trapz(f2,x=w2))
|
||||
print(np.trapz(normalize(w,f),x=w))
|
||||
print(np.trapz(_normalize(w,f),x=w))
|
||||
#print f2[np.argwhere(w2>40.0)],w[-10:]
|
||||
plt.plot(w2,f2)
|
||||
#plt.plot(wc,fc)
|
||||
|
||||
Reference in new issue
Block a user