From 73eba0c4f5bd675c18f3f6c2ad817550b0d37063 Mon Sep 17 00:00:00 2001 From: GermanHydrogen Date: Tue, 30 Jan 2024 10:52:42 +0100 Subject: [PATCH] Added dummy skyoffsets for testing --- pyobs/images/processors/offsets/__init__.py | 2 ++ .../processors/offsets/dummyskyoffsets.py | 24 ++++++++++++++++++ .../offsets/test_dummyskyoffsets.py | 25 +++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 pyobs/images/processors/offsets/dummyskyoffsets.py create mode 100644 tests/images/processors/offsets/test_dummyskyoffsets.py diff --git a/pyobs/images/processors/offsets/__init__.py b/pyobs/images/processors/offsets/__init__.py index e4fd968c..1ff322cf 100644 --- a/pyobs/images/processors/offsets/__init__.py +++ b/pyobs/images/processors/offsets/__init__.py @@ -10,6 +10,7 @@ from .projected import ProjectedOffsets from .fitsheader import FitsHeaderOffsets from .dummyoffsets import DummyOffsets +from .dummyskyoffsets import DummySkyOffsets __all__ = [ "Offsets", @@ -19,4 +20,5 @@ "FitsHeaderOffsets", "BrightestStarOffsets", "DummyOffsets", + "DummySkyOffsets" ] diff --git a/pyobs/images/processors/offsets/dummyskyoffsets.py b/pyobs/images/processors/offsets/dummyskyoffsets.py new file mode 100644 index 00000000..d0a86bf2 --- /dev/null +++ b/pyobs/images/processors/offsets/dummyskyoffsets.py @@ -0,0 +1,24 @@ +from copy import copy +from typing import Any, Union, Dict + +from astropy.coordinates import SkyCoord + +from pyobs.images import Image +from pyobs.images.meta import SkyOffsets +from pyobs.images.processors.offsets import Offsets +from pyobs.object import get_object + + +class DummySkyOffsets(Offsets): + def __init__(self, coord0: Union[SkyCoord, Dict[str, Any]], coord1: Union[SkyCoord, Dict[str, Any]], **kwargs: Any) -> None: + super().__init__(**kwargs) + sky_coord0 = get_object(coord0, SkyCoord) + sky_coord1 = get_object(coord1, SkyCoord) + self._offset = SkyOffsets(sky_coord0, sky_coord1) + + async def __call__(self, image: Image) -> Image: + image.set_meta(copy(self._offset)) + return image + + +__all__ = ["DummySkyOffsets"] diff --git a/tests/images/processors/offsets/test_dummyskyoffsets.py b/tests/images/processors/offsets/test_dummyskyoffsets.py new file mode 100644 index 00000000..57bb6555 --- /dev/null +++ b/tests/images/processors/offsets/test_dummyskyoffsets.py @@ -0,0 +1,25 @@ +import pytest +from astropy.coordinates import SkyCoord + +from pyobs.images import Image +from pyobs.images.meta import SkyOffsets +from pyobs.images.processors.offsets import DummySkyOffsets + + +@pytest.mark.asyncio +async def test_call(): + coord0 = SkyCoord(alt=90.0, az=0.0, unit="degree", frame="altaz") + coord1 = SkyCoord(alt=80.0, az=0.0, unit="degree", frame="altaz") + + offsets = DummySkyOffsets(coord0, coord1) + image = Image() + + result_image = await offsets(image) + + result_offset = result_image.get_meta(SkyOffsets) + + assert result_offset.coord0.alt.deg == 90.0 + assert result_offset.coord0.az.deg == 0.0 + + assert result_offset.coord1.alt.deg == 80.0 + assert result_offset.coord1.az.deg == 0.0