Skip to content

Commit

Permalink
Export plugin (deprecates/replaces "Export Plot") (#2722)
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry authored Mar 8, 2024
1 parent b4cdd08 commit 0655d4a
Show file tree
Hide file tree
Showing 33 changed files with 791 additions and 572 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ New Features

- Live-preview of aperture selection in plugins. [#2664, #2684]

- "Export Plot" plugin is now replaced with the more general "Export" plugin. [#2722]

Cubeviz
^^^^^^^

Expand Down
4 changes: 2 additions & 2 deletions docs/cubeviz/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ have valid flux units. For 3D data, the current :ref:`slice` is used.

.. _cubeviz-export-plot:

Export Plot
===========
Export
======

This plugin allows exporting the plot in a given viewer to various image formats.

Expand Down
4 changes: 2 additions & 2 deletions docs/imviz/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ Due to browser limitations, Canvas Rotation is only available on Chromium-based

.. _imviz-export-plot:

Export Plot
===========
Export
======

This plugin allows exporting the plot in a given viewer to a PNG or SVG file.
4 changes: 2 additions & 2 deletions docs/mosviz/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ display just the primary header metadata.

.. _mosviz-export-plot:

Export Plot
===========
Export
======

This plugin allows exporting the plot in a given viewer to various image formats.

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/api_plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Plugins API
.. automodapi:: jdaviz.configs.default.plugins.data_tools.data_tools
:no-inheritance-diagram:

.. automodapi:: jdaviz.configs.default.plugins.export_plot.export_plot
.. automodapi:: jdaviz.configs.default.plugins.export.export
:no-inheritance-diagram:

.. automodapi:: jdaviz.configs.default.plugins.gaussian_smooth.gaussian_smooth
Expand Down
4 changes: 2 additions & 2 deletions docs/specviz/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ using the |icon-line-select| (line selector) tool in the spectrum viewer.

.. _specviz-export-plot:

Export Plot
===========
Export
======

This plugin allows a given viewer's plot to be exported to various image formats.
4 changes: 2 additions & 2 deletions docs/specviz2d/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ Line Analysis

.. _specviz2d-export-plot:

Export Plot
===========
Export
======

This plugin allows exporting the plot in a given viewer to various image formats.
3 changes: 3 additions & 0 deletions jdaviz/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def to_unit(self, data, cid, values, original_units, target_units):
'j-plugin-section-header': 'components/plugin_section_header.vue',
'j-number-uncertainty': 'components/number_uncertainty.vue',
'j-plugin-popout': 'components/plugin_popout.vue',
'j-multiselect-toggle': 'components/multiselect_toggle.vue',
'plugin-previews-temp-disabled': 'components/plugin_previews_temp_disabled.vue', # noqa
'plugin-table': 'components/plugin_table.vue',
'plugin-dataset-select': 'components/plugin_dataset_select.vue',
Expand All @@ -134,6 +135,8 @@ def to_unit(self, data, cid, values, original_units, target_units):
'plugin-layer-select': 'components/plugin_layer_select.vue',
'plugin-layer-select-tabs': 'components/plugin_layer_select_tabs.vue',
'plugin-editable-select': 'components/plugin_editable_select.vue',
'plugin-inline-select': 'components/plugin_inline_select.vue',
'plugin-inline-select-item': 'components/plugin_inline_select_item.vue',
'plugin-action-button': 'components/plugin_action_button.vue',
'plugin-add-results': 'components/plugin_add_results.vue',
'plugin-auto-label': 'components/plugin_auto_label.vue',
Expand Down
28 changes: 28 additions & 0 deletions jdaviz/components/multiselect_toggle.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<template>
<div>
<v-row>
<div style="width: calc(100% - 32px)">
</div>
<div style="width: 32px">
<j-tooltip :tooltipcontent="tooltip || 'Toggle multiselect'">
<v-btn
icon
style="opacity: 0.7"
@click="() => $emit('update:multiselect', !multiselect)"
>
<img :src="multiselect ? icon_checktoradial : icon_radialtocheck" width="24" class="invert-if-dark"/>
</v-btn>
</j-tooltip>
</div>
</v-row>
</div>
</template>

<script>
module.exports = {
props: ['multiselect', 'icon_checktoradial', 'icon_radialtocheck', 'tooltip']
};
</script>

<style scoped>
</style>
22 changes: 22 additions & 0 deletions jdaviz/components/plugin_inline_select.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<template>
<div>
<v-row v-for="item in items" class="row-min-bottom-padding">
<plugin-inline-select-item
:item="item"
:selected.sync="selected"
@update:selected="$emit('update:selected', $event)"
:multiselect="multiselect"
:single_select_allow_blank="single_select_allow_blank"
></plugin-inline-select-item>
</v-row>
</div>
</template>

<script>
module.exports = {
props: ['items', 'selected', 'multiselect', 'single_select_allow_blank']
};
</script>

<style scoped>
</style>
56 changes: 56 additions & 0 deletions jdaviz/components/plugin_inline_select_item.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<template>
<div>
<v-btn
icon
:color="isSelected() ? 'accent' : 'default'"
@click="clicked"
>
<v-icon v-if="multiselect">{{isSelected() ? "mdi-checkbox-marked" : "mdi-checkbox-blank-outline"}}</v-icon>
<v-icon v-else>{{isSelected() ? "mdi-radiobox-marked" : "mdi-radiobox-blank"}}</v-icon>
</v-btn>
<span>
<j-layer-viewer-icon v-if="item.icon" :icon="item.icon" :prevent_invert_if_dark="false"></j-layer-viewer-icon>
<v-icon v-else-if="item.color && item.type" left :color="item.color">
{{ item.type=='spectral' ? 'mdi-chart-bell-curve' : 'mdi-chart-scatter-plot' }}
</v-icon>
{{ item.label }}
</span>
</div>
</template>

<script>
module.exports = {
props: ['item', 'selected', 'multiselect', 'single_select_allow_blank'],
methods: {
isSelected() {
if (this.multiselect) {
return this.selected.includes(this.item.label)
} else {
return this.selected === this.item.label
}
},
clicked() {
if (this.multiselect) {
if (this.isSelected()) {
this.selected.pop(this.item.label)
} else {
this.selected.push(this.item.label)
}
} else {
if (this.isSelected()) {
// TODO: setting to allow vs forbid blank
if (this.single_select_allow_blank) {
this.selected = ''
}
} else {
this.selected = this.item.label
}
}
this.$emit('update:selected', this.selected)
}
},
};
</script>

<style scoped>
</style>
2 changes: 1 addition & 1 deletion jdaviz/configs/cubeviz/cubeviz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ tray:
- cubeviz-moment-maps
- cubeviz-spectral-extraction
- imviz-aper-phot-simple
- g-export-plot
- export
viewer_area:
- container: col
children:
Expand Down
4 changes: 2 additions & 2 deletions jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ def test_remote_server_disable_save_serverside():

cubeviz_app = Application(config)
cubeviz_helper = Cubeviz(cubeviz_app)
ep = cubeviz_helper.plugins['Export Plot']
assert ep._obj.movie_enabled is False
exp = cubeviz_helper.plugins['Export']
assert 'mp4' not in exp.viewer_format.choices

mm = cubeviz_helper.plugins['Moment Maps']
assert mm._obj.export_enabled is False
Expand Down
83 changes: 35 additions & 48 deletions jdaviz/configs/cubeviz/plugins/tests/test_export_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from jdaviz.configs.default.plugins.export_plot.export_plot import HAS_OPENCV
from jdaviz.configs.default.plugins.export.export import HAS_OPENCV


# TODO: Remove skip when https://github.com/bqplot/bqplot/pull/1397/files#r726500097 is resolved.
Expand All @@ -13,12 +13,12 @@ def test_export_movie(cubeviz_helper, spectrum1d_cube, tmp_path):
os.chdir(tmp_path)
try:
cubeviz_helper.load_data(spectrum1d_cube, data_label="test")
plugin = cubeviz_helper.plugins["Export Plot"]
assert plugin.i_start == 0
assert plugin.i_end == 1
assert plugin.movie_filename == "mymovie.mp4"
plugin = cubeviz_helper.plugins["Export"]
assert plugin._obj.i_start == 0
assert plugin._obj.i_end == 1

plugin._obj.vue_save_movie("mp4")
plugin.viewer_format = 'mp4'
plugin._obj.export()
assert os.path.isfile("mymovie.mp4"), tmp_path
finally:
os.chdir(orig_path)
Expand All @@ -27,77 +27,64 @@ def test_export_movie(cubeviz_helper, spectrum1d_cube, tmp_path):
@pytest.mark.skipif(HAS_OPENCV, reason="opencv-python is installed")
def test_no_opencv(cubeviz_helper, spectrum1d_cube):
cubeviz_helper.load_data(spectrum1d_cube, data_label="test")
plugin = cubeviz_helper.plugins["Export Plot"]
assert plugin._obj.movie_msg != ""
plugin = cubeviz_helper.plugins["Export"]
assert 'mp4' in plugin.viewer_format.choices
assert not plugin._obj.movie_enabled
plugin.viewer_format = 'mp4'
with pytest.raises(ImportError, match="Please install opencv-python"):
plugin.save_movie()
plugin.export()


@pytest.mark.skipif(not HAS_OPENCV, reason="opencv-python is not installed")
def test_export_movie_not_cubeviz(imviz_helper):
plugin = imviz_helper.plugins["Export Plot"]

with pytest.raises(NotImplementedError, match="save_movie is not available for config"):
plugin._obj.save_movie()

# Also not available via plugin public API.
with pytest.raises(AttributeError):
plugin.save_movie()
plugin = imviz_helper.plugins["Export"]
assert 'mp4' not in plugin.viewer_format.choices


@pytest.mark.skipif(not HAS_OPENCV, reason="opencv-python is not installed")
def test_export_movie_cubeviz_exceptions(cubeviz_helper, spectrum1d_cube):
cubeviz_helper.load_data(spectrum1d_cube, data_label="test")
cubeviz_helper.default_viewer._obj.shape = (100, 100)
cubeviz_helper.app.get_viewer("uncert-viewer").shape = (100, 100)
plugin = cubeviz_helper.plugins["Export Plot"]
assert plugin._obj.movie_msg == ""
assert plugin.i_start == 0
assert plugin.i_end == 1
assert plugin.movie_filename == "mymovie.mp4"

with pytest.raises(NotImplementedError, match="filetype"):
plugin.save_movie(filetype="gif")

with pytest.raises(NotImplementedError, match="filetype"):
plugin.save_movie(filename="mymovie.gif", filetype=None)
plugin = cubeviz_helper.plugins["Export"]
assert plugin._obj.i_start == 0
assert plugin._obj.i_end == 1

plugin.viewer_format = 'mp4'
plugin._obj.i_end = 0
with pytest.raises(ValueError, match="No frames to write"):
plugin.save_movie(i_start=0, i_end=0)
plugin.export()

plugin._obj.i_end = 1
plugin._obj.movie_fps = 0
with pytest.raises(ValueError, match="Invalid frame rate"):
plugin.save_movie(fps=0)
plugin.export()

plugin.movie_filename = "fake_path/mymovie.mp4"
plugin._obj.movie_fps = 5
plugin.filename = "fake_path/mymovie.mp4"
with pytest.raises(ValueError, match="Invalid path"):
plugin.save_movie()

plugin.movie_filename = "mymovie.mp4"
plugin.viewer = 'spectrum-viewer'
with pytest.raises(TypeError, match=r"Movie for.*is not supported"):
plugin.save_movie()
plugin.export()

plugin.movie_filename = ""
plugin.filename = ""
plugin.viewer = 'uncert-viewer'
with pytest.raises(ValueError, match="Invalid filename"):
plugin.save_movie()
plugin.export()


@pytest.mark.skipif(not HAS_OPENCV, reason="opencv-python is not installed")
def test_export_movie_cubeviz_empty(cubeviz_helper):
plugin = cubeviz_helper.plugins["Export Plot"]
assert plugin.i_start == 0
assert plugin.i_end == 0
plugin = cubeviz_helper.plugins["Export"]
assert plugin._obj.i_start == 0
assert plugin._obj.i_end == 0

plugin.viewer_format = 'mp4'
with pytest.raises(ValueError, match="Selected viewer has no display shape"):
plugin.save_movie(i_start=0, i_end=1)
plugin.export()


def test_export_plot_exceptions(cubeviz_helper):
plugin = cubeviz_helper.plugins["Export Plot"]

with pytest.raises(NotImplementedError, match="filetype.*not supported"):
plugin.save_figure(filetype="gif")
plugin = cubeviz_helper.plugins["Export"]

plugin.filename = "/fake/path/image.png"
with pytest.raises(ValueError, match="Invalid path"):
plugin.save_figure(filename="/fake/path/image.png")
plugin.export()
2 changes: 1 addition & 1 deletion jdaviz/configs/default/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ toolbar:
tray:
- g-subset-plugin
- g-gaussian-smooth
- g-export-plot
- export
2 changes: 1 addition & 1 deletion jdaviz/configs/default/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
from .collapse.collapse import * # noqa
from .line_lists.line_lists import * # noqa
from .metadata_viewer.metadata_viewer import * # noqa
from .export_plot.export_plot import * # noqa
from .export.export import * # noqa
from .plot_options.plot_options import * # noqa
from .markers.markers import * # noqa
1 change: 1 addition & 0 deletions jdaviz/configs/default/plugins/export/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .export import * # noqa
Loading

0 comments on commit 0655d4a

Please sign in to comment.