aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/spectrum.py
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2017-02-16 15:57:00 +0800
committerAaron LI <aaronly.me@outlook.com>2017-02-17 01:16:46 +0800
commit0ad65eddf5abda46d9a1d05ea3f3d8a5c160c4d8 (patch)
tree1a661d9aa99ad7ce01dd6dc9356d1274aec1a2b2 /scripts/spectrum.py
parent00e26ca0a14f7918d9bbc4cb5d0d3afa2334b1fe (diff)
downloadchandra-acis-analysis-0ad65eddf5abda46d9a1d05ea3f3d8a5c160c4d8.tar.bz2
Add acis.py and spectrum.py modules
Also add astropy to the runtime dependencies.
Diffstat (limited to 'scripts/spectrum.py')
-rw-r--r--scripts/spectrum.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/scripts/spectrum.py b/scripts/spectrum.py
new file mode 100644
index 0000000..ad38b0d
--- /dev/null
+++ b/scripts/spectrum.py
@@ -0,0 +1,44 @@
+# Copyright (c) 2017 Weitian LI <liweitianux@live.com>
+# MIT license
+
+"""
+Chandra ACIS spectrum.
+"""
+
+
+from astropy.io import fits
+
+from acis import ACIS
+
+
+class Spectrum:
+ """
+ Chandra ACIS spectrum
+ """
+ def __init__(self, filepath):
+ self.filepath = filepath
+ self.fitsobj = fits.open(filepath)
+ ext_spec = self.fitsobj["SPECTRUM"]
+ self.header = ext_spec.header
+ # spectral data
+ self.channel = ext_spec.data.columns["CHANNEL"].array
+ self.counts = ext_spec.data.columns["COUNTS"].array
+ # spectral keywords
+ self.EXPOSURE = self.header.get("EXPOSURE")
+ self.BACKSCAL = self.header.get("BACKSCAL")
+
+ def calc_pb_flux(self, elow=9500, ehigh=12000):
+ """
+ Calculate the particle background flux:
+ flux = counts / exposure / area
+
+ Parameters
+ ----------
+ elow, ehigh : float, optional
+ Lower and upper energy limit for the particle background.
+ """
+ chlow = ACIS.energy2channel(elow)
+ chhigh = ACIS.energy2channel(ehigh)
+ counts = self.counts[(chlow-1):chhigh].sum()
+ flux = counts / self.EXPOSURE / self.BACKSCAL
+ return flux