Skip to content

Conversation

@embray
Copy link

@embray embray commented Dec 9, 2025

Follow-up to the discussion I opened at #630 to maybe put a little more concreteness behind it.

This primarily does two things:

  • Refactoring to improve generalizations for reading image data from different file formats besides just FITS
  • Support for reading ASDF files using libasdf

If it makes it easier I can also split this up into separate PRs, e.g. one for the general refactoring and one with the ASDF-specific stuff.

Writing ASDF files is not supported yet (as it's not yet supported in libasdf, though will be in a later version). So generalization of file output is not part of this.

Currently libasdf has a source-only release but we are also working on providing a conda package for it in conda-forge.

embray added 29 commits December 9, 2025 11:05
…o test

Nothing that does anything here yet, just bare minimum to test libasdf
detection and compile something with it.
Extend the existing (barely used) FitsReader class to implement
ImageFileReader

Extend FitsImageSource to also allow selecting FITS HDUs by extname
(should probably support extver as well, but this is less common)
This will be useful for creating a DetectionImage from some non-FITS
file type; mostly as a placeholder until reading a WCS from ASDF is
implemented.
...and prepare for the possibility of non-FITS images.
HDUs (even skipping over non-image HDUs)

Consequently make FitsReader::get(int) more sane: it returns the N-th
image HDU in the file (0-indexed) rather than FITSish 1-indexing.  This
enables more consistent use of ImageFileReader::get regardless of the
underlying file type.
Ndarray objects out of it.

There is a bit of a foot-gun here that AsdfFile has to be wrapped in
shared_ptr when using this.  I may try to get rid of that limitation
later.
…e_2d

This will be used to implement AsdfImageSource::getImageTile
classes

Drop use of enable_shared_from_this on AsdfFile which was misguided.
Should clarify that the lifetime of an `AsdfFile::Ndarray` is concurrent
with the `AsdfFile` itself (which is kept alive so long as we have a
pointer to its `FileAccessor`)
by the ImageFileReader.get() and iterator interfaces

Make this work again for FITS--for ASDF we need more work on the libasdf
side.
(I'm not even exactly sure what this is for yet, but it nicely
demonstrates how relatively easy it is now to abstract out the file
type)
Needed to add setLayer in the ImageSource base class for convenience; by
default this can just be a no-op where it's not applicable.
FITS tests--just their mirror images roughly

Header metadata isn't copied over yet though.
ImageFileReader::readImage on the base class--better name and more
general

Also fixes handling of image_type in FitsReader::get
This caught (and now fixes) some bugs in how the ImageTile::ImageType
was being passed through to AsdfImageSource::getImageTile
theory) which will make it easier to avoid having to write different
special cases for FITS and ASDF files specifically (even though they're
the only applicable cases for now)

For the ASDF case specifically support extracting a FitsWCS.  Right now
just provides a wrapper around the relevant libasdf GWCS extension
types--still need to then plug that into WCSLIB and add tests
supported) and initializing the wcsprm, etc.

Adds some tests based on the once for FITS but as noted it's a different
WCS with different results.  I tested the expected against wcslib and
GWCS as well.
this will be useful when matching WCS's to images
path for detection images and reference images

this just sets up the wiring--still need to implement parsing and
interpretation of the WCS path (and figurout where to document the
format)
kinda hacky but gets the job done for now; later may change this when
the libasdf gwcs module gets moved out to a separate library/plugin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant