diff options
author | Aaron LI <aly@aaronly.me> | 2017-09-03 10:39:10 +0800 |
---|---|---|
committer | Aaron LI <aly@aaronly.me> | 2017-09-03 10:39:10 +0800 |
commit | 1369952c740cff4b135a7fe9ca7b15e2cc92623a (patch) | |
tree | 4ed91b6b441ef19547a16aa2b1a6126994ff3b19 /astro/fits | |
parent | ecdef0b886ce8d87e6fff79406ff25552744ac66 (diff) | |
download | atoolbox-1369952c740cff4b135a7fe9ca7b15e2cc92623a.tar.bz2 |
rescale_image.py: Try also "PixSize" keyword; Add --pixelsize argument
Diffstat (limited to 'astro/fits')
-rwxr-xr-x | astro/fits/rescale_image.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/astro/fits/rescale_image.py b/astro/fits/rescale_image.py index b267359..d0ae218 100755 --- a/astro/fits/rescale_image.py +++ b/astro/fits/rescale_image.py @@ -28,9 +28,11 @@ from scipy import ndimage class FITSImage: - def __init__(self, filename): + def __init__(self, filename, pixelsize=None): self.filename = filename self.header, self.image = self.open_image(filename) + if pixelsize is not None: + self.pixelsize = pixelsize print("Loaded FITS image from file: %s" % filename) print("FITS image size: %dx%d" % (self.Nx, self.Ny)) print("Pixel size: %.1f [arcsec]" % self.pixelsize) @@ -90,8 +92,15 @@ class FITSImage: # Unit: [arcsec] if hasattr(self, "_pixelsize"): return self._pixelsize - else: - return abs(self.header["CDELT1"]) * 3600 # [deg] -> [arcsec] + + try: + return self.header["PixSize"] # [arcsec] + except KeyError: + try: + return abs(self.header["CDELT1"]) * 3600 # [deg] -> [arcsec] + except KeyError: + raise ValueError("Cannot obtain pixel size from header; " + + "please manually provide --pixelsize") @pixelsize.setter def pixelsize(self, value): @@ -170,13 +179,16 @@ def main(): help="scale interpolation order (default: 1)") parser.add_argument("-s", "--size", type=int, required=True, help="output image size (number of pixels)") + parser.add_argument("-p", "--pixelsize", type=float, + help="input FITS image pixel size [arcsec] " + + "(default: try to obtain from FITS header)") parser.add_argument("-i", "--infile", required=True, help="input FITS image") parser.add_argument("-o", "--outfile", required=True, help="output FITS image") args = parser.parse_args() - fitsimage = FITSImage(args.infile) + fitsimage = FITSImage(args.infile, pixelsize=args.pixelsize) fitsimage.rescale(shape=args.size, order=args.order) fitsimage.write(args.outfile, clobber=args.clobber) |