Skip to content

Use rustfits or astropy remote file access when possible. - #178

Merged
erykoff merged 24 commits into
mainfrom
astropy_remote
Oct 22, 2026
Merged

erykoff merged 24 commits into
mainfrom
astropy_remote

Conversation

@erykoff

@erykoff erykoff commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@erykoff
erykoff marked this pull request as draft July 24, 2026 23:49
@erykoff erykoff changed the title Use astropy remote file access when possible. Use rustfits or astropy remote file access when possible. Jul 29, 2026
@erykoff
erykoff marked this pull request as ready for review July 29, 2026 21:31
@erykoff
erykoff requested a review from esheldon July 29, 2026 21:32
Comment thread healsparse/fits_shim.py

self.fits_object = rustfits.FITS(filename, mode=rustfits_mode)
if mode == "r" and protocol != "file":
self.fits_object = rustfits.FITS(filename, mode=rustfits_mode, remote="ranged")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this defaulting to always using ranged? I think often this is not the best choice, much faster to use the default "download all and work with it in memory"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Hmm. Part of the problem is that only rustfits supports this. The other thing is that I was thinking that if somebody is handing a remote URI then they are asking to read it remotely (for good or ill). I also worry about trying to get too many parameters in at the top and passing them all down ... but if you think it's necessary I could.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

what is only supported by rustfits?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Right now I support various fits backends, but I am thinking that I should remove that ... or at least remove fitsio because I do require rustfits. So I'll do that cleanup on this PR.

But I also support astropy fits reading which is currently required for remote access via S3 or google cloud or webdav (I don't think rustfits supports these or it would be a great surprise). And only rustfits will "download the file to a temp cache and then read it". I personally find that behavior surprising. I would instead expect that if I give a remote protocol I want to read it remotely.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Getting this to work took some real code and decisions, where as the download version didn't take any.

Also the download is what cfitsio does.

From that point of view, ranged access not being default isn't a surprise, the ranged read existing at all is the nice addition (thanks for prompting it). It is nice astropy does it too.

Why does S3, google cloud, webdave require anything other than authentication? rustfits does support that through the keyword

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Comment thread setup.cfg Outdated
fitsio>=1.4.0
rustfits =
rustfits>=0.1.5
rustfits>=0.1.7

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think ranged landed in 0.1.8

@fjaviersanchez fjaviersanchez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The changes and tests look good to me. I just left a comment regarding astropy.io.fits but it shouldn't prevent you from merging this one. Thank you!

Comment thread healsparse/fits_shim.py
firstrow = (hdu.get_dims()[0], )
hdu.write(data, start=firstrow)
elif has_astropy:
elif self._use_astropy:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I might be missing something, but I think astropy.io.fits does allow appending. I think the only limitation is if the data block is compressed in certain formats. I think that you can either open the fits on append mode and append to the HDUList object or use fits.append.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

As far as I know, astropy fits does not allow you to stream append with tile compression, which is what I'm looking for here. You can only append a whole new HDU.

@erykoff
erykoff merged commit a452409 into main Oct 22, 2026
5 checks passed
@erykoff
erykoff deleted the astropy_remote branch October 22, 2026 21:13
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.

3 participants