Commit 898f5408 authored by Matthias Weidenthaler's avatar Matthias Weidenthaler
Browse files

Added fromfile feature for hdulists

parent 3f4284d5
...@@ -158,6 +158,23 @@ fsspec_HDUList.writeto(hdul_img, out_combined_img, overwrite=True) ...@@ -158,6 +158,23 @@ fsspec_HDUList.writeto(hdul_img, out_combined_img, overwrite=True)
fsspec_HDUList.writeto(hdul_img, out_combined_img, s3_options=s3_options, overwrite=True) fsspec_HDUList.writeto(hdul_img, out_combined_img, s3_options=s3_options, overwrite=True)
``` ```
### HDUList.fromfile
#### 老写法
```python
hdul_img = fits.HDUList.fromfile("hdulist.fits")
```
usage reference:
[https://docs.astropy.org/en/stable/io/fits/api/hdulists.html#astropy.io.fits.HDUList.fromfile](https://docs.astropy.org/en/stable/io/fits/api/hdulists.html#astropy.io.fits.HDUList.fromfile)
#### 新写法
```python
from csst_fs import fsspec_HDUList
hdul_img = fsspec_HDUList.fromfile("hdulist.fits")
hdul_img = fsspec_HDUList.fromfile("hdulist.fits", cache=False, s3_options=s3_options)
```
### table.Table.read ### table.Table.read
#### 老写法 #### 老写法
```python ```python
......
import fsspec import fsspec
from astropy.io import fits
from ..fsspec_fileobj import open_fileobj from ..fsspec_fileobj import open_fileobj
from ..s3_config import load_s3_options from ..s3_config import load_s3_options
def writeto(fits_HDUList, out_path, s3_options=load_s3_options(), *args, **kwargs): def writeto(fits_HDUList, out_path, *args, s3_options=load_s3_options(), **kwargs):
fileobj = open_fileobj(out_path, s3_options, mode='wb') fileobj = open_fileobj(out_path, s3_options, mode='wb')
fits_HDUList.writeto(fileobj, *args, **kwargs) fits_HDUList.writeto(fileobj, *args, **kwargs)
if hasattr(fileobj, 'close'): if hasattr(fileobj, 'close'):
fileobj.close() fileobj.close()
def fromfile(filename, *args, s3_options=load_s3_options(), **kwargs):
fileobj = open_fileobj(filename, s3_options, mode='rb')
return fits.HDUList.fromfile(fileobj, *args, **kwargs)
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment