aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2017-12-06 09:43:41 +0800
committerAaron LI <aly@aaronly.me>2017-12-06 09:43:41 +0800
commit84e43886b4ff16f17cac3d06f0d5d44d6aa0eacb (patch)
treec9c4712c336451941ec82e1c7db30d3275b6fcf8
parentb2679b9912ae82b6ba78b0380af8eae7a2ba07d9 (diff)
downloadatoolbox-84e43886b4ff16f17cac3d06f0d5d44d6aa0eacb.tar.bz2
astro/fitsimage.py: add MAD (median absolute deviation) to "info"
-rwxr-xr-xastro/fits/fitscube.py2
-rwxr-xr-xastro/fits/fitsimage.py20
2 files changed, 12 insertions, 10 deletions
diff --git a/astro/fits/fitscube.py b/astro/fits/fitscube.py
index bd44ce7..976e690 100755
--- a/astro/fits/fitscube.py
+++ b/astro/fits/fitscube.py
@@ -415,7 +415,7 @@ def cmd_corrupt(args):
def main():
parser = argparse.ArgumentParser(
- description="Create FITS cube from a series of image slices.")
+ description="FITS image cube manipulation tool")
subparsers = parser.add_subparsers(dest="subparser_name",
title="sub-commands",
help="additional help")
diff --git a/astro/fits/fitsimage.py b/astro/fits/fitsimage.py
index 74b03cf..186e09b 100755
--- a/astro/fits/fitsimage.py
+++ b/astro/fits/fitsimage.py
@@ -78,24 +78,26 @@ def cmd_info(args):
fimage = FITSImage(args.infile)
print("Image data shape: {0}".format(fimage.shape))
print("Data unit: %s" % fimage.bunit)
- image = fimage.image
+ data = fimage.image
if args.abs:
- image = np.abs(image)
+ data = np.abs(data)
if args.center:
print("Central box size: %d" % args.center)
- rows, cols = image.shape
+ rows, cols = data.shape
rc, cc = rows//2, cols//2
cs1, cs2 = args.center//2, (args.center+1)//2
- image = image[(rc-cs1):(rc+cs2), (cc-cs1):(cc+cs2)]
- mean = np.mean(image)
- median = np.median(image)
- iqr = np.diff(np.percentile(image, q=(25, 75)))
- std = np.std(image)
- rms = np.sqrt(np.mean(image**2))
+ data = data[(rc-cs1):(rc+cs2), (cc-cs1):(cc+cs2)]
+ mean = np.mean(data)
+ median = np.median(data)
+ std = np.std(data)
+ iqr = np.diff(np.percentile(data, q=(25, 75)))
+ mad = np.median(np.abs(data - median))
+ rms = np.sqrt(np.mean(data**2))
print("mean: %-12.6e" % mean)
print("median: %-12.6e" % median)
print("std: %-12.6e (standard deviation)" % std)
print("iqr: %-12.6e (interquartile range)" % iqr)
+ print("mad: %-12.6e (median absolute deviation)" % mad)
print("rms: %-12.6e (root-mean-squared)" % rms)