Skip to content

Commit 25c24fe

Browse files
bennahugoratt-priv-ciSpheMakh
authored
fixes polcal 47 (#619)
Co-authored-by: bennahugo <bennahugo@aol.com> Co-authored-by: Sphesihle Makhathini <sphemakh@gmail.com>
2 parents f98ad15 + 9dec814 commit 25c24fe

1 file changed

Lines changed: 43 additions & 6 deletions

File tree

  • stimela/cargo/cab/casa47_polcal/src

stimela/cargo/cab/casa47_polcal/src/run.py

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@
22
import sys
33
import logging
44
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
910

1011
CONFIG = os.environ["CONFIG"]
1112
INPUT = os.environ["INPUT"]
1213
OUTPUT = os.environ["OUTPUT"]
1314
MSDIR = os.environ["MSDIR"]
1415

15-
cab = utils.readJson(CONFIG)
16+
with open(CONFIG, "r") as _std:
17+
cab = yaml.safe_load(_std)
18+
19+
junk = cab["junk"]
1620

1721
args = {}
1822
for param in cab['parameters']:
@@ -25,4 +29,37 @@
2529
args[name] = value
2630

2731
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

Comments
 (0)