Skip to content
This repository was archived by the owner on Apr 18, 2023. It is now read-only.

Commit 8a363a9

Browse files
authoredFeb 1, 2020
Merge pull request #14 from hover2pi/extraction
Extraction
2 parents f1817d0 + e0d7d49 commit 8a363a9

25 files changed

+60111
-30753
lines changed
 

‎.gitignore

+8-3
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ venv.bak/
104104
.mypy_cache/
105105

106106
# Pipeline processed files
107-
files/*_rate.fits
108-
files/*_rateints.fits
109-
files/*_ramp.fits
107+
specialsoss/files/*_rate.fits
108+
specialsoss/files/*_ramp.fits
109+
specialsoss/files/*_cal.fits
110+
specialsoss/files/*_x1d.fits
111+
specialsoss/files/*_calints.fits
112+
specialsoss/files/*_x1dints.fits
113+
notebooks/*.fits
114+

‎.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
language: python
44
python:
55
- 3.6
6-
- 3.5
76

87
# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
98
install:

‎README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ SPECtral Image AnaLysis for SOSS
2626

2727
Authors: Joe Filippazzo
2828

29-
This pure Python 3.5+ package performs optimal spectral extraction routines
29+
This pure Python 3.6+ package performs optimal spectral extraction routines
3030
for the Single Object Slitless Spectroscopy (SOSS) mode of the
3131
Near-Infrared Imager and Slitless Spectrograph (NIRISS) instrument
3232
onboard the James Webb Space Telescope (JWST).

‎notebooks/SOSS end-to-end.ipynb

+261
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# End-to-end Test of SOSS Simulations\n",
8+
"This notebook will simulate SOSS data using `awesimsoss` and then quantify how well `specialsoss` can extract it.\n",
9+
"\n",
10+
"## Imports"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"metadata": {},
17+
"outputs": [],
18+
"source": [
19+
"# Imports\n",
20+
"from astropy.modeling.models import BlackBody1D\n",
21+
"from astropy.modeling.blackbody import FLAM\n",
22+
"import astropy.units as q\n",
23+
"from awesimsoss import TSO\n",
24+
"from bokeh.plotting import figure, show\n",
25+
"from bokeh.io import output_notebook\n",
26+
"import numpy as np\n",
27+
"from specialsoss import SossExposure\n",
28+
"output_notebook()"
29+
]
30+
},
31+
{
32+
"cell_type": "markdown",
33+
"metadata": {},
34+
"source": [
35+
"## Simulation\n",
36+
"First let's make a 1D blackbody spectrum."
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": null,
42+
"metadata": {},
43+
"outputs": [],
44+
"source": [
45+
"# Variables\n",
46+
"teff = 2000*q.K\n",
47+
"\n",
48+
"# Generate a blackbody at the given temperature from 0.5 - 3 um\n",
49+
"bb = BlackBody1D(temperature=teff)\n",
50+
"wave = np.linspace(0.5, 3., 1000)*q.um\n",
51+
"flux = bb(wave).to(FLAM, q.spectral_density(wave))*1E-8\n",
52+
"\n",
53+
"# Plot it\n",
54+
"fig = figure(width=800, height=300, x_axis_label='Wavelength [um]', y_axis_label='Flux Density [{}]'.format(flux.unit))\n",
55+
"fig.line(wave, flux, legend='Input Spectrum')\n",
56+
"show(fig)"
57+
]
58+
},
59+
{
60+
"cell_type": "markdown",
61+
"metadata": {},
62+
"source": [
63+
"Lets make a SOSS simulation for this star with 2 integrations and 2 groups using `awesimsoss`."
64+
]
65+
},
66+
{
67+
"cell_type": "code",
68+
"execution_count": null,
69+
"metadata": {},
70+
"outputs": [],
71+
"source": [
72+
"# Initialize the TSO object\n",
73+
"sim = TSO(nints=2, ngrps=2, star=[wave, flux])\n",
74+
"\n",
75+
"# Run the simulation\n",
76+
"sim.simulate()"
77+
]
78+
},
79+
{
80+
"cell_type": "code",
81+
"execution_count": null,
82+
"metadata": {},
83+
"outputs": [],
84+
"source": [
85+
"# Run the plot method\n",
86+
"sim.plot()"
87+
]
88+
},
89+
{
90+
"cell_type": "markdown",
91+
"metadata": {},
92+
"source": [
93+
"Now let's export the simulation to a pipeline ingestible '_uncal.fits' file."
94+
]
95+
},
96+
{
97+
"cell_type": "code",
98+
"execution_count": null,
99+
"metadata": {},
100+
"outputs": [],
101+
"source": [
102+
"# Name the file\n",
103+
"filename = 'SOSS_simulation_uncal.fits'\n",
104+
"\n",
105+
"# Export the data\n",
106+
"sim.export(filename)"
107+
]
108+
},
109+
{
110+
"cell_type": "markdown",
111+
"metadata": {},
112+
"source": [
113+
"## Reduction\n",
114+
"Next let's load the \"raw\" data into `specialsoss` by passing a filename to the `SossExposure` class."
115+
]
116+
},
117+
{
118+
"cell_type": "code",
119+
"execution_count": null,
120+
"metadata": {},
121+
"outputs": [],
122+
"source": [
123+
"# Initialize the exposure object with the '_uncal.fits' file\n",
124+
"obs = SossExposure(filename)"
125+
]
126+
},
127+
{
128+
"cell_type": "markdown",
129+
"metadata": {},
130+
"source": [
131+
"We can calibrate the data using the JWST reduction pipeline with the `calibrate` method."
132+
]
133+
},
134+
{
135+
"cell_type": "code",
136+
"execution_count": null,
137+
"metadata": {},
138+
"outputs": [],
139+
"source": [
140+
"# Run DETECTOR1 and SPEC2 pipelines\n",
141+
"obs.calibrate()"
142+
]
143+
},
144+
{
145+
"cell_type": "code",
146+
"execution_count": null,
147+
"metadata": {},
148+
"outputs": [],
149+
"source": [
150+
"# Check out object info\n",
151+
"obs.info"
152+
]
153+
},
154+
{
155+
"cell_type": "markdown",
156+
"metadata": {},
157+
"source": [
158+
"We can see the calibrated and uncalibrated data are stored as object properties (`uncal`, `rate`, `rateints`, `ramp`, `calints`, and `x1dints`) corresponding to the JWST pipeline dataproducts for SOSS mode, which can each be plotted and analyzed independently."
159+
]
160+
},
161+
{
162+
"cell_type": "code",
163+
"execution_count": null,
164+
"metadata": {},
165+
"outputs": [],
166+
"source": [
167+
"# Inspect `rateints` data\n",
168+
"# obs.rateints.data"
169+
]
170+
},
171+
{
172+
"cell_type": "markdown",
173+
"metadata": {},
174+
"source": [
175+
"## Extraction\n",
176+
"\n",
177+
"Now let's perform the spectral extraction on the `rateints` data."
178+
]
179+
},
180+
{
181+
"cell_type": "code",
182+
"execution_count": null,
183+
"metadata": {},
184+
"outputs": [],
185+
"source": [
186+
"# Run extraction method\n",
187+
"obs.extract('sum', 'rateints', name='Extracted Spectrum')"
188+
]
189+
},
190+
{
191+
"cell_type": "markdown",
192+
"metadata": {},
193+
"source": [
194+
"We can take a look at the extracted spectra like so."
195+
]
196+
},
197+
{
198+
"cell_type": "code",
199+
"execution_count": null,
200+
"metadata": {},
201+
"outputs": [],
202+
"source": [
203+
"# Plot extracted time series spectra\n",
204+
"obs.plot_results('Extracted Spectrum')"
205+
]
206+
},
207+
{
208+
"cell_type": "markdown",
209+
"metadata": {},
210+
"source": [
211+
"Finally, let's compare the extracted spectrum for the first integration with the input spectrum."
212+
]
213+
},
214+
{
215+
"cell_type": "code",
216+
"execution_count": null,
217+
"metadata": {},
218+
"outputs": [],
219+
"source": [
220+
"# Plot input spectrum...\n",
221+
"fig = figure(width=800, height=300, x_axis_label='Wavelength [um]', y_axis_label='Flux Density [{}]'.format(flux.unit))\n",
222+
"fig.line(wave, flux, legend='Input Spectrum')\n",
223+
"\n",
224+
"# ...and extracted spectrum\n",
225+
"wave_ext = obs.results['Extracted Spectrum']['wavelength']\n",
226+
"flux_ext = obs.results['Extracted Spectrum']['flux'][0]\n",
227+
"fig.line(wave_ext, flux_ext, legend='Extracted Spectrum')\n",
228+
"\n",
229+
"show(fig)"
230+
]
231+
},
232+
{
233+
"cell_type": "markdown",
234+
"metadata": {},
235+
"source": [
236+
"Voila!"
237+
]
238+
}
239+
],
240+
"metadata": {
241+
"kernelspec": {
242+
"display_name": "awesimsoss",
243+
"language": "python",
244+
"name": "awesimsoss"
245+
},
246+
"language_info": {
247+
"codemirror_mode": {
248+
"name": "ipython",
249+
"version": 3
250+
},
251+
"file_extension": ".py",
252+
"mimetype": "text/x-python",
253+
"name": "python",
254+
"nbconvert_exporter": "python",
255+
"pygments_lexer": "ipython3",
256+
"version": "3.6.8"
257+
}
258+
},
259+
"nbformat": 4,
260+
"nbformat_minor": 2
261+
}

0 commit comments

Comments
 (0)