Skip to content

Commit

Permalink
Merge branch 'master' into visp_wcs
Browse files Browse the repository at this point in the history
  • Loading branch information
Cadair authored Oct 12, 2023
2 parents b93aa21 + 8117b3c commit 47d41e6
Show file tree
Hide file tree
Showing 21 changed files with 208 additions and 87 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: build

on:
release:
types: [ released ]
pull_request:
workflow_dispatch:

jobs:
build:
uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish_pure_python.yml@v1
with:
upload_to_pypi: ${{ (github.event_name == 'release') && (github.event.action == 'released') }}
secrets:
pypi_token: ${{ secrets.PYPI_PASSWORD_STSCI_MAINTAINER }}
11 changes: 4 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,25 @@ concurrency:

jobs:
check:
name:
name:
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v1
with:
envs: |
- linux: check-style
- linux: check-security
- linux: check-build
test:
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@main
with:
envs: |
- linux: test
python-version: 3.9
- linux: test-numpy120
python-version: 3.9
- linux: test-numpy121
- linux: test-numpy125
python-version: 3.9
- linux: test-numpy122
python-version: 3.9
- linux: test
python-version: 3.10
- linux: test-numpy121
- linux: test-numpy125
python-version: 3.10
- linux: test-numpy122
python-version: 3.10
Expand Down Expand Up @@ -92,4 +89,4 @@ jobs:
cache-path: ${{ needs.crds.outputs.path }}
cache-key: crds-${{ needs.crds.outputs.context }}
envs: |
- linux: test-jwst-cov-xdist
- linux: py310-test-jwst-cov-xdist
16 changes: 0 additions & 16 deletions .github/workflows/publish-to-pypi.yml

This file was deleted.

1 change: 0 additions & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ conda:

# Set the version of Python and requirements required to build your docs
python:
system_packages: false
install:
- method: pip
path: .
Expand Down
19 changes: 18 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
0.18.4 (unreleased)
0.20.0 (unreleased)
-------------------

other
^^^^^

- Replace ``pkg_resources`` with ``importlib.metadata``. [#478]

0.19.0 (2023-09-15)
-------------------

Bug Fixes
Expand All @@ -7,6 +15,8 @@ Bug Fixes
- Synchronize ``array_shape`` and ``pixel_shape`` attributes of WCS
objects. [#439]

- Fix failures and warnings woth numpy 2.0. [#472]

other
^^^^^

Expand All @@ -23,6 +33,13 @@ other

- Code and docstrings clean up. [#460]

- Register all available asdf extension manifests from ``asdf-wcs-schemas``
except 1.0.0 (which contains duplicate tag versions). [#469]

- Register empty extension for 1.0.0 to avoid warning about a missing
extension when opening old files. [#475]


0.18.3 (2022-12-23)
-------------------
Bug Fixes
Expand Down
8 changes: 0 additions & 8 deletions conftest.py

This file was deleted.

6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import tomllib
except ImportError:
import tomli as tomllib
from pkg_resources import get_distribution

import importlib.metadata

try:
from sphinx_astropy.conf.v1 import * # noqa
Expand Down Expand Up @@ -83,7 +83,7 @@
# |version| and |release|, also used in various other places throughout the
# built documents.

release = get_distribution(project).version
release = importlib.metadata.version(project)
# for example take major/minor
version = '.'.join(release.split('.')[:2])

Expand Down
9 changes: 3 additions & 6 deletions gwcs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,11 @@
"""

import sys
from pkg_resources import get_distribution, DistributionNotFound
if sys.version_info < (3, 6):
raise ImportError("GWCS supports Python versions 3.6 and above.") # pragma: no cover
import importlib.metadata

try:
__version__ = get_distribution(__name__).version
except DistributionNotFound: # pragma: no cover
__version__ = importlib.metadata.version(__name__)
except importlib.metadata.PackageNotFoundError: # pragma: no cover
# package is not installed
pass # pragma: no cover

Expand Down
2 changes: 1 addition & 1 deletion gwcs/converters/tests/test_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def _assert_mapper_equal(a, b):

if isinstance(a.mapper, dict):
assert(a.mapper.__class__ == b.mapper.__class__) # nosec
assert(all(np.in1d(list(a.mapper), list(b.mapper)))) # nosec
assert(np.isin(list(a.mapper), list(b.mapper)).all()) # nosec
for k in a.mapper:
assert (a.mapper[k].__class__ == b.mapper[k].__class__) # nosec
assert(all(a.mapper[k].parameters == b.mapper[k].parameters)) # nosec
Expand Down
7 changes: 5 additions & 2 deletions gwcs/converters/tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

from astropy.modeling.models import Identity
from astropy import units as u
from asdf_astropy.converters.transform.tests.test_transform import (
assert_model_roundtrip)

try:
from asdf_astropy.testing.helpers import assert_model_roundtrip
except ImportError:
from asdf_astropy.converters.transform.tests.test_transform import assert_model_roundtrip

from ... import spectroscopy as sp
from ... import geometry
Expand Down
26 changes: 23 additions & 3 deletions gwcs/extension.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
from asdf.extension import ManifestExtension
import importlib.resources

from asdf.extension import Extension, ManifestExtension
from .converters.wcs import (
CelestialFrameConverter, CompositeFrameConverter, FrameConverter,
Frame2DConverter, SpectralFrameConverter, StepConverter,
Expand Down Expand Up @@ -40,19 +42,37 @@
# The order here is important; asdf will prefer to use extensions
# that occur earlier in the list.
WCS_MANIFEST_URIS = [
"asdf://asdf-format.org/astronomy/gwcs/manifests/gwcs-1.0.0",
f"asdf://asdf-format.org/astronomy/gwcs/manifests/{path.stem}"
for path in sorted((importlib.resources.files("asdf_wcs_schemas.resources") / "manifests").iterdir(), reverse=True)
]


# 1.0.0 contains multiple versions of the same tag, a bug fixed in
# 1.0.1 so only register 1.0.0 if it's the only available manifest
TRANSFORM_EXTENSIONS = [
ManifestExtension.from_uri(
uri,
legacy_class_names=["gwcs.extension.GWCSExtension"],
converters=WCS_MODEL_CONVERTERS,
)
for uri in WCS_MANIFEST_URIS
if len(WCS_MANIFEST_URIS) == 1 or '1.0.0' not in uri
]

# if we don't register something for the 1.0.0 extension/manifest
# opening old files will issue AsdfWarning messages stating that
# the file was produced with an extension that is not installed
# As the 1.0.1 and 1.1.0 extensions support all the required tags
# it's not a helpful warning so here we register an 'empty'
# extension for 1.0.0 which doesn't support any tags or types
# but will be installed into asdf preventing the warning
if len(TRANSFORM_EXTENSIONS) > 1:
class _EmptyExtension(Extension):
extension_uri = 'asdf://asdf-format.org/astronomy/gwcs/extensions/gwcs-1.0.0'
legacy_class_names=["gwcs.extension.GWCSExtension"]

TRANSFORM_EXTENSIONS.append(_EmptyExtension())


def get_extensions():
"""
Get the gwcs.converters extension.
Expand Down
2 changes: 1 addition & 1 deletion gwcs/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class LabelMapperArray(_LabelMapper):
fittable = False

def __init__(self, mapper, inputs_mapping=None, name=None, **kwargs):
if mapper.dtype.type is not np.unicode_:
if mapper.dtype.type is not np.str_:
mapper = np.asanyarray(mapper, dtype=int)
_no_label = 0
else:
Expand Down
Empty file added gwcs/tests/data/__init__.py
Empty file.
58 changes: 58 additions & 0 deletions gwcs/tests/test_extension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import io
import warnings

import asdf
import asdf_wcs_schemas
import gwcs.extension

import pytest


@pytest.mark.skipif(asdf_wcs_schemas.__version__ < "0.2.0", reason="version 0.2 provides the new manifests")
def test_empty_extension():
"""
Test that an empty extension was installed for gwcs 1.0.0
and that extensions are installed for gwcs 1.0.1 and 1.1.0
"""
extensions = gwcs.extension.get_extensions()
assert len(extensions) > 1

extensions_by_uri = {ext.extension_uri: ext for ext in extensions}

# check for duplicate uris
assert len(extensions_by_uri) == len(extensions)

# check that all 3 versions are installed
for version in ('1.0.0', '1.0.1', '1.1.0'):
assert f"asdf://asdf-format.org/astronomy/gwcs/extensions/gwcs-{version}" in extensions_by_uri

# the 1.0.0 extension should support no tags or types
legacy = extensions_by_uri["asdf://asdf-format.org/astronomy/gwcs/extensions/gwcs-1.0.0"]
assert len(legacy.tags) == 0
assert len(legacy.converters) == 0


def test_open_legacy_without_warning():
"""
Opening a file produced with extension 1.0.0 should not produce any
warnings because of the empty extension registered for 1.0.0
"""
asdf_bytes = b"""#ASDF 1.0.0
#ASDF_STANDARD 1.5.0
%YAML 1.1
%TAG ! tag:stsci.edu:asdf/
--- !core/asdf-1.1.0
asdf_library: !core/software-1.0.0 {author: The ASDF Developers, homepage: 'http://github.com/asdf-format/asdf',
name: asdf, version: 2.9.2}
history:
extensions:
- !core/extension_metadata-1.0.0
extension_class: asdf.extension._manifest.ManifestExtension
extension_uri: asdf://asdf-format.org/astronomy/gwcs/extensions/gwcs-1.0.0
software: !core/software-1.0.0 {name: gwcs, version: 0.18.0}
foo: 1
..."""
with warnings.catch_warnings():
warnings.simplefilter("error")
with asdf.open(io.BytesIO(asdf_bytes)) as af:
assert af['foo'] == 1
11 changes: 7 additions & 4 deletions gwcs/tests/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
import asdf
import numpy as np
from astropy import units as u
from asdf_astropy.converters.transform.tests.test_transform import (
assert_model_roundtrip)

try:
from asdf_astropy.testing.helpers import assert_model_roundtrip
except ImportError:
from asdf_astropy.converters.transform.tests.test_transform import assert_model_roundtrip

from .. import geometry

Expand Down Expand Up @@ -150,9 +153,9 @@ def test_spherical_to_cartesian_mixed_Q(spher_to_cart, unit1, unit2):

@pytest.mark.parametrize(
'x, y, z',
list(set(
sorted(list(set(
tuple(permutations([1 * u.m, 1, 1])) + tuple(permutations([1 * u.m, 1 * u.m, 1]))
))
)), key=str)
)
def test_cartesian_to_spherical_mixed_Q(cart_to_spher, x, y, z):
with pytest.raises(TypeError) as arg_err:
Expand Down
9 changes: 7 additions & 2 deletions gwcs/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import os.path
import numpy as np
from astropy.io import fits
from astropy import wcs as fitswcs
from astropy import units as u
from astropy import coordinates as coord
from astropy.modeling import models
from astropy.utils.data import get_pkg_data_filename
from astropy.tests.helper import assert_quantity_allclose
import pytest
from numpy.testing import assert_allclose

from .. import utils as gwutils
from ..utils import UnsupportedProjectionError

from . import data


data_path = os.path.split(os.path.abspath(data.__file__))[0]


def test_wrong_projcode():
with pytest.raises(UnsupportedProjectionError):
Expand All @@ -26,7 +31,7 @@ def test_wrong_projcode2():


def test_fits_transform():
hdr = fits.Header.fromfile(get_pkg_data_filename('data/simple_wcs2.hdr'))
hdr = fits.Header.fromfile(os.path.join(data_path, "simple_wcs2.hdr"))
gw1 = gwutils.make_fitswcs_transform(hdr)
w1 = fitswcs.WCS(hdr)
assert_allclose(gw1(1, 2), w1.wcs_pix2world(1, 2, 0), atol=10 ** -8)
Expand Down
Loading

0 comments on commit 47d41e6

Please sign in to comment.