Skip to content

Commit 308c6d1

Browse files
authored
Merge pull request #353 from sbetti22/jdaviz5-updates
Updates for jdaviz version 5.0
2 parents 49ce9fb + da68515 commit 308c6d1

31 files changed

Lines changed: 396 additions & 321 deletions

intro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ Star</td>
196196
<td><ul>
197197
<li>Use case: Continuum and emission-line modeling of AGN; 1.47-1.87um.</li>
198198
<li>Data: NIFS on Gemini; NGC 4151.</li>
199-
<li>Tools: specutils, cubeviz.</li>
199+
<li>Tools: specutils, jdaviz.</li>
200200
<li>Cross-instrument:</li>
201201
</ul>
202202
</td>

notebooks/MIRI/MRS_Mstar_analysis/JWST_Mstar_dataAnalysis_analysis.ipynb

Lines changed: 90 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@
101101
"from astropy.utils.data import download_file\n",
102102
"\n",
103103
"# To deal with 1D spectrum\n",
104+
"from photutils.aperture import CircularAperture\n",
104105
"from specutils import Spectrum1D\n",
105106
"from specutils.manipulation import box_smooth, extract_region\n",
106107
"from specutils.analysis import line_flux, centroid, equivalent_width\n",
107108
"from specutils.spectra import SpectralRegion\n",
108109
"from specutils import SpectrumList\n",
109-
"from jdaviz import Specviz\n",
110-
"from jdaviz import Cubeviz\n",
110+
"import jdaviz as jd\n",
111111
"\n",
112112
"# Display the video\n",
113113
"from IPython.display import YouTubeVideo"
@@ -245,9 +245,9 @@
245245
"cell_type": "markdown",
246246
"metadata": {},
247247
"source": [
248-
"## Specviz Visualization of the SpectrumList\n",
248+
"## Jdaviz Visualization of the SpectrumList\n",
249249
"\n",
250-
"You can visualize the spectrum list inside a Jupyter notebook using Specviz"
250+
"You can visualize the spectrum list inside a Jupyter notebook using Jdaviz"
251251
]
252252
},
253253
{
@@ -256,7 +256,9 @@
256256
"source": [
257257
"## Video 1:\n",
258258
" \n",
259-
"This Specviz Instructional Demo is from STScI's official YouTube channel and provides an introduction to Specviz."
259+
"This Specviz Instructional Demo is from STScI's official YouTube channel and provides an introduction to Jdaviz 1D Spectrum.\n",
260+
"\n",
261+
"*Note: Specviz has been deprecated as of Jdaviz Version 5.0. However, the general concepts and techniques are the same as loading in a 1D Spectrum to Jdaviz*"
260262
]
261263
},
262264
{
@@ -282,16 +284,16 @@
282284
"metadata": {},
283285
"outputs": [],
284286
"source": [
285-
"# Open these spectra up in Specviz\n",
286-
"specviz = Specviz()\n",
287-
"specviz.show()"
287+
"# Open these spectra up in Jdaviz\n",
288+
"jd1d = jd.new_app()\n",
289+
"jd1d.show()"
288290
]
289291
},
290292
{
291293
"cell_type": "markdown",
292294
"metadata": {},
293295
"source": [
294-
"#### Load in the spectrum list from above. Note, only the first spectrum in your list is displayed automatically. You will need to turn on the remaining spectra in the \"DATA\" drop-down, then hit the \"Home\" button in the toolbar, and scale our plot accordingly to see the other spectra."
296+
"#### Load in the spectrum list from above. We use the batch_load() helper in order to load multiple spectra at once. "
295297
]
296298
},
297299
{
@@ -301,16 +303,38 @@
301303
"outputs": [],
302304
"source": [
303305
"# Load in the spectrum list from above.\n",
304-
"specviz.load_data(splist)"
306+
"with jd1d.batch_load():\n",
307+
" for sp in splist:\n",
308+
" jd1d.load(sp, format='1D Spectrum')"
305309
]
306310
},
307311
{
308312
"cell_type": "markdown",
309313
"metadata": {},
310314
"source": [
311-
"## Cubeviz Visualization\n",
312315
"\n",
313-
"You can also visualize images inside a Jupyter notebook using Cubeviz\n"
316+
"After loading, only the spectra in the wavelength range of the first spectra are visible. Click on the house icon on the viewer to show all of the spectra. Then, click into the zoom button next to the house and select the second button to zoom to a drawn vertical region. Then select and drag the appropriate y range on the viewer. "
317+
]
318+
},
319+
{
320+
"cell_type": "code",
321+
"execution_count": null,
322+
"metadata": {},
323+
"outputs": [],
324+
"source": [
325+
"# Or, adjust the limits using the API calls to see all of the spectra. \n",
326+
"# You can provide it a scalar (which assumes the units of the loaded spectra) or an astropy.Quantity. \n",
327+
"viewer = jd1d.viewers['1D Spectrum']\n",
328+
"viewer.set_limits(x_min=4.9, x_max=29, y_min = 0, y_max=2.2e-1)"
329+
]
330+
},
331+
{
332+
"cell_type": "markdown",
333+
"metadata": {},
334+
"source": [
335+
"## 3D Spectrum Visualization\n",
336+
"\n",
337+
"You can also visualize images inside a Jupyter notebook using Jdaviz with a 3D Spectrum viewer.\n"
314338
]
315339
},
316340
{
@@ -319,7 +343,9 @@
319343
"source": [
320344
"## Video 2:\n",
321345
" \n",
322-
"This Cubeviz Instructional Demo is from STScI's official YouTube channel and provides an introduction to Cubeviz."
346+
"This Cubeviz Instructional Demo is from STScI's official YouTube channel and provides an introduction to Jdaviz viewing a 3D Spectrum.\n",
347+
"\n",
348+
"*Note: Cubeviz has been deprecated as of Jdaviz Version 5.0. However, the general concepts and techniques are the same as loading in a 3D Spectrum to Jdaviz*"
323349
]
324350
},
325351
{
@@ -338,15 +364,10 @@
338364
"metadata": {},
339365
"outputs": [],
340366
"source": [
341-
"cubeviz = Cubeviz()\n",
342-
"cubeviz.show()"
343-
]
344-
},
345-
{
346-
"cell_type": "markdown",
347-
"metadata": {},
348-
"source": [
349-
"#### Developer Note. Need to pick a different unit than meters. https://jira.stsci.edu/browse/JDAT-1792"
367+
"# create a new viewer, or comment out the line below to load the 3D spectrum into the original Jdaviz app. \n",
368+
"jd3d = jd.new_app()\n",
369+
"\n",
370+
"jd3d.show()"
350371
]
351372
},
352373
{
@@ -355,18 +376,30 @@
355376
"metadata": {},
356377
"outputs": [],
357378
"source": [
358-
"# Here, we load the data into the Cubeviz app for visual inspection.\n",
359-
"# In this case, we're just looking at a single channel because, unlike Specviz, Cubeviz can only load a single cube at a time.\n",
379+
"# Here, we load the data into the Jdaviz app for visual inspection.\n",
380+
"# In this case, we're just looking at a single channel. Note that Jdaviz can only load a single cube at a time.\n",
360381
"\n",
361382
"ch1short_cubefile = 'combine_dithers_all_exposures_ch1-long_s3d.fits'\n",
362-
"cubeviz.load_data(ch1short_cubefile)"
383+
"jd3d.load(ch1short_cubefile, format='3D Spectrum')"
363384
]
364385
},
365386
{
366387
"cell_type": "markdown",
367388
"metadata": {},
368389
"source": [
369-
"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."
390+
"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 or creating a region with photutils."
391+
]
392+
},
393+
{
394+
"cell_type": "code",
395+
"execution_count": null,
396+
"metadata": {},
397+
"outputs": [],
398+
"source": [
399+
"# photutils aperture\n",
400+
"my_region = [CircularAperture((20, 30), r=6)]\n",
401+
"\n",
402+
"jd3d.plugins['Subset Tools'].import_region(my_region, combination_mode='new')"
370403
]
371404
},
372405
{
@@ -378,21 +411,21 @@
378411
"# Now extract spectrum from your spectral viewer\n",
379412
"# NEED TO show how to use Spectral Extraction plugin and calculate mean instead of sum spectra\n",
380413
"try:\n",
381-
" spec_agb = cubeviz.get_data('Spectrum (Subset 1, sum)') # AGB star only\n",
414+
" spec_agb = jd3d.get_data('Spectrum (Subset 1, sum)') # AGB star only\n",
382415
" print(spec_agb)\n",
383416
" spec_agb_exists = True\n",
384417
"except Exception:\n",
385418
" print(\"There are no subsets selected.\")\n",
386419
" spec_agb_exists = False\n",
387-
" spec_agb = cubeviz.get_data('Spectrum (sum)') # Whole field of view\n",
420+
" spec_agb = jd3d.get_data('Spectrum (sum)') # Whole field of view\n",
388421
" print(spec_agb)"
389422
]
390423
},
391424
{
392425
"cell_type": "markdown",
393426
"metadata": {},
394427
"source": [
395-
"#### Developer Note: Since Cubeviz only displays a single cube at a time, you can't extract a full spectrum at the current time. So, you should use the spectrum defined above ('spec')"
428+
"#### Developer Note: Since Jdaviz only displays a single cube at a time, you can't extract a full spectrum at the current time. So, you should use the spectrum defined above ('spec')"
396429
]
397430
},
398431
{
@@ -456,7 +489,7 @@
456489
"source": [
457490
"## Visualize for Analysis the Single Spectrum1D Object Created Above from All 12 Individual Spectra\n",
458491
"\n",
459-
"You can visualize the extracted spectrum inside Specviz"
492+
"You can visualize the extracted spectrum inside Jdaviz"
460493
]
461494
},
462495
{
@@ -465,9 +498,9 @@
465498
"metadata": {},
466499
"outputs": [],
467500
"source": [
468-
"# Open these spectra up in Specviz\n",
469-
"specviz = Specviz()\n",
470-
"specviz.show()"
501+
"# Open these spectra up in a new Jdaviz app\n",
502+
"jd1ds = jd.new_app()\n",
503+
"jd1ds.show()"
471504
]
472505
},
473506
{
@@ -476,15 +509,18 @@
476509
"metadata": {},
477510
"outputs": [],
478511
"source": [
479-
"specviz.load_data(spec_agb)"
512+
"# using data_label allows you to name the new spectrum that is loaded\n",
513+
"jd1ds.load(spec_agb, format='1D Spectrum', data_label='AGB star')"
480514
]
481515
},
482516
{
483517
"cell_type": "raw",
484518
"metadata": {},
485519
"source": [
486520
"# To load the entire x1d spectrum loaded earlier, you can use this command instead\n",
487-
"specviz.load_data(spec)"
521+
"with jd.batch_load():\n",
522+
" for sp in splist:\n",
523+
" jd.load(sp, format='1D Spectrum')"
488524
]
489525
},
490526
{
@@ -493,7 +529,7 @@
493529
"metadata": {},
494530
"outputs": [],
495531
"source": [
496-
"# Make new video to show how to smooth spectrum in Specviz"
532+
"# todo: Make new video to show how to smooth spectrum in Jdaviz"
497533
]
498534
},
499535
{
@@ -525,7 +561,7 @@
525561
"metadata": {},
526562
"outputs": [],
527563
"source": [
528-
"# Make new video to show how to fit a blackbody model to the spectrum"
564+
"# todo: Make new video to show how to fit a blackbody model to the spectrum"
529565
]
530566
},
531567
{
@@ -534,7 +570,7 @@
534570
"metadata": {},
535571
"outputs": [],
536572
"source": [
537-
"spectra = specviz.get_spectra()\n",
573+
"spectra = jd1ds.datasets\n",
538574
"\n",
539575
"a = checkKey(spectra, \"BB1\")\n",
540576
"if a is True:\n",
@@ -679,7 +715,7 @@
679715
"metadata": {},
680716
"outputs": [],
681717
"source": [
682-
"# Subtract the continuum and plot in a new instance of specviz\n",
718+
"# Subtract the continuum and plot in a new instance of jdaviz\n",
683719
"bbsub_spectra = spec - ybest.value # continuum subtracted spectra - Dust only"
684720
]
685721
},
@@ -689,8 +725,9 @@
689725
"metadata": {},
690726
"outputs": [],
691727
"source": [
692-
"specviz = Specviz()\n",
693-
"specviz.show()"
728+
"jd1ds = jd.new_app()\n",
729+
"\n",
730+
"jd1ds.show()"
694731
]
695732
},
696733
{
@@ -699,7 +736,7 @@
699736
"metadata": {},
700737
"outputs": [],
701738
"source": [
702-
"specviz.load_data(bbsub_spectra)"
739+
"jd1ds.load(bbsub_spectra, format='1D Spectrum')"
703740
]
704741
},
705742
{
@@ -717,7 +754,7 @@
717754
"metadata": {},
718755
"outputs": [],
719756
"source": [
720-
"spectra = specviz.get_spectra()\n",
757+
"spectra = jd1ds.datasets\n",
721758
"\n",
722759
"a = checkKey(spectra, \"PolyFit\")\n",
723760
"if a is True:\n",
@@ -821,9 +858,9 @@
821858
"metadata": {},
822859
"outputs": [],
823860
"source": [
824-
"# Load 10 um feature back into specviz and calculate the Line flux; Line Centroid; Equivalent width\n",
825-
"specviz = Specviz()\n",
826-
"specviz.show()"
861+
"# Load 10 um feature into jdaviz and calculate the Line flux; Line Centroid; Equivalent width\n",
862+
"jd10um = jd.new_app()\n",
863+
"jd10um.show()"
827864
]
828865
},
829866
{
@@ -832,8 +869,8 @@
832869
"metadata": {},
833870
"outputs": [],
834871
"source": [
835-
"specviz.load_data(line_spec_consub, data_label='Continuum Subtraction')\n",
836-
"specviz.load_data(line_spec_norm, data_label='Normalized')"
872+
"jd10um.load(line_spec_consub, format='1D Spectrum', data_label='Continuum Subtraction')\n",
873+
"# jd10um.load(line_spec_norm, data_label='Normalized')"
837874
]
838875
},
839876
{
@@ -842,7 +879,7 @@
842879
"metadata": {},
843880
"outputs": [],
844881
"source": [
845-
"# Make new video to show how to measure lines within specviz"
882+
"# todo: Make new video to show how to measure lines within jdaviz"
846883
]
847884
},
848885
{
@@ -911,7 +948,7 @@
911948
"cell_type": "markdown",
912949
"metadata": {},
913950
"source": [
914-
"This is the end of the notebook that shows some basic analysis of a MIRI MRS spectrum using Cubeviz and Specviz. Much more analysis is possible."
951+
"This is the end of the notebook that shows some basic analysis of a MIRI MRS spectrum using Jdaviz. Much more analysis is possible."
915952
]
916953
},
917954
{
@@ -937,7 +974,8 @@
937974
"**Updated On:** 2020-08-11<br>\n",
938975
"**Updated On:** 2021-09-06 by B. Sargent, STScI Scientist, Space Telescope Science Institute (added MRS Simulated Data)<br>\n",
939976
"**Updated On:** 2021-12-12 by O. Fox, STScI Scientist (added blackbody and polynomial fitting within the notebook)<br>\n",
940-
"**Updated On:** 2024-10-29 by C. Pacifici, STScI Data Scientist, adapt to Jdaviz 4.0 (still need to update videos)<br>"
977+
"**Updated On:** 2024-10-29 by C. Pacifici, STScI Data Scientist, adapt to Jdaviz 4.0 (still need to update videos)<br>\n",
978+
"**Updated On:** 2026-05-05 by S. Betti, STScI Astronomical Data Scientist, adapt to Jdaviz 5.0 (still need to update videos)<br>\n"
941979
]
942980
},
943981
{
@@ -971,7 +1009,7 @@
9711009
"name": "python",
9721010
"nbconvert_exporter": "python",
9731011
"pygments_lexer": "ipython3",
974-
"version": "3.12.7"
1012+
"version": "3.11.15"
9751013
}
9761014
},
9771015
"nbformat": 4,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
jdaviz>=3.6.2
1+
jdaviz>=5.0
22
jwst>=1.11.4
33
radio-beam>=0.3.4
44
photutils>=1.9.0
126 KB
Loading
125 KB
Loading
128 KB
Loading
137 KB
Loading

0 commit comments

Comments
 (0)