diff --git a/jdaviz/configs/cubeviz/helper.py b/jdaviz/configs/cubeviz/helper.py index 42065f8401..ceab52f47a 100644 --- a/jdaviz/configs/cubeviz/helper.py +++ b/jdaviz/configs/cubeviz/helper.py @@ -1,3 +1,5 @@ +from astropy.utils.decorators import deprecated + from jdaviz.configs.default.plugins.line_lists.line_list_mixin import LineListMixin from jdaviz.configs.specviz import Specviz from jdaviz.core.events import AddDataMessage, SnackbarMessage @@ -112,6 +114,7 @@ def select_wavelength(self, wavelength): self.select_slice(wavelength) @property + @deprecated(since="4.2", alternative="viewers['spectrum-viewer']") def specviz(self): """ A Specviz helper (:class:`~jdaviz.configs.specviz.helper.Specviz`) for the Jdaviz diff --git a/jdaviz/configs/default/plugins/data_quality/data_quality.py b/jdaviz/configs/default/plugins/data_quality/data_quality.py index 10ad8619f6..4be983a345 100644 --- a/jdaviz/configs/default/plugins/data_quality/data_quality.py +++ b/jdaviz/configs/default/plugins/data_quality/data_quality.py @@ -53,8 +53,6 @@ class DataQuality(PluginTemplateMixin, ViewerSelectMixin): """ template_file = __file__, "data_quality.vue" - irrelevant_msg = Unicode("").tag(sync=True) - # `layer` is the science data layer science_layer_multiselect = Bool(False).tag(sync=True) science_layer_items = List().tag(sync=True) diff --git a/jdaviz/configs/default/plugins/model_fitting/model_fitting.py b/jdaviz/configs/default/plugins/model_fitting/model_fitting.py index f9346e5e2f..80e9a46a6b 100644 --- a/jdaviz/configs/default/plugins/model_fitting/model_fitting.py +++ b/jdaviz/configs/default/plugins/model_fitting/model_fitting.py @@ -79,6 +79,7 @@ class ModelFitting(PluginTemplateMixin, DatasetSelectMixin, Label of the residuals to apply when calling :meth:`calculate_fit` if ``residuals_calculate`` is ``True``. * :meth:`calculate_fit` + * :meth:`fitted_models` """ dialog = Bool(False).tag(sync=True) template_file = __file__, "model_fitting.vue" @@ -779,6 +780,14 @@ def equation_components(self): """ return re.split(r'[+*/-]', self.equation.value.replace(' ', '')) + @property + def fitted_models(self): + """ + Dictionary of all previously fitted models. + """ + # TODO: store this internally instead of within the app + return self.app.fitted_models + def vue_add_model(self, event): self.create_model_component() diff --git a/jdaviz/configs/default/plugins/viewers.py b/jdaviz/configs/default/plugins/viewers.py index 41050d5be0..23b9e20f7f 100644 --- a/jdaviz/configs/default/plugins/viewers.py +++ b/jdaviz/configs/default/plugins/viewers.py @@ -92,7 +92,7 @@ def user_api(self): elif isinstance(self, TableViewer): expose += [] else: - expose += ['set_limits', 'reset_limits'] + expose += ['set_limits', 'reset_limits', 'set_tick_format'] return ViewerUserApi(self, expose=expose) @property @@ -180,6 +180,24 @@ def get_limits(self): """ return self.state.x_min, self.state.x_max, self.state.y_min, self.state.y_max + def set_tick_format(self, fmt, axis): + """ + Manually set the tick format of one of the axes. + + Parameters + ---------- + fmt : str + Format of tick marks. + For example, ``'0.1e'`` to set scientific notation or ``'0.2f'`` to turn it off. + axis : {x, y} + The viewer axis. + """ + if axis not in ('x', 'y'): + raise ValueError("axis must be 'x' or 'y'") + # Examples of values for fmt are '0.1e' or '0.2f' + axis = {'x': 0, 'y': 1}[axis] + self.figure.axes[axis].tick_format = fmt + @property def native_marks(self): """ diff --git a/jdaviz/configs/mosviz/helper.py b/jdaviz/configs/mosviz/helper.py index bd3cf23e1e..ea424dddc6 100644 --- a/jdaviz/configs/mosviz/helper.py +++ b/jdaviz/configs/mosviz/helper.py @@ -8,6 +8,7 @@ from astropy import units as u from astropy.coordinates import SkyCoord from astropy.table import QTable +from astropy.utils.decorators import deprecated from glue.core.data import Data from glue.core.exceptions import IncompatibleAttribute @@ -862,6 +863,7 @@ def to_csv(self, filename="MOS_data.csv", selected=False, overwrite=False): table_df.to_csv(filename, index_label="Table Index") @property + @deprecated(since="4.2", alternative="viewers['spectrum-viewer']") def specviz(self): """ A Specviz helper (:class:`~jdaviz.configs.specviz.helper.Specviz`) for the Jdaviz @@ -872,6 +874,7 @@ def specviz(self): return self._specviz @property + @deprecated(since="4.2", alternative="viewers['spectrum-2d-viewer']") def specviz2d(self): """ A Specviz2d helper (:class:`~jdaviz.configs.specviz2d.helper.Specviz2d`) for the Jdaviz diff --git a/jdaviz/configs/specviz/helper.py b/jdaviz/configs/specviz/helper.py index 066456198b..3df706f0fd 100644 --- a/jdaviz/configs/specviz/helper.py +++ b/jdaviz/configs/specviz/helper.py @@ -85,6 +85,7 @@ def load_data(self, data, data_label=None, format=None, show_in_viewer=True, timeout=timeout, load_as_list=load_as_list) + @deprecated(since="4.2", alternative="get_data") def get_spectra(self, data_label=None, spectral_subset=None, apply_slider_redshift="Warn"): """Returns the current data loaded into the main viewer @@ -168,6 +169,7 @@ def get_spectral_regions(self, use_display_units=False): """ return self.app.get_subsets(spectral_only=True, use_display_units=use_display_units) + @deprecated(since="4.2", alternative="viewers['spectrum-viewer'].set_limits") def x_limits(self, x_min=None, x_max=None): """Sets the limits of the x-axis @@ -190,6 +192,7 @@ def x_limits(self, x_min=None, x_max=None): ref_spec = self.get_spectra(ref_index, apply_slider_redshift=False) self._set_scale(scale, ref_spec.spectral_axis, x_min, x_max) + @deprecated(since="4.2", alternative="viewers['spectrum-viewer'].set_limits") def y_limits(self, y_min=None, y_max=None): """Sets the limits of the y-axis @@ -249,18 +252,21 @@ def _set_scale(self, scale, axis, min_val=None, max_val=None): scale.max = float(max_val) + @deprecated(since="4.2", alternative="viewers['spectrum-viewer'].reset_limits") def autoscale_x(self): """Sets the x-axis limits to the min/max of the reference data """ self.x_limits("auto", "auto") + @deprecated(since="4.2", alternative="viewers['spectrum-viewer'].reset_limits") def autoscale_y(self): """Sets the y-axis limits to the min/max of the reference data """ self.y_limits("auto", "auto") + @deprecated(since="4.2", alternative="viewers['spectrum-viewer'].set_limits") def flip_x(self): """Flips the current limits of the x-axis @@ -268,6 +274,7 @@ def flip_x(self): scale = self.app.get_viewer(self._default_spectrum_viewer_reference_name).scale_x self.x_limits(x_min=scale.max, x_max=scale.min) + @deprecated(since="4.2", alternative="viewers['spectrum-viewer'].set_limits") def flip_y(self): """Flips the current limits of the y-axis @@ -275,6 +282,7 @@ def flip_y(self): scale = self.app.get_viewer(self._default_spectrum_viewer_reference_name).scale_y self.y_limits(y_min=scale.max, y_max=scale.min) + @deprecated(since="4.2", alternative="viewers['spectrum-viewer'].set_tick_format") def set_spectrum_tick_format(self, fmt, axis=None): """ Manually set the tick format of one of the axes of the profile viewer. @@ -293,10 +301,7 @@ def set_spectrum_tick_format(self, fmt, axis=None): warnings.warn("Please use either 0 or 1 for the axis value") return - # Examples of values for fmt are '0.1e' or '0.2f' - self.app.get_viewer( - self._default_spectrum_viewer_reference_name - ).figure.axes[axis].tick_format = fmt + self.viewers[self._default_spectrum_viewer_reference_name].set_tick_format(fmt, axis=['x', 'y'][axis]) def get_data(self, data_label=None, spectral_subset=None, cls=None, use_display_units=False): diff --git a/jdaviz/configs/specviz2d/helper.py b/jdaviz/configs/specviz2d/helper.py index 87522333cb..cc38a0a711 100644 --- a/jdaviz/configs/specviz2d/helper.py +++ b/jdaviz/configs/specviz2d/helper.py @@ -1,3 +1,5 @@ +from astropy.utils.decorators import deprecated + from jdaviz.configs.specviz import Specviz from jdaviz.core.helpers import ConfigHelper from jdaviz.core.events import SnackbarMessage @@ -19,6 +21,7 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @property + @deprecated(since="4.2", alternative="viewers['spectrum-viewer']") def specviz(self): """ A Specviz helper (`~jdaviz.configs.specviz.helper.Specviz`) for the Jdaviz @@ -152,6 +155,7 @@ def load_data(self, spectrum_2d=None, spectrum_1d=None, spectrum_1d_label=None, timeout=timeout ) + @deprecated(since="4.2") def load_trace(self, trace, data_label, show_in_viewer=True): """ Load a trace object and load into the spectrum-2d-viewer diff --git a/jdaviz/core/helpers.py b/jdaviz/core/helpers.py index 44242d1a01..689e6c847d 100644 --- a/jdaviz/core/helpers.py +++ b/jdaviz/core/helpers.py @@ -166,6 +166,7 @@ def viewers(self): for viewer in self.app._viewer_store.values()} @property + @deprecated(since="4.2", alternative="plugins['Model Fitting'].fitted_models") def fitted_models(self): """ Returns the fitted models. @@ -175,9 +176,12 @@ def fitted_models(self): parameters : dict dict of `astropy.modeling.Model` objects, or None. """ + plg = self.plugins.get('Model Fitting', None) + if plg is None: + raise ValueError("Model Fitting plugin does not exist") + return plg.fitted_models - return self.app.fitted_models - + @deprecated(since="4.2", alternative="plugins['Model Fitting'].fitted_models") def get_models(self, models=None, model_label=None, x=None, y=None): """ Loop through all models and output models of the label model_label. @@ -239,6 +243,7 @@ def get_models(self, models=None, model_label=None, x=None, y=None): return selected_models + @deprecated(since="4.2") def get_model_parameters(self, models=None, model_label=None, x=None, y=None): """ Convert each parameter of model inside models into a coordinate that diff --git a/notebooks/SpecvizExample.ipynb b/notebooks/SpecvizExample.ipynb index 8965f49c42..4fef1b409b 100644 --- a/notebooks/SpecvizExample.ipynb +++ b/notebooks/SpecvizExample.ipynb @@ -124,25 +124,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Or, if you've defined multiple regions, you can retrieve all defined regions/subsets via:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "specviz.get_spectra()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Screenshot Saving" + "## Exporting Viewer Image" ] }, { @@ -151,7 +133,9 @@ "metadata": {}, "outputs": [], "source": [ - "specviz.app.get_viewer(\"spectrum-viewer\").figure.save_png()" + "exp = specviz.plugins['Export']\n", + "exp.viewer = 'spectrum-viewer'\n", + "exp.export()" ] }, { @@ -160,7 +144,7 @@ "source": [ "## Panning/Zooming in Specviz\n", "### Limit Methods\n", - "You can use the methods x_limits() and y_limits() to modify the field of view of Specviz. You can provide it a scalar (which assumes the units of the loaded spectra), an Astropy Quantity, or 'auto' to automatically scale." + "You can use the methods to modify the field of view of the default spectrum viewer. You can provide it a scalar (which assumes the units of the loaded spectra) or an Astropy Quantity." ] }, { @@ -171,9 +155,8 @@ }, "outputs": [], "source": [ - "specviz.x_limits()\n", - "specviz.x_limits(7*u.um,7.2*u.um)\n", - "specviz.y_limits('auto', 170.0)" + "specviz.viewers['spectrum-viewer'].get_limits()\n", + "specviz.viewers['spectrum-viewer'].set_limits(x_min=7*u.um, x_max=7.2*u.um, y_max=170.0)" ] }, { @@ -190,17 +173,16 @@ "metadata": {}, "outputs": [], "source": [ - "# axis 1 corresponds to the Y-axis and axis 0 to the X-axis\n", "# fmt can be '0.1e' to set scientific notation or '0.2f' to turn it off\n", - "specviz.set_spectrum_tick_format(fmt=\"0.2f\", axis=1)" + "specviz.viewers['spectrum-viewer'].set_tick_format(fmt=\"0.2f\", axis='x')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "### Autoscale Methods\n", - "You can also quickly return to the default zoom using autoscale_x() and autoscale_y()" + "### Reset Zoom\n", + "You can also quickly return to the default zoom" ] }, { @@ -209,8 +191,7 @@ "metadata": {}, "outputs": [], "source": [ - "specviz.autoscale_x()\n", - "specviz.autoscale_y()" + "specviz.viewers['spectrum-viewer'].reset_limits()" ] }, { @@ -227,7 +208,7 @@ "metadata": {}, "outputs": [], "source": [ - "specviz.fitted_models" + "specviz.plugins['Model Fitting'].fitted_models" ] }, { @@ -243,24 +224,7 @@ "metadata": {}, "outputs": [], "source": [ - "specviz.fitted_models['Model']" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Alternatively, the following getter can be used" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "models = specviz.get_models()\n", - "models" + "specviz.plugins['Model Fitting'].fitted_models['Model']" ] } ],