Skip to content

Commit

Permalink
Completed secondary technical review
Browse files Browse the repository at this point in the history
  • Loading branch information
ojustino committed Sep 15, 2021
1 parent fca2e46 commit 6aeff26
Showing 1 changed file with 47 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,18 @@
"import time\n",
"import os\n",
"from copy import copy\n",
"\n",
"import numpy as np\n",
"from IPython.display import HTML, YouTubeVideo\n",
"\n",
"import astropy\n",
"import numpy as np\n",
"from astropy.io import fits, ascii\n",
"from astropy import units as u\n",
"from astropy.modeling import models\n",
"from astropy.utils.data import download_file\n",
"from specutils.fitting import fit_lines\n",
"from specutils import Spectrum1D\n",
"\n",
"from jdaviz.app import Application\n",
"from IPython.display import HTML"
"from jdaviz import Cubeviz\n",
"from jdaviz.app import Application"
]
},
{
Expand All @@ -84,10 +83,12 @@
"# 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 @@ -191,7 +192,7 @@
"plt.figure(1)\n",
"plt.plot(wave, flux1)\n",
"plt.plot(wave[wavemin:wavemax], flux1[wavemin:wavemax])\n",
"plt.plot(wave[continuummin:continuummax], flux1[continuummin:continuummax],color='r')\n",
"plt.plot(wave[continuummin:continuummax], flux1[continuummin:continuummax], color='r')\n",
"plt.show()"
]
},
Expand All @@ -218,7 +219,6 @@
"metadata": {},
"outputs": [],
"source": [
"from IPython.display import YouTubeVideo\n",
"vid = YouTubeVideo(\"HMSYwiH3Gl4\")\n",
"display(vid)"
]
Expand All @@ -229,8 +229,7 @@
"metadata": {},
"outputs": [],
"source": [
"from jdaviz import CubeViz\n",
"cubeviz = CubeViz()\n",
"cubeviz = Cubeviz()\n",
"cubeviz.app"
]
},
Expand All @@ -240,7 +239,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Here, we load the data into the cubeviz app.\n",
"# Here, we load the data into the Cubeviz app.\n",
"cubeviz.load_data(fn) "
]
},
Expand Down Expand Up @@ -384,7 +383,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Define Missing Spectral Regions if User Did Not in Cubeviz\n",
"# Define missing spectral regions if user did not in Cubeviz\n",
"if not regions:\n",
" line_region = SpectralRegion(1.630*u.um, 1.665*u.um)\n",
" \n",
Expand All @@ -398,7 +397,8 @@
"metadata": {},
"outputs": [],
"source": [
"# Apply the spectral region (This code creates new collapsed spectra if you did not create any yourself within jdaviz)\n",
"# Apply the spectral region\n",
"# (creates new collapsed spectra if user did not in jdaviz)\n",
"from specutils.manipulation import extract_region\n",
"\n",
"if not spectrum1:\n",
Expand Down Expand Up @@ -523,7 +523,7 @@
"metadata": {},
"outputs": [],
"source": [
"# List Data from Viewer\n",
"# List data from viewer\n",
"regions = cubeviz.app.get_data_from_viewer(\"uncert-viewer\")\n",
"regions"
]
Expand All @@ -534,7 +534,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Extract Continuum Model from Cubeviz above\n",
"# Extract continuum model from Cubeviz above\n",
"cont_psf_cube = cubeviz.app.get_data_from_viewer(\"uncert-viewer\", \"LinFitCont [Cube] 1\")"
]
},
Expand Down Expand Up @@ -622,11 +622,17 @@
"params"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"*(The following cell is just an example of how you can acces the model fit parameter values):*"
]
},
{
"cell_type": "raw",
"metadata": {},
"source": [
"# And this is just an example of how you can acces the model fit parameter values:\n",
"params['LinFitCont_3d']['slope']"
]
},
Expand All @@ -637,8 +643,7 @@
"outputs": [],
"source": [
"# Open up a new instance of Cubeviz to visualize continuum subtracted data\n",
"from jdaviz import CubeViz\n",
"cubeviz2 = CubeViz()\n",
"cubeviz2 = Cubeviz()\n",
"cubeviz2.app"
]
},
Expand Down Expand Up @@ -709,18 +714,21 @@
"HTML('<iframe width=\"700\" height=\"500\" src=\"https://data.science.stsci.edu/redirect/JWST/jwst-data_analysis_tools/IFU_cube_continuum_fit/multifit_p2.mov\" frameborder=\"0\" allowfullscreen></iframe>')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Wow, that multi-component fit looks great. Good deal.\n",
"\n",
"Now we're going to use the continuum psf cube from a prior cell with the Brackett model created in the above cell to create a full 3-D model of the central emission that isn't caused by the outflow [Fe II]."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Wow, that multi-component fit looks great. Good deal.\n",
"\n",
"# Now we're going to use the continuum psf cube from a prior cell \n",
"# with the Brackett model created in the above cell to create a full\n",
"# 3-D model of the central emission that isn't caused by the outflow [Fe II].\n",
"\n",
"# Extract the spectral regions defined in the spectral viewer\n",
"regions = cubeviz2.specviz.get_spectral_regions()\n",
"\n",
Expand All @@ -746,7 +754,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Get Gauss Model Spectrum and Model Cube\n",
"# Get gauss model spectrum and model cube\n",
"all_spec = cubeviz2.app.get_data_from_viewer('spectrum-viewer', 'Continuum Subtracted[SCI]') # AGN Center Data Cube\n",
"gauss_spec = cubeviz2.app.get_data_from_viewer('spectrum-viewer', 'GaussAll') # AGN Center Model Spec\n",
"gauss_cube = cubeviz2.app.get_data_from_viewer(\"uncert-viewer\", \"GaussAll [Cube] 1\") # AGN Center Model Cube"
Expand All @@ -758,8 +766,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Save your Gauss Model Cube If Necessary\n",
"import os\n",
"# Save your gauss model cube if necessary\n",
"if os.path.exists(\"gauss_model_cube.fits\"):\n",
" os.remove(\"gauss_model_cube.fits\")\n",
"else:\n",
Expand All @@ -771,12 +778,17 @@
"print(type(all_spec.flux))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"*(Developer Note: if saving with 'Count' doesn't work, try the following code.)*"
]
},
{
"cell_type": "raw",
"metadata": {},
"source": [
"# Developer Note: Saving with 'Count' doesn't work.\n",
"\n",
"print(all_spec.flux)\n",
"os.remove(\"all_spec.fits\")\n",
"specref=Spectrum1D(flux=all_spec.flux*u.Unit('Jy'), spectral_axis=all_spec.spectral_axis)\n",
Expand Down Expand Up @@ -826,9 +838,9 @@
"metadata": {},
"outputs": [],
"source": [
"# Save Parameters as a Pickle File if necessary\n",
"# Save parameters as a pickle file if necessary\n",
"save_obj(params, \"gauss_params.pkl\")\n",
"params=load_obj(\"gauss_params.pkl\")"
"params = load_obj(\"gauss_params.pkl\")"
]
},
{
Expand All @@ -850,7 +862,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Overwrite Gauss Model with only 2 of the components of interest\n",
"# Overwrite gauss model with only 2 of the components of interest\n",
"gauss_cube_2component = gauss_cube*0\n",
"\n",
"nz, ny, nx = gauss_cube_2component.shape\n",
Expand Down Expand Up @@ -954,8 +966,7 @@
"outputs": [],
"source": [
"# Open up a new instance of Cubeviz to visualize continuum subtracted data\n",
"from jdaviz import CubeViz\n",
"cubeviz3 = CubeViz()\n",
"cubeviz3 = Cubeviz()\n",
"cubeviz3.app"
]
},
Expand All @@ -972,9 +983,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python [conda env:dat-ifu-cont-adv] *",
"language": "python",
"name": "python3"
"name": "conda-env-dat-ifu-cont-adv-py"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -986,7 +997,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
"version": "3.8.10"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 6aeff26

Please sign in to comment.