File: test_real_data.py

package info (click to toggle)
purify 5.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 186,836 kB
  • sloc: cpp: 17,731; python: 510; xml: 182; makefile: 7; sh: 6
file content (82 lines) | stat: -rw-r--r-- 2,333 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import os 
import multiprocessing
import time
import numpy as np 
import pyfits
import glob
import subprocess
import matplotlib.pyplot as plt


"""
Script that runs tests of purify on real data.
"""

nice_value = 0

home = os.path.expanduser("~")
stokes_v_calculation = False 
outpath = home + "/purify_real_data/"
if stokes_v_calculation:
	outpath = home + "/purify_real_data_v/"

data = home + "/Dropbox/Visibility_Files/"

atca = "atca/"
vla = "vla/"
names = [atca + "0332-391", atca + "0114-476", vla + "CygA-X", vla + "3C129BC"]
imsize = ["1024", "1024", "1024", "1024"]
cellsizes = ["2", "2", "0.5","0.4"]

residual_convergences = ["3700", "-1", "20000", "-1"]

def make_path(name, outpath, epsilon_factor):
	return outpath + name + "/" + str(epsilon_factor) + "/"

def make_directory(path):
	if not os.path.exists(path):
		os.makedirs(path)

def run_test((name, inpath, cellsize, size, epsilon_factor, residual_convergence)):
	path = make_path(name, outpath, epsilon_factor)
	noise = " "
	make_directory(path)
	if stokes_v_calculation == True:
		noise = " --noise " + inpath + ".ms "
        cmd = ["screen -S "+ name.split("/")[-1] + "_" + str(epsilon_factor) + 
		" -d -m ~/dev/purify/build/purify" +
		" --name " + path + name.split("/")[-1] +
		" --measurement_set " + inpath + ".ms --n_mean " + str(epsilon_factor) + 
		noise +
		" --cellsize " + cellsize +
		" --size " + str(size) +
		" --diagnostic --power_iterations 200" +
                " --residual_convergence " + residual_convergence +
                " --relative_variation 0.005" +
                " --adapt_iter 100" +
                " --niters 500" +
                " --relative_gamma_adapt 1e-3"
        ]
	proc = subprocess.Popen(cmd, shell=True)
        print cmd
	print "Waiting for " + path
	while not os.path.exists(path + name.split("/")[-1] + "_solution_whiten_final.fits"):
		time.sleep(10)
	return

params = []
for i in range(len(names)):
	i = 2
	n = names[i]
	print "Looking for " + data + n
	if os.path.exists(data + n + ".ms"):
		print n + " found!"
		image_size = imsize[i] 
		pix_size = cellsizes[i]
		params.append((n, data + n, pix_size, image_size, 7, residual_convergences[i]))
	else:
		print n + " not found!"
	break
n_processors = multiprocessing.cpu_count() + 1
p = multiprocessing.Pool(min(n_processors, 1))
p.map(run_test, params)