Skip to content

Commit 9e01b72

Browse files
committed
Merge branch 'master' of github.com:sphemakh/Penthesilea
2 parents 87d4937 + c967b3f commit 9e01b72

13 files changed

Lines changed: 283 additions & 67 deletions

File tree

README.md

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,28 @@ Each of these executor images has an execution script (generally a pyxis script)
3535

3636

3737

38-
39-
40-
4138
## Requires
4239
* [Docker](http://docs.docker.com/)
4340
* Python
4441

4542
## Install
43+
For a system wide install run (requires sudo powers) :
4644
```
4745
pip install penthesilea
4846
```
47+
Alternatively, you can do a local install by enbabling the `--user` flag
48+
```
49+
pip install penthesilea --user
50+
```
51+
This will install the binaries in `$HOME/.local/bin` and the python packages at `$HOME/.local/lib//python2.7/site-packages`. Finally, add these paths to your *PATH* and *PYTHONPATH* respectively.
52+
On my bash shell I add the following to `$HOME/.bashrc` (you do you):
4953

50-
Or
54+
```
55+
export PATH=$PATH:$HOME/.local/bin
56+
export PYTHONPATH=$PYTHONPATH:$HOME/.local/lib//python2.7/site-package
57+
```
58+
59+
**Or**
5160

5261
Download the repo.
5362
```
@@ -57,13 +66,56 @@ Then install
5766
```
5867
cd Penthesilea
5968
python setup.py install
60-
penthesilea -pull # This will take some time
61-
penthesilea -build
6269
```
70+
Similarly, you can add the `--user` to `setup.py` flag to do a local install.
6371

6472
## Uninstall
6573
```
6674
pip uninstall penthesilea
6775
```
6876

69-
See the [wiki](../../wiki/) for tutorials.
77+
## For Mac Users
78+
79+
**Prerequisites**
80+
- install docker for Mac OS X (https://docs.docker.com/v1.8/installation/mac/)
81+
82+
- open a terminal and do the following commands:
83+
84+
```
85+
docker-machine env default
86+
eval "$(docker-machine env default)"
87+
```
88+
89+
This will set up the default docker environment (report to the documentation for user specific environment settings)
90+
91+
92+
Using docker on a Mac requires a particular setup and has some limitations
93+
- Mac OS does not allow folders not owned by the host user to be mounted onto containers. So, on a Mac you have to do the local install.
94+
95+
- Also, Casacore is known to have I/O issues when trying to read/write a file in a mounted volume on a Mac OS host (see Issue
96+
[#5](https://github.com/SpheMakh/Penthesilea/issues/5)).
97+
98+
So every I/O operation require additional data management to transfer the files in and out. If you are using a Mac you will have tell penthesilea that. Do this by enabling the `mac_os` flag in the *Pipeline* instance when writing your penthesilea script.
99+
100+
```
101+
from otrera import Pipeline
102+
Pipeline("The one pipeline to rule them all", ..., mac_os=True)
103+
```
104+
105+
## Building Penthesilea infrastructure
106+
As mentioned earlier, penthesilea is based on Docker. And before you start scripting penthesilea pipelines you first need to either build or pull the neccessary Docker images (base images). To pull the images from the Docker hub:
107+
```
108+
penthesilea pull
109+
```
110+
or build them locally
111+
```
112+
penthesilea -build-base
113+
```
114+
115+
Then finally, build the executor images
116+
```
117+
penthesilea -build
118+
```
119+
120+
121+
See the [wiki](../../wiki/) for tutorials.

examples/simulation_pipeline.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,26 @@
2020

2121

2222
# start oterera instance
23-
pipeline = Pipeline("Simulation Example", CONFIGS, data=DATA, ms_dir=MSDIR)
23+
pipeline = Pipeline("Simulation Example", CONFIGS, data=DATA, ms_dir=MSDIR, mac_os=True)
2424

2525
# Make empty MS
2626
simms_dict = pipeline.readJson(simms_template)
2727
simms_dict["msname"] = MS
2828
simms_dict["telescope"] = "meerkat"
29+
simms_dict["synthesis"] = 0.5
30+
simms_dict["direction"] = "J2000,90deg,-45deg"
31+
simms_dict["dtime"] = 60
32+
simms_dict["freq0"] = "750MHz"
33+
simms_dict["dfreq"] = "1MHz"
34+
simms_dict["nchan"] = 10
2935
pipeline.add("ares/simms", "simms_example", simms_dict, input=INPUT, output=OUTPUT,
3036
label="Creating MS")
3137

3238
# Simulate visibilities into it
3339
simulator_dict = pipeline.readJson(simulator_template)
3440
simulator_dict["msname"] = MS
41+
simulator_dict["addnoise"] = True
42+
simulator_dict["sefd"] = 831
3543
simulator_dict["skymodel"] = LSM
3644
pipeline.add("ares/simulator", "simulator_example", simulator_dict, input=INPUT, output=OUTPUT,
3745
label="Simulating visibilities")
@@ -42,8 +50,9 @@
4250

4351
imager_dict = pipeline.readJson(imager_template)
4452
imager_dict["weight"] = "briggs"
53+
imager_dict["imager"] = "wsclean"
4554
imager_dict["clean_iterations"] = 1000
46-
briggs_robust = 2,0,-2
55+
briggs_robust = 2, 0, -2
4756
prefix = imager_dict["imageprefix"]
4857

4958
for i, robust in enumerate(briggs_robust):

otrera/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from pipeliner import Pipeline
22
import os
33

4-
__version__ = "0.0.4"
4+
__version__ = "0.0.5"
55

otrera/pipeliner.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,29 @@
55
import sys
66
from otrera import penthesilea_docker as docker
77
import otrera.utils as utils
8+
import penthesilea
89
import tempfile
10+
import time
11+
12+
13+
ekhaya = penthesilea.__path__[0]
14+
15+
CONFIGS_ = {
16+
"ares/simms" : "{:s}/configs/simms_params.json".format(ekhaya),
17+
"ares/simulator" : "{:s}/configs/simulator_params.json".format(ekhaya),
18+
"ares/imager" : "{:s}/configs/imager_params.json".format(ekhaya),
19+
"ares/predict" : "{:s}/configs/simulator_params.json".format(ekhaya),
20+
"ares/calibrator" : "{:s}/configs/calibrator_params.json".format(ekhaya),
21+
"ares/sourcery" : "{:s}/configs/sourcery_params.json".format(ekhaya),
22+
"ares/flagms" : "{:s}/configs/flagms_params.json".format(ekhaya),
23+
"ares/autoflagger" : "{:s}/configs/autoflagger_params.json".format(ekhaya),
24+
"ares/subtract" : "{:s}/configs/subtract_params.json".format(ekhaya)
25+
}
26+
927

1028
class Pipeline(object):
1129

12-
def __init__(self, name, configs, data, ms_dir=None):
30+
def __init__(self, name, configs, data, ms_dir=None, mac_os=False):
1331

1432
self.name = name
1533
self.log = utils.logger(0,
@@ -21,6 +39,7 @@ def __init__(self, name, configs, data, ms_dir=None):
2139
self.data_path = data
2240
self.configs_path_container = "/configs"
2341
self.otrera_path = os.path.dirname(docker.__file__)
42+
self.MAC_OS = mac_os
2443

2544
self.ms_dir = ms_dir
2645
if ms_dir:
@@ -30,14 +49,19 @@ def __init__(self, name, configs, data, ms_dir=None):
3049

3150
def add(self, image, name, config,
3251
input=None, output=None, label="",
33-
build_first=False, build_dest=None, saveconf=None):
52+
build_first=False, build_dest=None,
53+
saveconf=None, add_time_stamp=True):
3454

3555
if build_first and build_dest:
3656
self.build(image, build_dest)
3757

58+
if add_time_stamp:
59+
name = "%s-%s"%(name, str(time.time()).replace(".",""))
3860

3961
cont = docker.Load(image, name, label=label, logger=self.log)
4062

63+
cont.add_environ("MAC_OS", str(self.MAC_OS))
64+
4165
# add standard volumes
4266
cont.add_volume(self.otrera_path, "/utils", perm="ro")
4367
cont.add_volume(self.data_path, "/data", perm="ro")
@@ -67,7 +91,11 @@ def add(self, image, name, config,
6791
confname_container = "%s/%s"%(self.configs_path_container,
6892
os.path.basename(saveconf))
6993

70-
utils.writeJson(saveconf, config)
94+
95+
template = utils.readJson(CONFIGS_[image])
96+
template.update(config)
97+
utils.writeJson(saveconf, template)
98+
7199
config = confname_container
72100
cont.add_volume("configs", self.configs_path_container, perm="ro")
73101
else:

penthesilea/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import os
22
import otrera
33

4-
__version__ = otrera.__version__
4+
#__version__ = otrera.__version__
55

6-
ekhaya = os.path.dirname(__file__)
6+
ekhaya = __path__[0]
77
STABLE_TAG = "stable.11.15"
88

99
# Path to base images
@@ -16,4 +16,5 @@
1616
PENTHESILEA_DATA = "{:s}/data".format(ekhaya)
1717

1818
# Path to config templates
19-
PENTHESILEA_CONFIG_TEMPLATES = "{:s}/configs".format(ekhaya)
19+
PENTHESILEA_CONFIG_TEMPLATES = configs = "{:s}/configs".format(ekhaya)
20+

penthesilea/ares/imager/src/pyxis-run.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,19 @@
88

99

1010
INDIR = os.environ["INPUT"]
11-
v.OUTDIR = os.environ["OUTPUT"]
1211
CONFIG = os.environ["CONFIG"]
1312
MSDIR = os.environ["MSDIR"]
13+
MAC_OS = os.environ["MAC_OS"]
14+
15+
if MAC_OS.lower() in ["yes", "true", "yebo", "1"]:
16+
MAC_OS = True
17+
else:
18+
MAC_OS = False
19+
20+
output = "./temp-output-xaba"
21+
v.OUTDIR = output if MAC_OS else os.environ["OUTPUT"]
22+
outdir = os.environ["OUTPUT"]
23+
1424
v.DESTDIR = "."
1525

1626
OUTFILE_Template = "${OUTDIR>/}results-${MS:BASE}"
@@ -79,3 +89,6 @@ def azishe():
7989
restore_lsm=False, psf=psf,
8090
channelize=channelise,
8191
**options)
92+
93+
if MAC_OS:
94+
x.sh("mv $output/* $outdir")

penthesilea/ares/simms/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ RUN mkdir -p /output /input
66
ADD src /code
77
WORKDIR /code
88

9-
CMD sh run.sh
9+
CMD python run.py

penthesilea/ares/simms/src/run.py

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import os
2+
import sys
3+
import json
4+
import pyfits
5+
import codecs
6+
7+
sys.path.append("/utils")
8+
import utils
9+
10+
CONFIG = os.environ["CONFIG"]
11+
INDIR = os.environ["INPUT"]
12+
MSDIR = os.environ["MSDIR"]
13+
MAC_OS = os.environ["MAC_OS"]
14+
15+
if MAC_OS.lower() in ["yes", "true", "yebo", "1"]:
16+
MAC_OS = True
17+
else:
18+
MAC_OS = False
19+
20+
outfile = "temp.json"
21+
22+
_ANTENNAS = {
23+
"meerkat": "meerkat.itrf.txt",
24+
"kat-7": "kat-7.itrf.txt",
25+
"jvlaa": "vlaa.itrf.txt",
26+
"jvlab": "vlab.itrf.txt",
27+
"jvlac": "vlac.itrf.txt",
28+
"jvlad": "vlad.itrf.txt",
29+
"wsrt": "wsrt.itrf.txt",
30+
"ska1mid254": "skamid254.itrf.txt",
31+
"ska1mid197": "skamid197.itrf.txt",
32+
}
33+
34+
_OBS = {
35+
"meerkat": "meerkat",
36+
"kat-7": "kat-7",
37+
"jvlaa": "vla",
38+
"jvlab": "vla",
39+
"jvlac": "vla",
40+
"jvlad": "vla",
41+
"wsrt": "wsrt",
42+
"ska1mid254": "meerkat",
43+
"ska1mid197": "meerkat",
44+
}
45+
46+
47+
48+
def readJson(conf):
49+
50+
with open(conf) as _std:
51+
jdict = json.load(_std)
52+
53+
out = {}
54+
55+
for key,val in jdict.iteritems():
56+
57+
if isinstance(val, unicode):
58+
val = str(val)
59+
60+
out[str(key)] = val
61+
62+
return out
63+
64+
65+
jdict = readJson(CONFIG)
66+
telescope = jdict["telescope"]
67+
68+
69+
jdict["outdir"] = "." if MAC_OS else MSDIR
70+
jdict["tel"] = _OBS[telescope]
71+
msname = jdict["msname"]
72+
73+
if jdict.get("antennas", False):
74+
jdict["pos"] = INDIR+"/"+jdict.get("antennas", "meetkat")
75+
jdict["coords"] = jdict.get("coord_sys", "enu")
76+
else:
77+
jdict["pos"] = "/data/observatories/"+_ANTENNAS[telescope]
78+
if not os.path.isdir(jdict["pos"]):
79+
jdict["pos_type"] = "ascii"
80+
jdict["coords"] = "itrf"
81+
82+
for item in ["antennas", "coord_sys", "telescope"]:
83+
jdict.pop(item, None)
84+
85+
imagename = jdict.pop("skymodel", False)
86+
87+
if jdict.pop("predict", False) and imagename:
88+
89+
for item in [INDIR, "/data/skymodels"]:
90+
_imagename = "{:s}/{:s}".format(item, imagename)
91+
if os.path.exists(_imagename):
92+
break
93+
94+
imagename = _imagename
95+
96+
with pyfits.open(imagename) as hdu:
97+
hdr = hdu[0].header
98+
99+
freq = filter(lambda ind: hdr["ctype%d"%ind].startswith("FREQ"),
100+
range(2, 5, 1))
101+
if freq:
102+
freq = freq[0]
103+
else:
104+
raise TypeError("Your FITS image has no frequency information")
105+
106+
nchan = hdr["naxis%d"%freq]
107+
freq0 = hdr["crval%d"%freq]
108+
dfreq = hdr["cdelt%d"%freq]
109+
110+
jdict["freq0"] = freq0
111+
jdict["dfreq"] = dfreq
112+
jdict["nchan"] = nchan
113+
114+
with codecs.open(outfile, "w", "utf8") as std:
115+
std.write( json.dumps(jdict, ensure_ascii=False) )
116+
117+
# Run simms
118+
utils.xrun("simms", ["-jc", outfile])
119+
120+
# move to
121+
if MAC_OS:
122+
if os.path.exists("{:s}/{:s}".format(MSDIR, msname)):
123+
utils.xrun("rm", ["-fr", "{:s}/{:s}".format(MSDIR, msname)])
124+
utils.xrun("mv", [msname, MSDIR])

penthesilea/ares/simms/src/run.sh

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)