-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainTimeWindowLC.py
108 lines (87 loc) · 2.72 KB
/
mainTimeWindowLC.py
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import os, sys
import yaml
import numpy
from matplotlib import pyplot
from xml.dom import minidom
import time
import subprocess
import glob
import json
from matplotlib.ticker import MaxNLocator
from astropy.time import Time
CHOICE = int(sys.argv[1]) # 0:run LC, 1: draw LC
# start and end of the mission
mintime = 239557417 # 2008-08-04T15:43:33.000
maxtime = 528835414.0 #492018214 # 2016-08-04T15:43:59.600
def make_yaml(baseYaml, nname):
d = yaml.load(open(baseYaml))
d['selection']['target'] = nname
outputyaml = '%s/%s.yaml'%(ndir,nname.replace(' ','_'))
print outputyaml
stream = file(outputyaml, 'w')
yaml.dump(d,stream)
return outputyaml
def make_run(baseRun, outname):
fbase = open(baseRun,'r')
fbaseL = fbase.read()
fbase.close()
fnew = open(outname,'w')
fnew.write(fbaseL) # .replace('novaname',nname))
fnew.close()
# read list of novae
filename = "/nfs/farm/g/glast/u/afrancko/software/blazarFlares/sourceList.txt"
f = open(filename)
fl = f.readlines()
f.close()
outdir = "/u/gl/afrancko/workdir/software/blazarFlares/blazars"
scriptPath = "/u/gl/afrancko/workdir/software/blazarFlares/lcpipe"
baseYaml = "%s/base.yaml"%scriptPath
baseRun = "%s/runLC.py"%scriptPath
nsubmit = 0
STARTFRESH = False
# loop over sources
for n in fl:
# skip lines that are commented out
if n[0] == "#":
continue
# read values for novae
nname = n.replace('\n','')
# create directory for novae
ndir = "%s/%s"%(outdir,nname.replace(' ','_'))
os.system("mkdir -p %s"%(ndir))
if STARTFRESH:
print "remove srcmdl fit files"
cmd = 'rm %s/*.fits'%ndir
print cmd
os.system(cmd)
cmd = 'rm %s/srcmdl*.xml'%ndir
print cmd
os.system(cmd)
cmd = 'rm %s/*.par'%ndir
print cmd
os.system(cmd)
# place a modified config file in each time bin directory
yamlFile = '%s/%s.yaml'%(ndir,nname.replace(' ','_'))
print "make yaml"
yamlFile = make_yaml(baseYaml, nname)
logFile = yamlFile.replace('.yaml','.log')
if CHOICE == 0:
nJobs = subprocess.check_output(["bjobs"]).count('afranck')
while (True):
nJobs = subprocess.check_output(["bjobs"]).count('afranck')
print "number of jobs ", nJobs
if nsubmit%30==0 and nsubmit>0:
print "submitted 30. Wait 30 sec."
time.sleep(30)
if nJobs>600:
print "wait 10 sec"
time.sleep(10)
else:
break
cmd = 'bsub -W 1500 -n 4 -R "span[ptile=4]" -o %s python %s "%s" %s'%(logFile, baseRun, nname, yamlFile)
print cmd
print "nsubmit ", nsubmit
nsubmit += 1
os.system(cmd)
#exit()
print "totel nsubmit ", nsubmit