-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecute_sim.py
More file actions
89 lines (60 loc) · 3.9 KB
/
execute_sim.py
File metadata and controls
89 lines (60 loc) · 3.9 KB
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
83
84
85
86
#run entire simulation in one go!!!
#this code is called by app.py, primarilly it calls initparam.py which sets directories up and then runs each run.py file created
import sys
import imp
from numpy import *
import os
import subprocess
import pdb
###primary running directory
#pathname='/Users/suresh/Source/wifis_simulator/' #string
#pathname='/home/miranda/files/GitHub_files/wifis_simulator/' #for miranda's computer ;)
pathname='/Users/miranda/Public/wifis_simulator/'
##make change current path to run_files directory (needed to run initparam.py
path=os.path.abspath(pathname+'run_files/')
sys.path.append(path)
#read in system variables provided from app.py, stored for now as strings in sys.argv
###sort into sets for ease of pushing to initparam.py, each set has one variable which has the name of each parameter and one which has the calue of each parameter as a string
###if multiple values given for a parameter it is given as a string with commas seperating different entries, split this string into list (in this case have lists as entries in list)
#denotes which files to save
savename=['SAVE_OBJCUBE','SAVE_PSFCUBE','SAVE_IND']
savestuff=[(sys.argv[1]),(sys.argv[2]),(sys.argv[3])]
#denotes basic properties of observation
basicname=['INT_SKY','INT_SCI','NFRAMES_SCI','NFRAMES_SKY']
basicstuff=[(sys.argv[5]).split(','),(sys.argv[6]).split(','),(sys.argv[7]).split(','),(sys.argv[8]).split(',')]
#denotes properties of objects to observe
objectstuff=[(sys.argv[10]).split(','),(sys.argv[11]).split(','),(sys.argv[12]).split(','),(sys.argv[13]).split(','),(sys.argv[14]).split(','),(sys.argv[15]).split(','),(sys.argv[16]).split(','),(sys.argv[17]).split(','),(sys.argv[18]).split(','),(sys.argv[19]).split(','),(sys.argv[20]).split(','),(sys.argv[21]).split(',')]
objectname=['MJ','SPEC','LABEL','TYPE','v1_1','v1_2','v4','v5','v6','v7','v9','v10']
directory=sys.argv[4] #this one isn't in a grouping
psffwhm=(sys.argv[9]).split(',') #neither is this
#*************all values still strings***************
#calculate how many runs will result from parameters given
nruns=len(basicstuff[0])*len(basicstuff[1])*len(basicstuff[2])*len(basicstuff[3])
#import initparam.py
import initparam
#run initparam, piping the necissary variables
initparam.constructParam(pathname+'basis_top.param',directory,nruns,psffwhm,objectstuff,basicstuff,objectname,basicname,savestuff,savename) ##will need to take in the directory name as well will also need to work out how many runs from user input, how many psf's too? maybe later don't want to write psf.param files so how to figure out how many times to do it with what values
##open the progress log
log=open(pathname+'runs/'+directory+'/supplements/progress', "a")
###run run.script, does all the runs set up by initparam)
subprocess.call([pathname+'runs/'+directory+'/run.script'],shell=1,executable='/bin/bash')
#delete files that we don't want to pass to the user (python codes, parameter files, run script . . .)
#subprocess.Popen(['find '+pathname+directory+'/ -type f \( -name "*.param" -o -name "*.py" -o -name "*.script" -o -name "*.paramc" \) -delete'],shell=1,executable='/bin/bash')
#change active path out of run_files
path=os.path.abspath(pathname+'/')
sys.path.append(path)
#make results directory
os.makedirs('../runs/'+directory+'/results')
subprocess.Popen(['find '+pathname+'runs/'+directory+' -name \'sky_*.fits\' -exec cp {} '+pathname+'runs/'+directory+'/results \\;'],shell=1,executable='/bin/bash')
#do analysis and save images
#go to right dir
path=os.path.abspath(pathname+'analysis/')
sys.path.append(path)
#import code
from analysis import *
#do it
doAnalysis(pathname+'runs/',directory,nruns)
#tar the directory that the simulations were in so the user can download it
subprocess.call(['tar','-cvf',pathname+'runs/'+directory+'/'+directory+'.tar', '../runs/'+directory+'/results/'])
#write done message to progress log
log.write('All Simulations Complete, files now available for download')