Skip to content

Commit 7139b13

Browse files
authored
Merge pull request #149 from /issues/148
Switch to fitsio to write FITS faster.
2 parents 3fbaab0 + f7fe9f7 commit 7139b13

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

changes/149.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Swtich to fitsio for 2-4x FITS writing speed improvement.

phrosty/pipeline.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
# Imports ASTRO
1919
from astropy.coordinates import SkyCoord
20-
from astropy.io import fits
2120
from astropy.table import Table
2221
import astropy.units as u
2322
from astropy.wcs.utils import skycoord_to_pixel
23+
import fitsio
2424

2525
# Imports INTERNAL
2626
from phrosty.imagesubtraction import sky_subtract, stampmaker
@@ -134,7 +134,7 @@ def get_psf( self, ra, dec ):
134134
stamp = self.psfobj.get_stamp( x, y )
135135
if self.keep_intermediate:
136136
outfile = self.save_dir / f"psf_{self.image.name}.fits"
137-
fits.writeto( outfile, stamp, overwrite=True )
137+
fitsio.write( outfile, stamp, clobber=True )
138138

139139
return stamp
140140

@@ -586,7 +586,11 @@ def log_error( x ):
586586

587587
def write_fits_file( self, data, header, savepath ):
588588
try:
589-
fits.writeto( savepath, data, header=header, overwrite=True )
589+
if header is not None:
590+
hdr_dict = dict(header.items())
591+
else:
592+
hdr_dict = None
593+
fitsio.write( savepath, data, header=hdr_dict, clobber=True )
590594
except Exception as e:
591595
SNLogger.exception( f"Exception writing FITS image {savepath}: {e}" )
592596
raise

0 commit comments

Comments
 (0)