-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test & Refactor of Offsets Processors (#335)
* Added unit test to DummyOffsets * Added unit tests to BrightStarOffsets * Refactored BrightestStarOffsets * Clarified the brightest star selection * Added unit test to AstrometryOffsets * Refactored AstrometryOffsets * Added finer test for finding the brightest star
- Loading branch information
1 parent
6782237
commit 66d4a15
Showing
7 changed files
with
154 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import numpy as np | ||
import pytest | ||
from astropy.io import fits | ||
from astropy.utils.data import get_pkg_data_filename | ||
|
||
from pyobs.images import Image | ||
from pyobs.images.meta import PixelOffsets, OnSkyDistance | ||
from pyobs.images.processors.offsets import AstrometryOffsets | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_call() -> None: | ||
filename = get_pkg_data_filename('data/j94f05bgq_flt.fits', package='astropy.wcs.tests') | ||
fits_file = fits.open(filename) | ||
header = fits_file[1].header | ||
header["TEL-RA"] = 5.63 | ||
header["TEL-DEC"] = -72.05 | ||
|
||
image = Image(header=header) | ||
|
||
offsets = AstrometryOffsets() | ||
|
||
output_image = await offsets(image) | ||
pixel_offset = output_image.get_meta(PixelOffsets) | ||
|
||
np.testing.assert_almost_equal(pixel_offset.dx, 128.94120449972797) | ||
np.testing.assert_almost_equal(pixel_offset.dy, -309.1795167877043) | ||
|
||
on_sky_distance = output_image.get_meta(OnSkyDistance) | ||
np.testing.assert_almost_equal(on_sky_distance.distance.value, 0.004575193216279022) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import logging | ||
|
||
import numpy as np | ||
import pytest | ||
from astropy.io import fits | ||
from astropy.table import QTable | ||
from astropy.utils.data import get_pkg_data_filename | ||
|
||
from pyobs.images import Image | ||
from pyobs.images.meta import PixelOffsets, OnSkyDistance | ||
from pyobs.images.processors.offsets import BrightestStarOffsets | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_missing_catalog(caplog: pytest.LogCaptureFixture) -> None: | ||
offsets = BrightestStarOffsets() | ||
image = Image() | ||
|
||
with caplog.at_level(logging.WARNING): | ||
await offsets(image) | ||
|
||
assert caplog.messages[0] == "No catalog found in image." | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_empty_catalog(caplog: pytest.LogCaptureFixture) -> None: | ||
offsets = BrightestStarOffsets() | ||
image = Image(catalog=QTable()) | ||
|
||
with caplog.at_level(logging.WARNING): | ||
await offsets(image) | ||
|
||
assert caplog.messages[0] == "No catalog found in image." | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_call() -> None: | ||
fn = get_pkg_data_filename('data/j94f05bgq_flt.fits', package='astropy.wcs.tests') | ||
f = fits.open(fn) | ||
|
||
catalog = QTable({"x": [2050], "y": [1020], "flux": [1]}) | ||
image = Image(data=np.zeros((20, 20)), catalog=catalog, header=f[1].header) | ||
|
||
offsets = BrightestStarOffsets() | ||
|
||
output_image = await offsets(image) | ||
pixel_offset = output_image.get_meta(PixelOffsets) | ||
|
||
assert pixel_offset.dx == 2.0 | ||
assert pixel_offset.dy == -4.0 | ||
|
||
on_sky_distance = output_image.get_meta(OnSkyDistance) | ||
np.testing.assert_almost_equal(on_sky_distance.distance.value, 6.06585686e-05) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_ordering() -> None: | ||
catalog = QTable({"x": [2050, 2049], "y": [1020, 1021], "flux": [1, 2]}) | ||
|
||
assert BrightestStarOffsets._get_brightest_star_position(catalog) == (2049, 1021) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import pytest | ||
|
||
from pyobs.images import Image | ||
from pyobs.images.meta import PixelOffsets | ||
from pyobs.images.processors.offsets import DummyOffsets | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_dummy_offsets() -> None: | ||
offsets = DummyOffsets("pyobs.images.meta.PixelOffsets", 10.0) | ||
image = Image() | ||
|
||
output_image = await offsets(image) | ||
offset = output_image.get_meta(PixelOffsets) | ||
assert offset.dx == 10.0 | ||
assert offset.dy == 10.0 |