Skip to content

Commit

Permalink
Fix for jdaviz 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Camilla Pacifici committed Oct 30, 2024
1 parent e1a7136 commit 25dcab5
Showing 1 changed file with 15 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"source": [
"**Use case:** Extract spatial-spectral features from IFU cube and measure their attributes.<br>\n",
"**Data:** Simulated [MIRI MRS](https://jwst-docs.stsci.edu/mid-infrared-instrument/miri-observing-modes/miri-medium-resolution-spectroscopy) spectrum of AGB star.<br>\n",
"**Tools:** specutils, jwst, photutils, astropy, scipy.<br>\n",
"**Tools:** specutils, astropy, scipy.<br>\n",
"**Cross-intrument:** NIRSpec, MIRI.<br>\n",
"**Documentation:** This notebook is part of a STScI's larger [post-pipeline Data Analysis Tools Ecosystem](https://jwst-docs.stsci.edu/jwst-post-pipeline-data-analysis) and can be [downloaded](https://github.com/spacetelescope/dat_pyinthesky/tree/main/jdat_notebooks/MRS_Mstar_analysis) directly from the [JDAT Notebook Github directory](https://github.com/spacetelescope/jdat_notebooks).<br>\n",
"**Source of Simulations:** [MIRISim](https://www.stsci.edu/jwst/science-planning/proposal-planning-toolbox/mirisim)<br>\n",
Expand Down Expand Up @@ -68,7 +68,7 @@
"# Import useful python packages\n",
"import numpy as np\n",
"\n",
"# Import packages to display images inline in the notebook\n",
"# Import packages to display imagesinline in the notebook\n",
"import matplotlib.pyplot as plt \n",
"%matplotlib inline \n",
"\n",
Expand Down Expand Up @@ -122,12 +122,10 @@
"# Save and Load Objects Using Pickle\n",
"import pickle\n",
"\n",
"\n",
"def save_obj(obj, name):\n",
" with open(name, 'wb') as f:\n",
" pickle.dump(obj, f, pickle.HIGHEST_PROTOCOL)\n",
"\n",
" \n",
"def load_obj(name):\n",
" with open(name, 'rb') as f:\n",
" return pickle.load(f)"
Expand Down Expand Up @@ -363,26 +361,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Next, you want to define a pixel region subset that is specific to the AGB star. You can do this with the regions utility button shown in the video below and drawing a circular region around the AGB star at approximate pixels x=20, y=30."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Video 3:\n",
" \n",
"Here is a video that quickly shows how to select a spatial region in Cubeviz."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Video showing the selection of the star with a circular region of interest\n",
"HTML('<iframe width=\"700\" height=\"500\" src=\"https://data.science.stsci.edu/redirect/JWST/jwst-data_analysis_tools/MRS_Mstar_analysis/region_select.mov\" frameborder=\"0\" allowfullscreen></iframe>')"
"Next, you want to define a pixel region subset that is specific to the AGB star. You can do this with the regions utility button and drawing a circular region around the AGB star at approximate pixels x=20, y=30."
]
},
{
Expand All @@ -392,16 +371,16 @@
"outputs": [],
"source": [
"# Now extract spectrum from your spectral viewer\n",
"# NEED TO show how to use Spectral Extraction plugin and calculate mean instead of sum spectra\n",
"try:\n",
" spec_agb = cubeviz.get_data('combine_dithers_all_exposures_ch1-long_s3d[SCI]',\n",
" spatial_subset='Subset 1', function='mean') # AGB star only\n",
" spec_agb = cubeviz.get_data('Spectrum (Subset 1, sum)') # AGB star only\n",
" print(spec_agb)\n",
" spec_agb_exists = True\n",
"except Exception:\n",
" print(\"There are no subsets selected.\")\n",
" spec_agb_exists = False\n",
" spec_agb = cubeviz.get_data('combine_dithers_all_exposures_ch1-long_s3d[SCI]',\n",
" function='mean') # Whole field of view"
" spec_agb = cubeviz.get_data('Spectrum (sum)') # Whole field of view\n",
" print(spec_agb)"
]
},
{
Expand Down Expand Up @@ -482,26 +461,13 @@
"specviz.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Developer Note: Cannot currently open a spectrum1d output from cubeviz in specviz. https://jira.stsci.edu/browse/JDAT-1791\n",
"\n",
"#specviz.load_data(spec_agb)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# For now, you must create your own spectrum1d object from your extracted cubeviz spectrum. \n",
"flux = spec_agb.flux\n",
"wavelength = spec_agb.spectral_axis\n",
"spec1d = Spectrum1D(spectral_axis=wavelength, flux=flux)\n",
"specviz.load_data(spec1d)"
"specviz.load_data(spec_agb)"
]
},
{
Expand All @@ -512,23 +478,13 @@
"specviz.load_data(spec)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Video 4:\n",
" \n",
"Here is a video that quickly shows how to smooth your spectrum in Specviz."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Video showing how to smooth a spectrum in Specviz\n",
"HTML('<iframe width=\"700\" height=\"500\" src=\"https://data.science.stsci.edu/redirect/JWST/jwst-data_analysis_tools/MRS_Mstar_analysis/smooth.mov\" frameborder=\"0\" allowfullscreen></iframe>')"
"# Make new video to show how to smooth spectrum in Specviz"
]
},
{
Expand All @@ -554,23 +510,13 @@
"For now switching to a blackbody."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Video 5:\n",
" \n",
"Here is a video that shows how to fit a blackbody model to the spectrum"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Video showing how to fit a blackbody \n",
"HTML('<iframe width=\"700\" height=\"500\" src=\"https://data.science.stsci.edu/redirect/JWST/jwst-data_analysis_tools/MRS_Mstar_analysis/blackbody_fit.mov\" frameborder=\"0\" allowfullscreen></iframe>')"
"# Make new video to show how to fit a blackbody model to the spectrum"
]
},
{
Expand Down Expand Up @@ -745,23 +691,13 @@
"specviz.load_data(bbsub_spectra)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Video 6:\n",
" \n",
"Here is a video that shows how to fit a polynomial to two separate spectral regions within a single subset to remove more underlying continuum"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Video showing how to fit a polynomial to two separate spectral regions within a single subset\n",
"HTML('<iframe width=\"700\" height=\"500\" src=\"https://data.science.stsci.edu/redirect/JWST/jwst-data_analysis_tools/MRS_Mstar_analysis/poly_fit.mov\" frameborder=\"0\" allowfullscreen></iframe>')"
"# Make new video to show how to fit a polynomial to two separate spectral regions within a single subset"
]
},
{
Expand Down Expand Up @@ -886,25 +822,13 @@
"specviz.load_data(line_spec_norm, data_label='Normalized')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Video7:\n",
" \n",
"Here is a video that shows how to make line analysis measurements within specviz (i.e., line flux, line centroid, equivalent width)<br>\n",
"Note: You want to calculate your equivalent width on the normalized spectrum<br>\n",
"Note: You can also hack to convert the line flux value into more conventional units<br>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Video showing how to measure lines within specviz\n",
"HTML('<iframe width=\"700\" height=\"500\" src=\"https://data.science.stsci.edu/redirect/JWST/jwst-data_analysis_tools/MRS_Mstar_analysis/line_analysis_plugin.mov\" frameborder=\"0\" allowfullscreen></iframe>')"
"# Make new video to show how to measure lines within specviz"
]
},
{
Expand Down Expand Up @@ -996,7 +920,8 @@
"**Author:** Olivia Jones, Project Scientist, UK ATC.<br>\n",
"**Updated On:** 2020-08-11<br>\n",
"**Updated On:** 2021-09-06 by B. Sargent, STScI Scientist, Space Telescope Science Institute (added MRS Simulated Data)<br>\n",
"**Updated On:** 2021-12-12 by O. Fox, STScI Scientist (added blackbody and polynomial fitting within the notebook)<br>"
"**Updated On:** 2021-12-12 by O. Fox, STScI Scientist (added blackbody and polynomial fitting within the notebook)<br>\n",
"**Updated On:** 2024-10-29 by C. Pacifici, STScI Data Scientist, adapt to Jdaviz 4.0 (still need to update videos)<br>"
]
},
{
Expand Down Expand Up @@ -1030,7 +955,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.11.10"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 25dcab5

Please sign in to comment.