aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2017-08-13 11:34:13 +0800
committerAaron LI <aly@aaronly.me>2017-08-13 11:34:13 +0800
commit7f14f76d7c54664fa9567bac0f83570aa1e7e53b (patch)
tree5f251fd159d98c982d14b53d867baef1e29baf78
parent8717b6b2fa9edc8ac290b4bfb6f4335b075e2ef5 (diff)
downloadfg21sim-7f14f76d7c54664fa9567bac0f83570aa1e7e53b.tar.bz2
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 <aly@aaronly.me>
-rw-r--r--fg21sim/utils/io.py29
1 files changed, 26 insertions, 3 deletions
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)