File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change 15
15
from desiutil .dust import ebv as dust_ebv
16
16
from desiutil .log import get_logger
17
17
from desispec .emlinefit import get_rf_em_waves
18
- from .util import checkgzip
18
+ from .util import checkgzip , get_tempfilename
19
19
20
20
def get_targetids (d , bitnames , log = None ):
21
21
"""
@@ -355,13 +355,14 @@ def write_emlines(
355
355
for i_emname , emname in enumerate (emnames ):
356
356
hdr ["RFWAVE{:02d}" .format (i_emname )] = "," .join (get_rf_em_waves (emname ).astype (str ))
357
357
358
- # AR write to fits
358
+ # AR write to fits via tempfile to avoid corrupted final file in case of a crash
359
359
if os .path .isfile (output ):
360
360
log .info ("Removing existing {}" .format (output ))
361
361
os .remove (output )
362
- fd = fitsio .FITS (output , "rw" )
363
- fd .write (d , extname = "EMLINEFIT" , header = hdr )
364
- fd .close ()
362
+ tmpfile = get_tempfilename (output )
363
+ with fitsio .FITS (tmpfile , "rw" ) as fd :
364
+ fd .write (d , extname = "EMLINEFIT" , header = hdr )
365
+ os .rename (tmpfile , output )
365
366
366
367
367
368
def plot_emlines (
You can’t perform that action at this time.
0 commit comments