Skip to content
This repository has been archived by the owner on Apr 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #64 from hover2pi/master
Browse files Browse the repository at this point in the history
awesimsoss v0.3.2
  • Loading branch information
hover2pi authored Mar 25, 2020
2 parents 784e542 + 0bf2000 commit 5585d22
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 46 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
language: python
python:
- 3.6
- 3.5

install:
- pip install git+https://github.com/astropy/astropy.git@763f069058cb1ee2038fa1cfa485452ec94b726e
- pip install git+https://github.com/spacetelescope/[email protected]
- pip install git+https://github.com/pypa/twine.git@68dc617bafbc8a32adbe41c12055efe6ba6d0e1e
- pip install -r requirements_dev.txt
- pip install -e .
- pip install pytest pytest-cov coveralls
Expand Down
37 changes: 23 additions & 14 deletions awesimsoss/awesim.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,11 @@ def export(self, outfile, all_data=False):
outfile: str
The path of the output file
"""
if not outfile.endswith('_uncal.fits'):
raise ValueError("Filename must end with '_uncal.fits'")

# Make a RampModel
data = self.tso
data = copy(self.tso)
mod = RampModel(data=data, groupdq=np.zeros_like(data), pixeldq=np.zeros((self.nrows, self.ncols)), err=np.zeros_like(data))
pix = utils.subarray_specs(self.subarray)

Expand Down Expand Up @@ -767,14 +770,17 @@ def plot_lightcurve(self, column, time_unit='s', resolution_mult=20, draw=True):
time = np.linspace(min(self.time), max(self.time), self.ngrps * self.nints * resolution_mult)
time = time * q.s.to('d')

# Generate transit model
tmodel = batman.TransitModel(self.tmodel, time)
tmodel.rp = self.rp[col]
theory = tmodel.light_curve(tmodel)
theory *= max(lightcurve) / max(theory)

time = time * q.d.to(time_unit)
# Convert time
time = time*q.d.to(time_unit)

lc.line(time, theory, legend=label + ' model', color=color, alpha=0.8)
# Add to figure
lc.line(time, theory, legend=label+' model', color=color, alpha=0.8)

# Convert datatime
data_time = self.time[self.ngrps - 1::self.ngrps].copy()
Expand All @@ -794,6 +800,8 @@ def plot_lightcurve(self, column, time_unit='s', resolution_mult=20, draw=True):
@run_required
def plot_spectrum(self, frame=0, order=None, noise=False, scale='log', draw=True):
"""
Plot a column sum of counts converted to flux density as a function of the mean column wavelength
Parameters
----------
frame: int
Expand All @@ -810,14 +818,14 @@ def plot_spectrum(self, frame=0, order=None, noise=False, scale='log', draw=True
# Get the data cube
tso = self._select_data(order, noise)

# Get extracted spectrum (Column sum for now)
# Get counts per wavelength (Column sum for now)
wave = np.mean(self.wave[0], axis=0)
flux_out = np.sum(tso[frame].data, axis=0)
response = 1. / self.order1_response
counts = np.sum(tso[frame].data, axis=0)
response = self.order1_response

# Convert response in [mJy/ADU/s] to [Flam/ADU/s] then invert so
# that we can convert the flux at each wavelegth into [ADU/s]
flux_out *= response / self.time[np.mod(self.ngrps, frame)]
flux_out = (counts/response/(self.time[np.mod(self.ngrps, frame)]*q.s)).value

# Trim wacky extracted edges
flux_out[0] = flux_out[-1] = np.nan
Expand Down Expand Up @@ -897,9 +905,9 @@ def _reset_psfs(self):

# Convert response in [mJy/ADU/s] to [Flam/ADU/s] then invert so
# that we can convert the flux at each wavelegth into [ADU/s]
response = self.frame_time / (response * q.mJy * ac.c / (wave * q.um)**2).to(self.star[1].unit).value
flux = np.interp(self.avg_wave[order - 1], self.star[0], self.star[1], left=0, right=0) * response
cube = mt.SOSS_psf_cube(filt=self.filter, order=order, subarray=self.subarray) * flux[:, None, None]
response = self.frame_time/(response*q.mJy*ac.c/(wave*q.um)**2).to(self.star[1].unit)
flux = np.interp(wave, self.star[0].value, self.star[1].value, left=0, right=0)*self.star[1].unit*response
cube = mt.SOSS_psf_cube(filt=self.filter, order=order, subarray=self.subarray)*flux[:, None, None]
setattr(self, 'order{}_response'.format(order), response)
setattr(self, 'order{}_psfs'.format(order), cube)

Expand All @@ -923,12 +931,12 @@ def _select_data(self, order, noise, reshape=True):
The selected data
"""
if order in [1, 2]:
tso = getattr(self, 'tso_order{}_ideal'.format(order))
tso = copy(getattr(self, 'tso_order{}_ideal'.format(order)))
else:
if noise:
tso = self.tso
tso = copy(self.tso)
else:
tso = self.tso_ideal
tso = copy(self.tso_ideal)

# Reshape data
if reshape:
Expand Down Expand Up @@ -1012,9 +1020,10 @@ def simulate(self, ld_coeffs=None, noise=True, model_grid=None, n_jobs=-1, **kwa
# Set the radius at the given wavelength from the transmission
# spectrum (Rp/R*)**2... or an array of ones
if self.planet is not None:
tdepth = np.interp(wave, self.planet[0], self.planet[1])
tdepth = np.interp(wave, self.planet[0].to(q.um).value, self.planet[1])
else:
tdepth = np.ones_like(wave)
tdepth[tdepth < 0] = np.nan
self.rp = np.sqrt(tdepth)

# Run multiprocessing to generate lightcurves
Expand Down
53 changes: 41 additions & 12 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,60 @@
name: awesimsoss
channels:
- conda-forge
- http://ssb.stsci.edu/astroconda
- defaults
dependencies:
- anaconda-client=1.7.2=py_0
- astropy=4.0=py36h0b31af3_1
- astroquery=0.4=py_0
- bzip2=1.0.8=h01d97ff_1
- ca-certificates=2019.6.16=hecc5488_0
- certifi=2019.3.9=py36_0
- clyent=1.2.2=py_1
- conda=4.7.12=py36_0
- conda-build=3.18.11=py36_0
- conda-package-handling=1.6.0=py36h01d97ff_0
- cryptography=2.7=py36h212c5bf_0
- docutils=0.14=py36_1001
- glob2=0.7=py_0
- healpy=1.11.0=py36_1
- imageio=2.5.0=py36_0
- libgcc=4.8.5=hdbeacc1_10
- liblief=0.9.0=h2a1bed3_1
- libsodium=1.0.16=h470a237_1
- lz4-c=1.8.3=h6de7cb9_1001
- lzo=2.10=h1de35cc_1000
- mkl-service=2.3.0=py36h0b31af3_0
- mkl_fft=1.1.0=py36h3b54f70_1
- mkl_random=1.1.0=py36h86efe34_0
- nbformat=4.4.0=py_1
- nbsphinx=0.3.5=py_0
- openssl=1.1.1b=h01d97ff_2
- pandoc=2.3.1=0
- pandocfilters=1.4.2=py_1
- pip=19.1.1=py36_0
- pkginfo=1.5.0.1=py_0
- py-lief=0.9.0=py36h6d6d4d2_1
- pycosat=0.6.3=py36h0b31af3_1002
- python-libarchive-c=2.9=py36_0
- ripgrep=11.0.2=h01d97ff_3
- ruamel_yaml=0.15.71=py36h1de35cc_1000
- snowballstemmer=1.2.1=py_1
- tblib=1.4.0=py_0
- tk=8.6.8=ha441bb4_0
- tqdm=4.36.1=py_0
- webencodings=0.5.1=py_1
- alabaster=0.7.12=py36_0
- appnope=0.1.0=py36hf537a9a_0
- asn1crypto=0.24.0=py36_0
- astropy=3.2.1=py36h1de35cc_0
- atomicwrites=1.3.0=py36_1
- attrs=19.1.0=py36_1
- babel=2.7.0=py_0
- backcall=0.1.0=py36_0
- beautifulsoup4=4.7.1=py36_1
- blas=1.0=mkl
- bleach=3.1.0=py36_0
- bokeh=1.2.0=py36_0
- bokeh=1.3.4
- cffi=1.12.3=py36hb5b8e2f_0
- chardet=3.0.4=py36_1
- click=7.0=py36_0
Expand Down Expand Up @@ -77,6 +99,7 @@ dependencies:
- jupyter_core=4.4.0=py36_0
- keyring=18.0.0=py36_0
- kiwisolver=1.1.0=py36h0a44026_0
- libarchive=3.3.3=h786848e_5
- libcxx=4.0.1=hcfea43d_1
- libcxxabi=4.0.1=hcfea43d_1
- libedit=3.1.20181209=hb402a30_0
Expand All @@ -95,18 +118,15 @@ dependencies:
- matplotlib=3.1.0=py36h54f8f79_0
- mistune=0.8.4=py36h1de35cc_0
- mkl=2019.4=233
- mkl-service=2.0.2=py36h1de35cc_0
- mkl_fft=1.0.12=py36h5e564d8_0
- mkl_random=1.0.2=py36h27c97d8_0
- more-itertools=7.0.0=py36_0
- mpmath=1.1.0=py36_0
- msgpack-python=0.6.1=py36h04f5b5a_1
- nbconvert=5.5.0=py_0
- ncurses=6.1=h0a44026_1
- networkx=2.3=py_0
- notebook=5.7.8=py36_0
- numpy=1.16.4=py36hacdab7b_0
- numpy-base=1.16.4=py36h6575580_0
- numpy=1.18.1=py36h7241aed_0
- numpy-base=1.18.1=py36h6575580_1
- olefile=0.46=py36_0
- packaging=19.0=py36_0
- pandas=0.24.2=py36h0a44026_0
Expand Down Expand Up @@ -185,7 +205,6 @@ dependencies:
- zlib=1.2.11=h1de35cc_3
- zstd=1.3.7=h5bba6e5_0
- asdf=2.3.3=py36_0
- astroquery=0.3.9=py36_0
- cfitsio=3.440=1
- crds=7.3.3=py36_0
- drizzle=1.13=py36_0
Expand All @@ -203,30 +222,40 @@ dependencies:
- stsci.tools=3.4.13=py36_1
- verhawk=0.0.2=py36_1
- webbpsf-data=0.8.0=0
- namedlist=1.7=py36_1
- pip:
- asteval==0.9.14
- bibtexparser==1.1.0
- awesimsoss==0.3.1
- batman-package==2.4.6
- bibtexparser==1.1.0
- dustmaps==1.0.4
- et-xmlfile==1.0.1
- exoctk==0.2.3
- flask==1.0.3
- future==0.17.1
- hotsoss==0.1.6
- itsdangerous==1.1.0
- jdcal==1.4
- jwst==0.13.8a0.dev37+g1f2237de
- jwst-backgrounds==1.1.1
- jwxml==0.3.0
- libarchive-c==2.9
- lief==0.9.0
- line-profiler==2.1.2
- llvmlite==0.29.0
- lmfit==0.9.13
- memory-profiler==0.55.0
- msgpack==0.6.1
- namedlist==1.7
- numba==0.44.1
- numpydoc==0.8.0
- openpyxl==2.5.8
- poppy==0.7.0
- progressbar2==3.42.0
- pscript==0.7.1
- pysiaf==0.2.4
- python-utils==2.3.0
- relic==1.1.2
- sedkit==0.3.1
- svo-filters==0.2.19
- uncertainties==3.1.1
- webbpsf==0.7.0
- werkzeug==0.15.4
- git+https://github.com/spacetelescope/jwst@1f2237de#egg=jwst
15 changes: 7 additions & 8 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ flake8==3.6.0
tox==3.5.3
coverage==4.5.2
Sphinx==1.8.2
twine==1.12.1
twine==3.1.1
click==7.0

astropy==3.0.3
astropy==4.0
numpy==1.16.1
bokeh==1.0.4
svo_filters==0.2.16
bokeh==1.3.4
svo_filters==0.2.19
scipy==1.1.0
astroquery==0.3.9
hotsoss==0.1.5
# webbpsf==0.7.0
astroquery==0.4
hotsoss==0.1.6
webbpsf
batman-package==2.4.6
# exoctk

pytest==4.0.0
pytest-runner==4.2
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.3.1
current_version = 0.3.2
commit = True
tag = True

Expand Down
6 changes: 2 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.6'
],
description="Advanced Webb Exposure SIMulator for SOSS",
entry_points={
Expand All @@ -47,6 +45,6 @@
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/hover2pi/awesimsoss',
version='0.3.1',
version='0.3.2',
zip_safe=False,
)
13 changes: 7 additions & 6 deletions tests/test_awesim.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,13 @@ def test_add_lines(self):
def test_export(self):
"""Test the export method"""
# Make the TSO object and save
test_tso = TSO(ngrps=2, nints=2, star=self.star, subarray='SUBSTRIP256')
test_tso.simulate()
try:
test_tso.export('outfile.fits')
except NameError:
pass
test_tso = TestTSO(add_planet=True)

# Good filename
test_tso.export('outfile_uncal.fits')

# Bad filename (no '_uncal')
self.assertRaises(ValueError, test_tso.export, 'outfile.fits')

def test_init(self):
"""Test that the TSO class is generated properly"""
Expand Down

0 comments on commit 5585d22

Please sign in to comment.