Skip to content

Commit

Permalink
Bugfix in ASTRONIRCAM loading
Browse files Browse the repository at this point in the history
Enable testing of load_image
  • Loading branch information
rhandberg committed Jun 29, 2021
1 parent cd2e1a8 commit 467c30e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flows/load_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def load_image(FILENAME):
elif telescope == 'SAI-2.5' and instrument == 'ASTRONIRCAM':
image.site = api.get_site(13) # Hard-coded the siteid for Caucasus Mountain Observatory
if 'MIDPOINT' in hdr:
image.obstime = Time(hdr['MIDPOINT'], format='mjd', scale='utc', location=image.site['EarthLocation'])
image.obstime = Time(hdr['MIDPOINT'], format='isot', scale='utc', location=image.site['EarthLocation'])
else:
image.obstime = Time(hdr['MJD-AVG'], format='mjd', scale='utc', location=image.site['EarthLocation'])
image.photfilter = {
Expand Down
3 changes: 3 additions & 0 deletions tests/input/SN2020aatc_K_20201213_495s.fits.gz
Git LFS file not shown
42 changes: 42 additions & 0 deletions tests/test_load_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Test loading of images.
.. codeauthor:: Rasmus Handberg <rasmush@phys.au.dk>
"""

import pytest
import numpy as np
from astropy.time import Time
from astropy.wcs import WCS
import os.path
import conftest
from flows.load_image import load_image

#--------------------------------------------------------------------------------------------------
@pytest.mark.parametrize('fpath', ['SN2020aatc_K_20201213_495s.fits.gz'])
def test_load_image(fpath):

# The test input directory containing the test-images:
INPUT_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'input')

# Load the image from the test-set:
img = load_image(os.path.join(INPUT_DIR, fpath))

# Check the attributes of the image object:
assert isinstance(img.image, np.ndarray)
assert img.image.dtype in ('float32', 'float64')
assert isinstance(img.mask, np.ndarray)
assert img.mask.dtype == 'bool'
assert isinstance(img.clean, np.ma.MaskedArray)
assert img.clean.dtype == img.image.dtype
assert isinstance(img.obstime, Time)
assert isinstance(img.exptime, float)
assert img.exptime > 0
assert isinstance(img.photfilter, str)
assert isinstance(img.wcs, WCS)

#--------------------------------------------------------------------------------------------------
if __name__ == '__main__':
pytest.main([__file__])

0 comments on commit 467c30e

Please sign in to comment.