Skip to content

Commit

Permalink
Benchmarking tweaks (DKISTDC#383)
Browse files Browse the repository at this point in the history
* Don't need to run the plots five times

* Add a non-plotting benchmark

* Changelog

* I suspect codspeed may only need the benchmark marker

The fixture may be superfluous

* Nope apparently that just makes it run but not actually measure

* Let's try just not saving it and hope it still gives us useful info

* Bring back savefig

* Add new visp ds without headers and corresponding pytest fixture

* Use new ds for plot benchmark

* Rework pixel_to_world benchmark

* Enforce running plot benchmark exactly once

* Use benchmark.pedantic correctly, I hope

* Just use a more manageable plot and hope that's useful
  • Loading branch information
SolarDrew authored May 17, 2024
1 parent 448787d commit 6f7ce1e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog/383.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Run plotting benchmarks fewer times for more manageable CI, and add a benchmark for generate_celestial_transform.
9 changes: 9 additions & 0 deletions dkist/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,12 @@ def large_visp_dataset(large_visp_dataset_file):
# dataset_from_fits(vispdir, "test_visp.asdf")

return load_dataset(large_visp_dataset_file)


@pytest.fixture(scope="session")
def visp_dataset_no_headers(tmp_path_factory):
vispdir = tmp_path_factory.mktemp("data")
with gzip.open(Path(rootdir) / "visp_no_headers.asdf.gz", mode="rb") as gfo:
with open(vispdir / "test_visp_no_headers.asdf", mode="wb") as afo:
afo.write(gfo.read())
return load_dataset(vispdir / "test_visp_no_headers.asdf")
Binary file added dkist/data/test/visp_no_headers.asdf.gz
Binary file not shown.
25 changes: 18 additions & 7 deletions dkist/tests/test_benchmarks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import matplotlib.pyplot as plt
import numpy as np
import pytest

from dkist import load_dataset
Expand All @@ -9,18 +10,28 @@ def test_load_asdf(benchmark, large_visp_dataset_file):
benchmark(load_dataset, large_visp_dataset_file)


@pytest.mark.benchmark
def test_pixel_to_world(benchmark, visp_dataset_no_headers, large_visp_dataset):
ds = visp_dataset_no_headers
# pxcoords2 = []
# for size in ds2.wcs.pixel_shape:
# pxcoords2.append(np.arange(size))

pxcoords = np.mgrid[:ds.wcs.pixel_shape[0]:50,
:ds.wcs.pixel_shape[1]:50,
:ds.wcs.pixel_shape[2]:50,
:ds.wcs.pixel_shape[3]:5]

benchmark(ds.wcs.pixel_to_world_values, *pxcoords)


@pytest.mark.benchmark
@pytest.mark.parametrize("axes", [
["y", "x", None, None],
["y", None, "x", None],
["y", None, None, "x"],
[None, "y", "x", None],
[None, "y", None, "x"],
[None, None, "y", "x"],
])
def test_plot_dataset(benchmark, axes, large_visp_dataset):
def test_plot_dataset(benchmark, axes, visp_dataset_no_headers):
@benchmark
def plot_and_save_fig(ds=large_visp_dataset, axes=axes):
def plot_and_save_fig(ds=visp_dataset_no_headers, axes=axes):
ds.plot(plot_axes=axes)
plt.savefig("tmpplot")
plt.close()

0 comments on commit 6f7ce1e

Please sign in to comment.