From 0cef09d5e470e925633b768d63fbfa04b0161a1c Mon Sep 17 00:00:00 2001 From: Andrew Thomas Date: Tue, 18 Jul 2023 08:16:50 -0400 Subject: [PATCH 1/2] Create tests/benchmark/ to demo use of pytest-benchmark plugin --- pyproject.toml | 1 + tests/benchmark/test_class_base_panel.py | 29 +++++++++++++++++++ tests/benchmark/test_holog.py | 37 ++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 tests/benchmark/test_class_base_panel.py create mode 100644 tests/benchmark/test_holog.py diff --git a/pyproject.toml b/pyproject.toml index ecabe8cd..4c215bad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,6 +23,7 @@ dependencies = [ 'prettytable', 'pytest', 'pytest-cov', +'pytest-benchmark[histogram]', 'pytest-html', 'scikit_image', 'scipy', diff --git a/tests/benchmark/test_class_base_panel.py b/tests/benchmark/test_class_base_panel.py new file mode 100644 index 00000000..061297cf --- /dev/null +++ b/tests/benchmark/test_class_base_panel.py @@ -0,0 +1,29 @@ +import pytest + +from astrohack._utils._panel_classes.base_panel import _gauss_elimination_numpy, BasePanel, \ + panel_models, imean, irigid, icorscp, icorlst, ixypara, icorrob, irotpara, ifulllst +from astrohack._utils._conversion import _convert_unit +import numpy as np + +def gauss_elimination_numpy(size=3): + """ + Tests the gaussian elimination routine by using an identity matrix + """ + for pos in range(size): + _gauss_elimination_numpy(np.identity(size), np.arange(size))[pos] == np.arange(size)[pos] + +def test_gauss_elimination_numpy(benchmark): + result = benchmark(gauss_elimination_numpy) + +def add_point(): + """ + Test the add point common function + """ + lepanel = BasePanel(panel_models[imean], np.zeros([4, 2]), np.zeros([4, 2]), 0.1, "TEST") + for i in range(30): + lepanel.add_sample([0, 0, 0, 0, 0]) + lepanel.add_margin([0, 0, 0, 0, 0]) + +def test_add_point(benchmark): + result = benchmark(add_point) + diff --git a/tests/benchmark/test_holog.py b/tests/benchmark/test_holog.py new file mode 100644 index 00000000..2e2529e0 --- /dev/null +++ b/tests/benchmark/test_holog.py @@ -0,0 +1,37 @@ +import os +from astrohack.gdown_utils import download +from astrohack import astrohack_local_client +from astrohack.extract_holog import extract_holog + +from astrohack.holog import holog + +def demo_setup(): + astrohack_local_client(cores=2, memory_limit="8GB") + download( + "J1924-2914.ms.calibrated.split.SPW3", folder=os.getcwd(), unpack=True + ) + extract_holog( + ms_name="J1924-2914.ms.calibrated.split.SPW3", + holog_name="alma.split.holog.zarr", + data_column="DATA", + parallel=True, + overwrite=True, + reuse_point_zarr=False, + ) + +def holog_demo(): + holog( + holog_name="alma.split.holog.zarr", + padding_factor=50, + grid_interpolation_mode="linear", + chan_average=True, + scan_average=True, + overwrite=True, + phase_fit=True, + apply_mask=True, + to_stokes=True, + parallel=True, + ) + +def test_holog_with_setup(benchmark): + benchmark.pedantic(holog_demo, setup=demo_setup, iterations=1, rounds=5) From 58a4c7ece8a0bb8c317af30639ede6c205c5dece Mon Sep 17 00:00:00 2001 From: Andrew Thomas Date: Tue, 18 Jul 2023 08:19:34 -0400 Subject: [PATCH 2/2] Include a pytest-benchmark example box/whisker plot --- demo.svg | 366 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 366 insertions(+) create mode 100644 demo.svg diff --git a/demo.svg b/demo.svg new file mode 100644 index 00000000..2a08ab3f --- /dev/null +++ b/demo.svg @@ -0,0 +1,366 @@ + +Speed in Microseconds (us)8000008000001600000160000024000002400000320000032000004000000400000048000004800000560000056000006400000640000072000007200000800000080000008800000880000096000009600000test_add_pointtest_gauss_elimination_numpytest_holog_with_setupMin: 11.7831 +Q1-1.5IQR: 11.7831 +Q1: 12.4560 +Median: 12.6369 +Q3: 13.1100 +Q3+1.5IQR: 14.0911 +Max: 115273.8130122.4102564102564323.6537883788206Min: 49.0560 +Q1-1.5IQR: 50.1771 +Q1: 51.7850 +Median: 52.2530 +Q3: 52.8570 +Q3+1.5IQR: 54.4651 +Max: 2413.7020340.99999999999994323.6525315587948Min: 7183199.8311 +Q1-1.5IQR: 7183199.8311 +Q1: 7667994.4708 +Median: 8448879.6082 +Q3: 9422011.2400 +Q3+1.5IQR: 9970512.6791 +Max: 9970512.6791559.589743589743551.9188373475414Speed in Microseconds (us)TrialDuration \ No newline at end of file