Exporting Data from Cubeviz

After data have been manipulated or analyzed, it is possible to export those data currently back into your Jupyter notebook.

Spatial Regions

See also

Export Spatial Regions

Documentation on how to export spatial regions.

Since Specviz can be accessed from Cubeviz, the following line of code can be used to extract the spectrum of a spatial subset named “Subset 1”:

subset1_spec1d = cubeviz.specviz.get_spectra(subset_to_apply="Subset 1")

An example without accessing Specviz:

subset1_spec1d = cubeviz.get_data(data_label=flux_data_label,
                                  subset_to_apply="Subset 1",
                                  function="mean")

Note that in the above example, the function keyword is used to tell Cubeviz how to collapse the flux cube down to a one dimensional spectrum - this is not necessarily equivalent to the collapsed spectrum in the spectrum viewer, which may have used a different collapse function.

To get all subsets from the spectrum viewer:

subset1_spec1d = cubeviz.app.get_subsets_from_viewer("spectrum-viewer")

To access the spatial regions themselves:

regions = cubeviz.get_interactive_regions()
regions

1D Spectra and Spectral Regions

See also

Export Spectra

Documentation on how to export data from the spectrum-viewer.

The following line of code can be used to extract a spectral subset named “Subset 2”:

subset2_spec1d = cubeviz.specviz.get_spectra("Subset 2")

3D Data Cubes

To extract the entire cube, you can run the following code (replace “data_name” with the name of the data you want to extract):

mydata = cubeviz.get_data(data_label="data_name")

The data is returned as a 3D specutils.Spectrum1D object.

To write out a specutils.Spectrum1D cube from Cubeviz (e.g., a fitted cube from Model Fitting), where the mask (if available) is as defined in Spectrum1D masks:

mydata.write("mydata.fits", format="jdaviz-cube")

Data can also be accessed directly from data_collection using the following code:

cubeviz.app.data_collection[0]

Which is returned as a Data object. The DataCollection object can be indexed to return all available data (i.e., not just using 0 like in the previous example).

Model Fits

For a list of model labels:

models = cubeviz.get_models()
models

Once you know the model labels, to get a specific model:

mymodel = cubeviz.get_models(model_label="ModelLabel", x=10)

To extract all of the model parameters:

myparams = cubeviz.get_model_parameters(model_label="ModelLabel", x=x, y=y)
myparams

where the model_label parameter identifies which model should be returned and the x and y parameters identify specifically which spaxel fits are to be returned, for models applied to every spaxel using the Apply to Cube button. Leaving x or y as None will mean that the models fit to every spaxel across that axis will be returned.

Markers Table

All mouseover information in the markers plugin can be exported to an astropy table by calling export_table() (see Accessing Plugin APIs).