|
2 | 2 | import sys |
3 | 3 | import logging |
4 | 4 | import Crasa.Crasa as crasa |
5 | | - |
6 | | -sys.path.append("/scratch/stimela") |
7 | | - |
8 | | -utils = __import__('utils') |
| 5 | +from casacore.tables import table |
| 6 | +import numpy |
| 7 | +import glob |
| 8 | +import yaml |
| 9 | +import shutil |
9 | 10 |
|
10 | 11 | CONFIG = os.environ["CONFIG"] |
11 | 12 | INPUT = os.environ["INPUT"] |
12 | 13 | OUTPUT = os.environ["OUTPUT"] |
13 | 14 | MSDIR = os.environ["MSDIR"] |
14 | 15 |
|
15 | | -cab = utils.readJson(CONFIG) |
| 16 | +with open(CONFIG, "r") as _std: |
| 17 | + cab = yaml.safe_load(_std) |
| 18 | + |
| 19 | +junk = cab["junk"] |
16 | 20 |
|
17 | 21 | args = {} |
18 | 22 | for param in cab['parameters']: |
|
25 | 29 | args[name] = value |
26 | 30 |
|
27 | 31 | task = crasa.CasaTask(cab["binary"], **args) |
28 | | -task.run() |
| 32 | +try: |
| 33 | + task.run() |
| 34 | +finally: |
| 35 | + for item in junk: |
| 36 | + for dest in [OUTPUT, MSDIR]: # these are the only writable volumes in the container |
| 37 | + items = glob.glob("{dest}/{item}".format(**locals())) |
| 38 | + for f in items: |
| 39 | + if os.path.isfile(f): |
| 40 | + os.remove(f) |
| 41 | + elif os.path.isdir(f): |
| 42 | + shutil.rmtree(f) |
| 43 | + # Leave other types |
| 44 | + |
| 45 | +gtab = args["caltable"] |
| 46 | +if not os.path.exists(gtab): |
| 47 | + raise RuntimeError("The gaintable was not created. Please refer to CASA {0:s} logfile for further details".format(cab["binary"])) |
| 48 | + |
| 49 | +tab = table(gtab) |
| 50 | +field_ids = numpy.unique(tab.getcol("FIELD_ID")) |
| 51 | +tab.close() |
| 52 | + |
| 53 | +tab = table(gtab+"::FIELD") |
| 54 | +field_names = tab.getcol("NAME") |
| 55 | +tab.close() |
| 56 | + |
| 57 | +field_in = args["field"].split(",") |
| 58 | + |
| 59 | +try: |
| 60 | + ids = map(int, field_in) |
| 61 | +except ValueError: |
| 62 | + ids = map(lambda a: field_names.index(a), field_in) |
| 63 | + |
| 64 | +if not set(ids).intersection(field_ids): |
| 65 | + raise RuntimeError("None of the fields has solutions after the calibration. Please refer to CASA the {} logfile for further details".format(cab["binary"])) |
0 commit comments