Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zkbt/f51fd0d8e6e28b0c55efea694a7fafad to your computer and use it in GitHub Desktop.
Save zkbt/f51fd0d8e6e28b0c55efea694a7fafad to your computer and use it in GitHub Desktop.
`Can we load your data file(s)?` | *ers-transit Data Checkpoint:* time-series extracted 1D spectra 🌈
{
"cells": [
{
"cell_type": "markdown",
"id": "5fe42af5",
"metadata": {},
"source": [
"# `Can we load your data file(s)?` | *ers-transit Data Checkpoint:* time-series extracted 1D spectra 🌈 \n",
"*1 March 2022*"
]
},
{
"cell_type": "markdown",
"id": "49add1e7",
"metadata": {},
"source": [
"This notebook aims to serve as a quick way to visualize and evaluate results produced for the [Spring 2022 Data Challenge with Simulated Data](https://ers-transit.github.io/data-challenge-with-simulated-data.html) for the [Webb Transiting Exoplanet Community Early Release Science Program](https://ers-transit.github.io/index.html)."
]
},
{
"cell_type": "markdown",
"id": "d14b2601",
"metadata": {},
"source": [
"*πŸͺπŸ€©β€οΈ This test snippet notebook designed to check whether we will be able to read your data files easily. A longer notebook, containing standardized visualizations and quantitative metrics, will be made available by the 21-23 March 2022 meeting.πŸͺπŸ€©β€οΈ*"
]
},
{
"cell_type": "markdown",
"id": "fd7900b1",
"metadata": {},
"source": [
"## πŸ§‘β€πŸ’» Load the Data\n",
"\n",
"Can we load in your time-series extracted 1D spectra? \n",
"\n",
"This notebook makes use of the `chromatic` toolkit, which can be installed via `pip install chromatic-lightcurves` and is documented [here](https://zkbt.github.io/chromatic/). It's meant to be a handy way to load, visualize, and do calculations with multiwavelength lightcurves."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "da37022e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'0.0.8'"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from chromatic import *\n",
"version()"
]
},
{
"cell_type": "markdown",
"id": "981d03a2",
"metadata": {},
"source": [
"`chromatic` can read time-series spectra in a few different file formats. These are the ones that work *so far*:\n",
"- `*.txt` files that contain columns `wavelength` (in microns), `time` (in days), `flux` (in any units), `uncertainty` (in the same units as `flux`) along with any other columns\n",
"- `*x1dints.fits` files from the STScI `jwst` pipeline, including all `x1dints` files produced as Stage 2 Data Products for the ers-transit Data Challenge for NIRSpec, NIRCam, MIRI\n",
"- `spectra_order*.npy` files produced as Stage 2 Data Products for the ers-transit Data Challenge for NIRISS\n",
"- `S3_*_Table_Save.txt` files from [Eureka!](https://github.com/kevin218/Eureka)\n",
"- `*.rainbow.npy` files generated by `chromatic` itself\n",
"\n",
"Now, let's try to read in that file!"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "bf64feda",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n",
"🌈 Warning: No times found! Making up imaginary ones!"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"The imaginary times assume 47.712 s/integration.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 42/42 [00:05<00:00, 7.39it/s]\n"
]
}
],
"source": [
"# define a path pointing to the file(s) for this data product\n",
"data_path = '/Users/zach/Data/JWST/Spring2022DataChallenge/'\n",
"file_path = os.path.join(data_path, 'MIRI/Stage 2 Output/*x1dints.fits')\n",
"data = Rainbow(file_path)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "fcabcb3c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"This chromatic light curve <🌈(387w, 1848t)>\n",
"has 387 wavelengths spanning 3.74 um to 14.4 um \n",
"and 1848 times spanning 0.00 d to 1.02 d.\n",
"\n"
]
}
],
"source": [
"print(f'''\n",
"This chromatic light curve {data}\n",
"has {data.nwave} wavelengths spanning {min(data.wavelength):.3} to {max(data.wavelength):.3} \n",
"and {data.ntime} times spanning {min(data.time):.2f} to {max(data.time):.2f}.\n",
"''')"
]
},
{
"cell_type": "markdown",
"id": "4e4022b5",
"metadata": {},
"source": [
"## Did it work?\n",
"\n",
"- If you've made it this far without an error, that's spectacular! Huzzah! We should be able to make some snazzy visualizations and calculate some useful metrics from your submitted data.\n",
"- If you ran into an error, please visit the `chromatic` file [input/output page](https://zkbt.github.io/chromatic/io/) and...\n",
" - ...see if your file format could be brought into alignment with one of the existing readers.\n",
" - ...try writing a new `chromatic` reader for your particular file format, so others can use it too.\n",
" - ...consider sending Zach Berta-Thompson a message on the `ers-transit` slack. He'll be happy to try to help!"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"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.9.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment