diff options
author | Aaron LI <aly@aaronly.me> | 2018-10-31 22:06:57 +0800 |
---|---|---|
committer | Aaron LI <aly@aaronly.me> | 2018-10-31 22:06:57 +0800 |
commit | a88b5bd561d5c09f053e29c40561423ba4c4e3d0 (patch) | |
tree | 625cd89e14509ce304ead845bdca40e60e6f7944 | |
parent | 8b5ee2468d2bdbaacf841487176b2a5e670dffb4 (diff) | |
download | fg21sim-a88b5bd561d5c09f053e29c40561423ba4c4e3d0.tar.bz2 |
bin/get-healpix-path: Check outfile existence early
-rwxr-xr-x | bin/get-healpix-patch | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/bin/get-healpix-patch b/bin/get-healpix-patch index e228962..a4dd1a4 100755 --- a/bin/get-healpix-patch +++ b/bin/get-healpix-patch @@ -23,18 +23,18 @@ def main(): description="Extract a patch from the all-sky HEALPix map") parser.add_argument("-C", "--clobber", action="store_true", help="overwrite the existing output files") - parser.add_argument("-c", "--config", dest="config", required=False, + parser.add_argument("-c", "--config", required=False, help="fg21sim configuration from which to " + "obtain the sky patch properties") - parser.add_argument("--center", dest="center", + parser.add_argument("--center", help="center coordinate of the sky patch; " + "format: ra,dec; unit: deg") - parser.add_argument("--size", dest="size", + parser.add_argument("--size", help="size of the sky patch; " + "format: xsize,ysize; unit: pixel") - parser.add_argument("--pixelsize", dest="pixelsize", type=float, + parser.add_argument("--pixelsize", type=float, help="pixel size of the sky patch; unit: [arcsec]") - parser.add_argument("-S", "--smooth", dest="smooth", action="store_true", + parser.add_argument("-S", "--smooth", action="store_true", help="Smooth the output patch with a Gaussian " + "filter of sigma 'sigma-npix' (next argument) " + "pixel size of the input HEALPix map") @@ -50,6 +50,13 @@ def main(): logger = logging.getLogger(tool) logger.info("COMMAND: {0}".format(" ".join(sys.argv))) + if os.path.exists(args.outfile): + if args.clobber: + os.remove(args.outfile) + logger.warning("Removed existing output file: %s" % args.outfile) + else: + raise FileExistsError("Output file exists: %s" % args.outfile) + logger.info("Importing necessary modules, waiting ...") import scipy.ndimage import healpy as hp @@ -116,7 +123,7 @@ def main(): sky.merge_header(hpheader.copy(strip=True)) sky.add_history(" ".join(sys.argv)) sky.data = image - sky.write(args.outfile, clobber=args.clobber) + sky.write(args.outfile) logger.info("Written extracted sky patch to file: %s" % args.outfile) |