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

Plotting helpers for TiledDataset #408

Merged
merged 31 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a461e02
Add broken plot method for TiledDataset
SolarDrew Jun 26, 2024
6ac0702
Need projection in plots
SolarDrew Jun 27, 2024
0cdacd2
Just plot the first image of each tile
SolarDrew Jun 27, 2024
be0d6fb
Clear x and y labels except on the middle edge tiles
SolarDrew Jun 27, 2024
fe1bc22
Make plot function plot at a user-supplied index
SolarDrew Jun 27, 2024
fb72210
Also pass plot kwargs through to ds.plot
SolarDrew Jun 27, 2024
744651e
More robust axis labelling
SolarDrew Jul 8, 2024
c081c01
Swap tile titles for suptitle with timestamp
SolarDrew Jul 8, 2024
e44f9c8
Optionally share colour scaling
SolarDrew Jul 8, 2024
2b5870b
Add figure test for `TiledDataset.plot()`
SolarDrew Jul 11, 2024
36d48c0
Update dkist/dataset/tiled_dataset.py
SolarDrew Jul 18, 2024
7b1880b
Add filter to tar file extraction
SolarDrew Jul 19, 2024
859da53
Use sample data for TiledDataset plot test and update hashes
SolarDrew Jul 19, 2024
41f4e19
Add changelog
SolarDrew Jul 19, 2024
bf1c76a
Try downloading data before tests instead of during
SolarDrew Jul 19, 2024
f4c11a8
Make sure we're not running figure tests outside the figure test env
SolarDrew Jul 22, 2024
cb260bc
Move sample data import into figure test
SolarDrew Jul 22, 2024
bb4156a
Yeah still need this
SolarDrew Jul 22, 2024
4cd8ed1
Explicit is better than implicit
SolarDrew Jul 22, 2024
e2d5348
Maybe this will help
SolarDrew Jul 22, 2024
feb12fd
Rebin tileddataset for plot test to reduce memory usage
SolarDrew Jul 24, 2024
a1cf462
Try more memory again and smaller plots
SolarDrew Jul 24, 2024
15bcfb2
Looks like we don't actually need this after all?
SolarDrew Jul 24, 2024
52f185a
Update dkist/dataset/tests/test_tiled_dataset.py
SolarDrew Jul 26, 2024
5a0a3b3
Update dkist/dataset/tests/test_tiled_dataset.py
SolarDrew Jul 26, 2024
d132559
Resinstate codecov upload in figure test
SolarDrew Jul 26, 2024
0a959ea
Update scale arg name to zscale
SolarDrew Jul 26, 2024
c48d712
Update figure hashes
SolarDrew Jul 26, 2024
959221a
Add codecov_upload script for circle CI
SolarDrew Jul 26, 2024
4748840
Merge branch 'main' into tiledds-improvements-plot
Cadair Aug 1, 2024
76b9a93
Update TiledDataset plot title
SolarDrew Aug 1, 2024
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
1 change: 1 addition & 0 deletions changelog/408.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `TiledDataset.plot()` quicklook method.
2 changes: 1 addition & 1 deletion dkist/data/_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
for i, tarpath in enumerate(results):
output_path = path / file_folder[Path(tarpath).name]
with tarfile.open(tarpath, "r:*") as tar:
tar.extractall(path=output_path, filter="data")
tar.extractall(path=output_path, filter=tarfile.fully_trusted_filter)

Check warning on line 60 in dkist/data/_sample.py

View check run for this annotation

Codecov / codecov/patch

dkist/data/_sample.py#L60

Added line #L60 was not covered by tests
results[i] = output_path

return results
Expand Down
19 changes: 18 additions & 1 deletion dkist/dataset/tests/test_tiled_dataset.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import copy

import matplotlib.pyplot as plt
import numpy as np
import pytest

from dkist import Dataset, TiledDataset
from dkist import Dataset, TiledDataset, load_dataset
from dkist.tests.helpers import figure_test


def test_tiled_dataset(simple_tiled_dataset, dataset):
Expand Down Expand Up @@ -59,3 +61,18 @@
assert ds.files == fm
assert ds.meta["inventory"] is inventory
assert ds.meta["headers"] is headers


# @pytest.mark.mpl_image_compare
SolarDrew marked this conversation as resolved.
Show resolved Hide resolved
@figure_test
@pytest.mark.parametrize("share_scale", [True, False])
def test_plot(share_scale):
SolarDrew marked this conversation as resolved.
Show resolved Hide resolved
from dkist.data.sample import VBI_AJQWW
ds = load_dataset(VBI_AJQWW)
newtiles = []
for tile in ds.flat:
newtiles.append(tile.rebin((1, 8, 8), operation=np.sum))
ds = TiledDataset(np.array(newtiles).reshape(ds.shape), inventory=ds.inventory)
fig = plt.figure(figsize=(600, 800))
ds.plot(0, share_scale=share_scale)
return plt.gcf()

Check warning on line 78 in dkist/dataset/tests/test_tiled_dataset.py

View check run for this annotation

Codecov / codecov/patch

dkist/dataset/tests/test_tiled_dataset.py#L70-L78

Added lines #L70 - L78 were not covered by tests
28 changes: 27 additions & 1 deletion dkist/dataset/tiled_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
from collections.abc import Collection

import matplotlib.pyplot as plt
import numpy as np

from astropy.table import vstack
Expand Down Expand Up @@ -124,5 +125,30 @@
"""
return self._data.shape

# TODO: def plot()
def plot(self, slice_index: int, share_scale=False, **kwargs):
vmin, vmax = np.inf, 0
fig = plt.figure()
for i, tile in enumerate(self.flat):
ax = fig.add_subplot(self.shape[0], self.shape[1], i+1, projection=tile[0].wcs)
tile[slice_index].plot(axes=ax, **kwargs)
if i == 0:
xlabel = ax.coords[0].get_axislabel() or ax.coords[0]._get_default_axislabel()
ylabel = ax.coords[1].get_axislabel() or ax.coords[1]._get_default_axislabel()
for coord in ax.coords:
if "b" in coord.axislabels.get_visible_axes():
fig.supxlabel(xlabel, y=0.05)
if "l" in coord.axislabels.get_visible_axes():
fig.supylabel(ylabel, x=0.05)
axmin, axmax = ax.get_images()[0].get_clim()
vmin = axmin if axmin < vmin else vmin
vmax = axmax if axmax > vmax else vmax
ax.set_ylabel(" ")
ax.set_xlabel(" ")
if share_scale:
for ax in fig.get_axes():
ax.get_images()[0].set_clim(vmin, vmax)
timestamp = self[0, 0].axis_world_coords("time")[-1].iso[slice_index]
fig.suptitle(f"TiledDataset {self.inventory['datasetId']} at time {timestamp} (slice={slice_index})", y=0.95)
SolarDrew marked this conversation as resolved.
Show resolved Hide resolved
return fig

Check warning on line 152 in dkist/dataset/tiled_dataset.py

View check run for this annotation

Codecov / codecov/patch

dkist/dataset/tiled_dataset.py#L129-L152

Added lines #L129 - L152 were not covered by tests

# TODO: def regrid()
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
"dkist.dataset.tests.test_plotting.test_2d_plot[aslice0]": "b31423d5ec45941849564f4ec7e276f2c52a0fa5038ce0b3c8d4af1b7f848a1d",
"dkist.dataset.tests.test_plotting.test_2d_plot[aslice1]": "cbb84fbae51d8238803f8f0d6820c575f024fe54b1656f1b181dc4ec645e9ff9",
"dkist.dataset.tests.test_plotting.test_2d_plot[aslice2]": "132c5615832daff457dacb4cb770498f1fbb4460a5b90b5d4d01d224c70eeb28",
"dkist.dataset.tests.test_plotting.test_2d_plot2": "409b5a10ad8ccf005331261505e63ce8febdc38eb8b5a34f8863e567e3cccb9c"
"dkist.dataset.tests.test_plotting.test_2d_plot2": "409b5a10ad8ccf005331261505e63ce8febdc38eb8b5a34f8863e567e3cccb9c",
"dkist.dataset.tests.test_tiled_dataset.test_plot[True]": "1d7b4a34ff6af242460934b8ff4b7d41adcd626eca6993b8ce51d8215043bcdb",
"dkist.dataset.tests.test_tiled_dataset.test_plot[False]": "5ac0baf18c66b87107fde794b0b6fae4cf1d78b01d31a5fbe84c23a00df4e19b"
}
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ addopts =
--doctest-rst
-p no:unraisableexception
-p no:threadexception
-m "not mpl_image_compare"
mpl-results-path = figure_test_images
mpl-deterministic = true
filterwarnings =
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ extras =
commands_pre =
oldestdeps: minimum_dependencies dkist --filename requirements-min.txt
oldestdeps: pip install -r requirements-min.txt cryptography<42 jsonschema==4.0.1
figure: python -c "from dkist.data.sample import download_all_sample_data; download_all_sample_data()"
pip freeze --all --no-input
commands =
figure: /bin/sh -c "mkdir -p ./figure_test_images; python -c 'import matplotlib as mpl; print(mpl.ft2font.__file__, mpl.ft2font.__freetype_version__, mpl.ft2font.__freetype_build_type__)' > ./figure_test_images/figure_version_info.txt"
Expand Down
Loading