Skip to content

Commit

Permalink
Update notebooks to remove deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
rosteen committed Dec 4, 2023
1 parent c508f86 commit ce2698a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 71 deletions.
48 changes: 22 additions & 26 deletions notebooks/IFU_cube_continuum_fit/NGC4151_FeII_ContinuumFit.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@
"outputs": [],
"source": [
"cubeviz = Cubeviz()\n",
"cubeviz.app"
"cubeviz.show()"
]
},
{
Expand All @@ -234,7 +234,7 @@
"outputs": [],
"source": [
"# Here, we load the data into the Cubeviz app.\n",
"cubeviz.load_data(fn) "
"cubeviz.load_data(fn)"
]
},
{
Expand Down Expand Up @@ -339,7 +339,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Retrieve the spectrum (Subset1) of the user-defined region from the Spectrum Viewer as a Spectrum1D object."
"Retrieve the spectra of the user-defined regions from the Spectrum Viewer as a Spectrum1D object."
]
},
{
Expand All @@ -349,9 +349,9 @@
"outputs": [],
"source": [
"# Extract spectra corresponding to the colored regions in cubeviz\n",
"spectrum1 = cubeviz.app.get_data_from_viewer('spectrum-viewer', 'Subset 1') # AGN Center\n",
"spectrum2 = cubeviz.app.get_data_from_viewer('spectrum-viewer', 'Subset 2') # Red shifted component\n",
"spectrum3 = cubeviz.app.get_data_from_viewer('spectrum-viewer', 'Subset 3') # Blue shifted component\n",
"spectrum1 = cubeviz.get_data(\"contents[SCI]\", spatial_subset='Subset 1', function=\"mean\") # AGN Center\n",
"spectrum2 = cubeviz.get_data(\"contents[SCI]\", spatial_subset='Subset 2', function=\"mean\") # Red shifted component\n",
"spectrum3 = cubeviz.get_data(\"contents[SCI]\", spatial_subset='Subset 3', function=\"mean\") # Blue shifted component\n",
"spectrum1"
]
},
Expand Down Expand Up @@ -495,14 +495,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Pulling Data from Viewers\n",
"## Pulling other data\n",
"\n",
"Note, in cubeviz, you have 4 viewers from which you can pull data. Make sure your data are properly loaded into each viewer before executing the get_data_from_viewer command:<br />\n",
"\n",
"Top Left: flux-viewer <br />\n",
"Center: uncert-viewer<br />\n",
"Top Right: mask-viewer<br />\n",
"Bottom: spectrum-viewer<br />"
"Note, in cubeviz, you can either return the collapsed spectra as we did above by using the `function`\n",
"keyword argument along with (optionally) a `spatial_subset`, or return the entire data cube by omitting\n",
"these keywords as below."
]
},
{
Expand All @@ -511,9 +508,8 @@
"metadata": {},
"outputs": [],
"source": [
"# List data from viewer\n",
"regions = cubeviz.app.get_data_from_viewer(\"uncert-viewer\")\n",
"regions"
"# List available data\n",
"print(cubeviz.app.data_collection)"
]
},
{
Expand All @@ -523,7 +519,7 @@
"outputs": [],
"source": [
"# Extract continuum model from Cubeviz above\n",
"cont_psf_cube = cubeviz.app.get_data_from_viewer(\"uncert-viewer\", \"LinFitCont [Cube] 1\")"
"cont_psf_cube = cubeviz.get_data(\"LinFitCont [Cube] 1\")"
]
},
{
Expand Down Expand Up @@ -636,7 +632,7 @@
"source": [
"# Open up a new instance of Cubeviz to visualize continuum subtracted data\n",
"cubeviz2 = Cubeviz()\n",
"cubeviz2.app"
"cubeviz2.show()"
]
},
{
Expand All @@ -646,7 +642,7 @@
"outputs": [],
"source": [
"cont_sub_cube = 'NGC4151_Hband_ContinuumSubtract.fits'\n",
"cubeviz2.app.load_data(cont_sub_cube, data_label='Continuum Subtracted')"
"cubeviz2.load_data(cont_sub_cube, data_label='Continuum Subtracted')"
]
},
{
Expand Down Expand Up @@ -737,7 +733,7 @@
"outputs": [],
"source": [
"# List spectra available in spectrum-viewer\n",
"spec = cubeviz2.app.get_data_from_viewer('spectrum-viewer') \n",
"spec = cubeviz2.specviz.get_spectra()\n",
"spec"
]
},
Expand All @@ -748,9 +744,9 @@
"outputs": [],
"source": [
"# 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"
"all_spec = cubeviz2.get_data('Continuum Subtracted[SCI]', function='mean') # AGN Center Data Cube\n",
"gauss_spec = cubeviz2.get_data('GaussAll', function='mean') # AGN Center Model Spec\n",
"gauss_cube = cubeviz2.get_data('GaussAll [Cube] 1') # AGN Center Model Cube"
]
},
{
Expand Down Expand Up @@ -963,7 +959,7 @@
"source": [
"# Open up a new instance of Cubeviz to visualize continuum subtracted data\n",
"cubeviz3 = Cubeviz()\n",
"cubeviz3.app"
"cubeviz3.show()"
]
},
{
Expand All @@ -973,7 +969,7 @@
"outputs": [],
"source": [
"cont_sub_cube = 'NGC4151_Hband_FinalSubtract.fits'\n",
"cubeviz3.app.load_data(cont_sub_cube, data_label='Red/Blue Shift')"
"cubeviz3.load_data(cont_sub_cube, data_label='Red/Blue Shift')"
]
}
],
Expand All @@ -993,7 +989,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.11.5"
},
"toc": {
"base_numbering": 1,
Expand Down
44 changes: 17 additions & 27 deletions notebooks/MRS_Mstar_analysis/JWST_Mstar_dataAnalysis_analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
},
Expand Down Expand Up @@ -288,9 +289,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [],
"source": [
"# Open these spectra up in Specviz\n",
Expand All @@ -312,7 +311,7 @@
"outputs": [],
"source": [
"# Load in the spectrum list from above. \n",
"specviz.load_spectrum(splist)"
"specviz.load_data(splist)"
]
},
{
Expand Down Expand Up @@ -346,9 +345,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [],
"source": [
"cubeviz = Cubeviz()\n",
Expand Down Expand Up @@ -394,9 +391,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [],
"source": [
"# Video showing the selection of the star with a circular region of interest\n",
Expand All @@ -410,7 +405,8 @@
"outputs": [],
"source": [
"# Now extract spectrum from your spectral viewer\n",
"spec_agb = cubeviz.app.get_data_from_viewer('spectrum-viewer', 'Subset 1') # AGB star only"
"spec_agb = cubeviz.get_data('combine_dithers_all_exposures_ch1-long_s3d[SCI]',\n",
" spatial_subset='Subset 1', function='mean') # AGB star only"
]
},
{
Expand Down Expand Up @@ -504,9 +500,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [],
"source": [
"# Open these spectra up in Specviz\n",
Expand All @@ -520,7 +514,7 @@
"source": [
"#### Developer Note: Cannot currently open a spectrum1d output from cubeviz in specviz. https://jira.stsci.edu/browse/JDAT-1791\n",
"\n",
"#specviz.load_spectrum(spec_agb)"
"#specviz.load_data(spec_agb)"
]
},
{
Expand All @@ -533,15 +527,15 @@
"flux = spec_agb.flux\n",
"wavelength = spec_agb.spectral_axis\n",
"spec1d = Spectrum1D(spectral_axis=wavelength, flux=flux)\n",
"specviz.load_spectrum(spec1d)"
"specviz.load_data(spec1d)"
]
},
{
"cell_type": "raw",
"metadata": {},
"source": [
"# To load the entire x1d spectrum loaded earlier, you can use this command instead\n",
"specviz.load_spectrum(spec)"
"specviz.load_data(spec)"
]
},
{
Expand Down Expand Up @@ -598,9 +592,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [],
"source": [
"# Video showing how to fit a blackbody \n",
Expand Down Expand Up @@ -776,7 +768,7 @@
"metadata": {},
"outputs": [],
"source": [
"specviz.load_spectrum(bbsub_spectra)"
"specviz.load_data(bbsub_spectra)"
]
},
{
Expand Down Expand Up @@ -842,9 +834,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [],
"source": [
"# Fit a local continuum between the flux densities at: 8.0 - 8.1 & 14.9 - 15.0 microns\n",
Expand Down Expand Up @@ -918,8 +908,8 @@
"metadata": {},
"outputs": [],
"source": [
"specviz.load_spectrum(line_spec_consub, data_label='Continuum Subtraction')\n",
"specviz.load_spectrum(line_spec_norm, data_label='Normalized')"
"specviz.load_data(line_spec_consub, data_label='Continuum Subtraction')\n",
"specviz.load_data(line_spec_norm, data_label='Normalized')"
]
},
{
Expand Down Expand Up @@ -1067,7 +1057,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.11.5"
}
},
"nbformat": 4,
Expand Down
27 changes: 9 additions & 18 deletions notebooks/ifu_optimal/ifu_optimal.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@
" err = hdulist['ERR'].data\n",
" w = wcs.WCS(hdulist[1].header)\n",
" hdr = hdulist[1].header\n",
" hdulist.info()\n",
" print(w)\n",
" \n",
"# Load with Spectrum1D \n",
Expand Down Expand Up @@ -171,7 +170,7 @@
"outputs": [],
"source": [
"cubeviz = Cubeviz()\n",
"cubeviz.app"
"cubeviz.show()"
]
},
{
Expand Down Expand Up @@ -219,21 +218,13 @@
"outputs": [],
"source": [
"# Data from local directory\n",
"# cubeviz.app.load_data(filename)\n",
"# cubeviz.load_data(filename)\n",
"\n",
"# Data from url:\n",
"url = filename\n",
"df = download_file(url)\n",
"time.sleep(2) # Sleep to avoid glue-jupyter timing issue\n",
"cubeviz.app.load_data(df)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"*Developer Note:* Spectral cube does not yet recognize JWST NIRSpec IFU datacubes, giving the above warning\n",
"for each FITS extension."
"cubeviz.load_data(df)"
]
},
{
Expand All @@ -248,11 +239,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"*Developer Note:* cubeviz.app.get_subsets_from_viewer method doesn't work if there are more than 2 datasets selected in the spectrum viewer:\n",
"*Developer Note (2023-12-04):* cubeviz.app.get_subsets_from_viewer method has been deprecated. \n",
"\n",
"#region1 = cubeviz.app.get_subsets_from_viewer('spectrum-viewer')\n",
"\n",
"#print(region1['Subset1'])\n"
"#print(region1['Subset1'])"
]
},
{
Expand All @@ -261,9 +252,8 @@
"metadata": {},
"outputs": [],
"source": [
"cubeviz_data = cubeviz.app.data_collection[0]\n",
"try:\n",
" region1 = cubeviz_data.get_selection_definition(format='astropy-regions')\n",
" region1 = cubeviz.get_interactive_regions()['Subset 1']\n",
" print(region1)\n",
" region1_exists = True\n",
"except Exception:\n",
Expand All @@ -286,7 +276,8 @@
"outputs": [],
"source": [
"try:\n",
" spectrum_subset1 = cubeviz.app.get_data_from_viewer('spectrum-viewer')['Subset 1']\n",
" spectrum_subset1 = cubeviz.get_data(cubeviz.app.data_collection[0].label,\n",
" spatial_subset=\"Subset 1\", function=\"mean\")\n",
" print(spectrum_subset1)\n",
"except Exception:\n",
" print(\"There are no subsets selected in the spectrum viewer.\")"
Expand Down Expand Up @@ -826,7 +817,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.11.5"
}
},
"nbformat": 4,
Expand Down

0 comments on commit ce2698a

Please sign in to comment.