Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imviz astrowidgets API: save #759

Merged
merged 2 commits into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions jdaviz/configs/imviz/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ def load_data(self, data, parser_reference=None, **kwargs):
self.app.load_data(
data, parser_reference=parser_reference, **kwargs)

def save(self, filename):
"""Save out the current image view to given PNG filename."""
if not filename.lower().endswith('.png'):
filename = filename + '.png'
viewer = self.app.get_viewer("viewer-1")
viewer.figure.save_png(filename=filename)

def center_on(self, point):
"""Centers the view on a particular point.

Expand Down
14 changes: 14 additions & 0 deletions jdaviz/configs/imviz/tests/test_astrowidgets_api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

import numpy as np
import pytest
from astropy import units as u
Expand All @@ -7,6 +9,18 @@
from jdaviz.configs.imviz.tests.utils import BaseImviz_WCS_NoWCS


# TODO: Remove skip when https://github.com/bqplot/bqplot/issues/1393 is resolved.
@pytest.mark.skip(reason="Cannot test due to file dialog popup")
class TestSave(BaseImviz_WCS_NoWCS):

def test_save(self, tmpdir):
filename = os.path.join(tmpdir.strpath, 'myimage')
self.imviz.save(filename)

# This only tests that something saved, not the content.
assert os.path.isfile(os.path.join(tmpdir.strpath, 'myimage.png'))


class TestCenterOffset(BaseImviz_WCS_NoWCS):

def test_center_offset_pixel(self):
Expand Down
20 changes: 19 additions & 1 deletion notebooks/ImvizExample.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,28 @@
"imviz.reset_markers()"
]
},
{
"cell_type": "markdown",
"id": "70698430-2683-4bb2-b273-e2ae436e641d",
"metadata": {},
"source": [
"You can save the active display as PNG file."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d6af9b27-e5b6-45b6-ac85-5d008faa88b1",
"metadata": {},
"outputs": [],
"source": [
"imviz.save('myimage.png')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ea66062b-a546-4d77-8119-b3f59d3c2104",
"id": "8ba68e57-3922-4999-9d4d-d7898578caa6",
"metadata": {},
"outputs": [],
"source": []
Expand Down