diff --git a/jdat_notebooks/IFU_cube_continuum_fit/NGC4151_FeII_ContinuumFit.ipynb b/jdat_notebooks/IFU_cube_continuum_fit/NGC4151_FeII_ContinuumFit.ipynb index d632acb0..50c0e14b 100644 --- a/jdat_notebooks/IFU_cube_continuum_fit/NGC4151_FeII_ContinuumFit.ipynb +++ b/jdat_notebooks/IFU_cube_continuum_fit/NGC4151_FeII_ContinuumFit.ipynb @@ -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" ] }, { @@ -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)" @@ -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()" ] }, @@ -218,7 +219,6 @@ "metadata": {}, "outputs": [], "source": [ - "from IPython.display import YouTubeVideo\n", "vid = YouTubeVideo(\"HMSYwiH3Gl4\")\n", "display(vid)" ] @@ -229,8 +229,7 @@ "metadata": {}, "outputs": [], "source": [ - "from jdaviz import CubeViz\n", - "cubeviz = CubeViz()\n", + "cubeviz = Cubeviz()\n", "cubeviz.app" ] }, @@ -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) " ] }, @@ -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", @@ -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", @@ -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" ] @@ -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\")" ] }, @@ -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']" ] }, @@ -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" ] }, @@ -709,18 +714,21 @@ "HTML('')" ] }, + { + "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", @@ -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" @@ -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", @@ -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", @@ -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\")" ] }, { @@ -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", @@ -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" ] }, @@ -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": { @@ -986,7 +997,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.6" + "version": "3.8.10" } }, "nbformat": 4,