-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_dolphot.py
executable file
·99 lines (87 loc) · 3.66 KB
/
run_dolphot.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
#! /usr/bin/env python
import argparse,os,subprocess
from wpipe import *
from shutil import which
def register(PID,task_name):
myPipe = Pipeline.get(PID)
myTask = Task(task_name,myPipe).create()
_t = Task.add_mask(myTask,'*','start','*')
_t = Task.add_mask(myTask,'*','parameters_written','*')
return
def run_dolphot(job_id,event_id,dp_id):
myJob = Job.get(job_id)
myPipe = Pipeline.get(int(myJob.pipeline_id))
paramDP = DataProduct.get(int(dp_id))
myTarget = Target.get(int(paramDP.target_id))
myConfig = Configuration.get(int(paramDP.config_id))
myParams = Parameters.getParam(int(myConfig.config_id))
targname = myTarget['name']
outfile = targname+'.phot'
logfile = outfile+".log"
dolphot_path = which('wfirstmask')
dolphot_path = dolphot_path[:-10]
dolphot = dolphot_path+"dolphot"
parameter_file = paramDP.relativepath+'/'+paramDP.filename
subprocess.run([dolphot,outfile," -p"+parameter_file," >",myConfig.logpath+'/'+logfile],cwd=myConfig.procpath)
def hyak_dolphot(job_id,event_id,dp_id):
myJob = Job.get(job_id)
myPipe = Pipeline.get(int(myJob.pipeline_id))
paramDP = DataProduct.get(int(dp_id))
parameter_file = paramDP.relativepath+'/'+paramDP.filename
myTarget = Target.get(int(paramDP.target_id))
myConfig = Configuration.get(int(paramDP.config_id))
myParams = Parameters.getParam(int(myConfig.config_id))
targname = myTarget['name']
outfile = targname+'.phot'
logfile = outfile+".log"
dolphot_path = which('wfirstmask')
dolphot_path = dolphot_path[:-10]
dolphot = dolphot_path+"dolphot"
slurmfile = parameter_file+'.slurm'
with open(slurmfile, 'w') as f:
f.write('#!/bin/bash' + '\n'+
'## Job Name' + '\n'+
'#SBATCH --job-name=dolphot_'+str(dp_id)+ '\n'+
'## Allocation Definition ' + '\n'+
'#SBATCH --account=astro' + '\n'+
'#SBATCH --partition=astro' + '\n'+
'## Resources' + '\n'+
'## Nodes' + '\n'+
'#SBATCH --ntasks=1' + '\n'+
'## Walltime (3 hours)' + '\n'+
'#SBATCH --time=100:00:00' + '\n'+
'## Memory per node' + '\n'+
'#SBATCH --mem=10G' + '\n'+
'## Specify the working directory for this job' + '\n'+
'#SBATCH --workdir='+myConfig.procpath + '\n'+
'##turn on e-mail notification' + '\n'+
dolphot+" "+outfile+" -p"+parameter_file+" >"+myConfig.logpath+'/'+logfile)
subprocess.run(['sbatch',slurmfile],cwd=myConfig.procpath)
def create_target(a=''):
pass
def parse_all():
parser = argparse.ArgumentParser()
parser.add_argument('--R','-R', dest='REG', action='store_true',
help='Specify to Register')
parser.add_argument('--P','-p',type=int, dest='PID',
help='Pipeline ID')
parser.add_argument('--N','-n',type=str, dest='task_name',
help='Name of Task to be Registered')
parser.add_argument('--E','-e',type=int, dest='event_id',
help='Event ID')
parser.add_argument('--J','-j',type=int, dest='job_id',
help='Job ID')
parser.add_argument('--DP','-dp',type=int, dest='dp_id',
help='Dataproduct ID')
return parser.parse_args()
if __name__ == '__main__':
args = parse_all()
if args.REG:
_t = register(args.PID,args.task_name)
else:
job_id = int(args.job_id)
event_id = int(args.event_id)
event = Event.get(event_id)
dp_id = Options.get('event',event_id)['dp_id']
hyak_dolphot(job_id,event_id,dp_id)
#run_dolphot(job_id,event_id,dp_id)