Skip to content

Commit

Permalink
Merge branch 'main' of github.com:DKISTDC/dkist into benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
SolarDrew committed Aug 8, 2024
2 parents d3284ab + b56cc10 commit 3f5aa08
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 8 deletions.
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
2 changes: 1 addition & 1 deletion .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
python-version: '3.12'
- run: python -m pip install .[tests] pytest-codspeed 'numpy<2'
- name: Run benchmarks
uses: CodspeedHQ/action@v2
uses: CodspeedHQ/action@v3
with:
token: ${{ secrets.CODSPEED_TOKEN }}
run: "pytest -vvv -r fEs --pyargs dkist --codspeed"
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 @@ -59,6 +59,7 @@ commands_pre =
oldestdeps: minimum_dependencies dkist --filename requirements-min.txt
oldestdeps: pip install -r requirements-min.txt cryptography<42 jsonschema==4.0.1
benchmarks: python -c "from dkist.data.sample import download_all_sample_data; download_all_sample_data()"
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

0 comments on commit 3f5aa08

Please sign in to comment.