Repository navigation
Support for fsspec filesystem configuration via fits.open - #19294
Conversation
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
This comment was marked as resolved.
This comment was marked as resolved.
|
Thanks @pllim! Is it ok to add fsspec to the intersphinx mapping? It certainly would have helped me when I was flipping between docs. |
|
Ignore the above, fsspec is already in the mapping. |
14d6d06 to
758b872
Compare
bsipocz
left a comment
There was a problem hiding this comment.
The code changes look good, thanks!
However, these 2 items needs to be addressed before merging:
- The new kwarg needs test coverage,
- the narrative docs needs an update,
|
|
||
| .. versionadded:: 5.2 | ||
|
|
||
| filesystem_kwargs : dict, optional |
There was a problem hiding this comment.
what about making this even more explicit, e.g. fsspec_filesystem_kwargs?
There was a problem hiding this comment.
I'm ok with that, only opted to drop fsspec_ because all together it's a lot of characters.
There was a problem hiding this comment.
I think the clarity is worth the extra characters; and if abbreviation is needed then I would instead drop filesystem for fs; but still think the whole spell out is worth it for this case.
| Configuring the ``fsspec`` block size and download strategy | ||
| ----------------------------------------------------------- | ||
|
|
||
| The ``fsspec`` package supports different data reading and caching strategies | ||
| which aim to find a balance between the number of network requests on one hand | ||
| and the total amount of data transferred on the other hand. By default, fsspec | ||
| will attempt to download data in large contiguous blocks using a buffered | ||
| *read ahead* strategy, similar to the strategy that is employed when operating | ||
| systems load local files into memory. | ||
|
|
||
| You can tune the performance of fsspec's buffering strategy by passing custom | ||
| ``block_size`` and ``cache_type`` parameters to `fsspec.open`. You can pass | ||
| these parameters via the ``fsspec_kwargs`` argument of `astropy.io.fits.open`. | ||
| For example, we can configure fsspec to make buffered reads with a minimum | ||
| ``block_size`` of 1 MB as follows: |
There was a problem hiding this comment.
Please update this documentation
|
What I've been doing is creating the fsspec object myself and then doing: with fs.open(fspath) as f, astropy.io.fits.open(f) as fits_obj:
...which works great (but might not be documented to work) and is in some sense nicely explicit, but allowing fsspec parameters to be passed in directly to |
bsipocz
left a comment
There was a problem hiding this comment.
Thanks for addressing the review, this LGTM now.
|
|
||
| .. versionadded:: 5.2 | ||
|
|
||
| fsspec_filesystem_kwargs : dict, optional |
There was a problem hiding this comment.
The order should match signature above.
There was a problem hiding this comment.
yikes, good catch!
There was a problem hiding this comment.
(the docstring was right but the call signature wasn't.)
| @@ -0,0 +1,4 @@ | |||
| Fix for ``fsspec`` configuration in ``fits.open`` for remote S3 objects. ``fits.open`` | |||
| now accepts the keyword argument ``filesystem_kwargs``, which is passed onto | |||
|
@bsipocz , why remove the API change label? |
| @@ -0,0 +1,4 @@ | |||
| Fix for ``fsspec`` configuration in ``fits.open`` for remote S3 objects. ``fits.open`` | |||
There was a problem hiding this comment.
Is this really only of use for S3 URIs? I had assumed it was generically useful for any supported fsspec URI scheme that could take additional parameters.
There was a problem hiding this comment.
Good catch, I've exposed my bias here.
As it adds to the API rather than changing it |
|
Hmm I see this in pre-deps. Is it transient or has to be fixed? |
|
It would have showed up in devdeps too that run remote data but that job is currently messed up by #19216 |
This one is on me, fixing now. |
|
Having 2 parameters, one of which meaning something different depending on the value of the first one, seems a bit complicated to me... If there is an alternative with passing a fsspec filesystem object as in @timj's example (#19294 (comment)), I would favor this option, it seems more explicit and flexible. |
|
@saimn I agree that the API is awkward. I also think the point of the cloud FITS feature via |
neutrinoceros
left a comment
There was a problem hiding this comment.
got a superficial nit left, but otherwise I'll lift my request for changes as all my important remarks were addressed.
|
closing/re-opening to check against newly added CI job since this PR adds (optional) dependencies (ref #19022) |
5a1e21c to
cb5bda0
Compare
|
@bmorris3 please pay attention to https://github.com/astropy/astropy/actions/runs/23204311204/job/67435317522?pr=19294 While not (yet) required because it's brand new, this job failing indicates that action needs to be taken. It should be clear what to do from the logs, but please let me know if not. Thanks ! |
Co-authored-by: Brigitta Sipőcz <[email protected]>
Co-authored-by: Clément Robert <[email protected]>
2213937 to
fd8b2ae
Compare
|
@bsipocz May I ask for a rereview? Thanks |
|
Merged. Thanks, all! |
Description
This pull request is a proposal to address #19292.
Remote FITS files can be partially read from S3 or Google Cloud through
fits.openviafsspec.open, which identifies the remote file system and opens the URI using an instance offsspec.filesystemwith the default parameters.fsspec.openworks in many cases, but does not give finer control over, e.g., the (buffer) block size.The remote FITS docs contain an example for configuring block size:
but the argument to
fits.openisurlrather thans3_uri, which perhaps was intended. This is why doctests have been passing, though running the above snippet will fail with an S3 prefix in place ofurl.UPDATE: the first API proposal has evolved. The old API suggestion is expandable below:
old API proposal
The proposed fix in this PR adds a keyword argument to
get_readable_fileobjcalledfilesystem, which get passed intofsspec.filesystem.fsspec.filesystemis the constructor which takesblock_sizeandcache_type, and alsoanon.The revised example looks like this:
To maintain backwards compatibility, I've made double-use of
fsspec_kwargs. Iffilesystem_kwargsis None (default),fsspec_kwargsgets passed tofsspec.open, as it always has. Iffilesystem_kwargsis not None,fsspec_kwargsgets passed tofsspec.filesystem.open. This way a user can control both the file system configuration and the file open configuration, if they want. I understand if folks think that's tricky, and I'm open to suggestions.The proposed fix in this PR adds a keyword argument to
get_readable_fileobjcalledfsspec_filesystem, which takes anfsspec.filesystem. This constructor takes configurable arguments likeprotocol,block_sizeandcache_type, and alsoanon.The revised example looks like this:
As before,
fsspec_kwargsgets passed tofsspec.open, as it always has.Fixes #19292