diff --git a/.circleci/codecov_upload.sh b/.circleci/codecov_upload.sh new file mode 100644 index 00000000..f062084e --- /dev/null +++ b/.circleci/codecov_upload.sh @@ -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 "$@" diff --git a/.circleci/config.yml b/.circleci/config.yml index 1c109696..3d543218 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 diff --git a/changelog/408.feature.rst b/changelog/408.feature.rst new file mode 100644 index 00000000..639fff80 --- /dev/null +++ b/changelog/408.feature.rst @@ -0,0 +1 @@ +Add `TiledDataset.plot()` quicklook method. diff --git a/dkist/data/_sample.py b/dkist/data/_sample.py index 7fce0d02..82e98401 100644 --- a/dkist/data/_sample.py +++ b/dkist/data/_sample.py @@ -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 diff --git a/dkist/dataset/tests/test_tiled_dataset.py b/dkist/dataset/tests/test_tiled_dataset.py index 4b6b4364..e6ed68b6 100644 --- a/dkist/dataset/tests/test_tiled_dataset.py +++ b/dkist/dataset/tests/test_tiled_dataset.py @@ -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): @@ -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() diff --git a/dkist/dataset/tiled_dataset.py b/dkist/dataset/tiled_dataset.py index eec8b9de..c4aad0e5 100644 --- a/dkist/dataset/tiled_dataset.py +++ b/dkist/dataset/tiled_dataset.py @@ -7,6 +7,7 @@ """ from collections.abc import Collection +import matplotlib.pyplot as plt import numpy as np from astropy.table import vstack @@ -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() diff --git a/dkist/tests/figure_hashes_mpl_391_ft_261_astropy_611_animators_111_ndcube_222.json b/dkist/tests/figure_hashes_mpl_391_ft_261_astropy_611_animators_111_ndcube_222.json index 01ef2660..3372396f 100644 --- a/dkist/tests/figure_hashes_mpl_391_ft_261_astropy_611_animators_111_ndcube_222.json +++ b/dkist/tests/figure_hashes_mpl_391_ft_261_astropy_611_animators_111_ndcube_222.json @@ -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" } \ No newline at end of file diff --git a/pytest.ini b/pytest.ini index 36c18926..ed8a2423 100644 --- a/pytest.ini +++ b/pytest.ini @@ -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 = diff --git a/tox.ini b/tox.ini index 39133a81..4e2ebe5f 100644 --- a/tox.ini +++ b/tox.ini @@ -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"