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 all 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
9 changes: 9 additions & 0 deletions .circleci/codecov_upload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash -e
curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --no-default-keyring --keyring trustedkeys.gpg --import
curl -Os https://uploader.codecov.io/latest/linux/codecov
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM.sig
gpgv codecov.SHA256SUM.sig codecov.SHA256SUM
shasum -a 256 -c codecov.SHA256SUM
chmod +x codecov
./codecov "$@"
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ jobs:
- run: *apt-install
- run: pip install --user -U tox tox-pypi-filter
- run: tox -v
# - run:
# name: Running codecov
# command: bash -e .circleci/codecov_upload.sh -f ".tmp/${TOXENV}/coverage.xml"
- run:
name: Running codecov
command: bash -e .circleci/codecov_upload.sh -f ".tmp/${TOXENV}/coverage.xml"
- store_artifacts:
path: .tmp/<< parameters.jobname >>/figure_test_images

Expand Down
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 @@ def _download_and_extract_sample_data(names, overwrite, path):
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)
results[i] = output_path

return results
Expand Down
18 changes: 17 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,17 @@ def test_tiled_dataset_from_components(dataset):
assert ds.files == fm
assert ds.meta["inventory"] is inventory
assert ds.meta["headers"] is headers


@figure_test
@pytest.mark.parametrize("share_zscale", [True, False], ids=["share_zscale", "indpendent_zscale"])
def test_tileddataset_plot(share_zscale):
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_zscale=share_zscale)
return plt.gcf()
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 @@ def shape(self):
"""
return self._data.shape

# TODO: def plot()
def plot(self, slice_index: int, share_zscale=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_zscale:
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"{self.inventory['instrumentName']} Dataset ({self.inventory['datasetId']}) at time {timestamp} (slice={slice_index})", y=0.95)
return fig

# 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_tileddataset_plot[share_zscale]": "08d480bf75e3461a3eb09b0fb78ac9a7e88ac6d80194f15a58ef531c7fc2bb53",
"dkist.dataset.tests.test_tiled_dataset.test_tileddataset_plot[indpendent_zscale]": "4d767a558ab1e0bd1bfeac5b8311a236e0ddcee484ae2b49cf32ffa8f0a4a93a"
}
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