Skip to content

Initial ASDF extension and tests#2211

Open
nden wants to merge 11 commits intoastropy:mainfrom
nden:asdf-init
Open

Initial ASDF extension and tests#2211
nden wants to merge 11 commits intoastropy:mainfrom
nden:asdf-init

Conversation

@nden
Copy link
Contributor

@nden nden commented Mar 4, 2026

This PR is a contribution to astropy/astropy-project#527 . It implements the initial setup for serializing photutils PSF and aperture objects to ASDF. The proposal mentioned the implementation will be in asdf-astropy. However, after discussion with the ASDF developers we decided to include the implementation in photutils in order to keep the library code in sync with the serialization more easily. This PR adds

  • ASDF extension
  • Schemas for one PSF model and one aperture
  • Converters for the obkects
  • Sets up testing of schemas and adds tests for the converters

I am not able to request reviewers so tagging here @larrybradley @perrygreenfield @braingram

@larrybradley
Copy link
Member

pre-commit.ci autofix

@nden
Copy link
Contributor Author

nden commented Mar 5, 2026

pre-commit.ci autofix

@nden
Copy link
Contributor Author

nden commented Mar 5, 2026

pre-commit.ci autofix

@nden
Copy link
Contributor Author

nden commented Mar 6, 2026

Bumping the min version of astropy to v 7.2 fixed the oldestdeps test. Is this an acceptable change?

@larrybradley
Copy link
Member

@nden Is astropy 7.2 (released Nov 2025) the only version that works? Requiring only the latest release of astropy does seem to be a bit restrictive. That would also put constraints on all photutils dependencies, like jwst, romancal, drizzlepac/hap, etc.

@nden
Copy link
Contributor Author

nden commented Mar 7, 2026

The failing tests were using astropy 6.1.4. It appears there was a follow up bug fix release, 6.1.7, which works.

Copy link

@braingram braingram left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not have enough experience with photutils to test if real instances of these classes roundtrip so I only looked at this from an asdf extension perspective. I left a few comments, questions and suggestions.

Overall looks like it's on the right track. Aside from the one suggested schema change the rest of the comments are mostly questions or test changes.

filterwarnings = [
'error', # turn warnings into exceptions
]
asdf_schema_root = 'photutils/resources/schemas'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this sufficient to run these tests in the CI? So far I see lots of --pyargs photutils in the CI jobs which result in unpredictable file paths which typically result in the pytest-asdf-plugin failing to find schemas to tests: asdf-format/pytest-asdf-plugin#8

It's unclear to me if it's helpful to test schemas as part of all CI jobs (for example oldestdeps or macos vs linux) so one thing to consider is delegating schema testing to 1 CI job (either an existing one or a new one).

FWIW if I run pytest locally it is picking up these tests. However I'm not familiar enough with the photutils CI to know what to expect here. For example, considering the py313-all-deps job:

Most of that difference appears to be from this PR having a base commit older than HEAD on main.

Comment on lines +245 to +246
'to_yaml_tree', # ASDF converter
'from_yaml_tree', # ASDF converter

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems useful to include these in the coverage measurement. Aren't they covered by the converter tests?

- tag_uri: tag:astropy.org:photutils/aperture/circular_aperture-1.0.0
schema_uri: asdf://astropy.org/photutils/schemas/aperture/circular_aperture-1.0.0
title: CircularAperture
description: ASDF schema for serializing a photutils CircularAperture.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description: ASDF schema for serializing a photutils CircularAperture.
description: Circular aperture with one or more positions.

This is a nitpick. Since this is a tag definition I don't think "ASDF schema" fits. I'm also on the fence about adding "photutils" since that's already in the URI (and in other context). If this is updated would you update the other descriptions to match?

anyOf:
- type: number
maxItems: 2
minItems: 2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
minItems: 2

These keywords don't apply to number

Comment on lines +25 to +37
anyOf:
- type: array
items:
anyOf:
- type: number
maxItems: 2
minItems: 2
- type: array
items:
type: number
maxItems: 2
minItems: 2
- tag: "tag:stsci.edu:asdf/core/ndarray-1.*"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
anyOf:
- type: array
items:
anyOf:
- type: number
maxItems: 2
minItems: 2
- type: array
items:
type: number
maxItems: 2
minItems: 2
- tag: "tag:stsci.edu:asdf/core/ndarray-1.*"
anyOf:
- type: array
minItems: 2
maxItems: 2
items:
type: number
- tag: "tag:stsci.edu:asdf/core/ndarray-1.*"

Is there any condition where this can be a list of lists? I think the converter can currently only produce:

  • a ndarray
  • a 2 item list of numbers


class CircularApertureConverter(Converter):
"""
Base class for aperture converters.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there (or is there a plan to add) child classes?

Base class for aperture converters.
"""

tags = ['tag:astropy.org:photutils/aperture/circular_aperture-*'] # noqa: RUF012, E501

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tags = ['tag:astropy.org:photutils/aperture/circular_aperture-*'] # noqa: RUF012, E501
tags = ('tag:astropy.org:photutils/aperture/circular_aperture-*',) # noqa: E501

Making this a tuple would allow removing the noqa for RUF012. Same applies to the other tags and types.

Comment on lines +28 to +30

assert np.all(aperture.positions == aperture2.positions)
assert aperture.r == aperture2.r

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert np.all(aperture.positions == aperture2.positions)
assert aperture.r == aperture2.r
assert np.all(aperture.positions == aperture2.positions)
assert aperture.r == aperture2.r

These should be in the with since asdf is using lazy loading and aperature2.positions may be a ndarray.

Comment on lines +31 to +35
assert psf.flux == psf2.flux
assert psf.x_0 == psf2.x_0
assert psf.y_0 == psf2.y_0
assert psf.radius == psf2.radius
assert psf.bbox_factor == psf2.bbox_factor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert psf.flux == psf2.flux
assert psf.x_0 == psf2.x_0
assert psf.y_0 == psf2.y_0
assert psf.radius == psf2.radius
assert psf.bbox_factor == psf2.bbox_factor
assert psf.flux == psf2.flux
assert psf.x_0 == psf2.x_0
assert psf.y_0 == psf2.y_0
assert psf.radius == psf2.radius
assert psf.bbox_factor == psf2.bbox_factor

Similar to https://github.com/astropy/photutils/pull/2211/changes#r2913554434 asdf is lazy loading and psf2 is coming from a file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants