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

Commit

Permalink
Merge pull request #14 from hover2pi/extraction
Browse files Browse the repository at this point in the history
Extraction
  • Loading branch information
hover2pi committed Feb 1, 2020
2 parents f1817d0 + e0d7d49 commit 8a363a9
Show file tree
Hide file tree
Showing 25 changed files with 60,111 additions and 30,753 deletions.
11 changes: 8 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ venv.bak/
.mypy_cache/

# Pipeline processed files
files/*_rate.fits
files/*_rateints.fits
files/*_ramp.fits
specialsoss/files/*_rate.fits
specialsoss/files/*_ramp.fits
specialsoss/files/*_cal.fits
specialsoss/files/*_x1d.fits
specialsoss/files/*_calints.fits
specialsoss/files/*_x1dints.fits
notebooks/*.fits

1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
language: python
python:
- 3.6
- 3.5

# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
install:
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ SPECtral Image AnaLysis for SOSS

Authors: Joe Filippazzo

This pure Python 3.5+ package performs optimal spectral extraction routines
This pure Python 3.6+ package performs optimal spectral extraction routines
for the Single Object Slitless Spectroscopy (SOSS) mode of the
Near-Infrared Imager and Slitless Spectrograph (NIRISS) instrument
onboard the James Webb Space Telescope (JWST).
Expand Down
261 changes: 261 additions & 0 deletions notebooks/SOSS end-to-end.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# End-to-end Test of SOSS Simulations\n",
"This notebook will simulate SOSS data using `awesimsoss` and then quantify how well `specialsoss` can extract it.\n",
"\n",
"## Imports"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Imports\n",
"from astropy.modeling.models import BlackBody1D\n",
"from astropy.modeling.blackbody import FLAM\n",
"import astropy.units as q\n",
"from awesimsoss import TSO\n",
"from bokeh.plotting import figure, show\n",
"from bokeh.io import output_notebook\n",
"import numpy as np\n",
"from specialsoss import SossExposure\n",
"output_notebook()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Simulation\n",
"First let's make a 1D blackbody spectrum."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Variables\n",
"teff = 2000*q.K\n",
"\n",
"# Generate a blackbody at the given temperature from 0.5 - 3 um\n",
"bb = BlackBody1D(temperature=teff)\n",
"wave = np.linspace(0.5, 3., 1000)*q.um\n",
"flux = bb(wave).to(FLAM, q.spectral_density(wave))*1E-8\n",
"\n",
"# Plot it\n",
"fig = figure(width=800, height=300, x_axis_label='Wavelength [um]', y_axis_label='Flux Density [{}]'.format(flux.unit))\n",
"fig.line(wave, flux, legend='Input Spectrum')\n",
"show(fig)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Lets make a SOSS simulation for this star with 2 integrations and 2 groups using `awesimsoss`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Initialize the TSO object\n",
"sim = TSO(nints=2, ngrps=2, star=[wave, flux])\n",
"\n",
"# Run the simulation\n",
"sim.simulate()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Run the plot method\n",
"sim.plot()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now let's export the simulation to a pipeline ingestible '_uncal.fits' file."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Name the file\n",
"filename = 'SOSS_simulation_uncal.fits'\n",
"\n",
"# Export the data\n",
"sim.export(filename)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Reduction\n",
"Next let's load the \"raw\" data into `specialsoss` by passing a filename to the `SossExposure` class."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Initialize the exposure object with the '_uncal.fits' file\n",
"obs = SossExposure(filename)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can calibrate the data using the JWST reduction pipeline with the `calibrate` method."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Run DETECTOR1 and SPEC2 pipelines\n",
"obs.calibrate()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Check out object info\n",
"obs.info"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Inspect `rateints` data\n",
"# obs.rateints.data"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Extraction\n",
"\n",
"Now let's perform the spectral extraction on the `rateints` data."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Run extraction method\n",
"obs.extract('sum', 'rateints', name='Extracted Spectrum')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can take a look at the extracted spectra like so."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Plot extracted time series spectra\n",
"obs.plot_results('Extracted Spectrum')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Finally, let's compare the extracted spectrum for the first integration with the input spectrum."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Plot input spectrum...\n",
"fig = figure(width=800, height=300, x_axis_label='Wavelength [um]', y_axis_label='Flux Density [{}]'.format(flux.unit))\n",
"fig.line(wave, flux, legend='Input Spectrum')\n",
"\n",
"# ...and extracted spectrum\n",
"wave_ext = obs.results['Extracted Spectrum']['wavelength']\n",
"flux_ext = obs.results['Extracted Spectrum']['flux'][0]\n",
"fig.line(wave_ext, flux_ext, legend='Extracted Spectrum')\n",
"\n",
"show(fig)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Voila!"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "awesimsoss",
"language": "python",
"name": "awesimsoss"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 8a363a9

Please sign in to comment.