diff options
author | Aaron LI <aly@aaronly.me> | 2017-09-13 08:45:43 +0800 |
---|---|---|
committer | Aaron LI <aly@aaronly.me> | 2017-09-13 08:46:23 +0800 |
commit | a39f3f91b566f43fde5147c327ab6d725c1a92b1 (patch) | |
tree | 683cd16f3634984c6715d2b91825541c27be7b9f /astro | |
parent | 4c6702d5ea1375e7524ce9182f734eb4f6485580 (diff) | |
download | atoolbox-a39f3f91b566f43fde5147c327ab6d725c1a92b1.tar.bz2 |
run_oskar.py: Add argument --chunk-size; Update --vis-oskar
* Add argument --chunk-size: overwrite the max sources per chunk in the
configuration file
* Remove argument --no-vis-ms
* Change argument --no-vis-oskar to --vis-oskar
* Change argument --dryrun to --dry-run
Diffstat (limited to 'astro')
-rwxr-xr-x | astro/oskar/run_oskar.py | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/astro/oskar/run_oskar.py b/astro/oskar/run_oskar.py index 8cbfab2..0d1ebae 100755 --- a/astro/oskar/run_oskar.py +++ b/astro/oskar/run_oskar.py @@ -15,26 +15,34 @@ import shutil from time import time -def run_oskar(configfile, model, freq, vis_oskar, vis_ms, - telescope=None, dryrun=False): - if vis_oskar is None and vis_ms is None: +def run_oskar(configfile, model, freq, vis_ms, vis_oskar=None, + telescope=None, chunksize=None, dryrun=False): + """ + Update simulation settings in the configuration file, + and run the simulator ``oskar_sim_interferometer``. + """ + if chunksize is not None: + chunksize = int(chunksize) + if vis_ms is None and vis_oskar is None: raise ValueError("both 'vis_oskar' & 'vis_ms' are missing") - prog = "oskar_sim_interferometer" print("Update simulation settings ...") + simulator = "oskar_sim_interferometer" for item, value in [ + ("simulator/max_sources_per_chunk", chunksize), ("sky/oskar_sky_model/file", model), ("telescope/input_directory", telescope), ("observation/start_frequency_hz", str(freq*1e6)), ("interferometer/oskar_vis_filename", vis_oskar), ("interferometer/ms_filename", vis_ms)]: if value is not None: - subprocess.check_call([prog, "--set", configfile, item, value]) + subprocess.check_call([simulator, "--set", + configfile, item, value]) print("Updated '%s' -> '%s'" % (item, value)) print("-------------------------------------------------------------") print("Simulating %s @ %.2f [MHz] ..." % (model, freq)) - cmd = [prog, configfile] + cmd = [simulator, configfile] if dryrun: print("Dry run mode!") print("CMD: %s" % " ".join(cmd)) @@ -49,7 +57,7 @@ def run_oskar(configfile, model, freq, vis_oskar, vis_ms, def main(): default_fconfig = "sim_interferometer.f{freq:06.2f}.ini" parser = argparse.ArgumentParser() - parser.add_argument("-d", "--dryrun", dest="dryrun", action="store_true", + parser.add_argument("-d", "--dry-run", dest="dryrun", action="store_true", help="dry run") parser.add_argument("-c", "--config", dest="config", required=True, help="OSKAR base/common configuration file") @@ -58,12 +66,11 @@ def main(): help="filename pattern of the configuration files " + "updated for OSKAR usage " + "(default: %s)" % default_fconfig) - parser.add_argument("--no-vis-oskar", dest="no_vis_oskar", + parser.add_argument("-S", "--chunk-size", dest="chunk_size", type=float, + help="overwrite the chunk size in config file") + parser.add_argument("--vis-oskar", dest="vis_oskar", action="store_true", - help="not save visibility in OSKAR native format") - parser.add_argument("--no-vis-ms", dest="no_vis_ms", - action="store_true", - help="not save visibility in MeasurementSet format") + help="also save visibility in OSKAR native format") parser.add_argument("-t", "--telescope", dest="telescope", help="overwrite the telescope model in config file") parser.add_argument("-o", "--outdir", dest="outdir", @@ -96,20 +103,17 @@ def main(): print("[%d/%d] %s @ %.2f [MHz]" % (i+1, Nosm, skyfile, freq)) print("-------------------------------------------------------------") basename = os.path.splitext(os.path.basename(skyfile))[0] - if args.no_vis_oskar: - vis_oskar = "" - else: + if args.vis_oskar: vis_oskar = os.path.join(args.outdir, basename+".oskar") - if args.no_vis_ms: - vis_ms = "" else: - vis_ms = os.path.join(args.outdir, basename+".ms") + vis_oskar = None + vis_ms = os.path.join(args.outdir, basename+".ms") configfile = args.fconfig.format(freq=freq) shutil.copy(args.config, configfile) print("Copied OSKAR configuration file as: %s" % configfile) run_oskar(configfile=configfile, freq=freq, - model=skyfile, telescope=args.telescope, - vis_oskar=vis_oskar, vis_ms=vis_ms, + model=skyfile, vis_ms=vis_ms, vis_oskar=vis_oskar, + telescope=args.telescope, chunksize=args.chunksize, dryrun=args.dryrun) t2 = time() |