### Running Jdaviz Example Notebooks
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/quickstart.rst
Instructions for running Jdaviz example notebooks using the Jupyter notebook or Jupyter Lab environments. This allows users to test Jdaviz with pre-defined workflows and sample data.
```Shell
jupyter notebook /path/to/jdaviz/notebooks/ImvizExample.ipynb
```
```Shell
jupyter lab /path/to/jdaviz/notebooks/ImvizExample.ipynb
```
--------------------------------
### Developer Installation and Workflow
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/installation.rst
Clones the Jdaviz repository, sets up remote upstream, fetches tags and main branch, and creates a new branch for development. Includes rebasing on the upstream main branch.
```bash
git clone git@github.com:username/jdaviz.git
cd jdaviz
git remote add upstream git@github.com:spacetelescope/jdaviz.git
git fetch upstream main
git fetch upstream --tags
git checkout -b my-new-feature
git fetch upstream --tags
git fetch upstream main
git rebase upstream/main
```
--------------------------------
### Install Jdaviz with Optional Dependencies
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/installation.rst
Installs Jdaviz with optional dependencies for Roman Space Telescope data, audio sonification (strauss), or Qt-based standalone applications. The 'all' flag installs all optional dependencies.
```bash
pip install -U jdaviz[roman]
pip install -U jdaviz[strauss]
pip install -U jdaviz[qt]
pip install -U jdaviz[all]
```
--------------------------------
### Initialize and Load Data in Cubeviz
Source: https://github.com/spacetelescope/jdaviz/blob/main/jdaviz/configs/cubeviz/cubeviz.ipynb
This snippet shows how to create an instance of the Cubeviz application and load a data file into it. It includes basic setup and data loading steps.
```Python
# PREFIX
from jdaviz import Cubeviz
cubeviz = Cubeviz(verbosity='JDAVIZ_VERBOSITY', history_verbosity='JDAVIZ_HISTORY_VERBOSITY')
data_path = 'DATA_FILENAME'
if data_path:
cubeviz.load_data('DATA_FILENAME')
cubeviz.app
```
--------------------------------
### Jdaviz Standalone Application Usage
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/quickstart.rst
Shows how to launch the Jdaviz standalone application from the command line. This includes using the `--help` flag for syntax and usage, and specifying data files and configurations.
```Shell
jdaviz --help
```
```Shell
jdaviz --layout=[imviz|specviz|cubeviz|mosviz|specviz2d] /path/to/data/file
```
```Shell
jdaviz --layout=imviz my_image.fits
```
```Shell
jdaviz
```
--------------------------------
### Jdaviz in Jupyter Notebook
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/quickstart.rst
Demonstrates how to import and use the Imviz configuration of Jdaviz within a Jupyter notebook. This includes loading data files and displaying the application.
```Python
from jdaviz import Imviz
imviz = Imviz()
imviz.show()
imviz.load_data('filename.fits', data_label='MyData')
```
--------------------------------
### Initialize JDaviz Application
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/cubeviz_spectral_spatial_interactions.ipynb
Initializes the JDaviz application with a specific configuration (e.g., 'cubeviz'). This is the starting point for most JDaviz workflows.
```Python
from jdaviz.app import Application
app = Application(configuration='cubeviz')
app
```
--------------------------------
### Install Jdaviz from GitHub (Development Version)
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/installation.rst
Installs the latest development version of Jdaviz directly from its GitHub repository using pip. The --upgrade flag ensures the latest version is installed.
```bash
pip install git+https://github.com/spacetelescope/jdaviz --upgrade
```
--------------------------------
### Install Jdaviz (Latest Release Version)
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/installation.rst
Installs the latest stable release version of Jdaviz using pip. The --upgrade flag ensures the latest release is installed.
```bash
pip install jdaviz --upgrade
```
--------------------------------
### Access plugins
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/cubeviz_aperture_photometry.ipynb
Gets handles to the 'Aperture Photometry' and 'Slice' plugins.
```python
plg = cubeviz.plugins["Aperture Photometry"]._obj
cube_slice_plg = cubeviz.plugins["Slice"]._obj
```
--------------------------------
### Run Jdaviz Web Application from Command Line
Source: https://github.com/spacetelescope/jdaviz/blob/main/README.rst
Demonstrates how to launch the Jdaviz web application using the command-line interface. Includes examples for general help and starting with a specific layout and data file.
```bash
jdaviz --help
jdaviz --layout=specviz /path/to/data/spectral_file
```
--------------------------------
### Initialize Mosviz and Load NIRISS Data
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/MosvizNIRISSExample.ipynb
Initializes the Mosviz application and loads a sample NIRISS dataset. It also includes steps for downloading and extracting the example data from a remote URL.
```Python
from astropy.utils.data import download_file
import pathlib
import tempfile
import warnings
from zipfile import ZipFile
from jdaviz import Mosviz
warnings.simplefilter('ignore')
mosviz = Mosviz()
mosviz.show()
# Run this cell if your desired data path is a temporary directory.
data_dir = tempfile.gettempdir()
example_data = 'https://stsci.box.com/shared/static/txtjqn2wn0oowolf7pt4x11cz4w2x1ga.zip'
fn = download_file(example_data, cache=True)
with ZipFile(fn, 'r') as sample_data_zip:
sample_data_zip.extractall(data_dir)
level3_path = pathlib.Path(data_dir)
data_dir = level3_path
mosviz.load_data(directory=f"{data_dir}/niriss_1324_reprocessed/", instrument="niriss")
```
--------------------------------
### Setup and Warnings
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/SpecvizExample.ipynb
Imports necessary libraries and suppresses warnings for a cleaner execution environment.
```python
import warnings
import astropy.units as u
# Suppress warnings
with warnings.catch_warnings():
warnings.simplefilter("ignore")
```
--------------------------------
### Download and Extract Example Data
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/MosvizExample.ipynb
Downloads example data from a URL, extracts it using the zipfile package, and prepares it for loading into Mosviz. Requires astropy.
```python
from zipfile import ZipFile
from astropy.utils.data import download_file
import pathlib
example_data = 'https://stsci.box.com/shared/static/ovyxi5eund92yoadvv01mynwt8t5n7jv.zip'
fn = download_file(example_data, cache=True)
with ZipFile(fn, 'r') as sample_data_zip:
sample_data_zip.extractall(data_dir)
data_dir = (pathlib.Path(data_dir) / 'mosviz_nirspec_data_0.3' / 'level3')
```
--------------------------------
### Initialize and Show Specviz
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/specviz_line_lists.ipynb
Initializes the Specviz application and displays the user interface. This is the starting point for using Specviz.
```Python
from jdaviz.app import Application
from jdaviz import Specviz
#app = Application(configuration='cubeviz')
specviz = Specviz()
specviz.show()
```
--------------------------------
### Run Jdaviz Example Notebook
Source: https://github.com/spacetelescope/jdaviz/blob/main/README.rst
Provides instructions on how to execute a sample Jdaviz notebook, such as 'CubevizExample.ipynb', by launching the Jupyter notebook server with the correct path.
```bash
jupyter notebook /path/to/jdaviz/notebooks/CubevizExample.ipynb
```
--------------------------------
### Install Common Jdaviz Dependencies with Conda
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/installation.rst
Installs essential Jdaviz dependencies like 'bottleneck', 'notebook', and 'jupyterlab' from the conda-forge channel. These are often required for a full Jdaviz experience.
```bash
conda install bottleneck
conda install -c conda-forge notebook
conda install -c conda-forge jupyterlab
```
--------------------------------
### Initialize Imviz application
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/imviz_simple_aper_phot.ipynb
Creates an instance of the Imviz application, which is the main interface for image visualization and analysis.
```Python
imviz = Imviz()
```
--------------------------------
### Imviz: Explore the Plugin Toolbar (Old Version)
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/video_tutorials.rst
An older version of the tutorial guiding users through the plugin toolbar in Imviz.
```Video
```
--------------------------------
### Initialize Cubeviz
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/cubeviz_aperture_photometry.ipynb
Creates an instance of the Cubeviz application.
```python
cubeviz = Cubeviz()
```
--------------------------------
### Example Notebook Updates
Source: https://github.com/spacetelescope/jdaviz/blob/main/CHANGES.rst
Updates and additions to the example notebooks to reflect new features and usage patterns.
```Python
# Updated example notebooks.
```
--------------------------------
### Install jdaviz with Roman Dependencies
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/RampvizExample.ipynb
Installs the jdaviz package from source, including optional dependencies required for Roman telescope data.
```bash
pip install .[roman]
```
--------------------------------
### Backend Module Integration Example
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/cubeviz_fitting.ipynb
Shows an example of how the spectral fitting backend code can be integrated into a module. It demonstrates calling a hypothetical `fit_model_to_spectrum` function with the spectrum, model components, and expression.
```Python
from jdaviz.configs.default.plugins.model_fitting import fitting_backend as fb
model_list = [g1,g2,g3,zero_level]
fitted_model, fitted_spectrum = fb.fit_model_to_spectrum(spectrum, model_list, expression, run_fitter=True)
```
--------------------------------
### Start Cubeviz Application
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/cubeviz_spectral_fitting.ipynb
Initializes and displays the Cubeviz application. It also includes code to suppress warnings during the process.
```python
# Suppress warnings
import warnings
with warnings.catch_warnings():
warnings.simplefilter("ignore")
from jdaviz import Cubeviz
cubeviz = Cubeviz()
cubeviz.show()
```
--------------------------------
### Example Notebooks Update
Source: https://github.com/spacetelescope/jdaviz/blob/main/CHANGES.rst
Updated example notebooks (except MosvizExample) to use in-flight JWST data.
```text
Updated example notebooks (except MosvizExample) to use in-flight JWST data.
```
--------------------------------
### Load Data into JDaviz Mosviz
Source: https://github.com/spacetelescope/jdaviz/blob/main/jdaviz/configs/mosviz/mosviz.ipynb
Initializes the Mosviz application and loads data from a specified directory and instrument. Requires the 'jdaviz' library.
```Python
# PREFIX
import pathlib
from jdaviz import Mosviz
data_path = pathlib.Path('DATA_FILENAME')
mosviz = Mosviz(verbosity='JDAVIZ_VERBOSITY', history_verbosity='JDAVIZ_HISTORY_VERBOSITY')
data_path = 'DATA_FILENAME'
if data_path:
mosviz.load_data(directory=data_path, instrument='INSTRUMENT')
mosviz.app
```
--------------------------------
### Display the Imviz application
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/imviz_simple_aper_phot.ipynb
Renders the Imviz application window, making it visible for user interaction.
```Python
imviz.show()
```
--------------------------------
### Import necessary libraries
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/cubeviz_aperture_photometry.ipynb
Imports core libraries for data handling, WCS, regions, and jdaviz.
```python
import numpy as np
from astropy import units as u
from astropy.io import fits
from astropy.nddata import StdDevUncertainty
from astropy.wcs import WCS
from regions import RectanglePixelRegion, PixCoord
from specutils import Spectrum1D
from jdaviz import Cubeviz
```
--------------------------------
### Initialize and Show MOSViz
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/mosviz_niriss_parser.ipynb
Initializes the MOSViz application and displays the user interface. This is a common starting point for using MOSViz.
```Python
from jdaviz.configs.mosviz.helper import Mosviz
from astropy.io import fits
from pyinstrument import Profiler
mosviz = Mosviz()
mosviz.show()
```
--------------------------------
### Initialize and Show Specviz
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/mosviz_niriss_parser.ipynb
Initializes the Specviz application and displays the user interface. This is a starting point for spectral data visualization.
```Python
from jdaviz.configs.specviz.helper import Specviz
from astropy.io import fits
from specutils import Spectrum1D, SpectrumList
specviz = Specviz()
specviz.show()
```
--------------------------------
### Display Cubeviz viewer
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/cubeviz_aperture_photometry.ipynb
Shows the Cubeviz interface.
```python
cubeviz.show()
```
--------------------------------
### Install Jdaviz using Conda and Pip
Source: https://github.com/spacetelescope/jdaviz/blob/main/README.rst
Instructions for setting up a dedicated environment for Jdaviz using conda and then installing the package via pip. It's recommended to use a new environment to avoid version conflicts.
```bash
conda create -n jdaviz-env python=3.12
conda activate jdaviz-env
pip install jdaviz --upgrade
```
--------------------------------
### Open Aperture Photometry plugin
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/cubeviz_aperture_photometry.ipynb
Opens the Aperture Photometry plugin in the Cubeviz tray.
```python
plg.open_in_tray()
```
--------------------------------
### Jdaviz Configuration for Toolbar Plugin
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/dev/ui_description.rst
Example YAML configuration file demonstrating how to register and display the 'test-button' plugin in the Jdaviz toolbar.
```yaml
components:
menu_bar: false
toolbar: true
tray_bar: true
content_area: true
toolbar:
- test-button
menu_bar:
tray_bar:
content_area:
```
--------------------------------
### JDaviz App-Specific Method Examples
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/mosviz_concept.ipynb
Provides examples of application-specific methods in JDaviz for common operations like rescaling spectra, switching views, retrieving current spectrum data, and potentially computing redshifts.
```Python
mosapp.rescale_both_spectra()
mosapp.switch_to_spectrum_slits()
#vs
mosapp.switch_to_table_slits()
spec1d, spec2d, image2d, tablerow = mosapp.get_current_spectrum()
mosapp.compute_redshift_on_all_spectra(...)
```
--------------------------------
### Initialize JDaviz Application
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/cubeviz_data_interactions.ipynb
Initializes the JDaviz application with the Cubeviz configuration and suppresses warnings. This is the first step to using the application programmatically.
```Python
import warnings
with warnings.catch_warnings():
warnings.simplefilter("ignore")
from jdaviz.app import Application
app = Application(configuration='cubeviz')
app
```
--------------------------------
### Initialize and Load Data in Cubeviz
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/cubeviz_aperture_photometry.ipynb
Initializes the Jdaviz Cubeviz application and loads the previously created spectral cube data with a specified label.
```Python
cubeviz2 = Cubeviz()
cubeviz2.load_data(test_cube2, data_label="test")
```
--------------------------------
### Install Jupyter in Anaconda Navigator Environment
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/installation.rst
Installs the 'jupyter' package within an Anaconda Navigator environment. This is a workaround if direct pip installation of Jdaviz fails, ensuring JupyterLab is available.
```bash
pip install jupyter
```
--------------------------------
### Load data into Cubeviz
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/cubeviz_aperture_photometry.ipynb
Loads the prepared data cube into the Cubeviz viewer with a specified label.
```python
cubeviz.load_data(test_cube, data_label="test")
```
--------------------------------
### Install Jdaviz within Anaconda Navigator Environment
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/installation.rst
Installs Jdaviz using pip within an environment created and managed by Anaconda Navigator. This is an alternative installation method for users who prefer a GUI.
```bash
pip install jdaviz
```
--------------------------------
### Install Jdaviz in Editable Mode
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/installation.rst
Installs the Jdaviz package in an editable mode, allowing local code changes to reflect in runtime after restarting the Python kernel.
```bash
pip install -e .
```
--------------------------------
### Initialize and Show Specviz
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/specviz_minimal.ipynb
Creates an instance of the Specviz helper class and displays the visualization tool. This is the starting point for interactive spectral visualization.
```Python
from jdaviz import Specviz
specviz = Specviz()
specviz.show()
```
--------------------------------
### Run Jdaviz Installation in Jupyter Notebook
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/installation.rst
Executes the pip installation command for Jdaviz within the first cell of a Jupyter notebook. This is used after launching JupyterLab from an Anaconda Navigator environment.
```python
pip install jdaviz
```
--------------------------------
### Enable Jdaviz Hot Reloading
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/installation.rst
Installs the 'watchdog' package and enables hot reloading of Vue.js templates within a Jdaviz notebook environment.
```bash
pip install watchdog
```
```python
from jdaviz import enable_hot_reloading
enable_hot_reloading()
```
--------------------------------
### Initialize Mosviz with Application
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/mosviz_concept.ipynb
Demonstrates initializing the Jdaviz Application and Mosviz helper class. This is the standard way to set up Mosviz.
```Python
from jdaviz.app import Application
from jdaviz.mosviz import MosvizHelper
app = Application()
mosviz = Mosviz(app)
mosviz.app.show()
```
--------------------------------
### Enable Python Autoreloading
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/installation.rst
Enables magic commands for Python autoreloading in a notebook, which automatically reloads modules before executing code.
```python
%load_ext autoreload
%autoreload 2
```
--------------------------------
### Get Spectral Selection Region
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/cubeviz_spectral_spatial_interactions.ipynb
Obtains the currently selected spectral region from the spectrum viewer. This region can then be used for further analysis, such as calculating flux.
```Python
reg = app.get_spectral_selection() # <- `reg` is a specutils.SpectralRegion
```
--------------------------------
### Get Spectrum from Viewer (Option 2)
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/cubeviz_spectral_spatial_interactions.ipynb
Retrieves the spectrum from a specific viewer named 'spectrum'. This approach is considered more generalizable for integrating with other tools.
```Python
spec = app.get_viewer('spectrum').get_spectrum() #<- needs to be a Spectrum1D
smoothed_spec = box_smooth(spec, 5)
app.get_viewer('spectrum').add_layerordataorsomething(smoothed_spec)
```
--------------------------------
### Initialize and Load Data with JDAViz Imviz
Source: https://github.com/spacetelescope/jdaviz/blob/main/jdaviz/configs/imviz/imviz.ipynb
This snippet shows how to create an instance of the Imviz application from the jdaviz library, load a specified data file, and access the application object. It includes basic error handling for the data path.
```Python
# PREFIX
from jdaviz import Imviz
imviz = Imviz(verbosity='JDAVIZ_VERBOSITY', history_verbosity='JDAVIZ_HISTORY_VERBOSITY')
data_path = 'DATA_FILENAME'
if data_path:
imviz.load_data('DATA_FILENAME')
imviz.app
```
--------------------------------
### Create and Activate Conda Environment
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/installation.rst
Creates a new Conda environment named 'jdaviz-env' with Python 3.11 and activates it. This is recommended to avoid package version conflicts.
```bash
conda create -n jdaviz-env python=3.11
conda activate jdaviz-env
```
--------------------------------
### Initialize and Show Mosviz
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/MosvizExample.ipynb
Initializes the Mosviz application and displays the user interface. This is the first step to using Mosviz.
```python
from jdaviz import Mosviz
mosviz = Mosviz()
mosviz.show()
```
--------------------------------
### Cubeviz: Measure Emission Line Properties
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/video_tutorials.rst
This video, from JWebbinar 02/2023, guides users on measuring emission line properties within the Cubeviz configuration.
```Video
```
--------------------------------
### Get Spectrum from Viewer (Option 1)
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/cubeviz_spectral_spatial_interactions.ipynb
Retrieves the 'most recent' spectrum from the spectrum viewer as a Spectrum1D object. This is part of the preferred workflow for accessing spectral data.
```Python
spec = app.get_spectrum() # <- this gets the "most recent" plot in the spectrum viewer, as a Spectrum1D
spec.spectral_axis, spec.flux
```
--------------------------------
### Cubeviz: Create Moment Maps
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/video_tutorials.rst
This tutorial, from JWebbinar 05/2024, explains how to create moment maps using the Cubeviz configuration.
```Video
```
--------------------------------
### Initialize Imviz and Viewer
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/ImvizExample.ipynb
Creates an instance of the Imviz class and retrieves the default viewer associated with it. This sets up the environment for image visualization.
```Python
imviz = Imviz()
viewer = imviz.default_viewer
```
--------------------------------
### Enable Jupyter Widgets Extension
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/installation.rst
Enables the 'ipywidgets' notebook extension, which is necessary for interactive widgets within Jupyter notebooks and JupyterLab. This command should be run after activating the correct environment.
```bash
jupyter nbextension enable --py widgetsnbextension
```
--------------------------------
### JDaviz Plugin Vue Template Example
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/dev/ui_style_guide.rst
This snippet shows a typical Vue.js template structure for a JDaviz plugin. It utilizes the `j-tray-plugin` component for overall layout and includes form elements like `v-text-field` with validation and a `plugin-action-button` for triggering actions. The example demonstrates how to bind Vue data to traitlets and handle user input.
```Vue.js
....
{add_model(e); validate()}"
>Action Text
```
--------------------------------
### Download Roman example data
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/imviz_dq_concept.ipynb
Downloads a sample Roman L2 ASDF file using astropy's download_file utility. This requires the 'roman_datamodels' and 'rad' packages to be installed.
```Python
from astropy.utils.data import download_file
# With the following optional dependencies, load a Roman L2 file:
# roman_datamodels==0.18 rad==0.18
roman_l2_url = 'https://stsci.box.com/shared/static/ktpt4li627kq4mipi3er5yd4qw6hq7ll.asdf'
path = download_file(roman_l2_url, cache=True)
```
--------------------------------
### Imviz: Interact with Viewer from Notebook
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/video_tutorials.rst
This tutorial, from JWebbinar 02/2023, shows how to interact with the Imviz viewer directly from your notebook environment.
```Video
```
--------------------------------
### Load Data with Specviz
Source: https://github.com/spacetelescope/jdaviz/blob/main/jdaviz/configs/specviz/specviz.ipynb
Initializes the Specviz application and loads a specified data file. Requires the jdaviz library. The verbosity levels for the application and history can be configured.
```Python
from jdaviz import Specviz
specviz = Specviz(verbosity='JDAVIZ_VERBOSITY', history_verbosity='JDAVIZ_HISTORY_VERBOSITY')
data_path = 'DATA_FILENAME'
if data_path:
specviz.load_data(data_path)
specviz.app
```
--------------------------------
### Add and Use Custom Colormap in Imviz
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/imviz/displayimages.rst
Provides an example of how to add a custom colormap to Glue and then use it within Imviz. This requires running Imviz in a notebook environment and adding the colormap before starting Imviz.
```python
from glue.config import colormaps
from photutils.utils import make_random_cmap
randcmap = make_random_cmap(ncolors=256)
randcmap.colors[0] = 0. # To make your background black
colormaps.add('photutils_cmap', randcmap)
```
```python
imviz = Imviz()
imviz.load_data('myimage.fits')
imviz.default_viewer.set_colormap('photutils_cmap')
```
--------------------------------
### Access and Modify MOS Table Data
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/MosvizNIRISSExample.ipynb
Demonstrates how to interact with the MOS table using the Mosviz API. This includes exporting the table, setting redshifts, getting column data, updating columns, adding new columns, and hiding columns.
```Python
# Export the entire table to a QTable object
mosviz.to_table()
# Set the redshift for the currently selected object
mosviz.set_redshift(0.896)
# Extract the array of a single column
mosviz.get_column('Redshift')
# Update a specific row's value in a column
mosviz.update_column('Redshift', 1.158, row=4)
# Add a new custom column
mosviz.add_column('Notes')
# Populate the value for a specific row in the new column
mosviz.update_column('Notes', 'low S/N', row=2)
# Hide a column from the UI
mosviz.hide_column('Notes')
```
--------------------------------
### Resolve vispy installation issues
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/known_bugs.rst
Provides a workaround for vispy installation failures on certain platforms and Python versions. It suggests creating a new conda environment, activating it, and installing a compatible version of vispy (>=0.6.5) before installing jdaviz.
```bash
conda create -n jdaviz python=3.12
conda activate jdaviz
pip install vispy>=0.6.5
pip install jdaviz --no-cache-dir
```
--------------------------------
### Instantiate and Show Specviz
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/specviz/displaying.rst
Demonstrates how to programmatically instantiate and display the Specviz tool using its helper class. This is useful for integrating Specviz functionality into custom workflows or notebooks.
```python
from jdaviz import Specviz
# Instantiate an instance of Specviz
specviz = Specviz()
# Display Specviz
specviz.show()
```
--------------------------------
### jdaviz Bug Fix: Specviz2d Example Notebook File
Source: https://github.com/spacetelescope/jdaviz/blob/main/CHANGES.rst
Replaced a file in the example notebook for Specviz2d. This ensures the example notebook is up-to-date and functional.
```APIDOC
Replace file in example notebook for Specviz2d.
- Ensures example notebook is up-to-date and functional.
- Improves usability of examples.
```
--------------------------------
### Initialize and Display Cubeviz
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/CubevizExample.ipynb
Creates an instance of the Cubeviz application and displays it.
```Python
cubeviz = Cubeviz()
cubeviz.show()
```
--------------------------------
### Imviz: Open Image Data (Old Version)
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/video_tutorials.rst
An older version of the tutorial demonstrating how to open image data in Imviz.
```Video
```
--------------------------------
### Create Specviz2d Instance
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/Specviz2dExample.ipynb
Initializes the Specviz2d application, which is used for spectral data visualization and analysis within the Jdaviz framework.
```Python
from jdaviz import Specviz2d
specviz2d = Specviz2d()
```
--------------------------------
### Get and Set Zoom Level
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/ImvizExample.ipynb
Demonstrates how to get the current zoom level of the viewer and set it directly or relatively.
```Python
# Get the current zoom level.
viewer.zoom_level
# Set the zoom level directly.
viewer.zoom_level = 1
# Set the relative zoom based on current zoom level.
viewer.zoom(2)
```
--------------------------------
### Create and Control a Second Viewer
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/imviz_roman_asdf.ipynb
Demonstrates how to create a new image viewer, add data to it, adjust its view, and manage its lifecycle.
```python
viewer_2_name = 'my-viewer-1'
# Do not pass in viewer_name if you want it auto-generated.
# If auto-generated, viewer name will be 'imviz-1'.
viewer_2 = imviz.create_image_viewer(viewer_name=viewer_2_name)
```
```python
# Show the first image in the second viewer.
imviz.app.add_data_to_viewer(viewer_2_name, "exposure 1[DATA]")
```
```python
viewer_2.zoom(4)
```
```python
viewer_2.cuts = '95%'
```
```python
viewer_2.center_on((1500, 1000))
```
```python
imviz.destroy_viewer(viewer_2_name)
```
--------------------------------
### Jdaviz Toolbar Plugin Example
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/dev/ui_description.rst
An example of a Jdaviz plugin that adds a button to the toolbar area, inheriting from TemplateMixin and using the @tools decorator.
```python
@tools('test-button')
class TestButton(TemplateMixin):
template = Unicode("""
Press me!
""").tag(sync=True)
```
--------------------------------
### Load Data into Imviz
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/imviz_roman_asdf.ipynb
Initializes the Imviz application and loads two simulated Roman telescope exposures, suppressing potential ErfaWarnings during loading.
```Python
# load the observations into the helper
imviz = Imviz()
with warnings.catch_warnings():
warnings.simplefilter('ignore') # ErfaWarning
imviz.load_data(image_model1, ext='data', data_label='exposure 1')
imviz.load_data(image_model2, ext='data', data_label='exposure 2')
```
--------------------------------
### Cubeviz 4.2.2 Changes: Example Notebook Update
Source: https://github.com/spacetelescope/jdaviz/blob/main/CHANGES.rst
A minor change in Cubeviz for version 4.2.2 involves replacing a file and fixing a label in an example notebook.
```text
Replace file and fix label in example notebook. [#3537]
```
--------------------------------
### Imviz: Aperture Photometry (Old Version)
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/video_tutorials.rst
An older version of the tutorial explaining how to perform aperture photometry using Imviz.
```Video
```
--------------------------------
### Initialize Imviz and Viewer
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/ImvizDitheredExample.ipynb
Creates an instance of the Imviz class and retrieves the default viewer, which is used for all subsequent image display and manipulation operations.
```Python
imviz = Imviz()
viewer = imviz.default_viewer
```
--------------------------------
### Configure and Run Aperture Photometry
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/cubeviz_aperture_photometry.ipynb
Accesses the Aperture Photometry plugin in Cubeviz, sets the dataset and selected subsets for aperture and background, and then executes the aperture photometry calculation.
```Python
plg2 = cubeviz2.plugins["Aperture Photometry"]._obj
plg2.open_in_tray()
plg2.dataset_selected = "test[FLUX]"
plg2.aperture_selected = "Subset 1"
plg2.background_selected = "Subset 2"
plg2.vue_do_aper_phot()
```
--------------------------------
### Fix scikit-image installation on older MacOS
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/known_bugs.rst
Addresses installation failures on MacOS 10.13 and older by reinstalling scikit-image. It provides two methods: one using pip and conda, and another using pip with a specific flag to build from source.
```bash
pip uninstall scikit-image
conda install scikit-image
```
```bash
pip install -U --no-binary scikit-image scikit-image.
```
--------------------------------
### JDaviz Form Validation Error Display
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/dev/ui_style_guide.rst
Provides methods for displaying custom validation error messages within the UI, either inline or using alerts, to guide users and manage input states effectively.
```Vue
WARNING: warning message
Detailed error message
```
--------------------------------
### Initialize Imviz and Load RGB Channels
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/imviz_color_display.ipynb
Initializes the Imviz application and loads the prepared Red, Green, and Blue image data into separate layers with corresponding labels. It then accesses the default viewer and displays the Imviz application.
```Python
imviz = Imviz()
imviz.load_data(im_r, data_label='Red')
imviz.load_data(im_g, data_label='Green')
imviz.load_data(im_b, data_label='Blue')
viewer = imviz.default_viewer._obj
imviz.show()
```
--------------------------------
### Perform aperture photometry
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/cubeviz_aperture_photometry.ipynb
Executes the aperture photometry calculation.
```python
plg.vue_do_aper_phot()
```
--------------------------------
### Configure Aperture Photometry
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/cubeviz_aperture_photometry.ipynb
Sets the dataset and aperture for the photometry calculation.
```python
plg.dataset_selected = "test[FLUX]"
plg.aperture_selected = "Subset 1"
```
--------------------------------
### Reset viewer limits
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/cubeviz_aperture_photometry.ipynb
Resets the display limits of the default viewer.
```python
cubeviz.default_viewer._obj.state.reset_limits()
```
--------------------------------
### Change slice and re-photometer
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/cubeviz_aperture_photometry.ipynb
Changes the spectral slice and re-runs the aperture photometry.
```python
cube_slice_plg.slice = 0
plg.vue_do_aper_phot()
# Change back
cube_slice_plg.slice = 4
```
--------------------------------
### Initialize and Configure Jdaviz Application
Source: https://github.com/spacetelescope/jdaviz/blob/main/jdaviz/configs/default/default.ipynb
This snippet shows how to create an instance of the Jdaviz Application, set its configuration, and adjust verbosity levels for application output and command history. It also demonstrates loading data if a data file path is provided.
```Python
from jdaviz.app import Application
app = Application(configuration='default')
app.verbosity = 'JDAVIZ_VERBOSITY'
app.history_verbosity = 'JDAVIZ_HISTORY_VERBOSITY'
data_path = 'DATA_FILENAME'
if data_path:
app.load_data('DATA_FILENAME')
app
```
--------------------------------
### Export photometry results
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/cubeviz_aperture_photometry.ipynb
Exports the results of the aperture photometry calculations to a table.
```python
t = cubeviz.plugins['Aperture Photometry'].export_table()
t # Should have 5 rows
```
--------------------------------
### Define aperture region
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/cubeviz_aperture_photometry.ipynb
Creates a rectangular aperture region in pixel coordinates.
```python
aper = RectanglePixelRegion(center=PixCoord(x=1, y=2), width=3, height=5)
```
--------------------------------
### List Available Specutils Loaders
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/create_products.rst
This snippet demonstrates how to list the available data formats that specutils can read. This is useful for understanding which file types are natively supported or can be adapted for use with specutils loaders.
```python
from specutils import Spectrum
Spectrum.read.list_formats()
```
--------------------------------
### Imviz: Align Images (Old Version)
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/video_tutorials.rst
An older version of the tutorial demonstrating the process of aligning images within Imviz.
```Video
```
--------------------------------
### Create and Display Specviz Instance
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/SpecvizExample.ipynb
Initializes the Specviz application and displays it within the notebook. The display height can be adjusted using the 'height' keyword argument, and it can be popped out into a separate window using 'loc="popout:window"'.
```python
from jdaviz import Specviz
specviz = Specviz()
specviz.show()
```
--------------------------------
### Initialize and Load Data in Imviz
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/imviz_colorbar_mpl.ipynb
Initializes the Jdaviz Imviz plugin and loads the generated test image data.
```Python
imviz = Imviz()
imviz.load_data(image, data_label="test image")
imviz.show()
```
--------------------------------
### Aperture photometry on collapsed data
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/cubeviz_aperture_photometry.ipynb
Sets the collapsed data as the dataset and performs aperture photometry.
```python
plg.dataset_selected = "test[FLUX] collapsed"
plg.vue_do_aper_phot()
```
--------------------------------
### Syntactic Sugar for Mosviz Initialization
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/mosviz_concept.ipynb
Provides a quicker, syntactic sugar version for initializing Mosviz, where a default application is created if none is provided.
```Python
mosviz = Mosviz() #<- default app=None would mean "make a new empty glue Application"
mosviz # <- Mosviz._repr_html_ just yields whatever the .app.show() gives
```
--------------------------------
### Collapse data cube
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/cubeviz_aperture_photometry.ipynb
Accesses the Collapse plugin and performs a collapse operation on the data cube.
```python
collapse_plg = cubeviz.plugins["Collapse"]._obj
collapse_plg.vue_collapse()
cubeviz.app.add_data_to_viewer("uncert-viewer", "test[FLUX] collapsed")
```
--------------------------------
### Imviz: Overplot a Catalog (Old Version)
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/video_tutorials.rst
An older version of the tutorial showing how to overplot a catalog onto image data using Imviz.
```Video
```
--------------------------------
### Initialize Mosviz App
Source: https://github.com/spacetelescope/jdaviz/blob/main/docs/mosviz/notebook.rst
Initializes an instance of the Mosviz app in a Jupyter notebook. The `show()` method displays the application. If only using the API, `show()` can be commented out.
```python
from jdaviz import Mosviz
mosviz = Mosviz()
# If solely using the Mosviz API, feel free to comment out the following line.
mosviz.show()
```
--------------------------------
### Calculate moment map
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/cubeviz_aperture_photometry.ipynb
Accesses the Moment Maps plugin and calculates the moment 0 map.
```python
moment_plg = cubeviz.plugins["Moment Maps"]
m = moment_plg.calculate_moment()
cubeviz.app.add_data_to_viewer("uncert-viewer", "test[FLUX] moment 0")
```
--------------------------------
### Load data and display in Imviz
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/imviz_custom_colormap.ipynb
Illustrates how to create sample data, initialize Imviz, load the data, and display the viewer.
```Python
# Some data for Imviz.
arr = np.arange(100).reshape((10, 10))
```
```Python
imviz = Imviz()
imviz.load_data(arr, data_label='array')
imviz.show()
```
--------------------------------
### Import region into Cubeviz
Source: https://github.com/spacetelescope/jdaviz/blob/main/notebooks/concepts/cubeviz_aperture_photometry.ipynb
Imports the defined aperture region into the Cubeviz 'Subset Tools' plugin.
```python
cubeviz.plugins['Subset Tools'].import_region(aper)
```