From 914ba634863989da14daa9ea7f45e940398facc6 Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Fri, 17 May 2024 15:08:01 +0100 Subject: [PATCH 01/23] Try slower plot again to see how it does now with performance improvements from #370 --- dkist/tests/test_benchmarks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dkist/tests/test_benchmarks.py b/dkist/tests/test_benchmarks.py index 25f0c6ed..b448e3df 100644 --- a/dkist/tests/test_benchmarks.py +++ b/dkist/tests/test_benchmarks.py @@ -27,7 +27,7 @@ def test_pixel_to_world(benchmark, visp_dataset_no_headers, large_visp_dataset): @pytest.mark.benchmark @pytest.mark.parametrize("axes", [ - ["y", None, None, "x"], + [None, "y", "x", None], ]) def test_plot_dataset(benchmark, axes, visp_dataset_no_headers): @benchmark From 68db21474b0673dcb89bbcb37266bab8cb22715c Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Mon, 20 May 2024 14:02:17 +0100 Subject: [PATCH 02/23] Don't need both fixtures in this test any more --- dkist/tests/test_benchmarks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dkist/tests/test_benchmarks.py b/dkist/tests/test_benchmarks.py index b448e3df..496dbc33 100644 --- a/dkist/tests/test_benchmarks.py +++ b/dkist/tests/test_benchmarks.py @@ -11,7 +11,7 @@ def test_load_asdf(benchmark, large_visp_dataset_file): @pytest.mark.benchmark -def test_pixel_to_world(benchmark, visp_dataset_no_headers, large_visp_dataset): +def test_pixel_to_world(benchmark, visp_dataset_no_headers): ds = visp_dataset_no_headers # pxcoords2 = [] # for size in ds2.wcs.pixel_shape: From 98aee6b0ece2d1af0decf2c555bbb9cdc402dfc8 Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Mon, 20 May 2024 14:03:18 +0100 Subject: [PATCH 03/23] Don't need this old stuff either --- dkist/tests/test_benchmarks.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/dkist/tests/test_benchmarks.py b/dkist/tests/test_benchmarks.py index 496dbc33..d82fed41 100644 --- a/dkist/tests/test_benchmarks.py +++ b/dkist/tests/test_benchmarks.py @@ -13,9 +13,6 @@ def test_load_asdf(benchmark, large_visp_dataset_file): @pytest.mark.benchmark def test_pixel_to_world(benchmark, visp_dataset_no_headers): 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, From 9bdefbecc13619cee26053f4d86cf02c0a86e46a Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Mon, 20 May 2024 14:04:12 +0100 Subject: [PATCH 04/23] Use more points for pixel_to_world benchmark --- dkist/tests/test_benchmarks.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dkist/tests/test_benchmarks.py b/dkist/tests/test_benchmarks.py index d82fed41..c604662c 100644 --- a/dkist/tests/test_benchmarks.py +++ b/dkist/tests/test_benchmarks.py @@ -14,9 +14,9 @@ def test_load_asdf(benchmark, large_visp_dataset_file): def test_pixel_to_world(benchmark, visp_dataset_no_headers): ds = visp_dataset_no_headers - pxcoords = np.mgrid[:ds.wcs.pixel_shape[0]:50, - :ds.wcs.pixel_shape[1]:50, - :ds.wcs.pixel_shape[2]:50, + pxcoords = np.mgrid[:ds.wcs.pixel_shape[0]:5, + :ds.wcs.pixel_shape[1]:5, + :ds.wcs.pixel_shape[2]:5, :ds.wcs.pixel_shape[3]:5] benchmark(ds.wcs.pixel_to_world_values, *pxcoords) From 86671cbd4a40944f395e8ccef8689110b94f3c2b Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Thu, 6 Jun 2024 11:56:02 +0100 Subject: [PATCH 05/23] Add some more benchmarks --- dkist/tests/test_benchmarks.py | 64 ++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/dkist/tests/test_benchmarks.py b/dkist/tests/test_benchmarks.py index c604662c..88705231 100644 --- a/dkist/tests/test_benchmarks.py +++ b/dkist/tests/test_benchmarks.py @@ -1,8 +1,14 @@ import matplotlib.pyplot as plt import numpy as np import pytest +from numpy.random import default_rng + +import astropy.units as u +from astropy.modeling.models import Tabular1D from dkist import load_dataset +from dkist.wcs.models import (Ravel, generate_celestial_transform, + update_celestial_transform_parameters) @pytest.mark.benchmark @@ -32,3 +38,61 @@ def plot_and_save_fig(ds=visp_dataset_no_headers, axes=axes): ds.plot(plot_axes=axes) plt.savefig("tmpplot") plt.close() + + +@pytest.mark.benchmark +def test_generate_celestial(benchmark): + benchmark(generate_celestial_transform, + crpix=[0, 0] * u.pix, + crval=[0, 0] * u.arcsec, + cdelt=[1, 1] * u.arcsec/u.pix, + pc=np.identity(2) * u.pix, + ) + + +@pytest.mark.benchmark +def test_update_celestial(benchmark): + trsfm = generate_celestial_transform( + crpix=[0, 0] * u.pix, + crval=[0, 0] * u.arcsec, + cdelt=[1, 1] * u.arcsec/u.pix, + pc=np.identity(2) * u.pix) + + benchmark(update_celestial_transform_parameters, + trsfm, + [1, 1] * u.pix, + [0.5, 0.5] * u.arcsec/u.pix, + np.identity(2) * u.pix, + [1, 1] * u.arcsec, + 180 * u.deg, + ) + + +@pytest.mark.benchmark +def test_raveled_tab1d_model(benchmark): + ndim = 3 + rng = default_rng() + array_shape = rng.integers(1, 21, ndim) + array_bounds = array_shape - 1 + ravel = Ravel(array_shape) + nelem = np.prod(array_shape) + units = u.pix + values = np.arange(nelem) * units + lut_values = values + tabular = Tabular1D( + values, + lut_values, + bounds_error=False, + fill_value=np.nan, + method="linear", + ) + raveled_tab = ravel | tabular + # adding the new axis onto array_bounds makes broadcasting work below + array_bounds = array_bounds[:, np.newaxis] + # use 5 as an arbitrary number of inputs + random_number_shape = len(array_shape), 5 + random_numbers = rng.random(random_number_shape) + raw_inputs = random_numbers * array_bounds + inputs = tuple(raw_inputs * units) + + benchmark(raveled_tab, *inputs) From adee6da07caed98f8e31ad138aa81f1d13b7a5fd Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Thu, 6 Jun 2024 11:57:05 +0100 Subject: [PATCH 06/23] Need units on parameters for updating vct some of the time Not sure how this snuck past the tests in the first place --- dkist/wcs/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dkist/wcs/models.py b/dkist/wcs/models.py index bcdb115c..ab3a5e7c 100755 --- a/dkist/wcs/models.py +++ b/dkist/wcs/models.py @@ -130,7 +130,7 @@ def update_celestial_transform_parameters( -crpix[0], -crpix[1], pc, - transform[2].translation.value, + transform[2].translation.value * pc.unit if hasattr(pc, "unit") else transform[2].translation.value, cdelt[0], cdelt[1], crval[0], From 38b341b4900fd873fa4eba7d98c23ead3c634170 Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Thu, 6 Jun 2024 13:29:01 +0100 Subject: [PATCH 07/23] Benchmarks are taking too long again --- dkist/tests/test_benchmarks.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dkist/tests/test_benchmarks.py b/dkist/tests/test_benchmarks.py index 88705231..88f733c9 100644 --- a/dkist/tests/test_benchmarks.py +++ b/dkist/tests/test_benchmarks.py @@ -20,9 +20,9 @@ def test_load_asdf(benchmark, large_visp_dataset_file): def test_pixel_to_world(benchmark, visp_dataset_no_headers): ds = visp_dataset_no_headers - pxcoords = np.mgrid[:ds.wcs.pixel_shape[0]:5, - :ds.wcs.pixel_shape[1]:5, - :ds.wcs.pixel_shape[2]:5, + 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) From 78eb098fc53f40033273adfe91a32baeb24dc9f1 Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Thu, 6 Jun 2024 14:44:28 +0100 Subject: [PATCH 08/23] Nope too slow --- dkist/tests/test_benchmarks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dkist/tests/test_benchmarks.py b/dkist/tests/test_benchmarks.py index 88f733c9..16072eaf 100644 --- a/dkist/tests/test_benchmarks.py +++ b/dkist/tests/test_benchmarks.py @@ -30,7 +30,7 @@ def test_pixel_to_world(benchmark, visp_dataset_no_headers): @pytest.mark.benchmark @pytest.mark.parametrize("axes", [ - [None, "y", "x", None], + ["y", None, None, "x"], ]) def test_plot_dataset(benchmark, axes, visp_dataset_no_headers): @benchmark From 19d80e5eb338f7007c46a580874de0a16a54ce4f Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Thu, 6 Jun 2024 15:36:59 +0100 Subject: [PATCH 09/23] Benchmark dataset slicing --- dkist/tests/test_benchmarks.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dkist/tests/test_benchmarks.py b/dkist/tests/test_benchmarks.py index 16072eaf..11dfbfbe 100644 --- a/dkist/tests/test_benchmarks.py +++ b/dkist/tests/test_benchmarks.py @@ -96,3 +96,10 @@ def test_raveled_tab1d_model(benchmark): inputs = tuple(raw_inputs * units) benchmark(raveled_tab, *inputs) + + +@pytest.mark.benchmark +def test_slice_dataset(benchmark, large_visp_dataset): + @benchmark + def slice_dataset(dataset=large_visp_dataset, idx = np.s_[:2, 10:15, 0]): + sliced = dataset[idx] From 7b252d3f8560c5e20260e038d550618dd2aee3ef Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Fri, 7 Jun 2024 10:41:20 +0100 Subject: [PATCH 10/23] Add changelog --- changelog/387.trivial.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/387.trivial.rst diff --git a/changelog/387.trivial.rst b/changelog/387.trivial.rst new file mode 100644 index 00000000..70c2b2cf --- /dev/null +++ b/changelog/387.trivial.rst @@ -0,0 +1 @@ +Add some more benchmarks to track performance of more parts of the user tools. From 0ec14e043b3570a7c96c9c8215d8d091fa45eb94 Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Fri, 17 May 2024 15:08:01 +0100 Subject: [PATCH 11/23] Try slower plot again to see how it does now with performance improvements from #370 --- dkist/tests/test_benchmarks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dkist/tests/test_benchmarks.py b/dkist/tests/test_benchmarks.py index 25f0c6ed..b448e3df 100644 --- a/dkist/tests/test_benchmarks.py +++ b/dkist/tests/test_benchmarks.py @@ -27,7 +27,7 @@ def test_pixel_to_world(benchmark, visp_dataset_no_headers, large_visp_dataset): @pytest.mark.benchmark @pytest.mark.parametrize("axes", [ - ["y", None, None, "x"], + [None, "y", "x", None], ]) def test_plot_dataset(benchmark, axes, visp_dataset_no_headers): @benchmark From 6b6472923f170910bc11b25819b97b83d70bf92a Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Mon, 20 May 2024 14:02:17 +0100 Subject: [PATCH 12/23] Don't need both fixtures in this test any more --- dkist/tests/test_benchmarks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dkist/tests/test_benchmarks.py b/dkist/tests/test_benchmarks.py index b448e3df..496dbc33 100644 --- a/dkist/tests/test_benchmarks.py +++ b/dkist/tests/test_benchmarks.py @@ -11,7 +11,7 @@ def test_load_asdf(benchmark, large_visp_dataset_file): @pytest.mark.benchmark -def test_pixel_to_world(benchmark, visp_dataset_no_headers, large_visp_dataset): +def test_pixel_to_world(benchmark, visp_dataset_no_headers): ds = visp_dataset_no_headers # pxcoords2 = [] # for size in ds2.wcs.pixel_shape: From f0247d7e2a1e686c5494a6e289fe09704e2ed61f Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Mon, 20 May 2024 14:03:18 +0100 Subject: [PATCH 13/23] Don't need this old stuff either --- dkist/tests/test_benchmarks.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/dkist/tests/test_benchmarks.py b/dkist/tests/test_benchmarks.py index 496dbc33..d82fed41 100644 --- a/dkist/tests/test_benchmarks.py +++ b/dkist/tests/test_benchmarks.py @@ -13,9 +13,6 @@ def test_load_asdf(benchmark, large_visp_dataset_file): @pytest.mark.benchmark def test_pixel_to_world(benchmark, visp_dataset_no_headers): 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, From f0c6f9e6cff384c8e58ff9f3a8eced115d7f5461 Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Mon, 20 May 2024 14:04:12 +0100 Subject: [PATCH 14/23] Use more points for pixel_to_world benchmark --- dkist/tests/test_benchmarks.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dkist/tests/test_benchmarks.py b/dkist/tests/test_benchmarks.py index d82fed41..c604662c 100644 --- a/dkist/tests/test_benchmarks.py +++ b/dkist/tests/test_benchmarks.py @@ -14,9 +14,9 @@ def test_load_asdf(benchmark, large_visp_dataset_file): def test_pixel_to_world(benchmark, visp_dataset_no_headers): ds = visp_dataset_no_headers - pxcoords = np.mgrid[:ds.wcs.pixel_shape[0]:50, - :ds.wcs.pixel_shape[1]:50, - :ds.wcs.pixel_shape[2]:50, + pxcoords = np.mgrid[:ds.wcs.pixel_shape[0]:5, + :ds.wcs.pixel_shape[1]:5, + :ds.wcs.pixel_shape[2]:5, :ds.wcs.pixel_shape[3]:5] benchmark(ds.wcs.pixel_to_world_values, *pxcoords) From b6bf0e9d5545d48890574ac08113d4ab6b73397d Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Thu, 6 Jun 2024 11:56:02 +0100 Subject: [PATCH 15/23] Add some more benchmarks --- dkist/tests/test_benchmarks.py | 64 ++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/dkist/tests/test_benchmarks.py b/dkist/tests/test_benchmarks.py index c604662c..88705231 100644 --- a/dkist/tests/test_benchmarks.py +++ b/dkist/tests/test_benchmarks.py @@ -1,8 +1,14 @@ import matplotlib.pyplot as plt import numpy as np import pytest +from numpy.random import default_rng + +import astropy.units as u +from astropy.modeling.models import Tabular1D from dkist import load_dataset +from dkist.wcs.models import (Ravel, generate_celestial_transform, + update_celestial_transform_parameters) @pytest.mark.benchmark @@ -32,3 +38,61 @@ def plot_and_save_fig(ds=visp_dataset_no_headers, axes=axes): ds.plot(plot_axes=axes) plt.savefig("tmpplot") plt.close() + + +@pytest.mark.benchmark +def test_generate_celestial(benchmark): + benchmark(generate_celestial_transform, + crpix=[0, 0] * u.pix, + crval=[0, 0] * u.arcsec, + cdelt=[1, 1] * u.arcsec/u.pix, + pc=np.identity(2) * u.pix, + ) + + +@pytest.mark.benchmark +def test_update_celestial(benchmark): + trsfm = generate_celestial_transform( + crpix=[0, 0] * u.pix, + crval=[0, 0] * u.arcsec, + cdelt=[1, 1] * u.arcsec/u.pix, + pc=np.identity(2) * u.pix) + + benchmark(update_celestial_transform_parameters, + trsfm, + [1, 1] * u.pix, + [0.5, 0.5] * u.arcsec/u.pix, + np.identity(2) * u.pix, + [1, 1] * u.arcsec, + 180 * u.deg, + ) + + +@pytest.mark.benchmark +def test_raveled_tab1d_model(benchmark): + ndim = 3 + rng = default_rng() + array_shape = rng.integers(1, 21, ndim) + array_bounds = array_shape - 1 + ravel = Ravel(array_shape) + nelem = np.prod(array_shape) + units = u.pix + values = np.arange(nelem) * units + lut_values = values + tabular = Tabular1D( + values, + lut_values, + bounds_error=False, + fill_value=np.nan, + method="linear", + ) + raveled_tab = ravel | tabular + # adding the new axis onto array_bounds makes broadcasting work below + array_bounds = array_bounds[:, np.newaxis] + # use 5 as an arbitrary number of inputs + random_number_shape = len(array_shape), 5 + random_numbers = rng.random(random_number_shape) + raw_inputs = random_numbers * array_bounds + inputs = tuple(raw_inputs * units) + + benchmark(raveled_tab, *inputs) From 81fd08477be6c1c89247a9300b1ab668df55c420 Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Thu, 6 Jun 2024 11:57:05 +0100 Subject: [PATCH 16/23] Need units on parameters for updating vct some of the time Not sure how this snuck past the tests in the first place --- dkist/wcs/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dkist/wcs/models.py b/dkist/wcs/models.py index bcdb115c..ab3a5e7c 100755 --- a/dkist/wcs/models.py +++ b/dkist/wcs/models.py @@ -130,7 +130,7 @@ def update_celestial_transform_parameters( -crpix[0], -crpix[1], pc, - transform[2].translation.value, + transform[2].translation.value * pc.unit if hasattr(pc, "unit") else transform[2].translation.value, cdelt[0], cdelt[1], crval[0], From cea4931598fcec820582315084410a5346a07e27 Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Thu, 6 Jun 2024 13:29:01 +0100 Subject: [PATCH 17/23] Benchmarks are taking too long again --- dkist/tests/test_benchmarks.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dkist/tests/test_benchmarks.py b/dkist/tests/test_benchmarks.py index 88705231..88f733c9 100644 --- a/dkist/tests/test_benchmarks.py +++ b/dkist/tests/test_benchmarks.py @@ -20,9 +20,9 @@ def test_load_asdf(benchmark, large_visp_dataset_file): def test_pixel_to_world(benchmark, visp_dataset_no_headers): ds = visp_dataset_no_headers - pxcoords = np.mgrid[:ds.wcs.pixel_shape[0]:5, - :ds.wcs.pixel_shape[1]:5, - :ds.wcs.pixel_shape[2]:5, + 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) From 18b59a693e21861f76a2c24c92ecbd470dc3cfa7 Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Thu, 6 Jun 2024 14:44:28 +0100 Subject: [PATCH 18/23] Nope too slow --- dkist/tests/test_benchmarks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dkist/tests/test_benchmarks.py b/dkist/tests/test_benchmarks.py index 88f733c9..16072eaf 100644 --- a/dkist/tests/test_benchmarks.py +++ b/dkist/tests/test_benchmarks.py @@ -30,7 +30,7 @@ def test_pixel_to_world(benchmark, visp_dataset_no_headers): @pytest.mark.benchmark @pytest.mark.parametrize("axes", [ - [None, "y", "x", None], + ["y", None, None, "x"], ]) def test_plot_dataset(benchmark, axes, visp_dataset_no_headers): @benchmark From f6ae66060662a3425ac54624827ef69949a62e52 Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Thu, 6 Jun 2024 15:36:59 +0100 Subject: [PATCH 19/23] Benchmark dataset slicing --- dkist/tests/test_benchmarks.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dkist/tests/test_benchmarks.py b/dkist/tests/test_benchmarks.py index 16072eaf..11dfbfbe 100644 --- a/dkist/tests/test_benchmarks.py +++ b/dkist/tests/test_benchmarks.py @@ -96,3 +96,10 @@ def test_raveled_tab1d_model(benchmark): inputs = tuple(raw_inputs * units) benchmark(raveled_tab, *inputs) + + +@pytest.mark.benchmark +def test_slice_dataset(benchmark, large_visp_dataset): + @benchmark + def slice_dataset(dataset=large_visp_dataset, idx = np.s_[:2, 10:15, 0]): + sliced = dataset[idx] From 05f27feded85bbeba7bfb5290b5c39c6df1ee46b Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Fri, 7 Jun 2024 10:41:20 +0100 Subject: [PATCH 20/23] Add changelog --- changelog/387.trivial.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/387.trivial.rst diff --git a/changelog/387.trivial.rst b/changelog/387.trivial.rst new file mode 100644 index 00000000..70c2b2cf --- /dev/null +++ b/changelog/387.trivial.rst @@ -0,0 +1 @@ +Add some more benchmarks to track performance of more parts of the user tools. From 29aa7c82bd06d18da957f8c44f50c72778db9d2e Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Wed, 17 Jul 2024 14:33:31 +0100 Subject: [PATCH 21/23] Update dkist/wcs/models.py Co-authored-by: Stuart Mumford --- dkist/wcs/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dkist/wcs/models.py b/dkist/wcs/models.py index ab3a5e7c..7c44df00 100755 --- a/dkist/wcs/models.py +++ b/dkist/wcs/models.py @@ -130,7 +130,7 @@ def update_celestial_transform_parameters( -crpix[0], -crpix[1], pc, - transform[2].translation.value * pc.unit if hasattr(pc, "unit") else transform[2].translation.value, + transform[2].translation.quantity if hasattr(pc, "unit") else transform[2].translation.value, cdelt[0], cdelt[1], crval[0], From e37a5e57268994762a10b3ddc977a1e0168b509d Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Wed, 17 Jul 2024 14:56:29 +0100 Subject: [PATCH 22/23] Add tests to hit update_celestial_transform and make sure the units are working sensibly --- dkist/wcs/tests/test_models.py | 40 +++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/dkist/wcs/tests/test_models.py b/dkist/wcs/tests/test_models.py index f3e4a52b..8c300377 100755 --- a/dkist/wcs/tests/test_models.py +++ b/dkist/wcs/tests/test_models.py @@ -12,7 +12,7 @@ from dkist.wcs.models import (AsymmetricMapping, Ravel, Unravel, VaryingCelestialTransform, VaryingCelestialTransform2D, VaryingCelestialTransform3D, - generate_celestial_transform, + generate_celestial_transform, update_celestial_transform_parameters, varying_celestial_transform_from_tables) @@ -52,6 +52,44 @@ def test_generate_celestial_unitless(): assert u.allclose(shift1.offset, 0) +def test_update_celestial(): + trsfm = generate_celestial_transform( + crpix=[0, 0] * u.pix, + crval=[0, 0] * u.arcsec, + cdelt=[1, 1] * u.arcsec/u.pix, + pc=np.identity(2) * u.pix) + + update_celestial_transform_parameters( + trsfm, + [1, 1] * u.pix, + [0.5, 0.5] * u.arcsec/u.pix, + np.identity(2) * u.pix, + [1, 1] * u.arcsec, + 180 * u.deg) + + # Copout and only test that one parameter is correct + shift1 = trsfm.left.left.left.left.right + assert u.allclose(shift1.offset.quantity, 1 * u.pix) + +def test_update_celestial_unitless(): + trsfm = generate_celestial_transform( + crpix=[0, 0], + crval=[0, 0], + cdelt=[1, 1], + pc=np.identity(2)) + + update_celestial_transform_parameters( + trsfm, + [1, 1], + [0.5, 0.5], + np.identity(2), + [1, 1], + 180) + + shift1 = trsfm.left.left.left.left.right + assert u.allclose(shift1.offset.value, -1) + + def test_varying_transform_no_lon_pole_unit(): varying_matrix_lt = [rotation_matrix(a)[:2, :2] for a in np.linspace(0, 90, 10)] * u.pix # Without a lon_pole passed, the transform was originally setting From c4d0ffce9a92c4c1724f9899b2fb851bfdf4a57e Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Thu, 18 Jul 2024 10:19:06 +0100 Subject: [PATCH 23/23] Correct test comparison value --- dkist/wcs/tests/test_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dkist/wcs/tests/test_models.py b/dkist/wcs/tests/test_models.py index 8c300377..c98e8fa5 100755 --- a/dkist/wcs/tests/test_models.py +++ b/dkist/wcs/tests/test_models.py @@ -69,7 +69,7 @@ def test_update_celestial(): # Copout and only test that one parameter is correct shift1 = trsfm.left.left.left.left.right - assert u.allclose(shift1.offset.quantity, 1 * u.pix) + assert u.allclose(shift1.offset.quantity, -1 * u.pix) def test_update_celestial_unitless(): trsfm = generate_celestial_transform(