This repository has been archived by the owner on Apr 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from hover2pi/extraction
Extraction
- Loading branch information
Showing
25 changed files
with
60,111 additions
and
30,753 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.