diff options
author | Aaron LI <aly@aaronly.me> | 2018-08-09 15:00:16 +0800 |
---|---|---|
committer | Aaron LI <aly@aaronly.me> | 2018-08-09 15:00:16 +0800 |
commit | 1a0e23f1b40f1204bb1e8f8ca35692b7c984a254 (patch) | |
tree | cdb5c067585c0bbd58624a30b4555e05b92cc0c4 | |
parent | 0cbb8d5f65c60b2bb24ca1e174c880d23c818ded (diff) | |
download | atoolbox-1a0e23f1b40f1204bb1e8f8ca35692b7c984a254.tar.bz2 |
astro/fitsimage.py: Add "flip" sub-command
-rwxr-xr-x | astro/fits/fitsimage.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/astro/fits/fitsimage.py b/astro/fits/fitsimage.py index 95c9ed8..edc1255 100755 --- a/astro/fits/fitsimage.py +++ b/astro/fits/fitsimage.py @@ -150,6 +150,15 @@ class FITSImage: self.pixelsize = pixelsize_old * (self.Nx / Nx2) return self.image + def flip(self, direction): + if direction == "lr": + self.image = np.fliplr(self.image) + elif direction == "ud": + self.image = np.flipud(self.image) + else: + raise ValueError("invalid flip direction: %s" % direction) + return self.image + def write(self, outfile, clobber=False): self.header.add_history(" ".join(sys.argv)) hdu = fits.PrimaryHDU(data=self.data, header=self.header) @@ -425,6 +434,24 @@ def main(): help="output zoomed FITS image") parser_zoom.set_defaults(func=cmd_zoom) + # sub-command: "flip" + parser_flip = subparsers.add_parser( + "flip", help="flip the image left-right or up-down") + parser_flip.add_argument("-C", "--clobber", action="store_true", + help="overwrite existing output file") + parser_flip.add_argument("-i", "--infile", required=True, + help="input FITS image") + parser_flip.add_argument("-o", "--outfile", required=True, + help="output flipped FITS image") + exgrp_flip = parser_flip.add_mutually_exclusive_group(required=True) + exgrp_flip.add_argument("-l", "--left-right", dest="lr", + action="store_true", + help="flip in the left/right direction") + exgrp_flip.add_argument("-u", "--up-down", dest="ud", + action="store_true", + help="flip in the left/right direction") + parser_flip.set_defaults(func=cmd_flip) + args = parser.parse_args() args.func(args) |