aboutsummaryrefslogtreecommitdiffstats
path: root/astro/chandra
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2015-06-16 16:46:23 +0800
committerAaron LI <aaronly.me@outlook.com>2015-06-16 16:46:23 +0800
commit9c7782686fd607fd4e38038ed44f0307da0cd8c7 (patch)
treef4c3d7167f9f86974f0b3ff19ce910a4feb88cbb /astro/chandra
parent4b96527999e0b63917efa68ddfdffa57122c22cf (diff)
downloadatoolbox-9c7782686fd607fd4e38038ed44f0307da0cd8c7.tar.bz2
Updated astro tools.
* fit_betasbp_cut.py - fixed 'dof' calculation with 'n-p-1' - fixed 'par_eps' calculation/configuration - added 'fit_model_bounds' using 'scipy.optimize.minimize' to perform function minimization with bounds - split the data cut section to function 'cut_data' - added argument 'options' to 'fit_model_bounds' * marx_pntsrc.py Run MARX simulation on a given list of point sources, merge the output simulation results, and finally convert into FITS image. * blanksky_add_time.py Add a time column for the chandra blanksky event file. The time data are generated with a uniform distribution between TSTART and TSTOP.
Diffstat (limited to 'astro/chandra')
-rwxr-xr-xastro/chandra/blanksky_add_time.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/astro/chandra/blanksky_add_time.py b/astro/chandra/blanksky_add_time.py
new file mode 100755
index 0000000..a4d0cb6
--- /dev/null
+++ b/astro/chandra/blanksky_add_time.py
@@ -0,0 +1,73 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+#
+# Aaron LI
+# 2015/06/16
+
+"""
+Add a time column for the chandra blanksky event file.
+The time data are generated with a uniform distribution
+between TSTART and TSTOP.
+"""
+
+__version__ = "0.1.0"
+__date__ = "2015/06/16"
+
+import sys
+import argparse
+
+import numpy as np
+try:
+ from astropy.io import fits
+except ImportError:
+ try:
+ import pyfits as fits
+ except ImportError:
+ raise ImportError("cannot import 'astropy.io.fits' or 'pyfits'")
+
+
+def add_time_column(fitsfile, blockname="EVENTS"):
+ """
+ Add a time column to the specified block of the input fits file.
+ The time data are generated with a uniform distribution
+ between TSTART and TSTOP.
+
+ Return:
+ A fits object with the new time column.
+ """
+ if isinstance(fitsfile, str):
+ fitsfile = fits.open(fitsfile)
+ table = fitsfile[blockname]
+ tstart = table.header["TSTART"]
+ tstop = table.header["TSTOP"]
+ counts = len(table.data)
+ time_data = np.random.uniform(tstart, tstop, counts)
+ time_col = fits.Column(name="time", format="1D", unit="s", array=time_data)
+ newtable = fits.BinTableHDU.from_columns(
+ fits.ColDefs([time_col]) + table.columns)
+ fitsfile[blockname].data = newtable.data
+ return fitsfile
+
+
+def main():
+ parser = argparse.ArgumentParser(
+ description="Add a time column for Chandra blanksky event file.")
+ parser.add_argument("-V", "--version", action="version",
+ version="%(prog)s " + "%s (%s)" % (__version__, __date__))
+ parser.add_argument("infile", help="input chandra blanksky file")
+ parser.add_argument("outfile", nargs="?", default=None,
+ help="modified blanksky file. IN-PLACE modification if omitted.")
+ parser.add_argument("-C", "--clobber", dest="clobber",
+ action="store_true", help="overwrite output file if exists")
+ args = parser.parse_args()
+
+ newfits = add_time_column(args.infile)
+ if args.outfile:
+ newfits.writeto(args.outfile, clobber=args.clobber)
+ else:
+ newfits.writeto(args.infile, clobber=True)
+
+
+if __name__ == "__main__":
+ main()
+