Skip to content

Commit

Permalink
Merge pull request #472 from astrofrog/fix-ci-failures
Browse files Browse the repository at this point in the history
Fix Continuous Integration folllowing changes in Sunpy 6.0.0 and 6.0.1
  • Loading branch information
astrofrog authored Oct 11, 2024
2 parents 87626a2 + 1e5c275 commit 04ccfc6
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 114 deletions.
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test = [
]
testall = [
"shapely>=2.0.2", # 2.0.2 fixed a bug that causes changes in test results
"sunpy[map]>=2.1",
"sunpy[map]>=6.0.1",
"asdf",
"gwcs",
"pyvo",
Expand Down Expand Up @@ -92,6 +92,9 @@ filterwarnings = [
"ignore:'xdrlib' is deprecated and slated for removal in Python 3.13",
# This is a pyvo issue with Python 3.11
"ignore:'cgi' is deprecated and slated for removal in Python 3.13",
# Issue with zarr and dask mismatch
"ignore:ignoring keyword argument 'read_only'"

]

[tool.coverage.run]
Expand Down
Binary file not shown.
Binary file not shown.
48 changes: 5 additions & 43 deletions reproject/adaptive/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
from ...tests.helpers import array_footprint_to_hdulist
from ..high_level import reproject_adaptive

DATA = os.path.join(os.path.dirname(__file__), "..", "..", "tests", "data")


def as_high_level_wcs(wcs):
return HighLevelWCSWrapper(SlicedLowLevelWCS(wcs, Ellipsis))
Expand Down Expand Up @@ -763,50 +761,14 @@ def test_invald_bad_value_mode():
)


def prepare_test_data(file_format):
pytest.importorskip("sunpy", minversion="2.1.0")
from sunpy.coordinates.ephemeris import get_body_heliographic_stonyhurst
from sunpy.map import Map

if file_format == "fits":
map_aia = Map(os.path.join(DATA, "aia_171_level1.fits"))
data = map_aia.data
wcs = map_aia.wcs
date = map_aia.date
target_wcs = wcs.deepcopy()
elif file_format == "asdf":
pytest.importorskip("astropy", minversion="4.0")
pytest.importorskip("gwcs", minversion="0.12")
asdf = pytest.importorskip("asdf")
aia = asdf.open(os.path.join(DATA, "aia_171_level1.asdf"))
data = aia["data"][...]
wcs = aia["wcs"]
date = wcs.output_frame.reference_frame.obstime
target_wcs = Map(os.path.join(DATA, "aia_171_level1.fits")).wcs.deepcopy()
else:
raise ValueError("file_format should be fits or asdf")

# Reproject to an observer on Venus

target_wcs.wcs.cdelt = ([24, 24] * u.arcsec).to(u.deg)
target_wcs.wcs.crpix = [64, 64]
venus = get_body_heliographic_stonyhurst("venus", date)
target_wcs.wcs.aux.hgln_obs = venus.lon.to_value(u.deg)
target_wcs.wcs.aux.hglt_obs = venus.lat.to_value(u.deg)
target_wcs.wcs.aux.dsun_obs = venus.radius.to_value(u.m)

return data, wcs, target_wcs


@pytest.mark.filterwarnings("ignore::FutureWarning")
@pytest.mark.array_compare(single_reference=True)
@pytest.mark.parametrize("file_format", ["fits", "asdf"])
def test_reproject_adaptive_roundtrip(file_format):
def test_reproject_adaptive_roundtrip(aia_test_data):
# Test the reprojection with solar data, which ensures that the masking of
# pixels based on round-tripping works correctly. Using asdf is not just
# about testing a different format but making sure that GWCS works.

data, wcs, target_wcs = prepare_test_data(file_format)
data, wcs, target_wcs = aia_test_data

output, footprint = reproject_adaptive(
(data, wcs), target_wcs, (128, 128), center_jacobian=True, kernel="hann"
Expand All @@ -826,14 +788,14 @@ def test_reproject_adaptive_roundtrip(file_format):


@pytest.mark.filterwarnings("ignore::FutureWarning")
@pytest.mark.array_compare()
def test_reproject_adaptive_uncentered_jacobian():
@pytest.mark.array_compare(single_reference=True)
def test_reproject_adaptive_uncentered_jacobian(aia_test_data):
# Explicitly test the uncentered-Jacobian path for a non-affine transform.
# For this case, output pixels change by 6% at most, and usually much less.
# (Though more nan pixels are present, as the uncentered calculation draws
# in values from a bit further away.)

data, wcs, target_wcs = prepare_test_data("fits")
data, wcs, target_wcs = aia_test_data

output, footprint = reproject_adaptive(
(data, wcs), target_wcs, (128, 128), center_jacobian=False, kernel="hann"
Expand Down
42 changes: 42 additions & 0 deletions reproject/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import dask.array as da
import numpy as np
import pytest
from astropy import units as u
from astropy.io import fits
from astropy.nddata import NDData
from astropy.wcs import WCS
Expand Down Expand Up @@ -219,3 +220,44 @@ def valid_celestial_output_projections(request, simple_celestial_wcs):
output_value = wcs

return wcs, shape, output_value, kwargs


DATA = os.path.join(os.path.dirname(__file__), "tests", "data")


@pytest.fixture(params=["fits", "asdf"])
def aia_test_data(request):

pytest.importorskip("sunpy", minversion="6.0.1")

from sunpy.coordinates.ephemeris import get_body_heliographic_stonyhurst
from sunpy.map import Map

if request.param == "fits":
map_aia = Map(os.path.join(DATA, "aia_171_level1.fits"))
data = map_aia.data
wcs = map_aia.wcs
date = map_aia.reference_date
target_wcs = wcs.deepcopy()
elif request.param == "asdf":
pytest.importorskip("astropy", minversion="4.0")
pytest.importorskip("gwcs", minversion="0.12")
asdf = pytest.importorskip("asdf")
aia = asdf.open(os.path.join(DATA, "aia_171_level1.asdf"))
data = aia["data"][...]
wcs = aia["wcs"]
date = wcs.output_frame.reference_frame.obstime
target_wcs = Map(os.path.join(DATA, "aia_171_level1.fits")).wcs.deepcopy()
else:
raise ValueError("file_format should be fits or asdf")

# Reproject to an observer on Venus

target_wcs.wcs.cdelt = ([24, 24] * u.arcsec).to(u.deg)
target_wcs.wcs.crpix = [64, 64]
venus = get_body_heliographic_stonyhurst("venus", date)
target_wcs.wcs.aux.hgln_obs = venus.lon.to_value(u.deg)
target_wcs.wcs.aux.hglt_obs = venus.lat.to_value(u.deg)
target_wcs.wcs.aux.dsun_obs = venus.radius.to_value(u.m)

return data, wcs, target_wcs
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified reproject/interpolation/tests/reference/test_small_cutout.fits
Binary file not shown.
67 changes: 14 additions & 53 deletions reproject/interpolation/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,47 +521,15 @@ def test_reproject_with_output_array(roundtrip_coords):


@pytest.mark.array_compare(single_reference=True)
@pytest.mark.parametrize("file_format", ["fits", "asdf"])
@pytest.mark.remote_data
def test_reproject_roundtrip(file_format):
def test_reproject_roundtrip(aia_test_data):
# Test the reprojection with solar data, which ensures that the masking of
# pixels based on round-tripping works correctly. Using asdf is not just
# about testing a different format but making sure that GWCS works.

# The observer handling changed in 2.1.
pytest.importorskip("sunpy", minversion="2.1.0")
from sunpy.coordinates.ephemeris import get_body_heliographic_stonyhurst
from sunpy.map import Map

if file_format == "fits":
map_aia = Map(get_pkg_data_filename("data/aia_171_level1.fits", package="reproject.tests"))
data = map_aia.data
wcs = map_aia.wcs
date = map_aia.date
target_wcs = wcs.deepcopy()
elif file_format == "asdf":
pytest.importorskip("astropy", minversion="4.0")
pytest.importorskip("gwcs", minversion="0.12")
asdf = pytest.importorskip("asdf")
aia = asdf.open(
get_pkg_data_filename("data/aia_171_level1.asdf", package="reproject.tests")
)
data = aia["data"][...]
wcs = aia["wcs"]
date = wcs.output_frame.reference_frame.obstime
target_wcs = Map(
get_pkg_data_filename("data/aia_171_level1.fits", package="reproject.tests")
).wcs.deepcopy()
else:
raise ValueError("file_format should be fits or asdf")
pytest.importorskip("sunpy", minversion="6.0.1")

# Reproject to an observer on Venus
target_wcs.wcs.cdelt = ([24, 24] * u.arcsec).to(u.deg)
target_wcs.wcs.crpix = [64, 64]
venus = get_body_heliographic_stonyhurst("venus", date)
target_wcs.wcs.aux.hgln_obs = venus.lon.to_value(u.deg)
target_wcs.wcs.aux.hglt_obs = venus.lat.to_value(u.deg)
target_wcs.wcs.aux.dsun_obs = venus.radius.to_value(u.m)
data, wcs, target_wcs = aia_test_data

output, footprint = reproject_interp((data, wcs), target_wcs, (128, 128))

Expand All @@ -578,31 +546,20 @@ def test_reproject_roundtrip(file_format):
return array_footprint_to_hdulist(output, footprint, header_out)


def test_reproject_roundtrip_kwarg():
def test_reproject_roundtrip_kwarg(aia_test_data):
# Make sure that the roundtrip_coords keyword argument has an effect. This
# is a regression test for a bug that caused the keyword argument to be
# ignored when in parallel/blocked mode.

pytest.importorskip("sunpy", minversion="2.1.0")
from sunpy.coordinates.ephemeris import get_body_heliographic_stonyhurst
from sunpy.map import Map
pytest.importorskip("sunpy", minversion="6.0.1")

map_aia = Map(get_pkg_data_filename("data/aia_171_level1.fits", package="reproject.tests"))

# Reproject to an observer on Venus
target_wcs = map_aia.wcs.deepcopy()
target_wcs.wcs.cdelt = ([24, 24] * u.arcsec).to(u.deg)
target_wcs.wcs.crpix = [64, 64]
venus = get_body_heliographic_stonyhurst("venus", map_aia.date)
target_wcs.wcs.aux.hgln_obs = venus.lon.to_value(u.deg)
target_wcs.wcs.aux.hglt_obs = venus.lat.to_value(u.deg)
target_wcs.wcs.aux.dsun_obs = venus.radius.to_value(u.m)
data, wcs, target_wcs = aia_test_data

output_roundtrip_1 = reproject_interp(
map_aia, target_wcs, shape_out=(128, 128), return_footprint=False, roundtrip_coords=True
(data, wcs), target_wcs, shape_out=(128, 128), return_footprint=False, roundtrip_coords=True
)
output_roundtrip_2 = reproject_interp(
map_aia,
(data, wcs),
target_wcs,
shape_out=(128, 128),
return_footprint=False,
Expand All @@ -613,10 +570,14 @@ def test_reproject_roundtrip_kwarg():
assert_allclose(output_roundtrip_1, output_roundtrip_2)

output_noroundtrip_1 = reproject_interp(
map_aia, target_wcs, shape_out=(128, 128), return_footprint=False, roundtrip_coords=False
(data, wcs),
target_wcs,
shape_out=(128, 128),
return_footprint=False,
roundtrip_coords=False,
)
output_noroundtrip_2 = reproject_interp(
map_aia,
(data, wcs),
target_wcs,
shape_out=(128, 128),
return_footprint=False,
Expand Down
Binary file modified reproject/mosaicking/tests/reference/test_coadd_solar_map.fits
Binary file not shown.
4 changes: 1 addition & 3 deletions reproject/mosaicking/tests/test_coadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,7 @@ def test_coadd_solar_map():
# and combine them into a single one. This uses weight maps that are not
# uniform and also include NaN values.

# The reference image was generated for sunpy 6.0.0 - it will not work
# for previous versions.
pytest.importorskip("sunpy", minversion="6.0.0")
pytest.importorskip("sunpy", minversion="6.0.1")
from sunpy.map import Map, all_coordinates_from_map

# Load in three images from different viewpoints around the Sun
Expand Down
2 changes: 1 addition & 1 deletion reproject/mosaicking/tests/test_wcs_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def test_solar_wcs():
# Regression test for issues that occurred when trying to find
# the optimal WCS for a set of solar WCSes

pytest.importorskip("sunpy", minversion="2.1.0")
pytest.importorskip("sunpy", minversion="6.0.1")

# Make sure the WCS <-> frame functions are registered

Expand Down
24 changes: 12 additions & 12 deletions reproject/tests/data/aia_171_level1.asdf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ history:
extension_uri: asdf://asdf-format.org/core/extensions/core-1.5.0
manifest_software: !core/software-1.0.0 {name: asdf_standard, version: 1.1.1}
software: !core/software-1.0.0 {name: asdf-astropy, version: 0.6.1}
- !core/extension_metadata-1.0.0
extension_class: asdf.extension._manifest.ManifestExtension
extension_uri: asdf://asdf-format.org/astronomy/gwcs/extensions/gwcs-1.2.0
manifest_software: !core/software-1.0.0 {name: asdf_wcs_schemas, version: 0.4.0}
software: !core/software-1.0.0 {name: gwcs, version: 0.21.0}
- !core/extension_metadata-1.0.0
extension_class: asdf.extension._manifest.ManifestExtension
extension_uri: asdf://asdf-format.org/transform/extensions/transform-1.5.0
Expand All @@ -23,13 +28,8 @@ history:
software: !core/software-1.0.0 {name: asdf-astropy, version: 0.6.1}
- !core/extension_metadata-1.0.0
extension_class: asdf.extension._manifest.ManifestExtension
extension_uri: asdf://asdf-format.org/astronomy/gwcs/extensions/gwcs-1.2.0
manifest_software: !core/software-1.0.0 {name: asdf_wcs_schemas, version: 0.4.0}
software: !core/software-1.0.0 {name: gwcs, version: 0.21.0}
- !core/extension_metadata-1.0.0
extension_class: asdf.extension._manifest.ManifestExtension
extension_uri: asdf://sunpy.org/extensions/sunpy-1.1.0
software: !core/software-1.0.0 {name: sunpy, version: 5.1.5}
extension_uri: asdf://sunpy.org/extensions/sunpy-1.1.1
software: !core/software-1.0.0 {name: sunpy, version: 6.0.2}
- !core/extension_metadata-1.0.0
extension_class: asdf.extension._manifest.ManifestExtension
extension_uri: asdf://asdf-format.org/astronomy/coordinates/extensions/coordinates-1.1.0
Expand Down Expand Up @@ -332,21 +332,21 @@ wcs: !<tag:stsci.edu:gwcs/wcs-1.2.0>
data: !<tag:astropy.org:astropy/coordinates/representation-1.1.0>
components:
distance: !unit/quantity-1.1.0 {datatype: float64, unit: !unit/unit-1.0.0 m,
value: 147724815127.9968}
value: 147724815127.99683}
lat: !<tag:astropy.org:astropy/coordinates/latitude-1.1.0> {datatype: float64,
unit: !unit/unit-1.0.0 deg, value: -6.821923074710445}
unit: !unit/unit-1.0.0 deg, value: -6.821923074710443}
lon: !<tag:astropy.org:astropy/coordinates/longitude-1.1.0>
datatype: float64
unit: !unit/unit-1.0.0 deg
value: 359.98690027534224
value: 359.9868885126059
wrap_angle: !<tag:astropy.org:astropy/coordinates/angle-1.1.0> {
datatype: float64, unit: !unit/unit-1.0.0 deg, value: 360.0}
type: SphericalRepresentation
frame_attributes:
obstime: !time/time-1.1.0 2011-02-15T00:00:00.340
obstime: !time/time-1.1.0 2011-02-15T00:00:01.340
rsun: !unit/quantity-1.1.0 {datatype: float64, unit: !unit/unit-1.0.0 km,
value: 696000.0}
obstime: !time/time-1.1.0 2011-02-15T00:00:00.340
obstime: !time/time-1.1.0 2011-02-15T00:00:01.340
rsun: !unit/quantity-1.1.0 {datatype: float64, unit: !unit/unit-1.0.0 km,
value: 696000.0}
unit: [!unit/unit-1.0.0 arcsec, !unit/unit-1.0.0 arcsec]
Expand Down
2 changes: 1 addition & 1 deletion reproject/tests/test_high_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def test_dask_schedulers(reproject_function, scheduler, wcs_type):
wcs_out = WCS(hdu_out.header)
shape_out = hdu_out.data.shape
elif wcs_type == "gwcs":
pytest.importorskip("sunpy", minversion="2.1.0")
pytest.importorskip("sunpy", minversion="6.0.1")
asdf = pytest.importorskip("asdf")
if reproject_function == reproject_exact:
pytest.skip()
Expand Down

0 comments on commit 04ccfc6

Please sign in to comment.