From 7f14f76d7c54664fa9567bac0f83570aa1e7e53b Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sun, 13 Aug 2017 11:34:13 +0800 Subject: utils/io.py: Fix a dtype bug; Improve comments and FITS header Fix the dtype bug in "write_fits_image()" function. Signed-off-by: Aaron LI --- fg21sim/utils/io.py | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'fg21sim') diff --git a/fg21sim/utils/io.py b/fg21sim/utils/io.py index 49fa3c1..c8fb20e 100644 --- a/fg21sim/utils/io.py +++ b/fg21sim/utils/io.py @@ -4,6 +4,19 @@ """ Input/output utilities ---------------------- +* dataframe_to_csv: + Save the given Pandas DataFrame into a CSV text file. + +* pickle_dump: + Dump the given object into the output file using ``pickle.dump()``. + +* pickle_load: + Load the pickled Python back from the given file. + +* write_fits_image: + Write the supplied image (together with header information) into + the output FITS file. + * read_fits_healpix: Read the HEALPix map from a FITS file or a BinTableHDU to 1D array in *RING* ordering. @@ -103,8 +116,10 @@ def dataframe_to_csv(df, outfile, comment=None, clobber=False): # Add a default header comment if comment is None: - comment = ["by %s" % __name__, - "at %s" % datetime.now().isoformat()] + comment = [ + "by %s" % __name__, + "at %s" % datetime.now(timezone.utc).astimezone().isoformat(), + ] with open(outfile, "w") as fh: # Write header comments with ``#`` prefixed. @@ -189,8 +204,16 @@ def write_fits_image(outfile, image, header=None, float32=True, """ _create_dir(outfile) _check_existence(outfile, clobber=clobber, remove=True) + + hdr = fits.Header() + hdr["CREATOR"] = (__name__, "File creator") + hdr["DATE"] = (datetime.now(timezone.utc).astimezone().isoformat(), + "File creation date") + if header is not None: + hdr.extend(header, update=True) + if float32: - image = np.asarray(image, dtype=float32) + image = np.asarray(image, dtype=np.float32) hdu = fits.PrimaryHDU(data=image, header=header) hdu.writeto(outfile, checksum=checksum) logger.info("Wrote image to FITS file: %s" % outfile) -- cgit v1.2.2