diff options
author | Aaron LI <aaronly.me@outlook.com> | 2015-12-12 23:01:02 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@outlook.com> | 2015-12-12 23:01:02 +0800 |
commit | 5c58e9e57523479aa55717b68cc43550ddb2dae6 (patch) | |
tree | 509492e568fc57cac7b6e05974ac3c1a09f8e80a /astro/marx/marx_pntsrc.py | |
parent | 9c16b8c465df5f2d2e3eb5ecc91f5069b3150474 (diff) | |
download | atoolbox-5c58e9e57523479aa55717b68cc43550ddb2dae6.tar.bz2 |
Add `randpoints.py` to generate point source informations
Diffstat (limited to 'astro/marx/marx_pntsrc.py')
-rwxr-xr-x | astro/marx/marx_pntsrc.py | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/astro/marx/marx_pntsrc.py b/astro/marx/marx_pntsrc.py index 31ffe49..97b1575 100755 --- a/astro/marx/marx_pntsrc.py +++ b/astro/marx/marx_pntsrc.py @@ -16,6 +16,7 @@ import sys import argparse import subprocess import re +import os def marx_pntsrc(pfile, ra, dec, flux, outdir): @@ -32,15 +33,40 @@ def marx_pntsrc(pfile, ra, dec, flux, outdir): def marxcat(indirs, outdir): """ Concatenate a list of MARX simulation results. + + Note: the number of MARX results to be concatenated at *one* time + can not be to many, otherwise the 'marxcat' tool will failed. """ if isinstance(indirs, list): - marxdirs = " ".join(indirs) + pass elif isinstance(indirs, str): - marxdirs = indirs + indirs = indirs.split() else: raise ValueError("invalid indirs type: %s" % indirs) - cmd = "marxcat %(marxdirs)s %(outdir)s" % \ - {"marxdirs": marxdirs, "outdir": outdir} + pid = os.getpid() + tempdir = "_marx_tmp%d" % pid + cmd = "cp -a %(marxdir)s %(tempdir)s" % \ + {"marxdir": indirs[0], "tempdir": tempdir} + print("CMD: %s" % cmd, file=sys.stderr) + subprocess.call(cmd, shell=True) + del indirs[0] + while len(indirs) > 0: + # concatenated 10 directories each time + catdirs = indirs[:9] + del indirs[:9] + catdirs = tempdir + " " + " ".join(catdirs) + # concatenate MARX results + cmd = "marxcat %(catdirs)s %(outdir)s" % \ + {"catdirs": catdirs, "outdir": outdir} + print("CMD: %s" % cmd, file=sys.stderr) + subprocess.call(cmd, shell=True) + # move output results to temporary directory + cmd = "rm -rf %(tempdir)s && mv %(outdir)s %(tempdir)s" % \ + {"tempdir": tempdir, "outdir": outdir} + print("CMD: %s" % cmd, file=sys.stderr) + subprocess.call(cmd, shell=True) + cmd = "mv %(tempdir)s %(outdir)s" % \ + {"tempdir": tempdir, "outdir": outdir} print("CMD: %s" % cmd, file=sys.stderr) subprocess.call(cmd, shell=True) @@ -78,7 +104,7 @@ def main(): ra, dec, flux = map(float, line.split()) print("INFO: ra = %g, dec = %g, flux = %g" % (ra, dec, flux), file=sys.stderr) - outdir = "%sp%02d" % (args.outprefix, i) + outdir = "%sp%03d" % (args.outprefix, i) print("INFO: outdir = %s" % outdir, file=sys.stderr) outdirs.append(outdir) marx_pntsrc(args.pfile, ra, dec, flux, outdir) |