Skip to content

Commit

Permalink
do not require fitsio by default; user can install fitsio if they wan…
Browse files Browse the repository at this point in the history
…t to do IO with the functions in this repo
  • Loading branch information
mr-superonion committed Oct 19, 2023
1 parent 1896da7 commit 16a3ce4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions fpfs/io.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import fitsio
from datetime import date
from numpy.lib.recfunctions import structured_to_unstructured
from . import __version__


def save_catalog(filename, arr, **kwargs):
try:
import fitsio
except ImportError:
raise ImportError(
"Cannot import fitsio to save the catalog",
"please install fitsio.",
)
"""
Save a numpy.ndarray to a fits file.
Expand All @@ -22,7 +28,6 @@ def save_catalog(filename, arr, **kwargs):
arr = structured_to_unstructured(arr)
assert "dtype" in kwargs.keys(), "dtype (shape or coords?) is not specific"
today = date.today()
kwargs["compress"] = ("fitsio-gzip_2",)
kwargs["image compress"] = ("fpfs",)
kwargs["version"] = (__version__,)
kwargs["date"] = (today,)
Expand Down Expand Up @@ -50,6 +55,13 @@ def save_image(filename, arr):
filename (str):
Path of the output fits file.
"""
try:
import fitsio
except ImportError:
raise ImportError(
"Cannot import fitsio to save the image",
"please install fitsio.",
)
# gzip compression is used by default
fitsio.write(filename, arr, compress="GZIP_2", qlevel=None)
return
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
astropy
fitsio
flake8
galsim
matplotlib
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"galsim",
"astropy",
"matplotlib",
"fitsio",
],
packages=find_packages(),
scripts=scripts,
Expand Down

0 comments on commit 16a3ce4

Please sign in to comment.