| 1 | #! /usr/bin/env python |
|---|
| 2 | # Title: CTIP Mode A Workflow for AstroGrid |
|---|
| 3 | # Author: Dr Dugan Witherick, University College London |
|---|
| 4 | # Date: 8th April 2008 |
|---|
| 5 | # Usage: ctip-modea.py dayofyear f10.7 |
|---|
| 6 | # Example: ctip-modea.py 82 120 |
|---|
| 7 | |
|---|
| 8 | import sys, xmlrpclib, os, time |
|---|
| 9 | prefix = file(os.path.expanduser("~/.astrogrid-desktop")).next().rstrip() |
|---|
| 10 | acr = xmlrpclib.Server(prefix+"xmlrpc") |
|---|
| 11 | ag = acr.astrogrid |
|---|
| 12 | |
|---|
| 13 | dayofyear = 82 |
|---|
| 14 | f107 = 120 |
|---|
| 15 | kp = 27 |
|---|
| 16 | maxRefreshRate = 300 |
|---|
| 17 | refreshRate = 2 |
|---|
| 18 | |
|---|
| 19 | if len(sys.argv) == 3: |
|---|
| 20 | dayofyear = sys.argv[1] |
|---|
| 21 | f107 = sys.argv[2] |
|---|
| 22 | |
|---|
| 23 | print '#################################' |
|---|
| 24 | print '# #' |
|---|
| 25 | print '# CTIP Mode A #' |
|---|
| 26 | print '# #' |
|---|
| 27 | print '#################################' |
|---|
| 28 | print '' |
|---|
| 29 | print 'Using the following parameters:' |
|---|
| 30 | print '' |
|---|
| 31 | |
|---|
| 32 | ctipmodeaivo = "ivo://uk.ac.ral.ukssdc/CTIP/v1" |
|---|
| 33 | |
|---|
| 34 | userInfo = ag.community.getUserInformation() |
|---|
| 35 | saveFolder = userInfo['id']+"CTIP" |
|---|
| 36 | if ag.myspace.exists(saveFolder) == False: |
|---|
| 37 | ag.myspace.createFolder(saveFolder) |
|---|
| 38 | |
|---|
| 39 | ctipStruct = ag.applications.createTemplateStruct(ctipmodeaivo,'Simple') |
|---|
| 40 | |
|---|
| 41 | ctipStruct['input']['DayOfYear']['value'] = dayofyear |
|---|
| 42 | ctipStruct['input']['F10']['value'] = f107 |
|---|
| 43 | ctipStruct['input']['KP']['value'] = kp |
|---|
| 44 | |
|---|
| 45 | baseOut = saveFolder+'/CTIP_A_'+str(dayofyear)+'-'+str(f107)+'-'+str(kp) |
|---|
| 46 | |
|---|
| 47 | print ' Base Filename: '+baseOut |
|---|
| 48 | print ' Day of Year: '+str(dayofyear) |
|---|
| 49 | print ' F10.7: '+str(f107) |
|---|
| 50 | print ' KP: '+str(kp) |
|---|
| 51 | print 'Max. Refresh Rate: '+str(maxRefreshRate) |
|---|
| 52 | |
|---|
| 53 | ctipStruct['output']['OutputHt']['indirect'] = True |
|---|
| 54 | ctipStruct['output']['OutputHt']['value'] = baseOut+'OutputHt.txt' |
|---|
| 55 | |
|---|
| 56 | ctipStruct['output']['OutputTn']['indirect'] = True |
|---|
| 57 | ctipStruct['output']['OutputTn']['value'] = baseOut+'OutputTn.txt' |
|---|
| 58 | |
|---|
| 59 | ctipStruct['output']['OutputMMRO']['indirect'] = True |
|---|
| 60 | ctipStruct['output']['OutputMMRO']['value'] = baseOut+'OutputMMRO.txt' |
|---|
| 61 | |
|---|
| 62 | ctipStruct['output']['OutputVnY']['indirect'] = True |
|---|
| 63 | ctipStruct['output']['OutputVnY']['value'] = baseOut+'OutputVnY.txt' |
|---|
| 64 | |
|---|
| 65 | ctipStruct['output']['OutputMMM']['indirect'] = True |
|---|
| 66 | ctipStruct['output']['OutputMMM']['value'] = baseOut+'OutputMMM.txt' |
|---|
| 67 | |
|---|
| 68 | ctipStruct['output']['OutputNe']['indirect'] = True |
|---|
| 69 | ctipStruct['output']['OutputNe']['value'] = baseOut+'OutputNe.txt' |
|---|
| 70 | |
|---|
| 71 | ctipStruct['output']['OutputMMRO2']['indirect'] = True |
|---|
| 72 | ctipStruct['output']['OutputMMRO2']['value'] = baseOut+'OutputMMRO2.txt' |
|---|
| 73 | |
|---|
| 74 | ctipStruct['output']['OutputMMRN2']['indirect'] = True |
|---|
| 75 | ctipStruct['output']['OutputMMRN2']['value'] = baseOut+'OutputMMRN2.txt' |
|---|
| 76 | |
|---|
| 77 | ctipStruct['output']['OutputVnX']['indirect'] = True |
|---|
| 78 | ctipStruct['output']['OutputVnX']['value'] = baseOut+'OutputVnX.txt' |
|---|
| 79 | |
|---|
| 80 | ctipStruct['output']['OutputLog']['indirect'] = True |
|---|
| 81 | ctipStruct['output']['OutputLog']['value'] = baseOut+'OutputLog.txt' |
|---|
| 82 | |
|---|
| 83 | ctipStruct['output']['OutputVnZ']['indirect'] = True |
|---|
| 84 | ctipStruct['output']['OutputVnZ']['value'] = baseOut+'OutputVnZ.txt' |
|---|
| 85 | |
|---|
| 86 | ctipDoc = ag.applications.convertStructToDocument(ctipStruct) |
|---|
| 87 | ag.applications.validate(ctipDoc) |
|---|
| 88 | |
|---|
| 89 | print '' |
|---|
| 90 | print 'Starting CTIP at '+time.ctime() |
|---|
| 91 | eid = ag.applications.submit(ctipDoc) |
|---|
| 92 | print 'Job ID - '+eid |
|---|
| 93 | print '' |
|---|
| 94 | |
|---|
| 95 | jobinfo = ag.applications.getExecutionInformation(eid) |
|---|
| 96 | jobstat = jobinfo['status'] |
|---|
| 97 | print jobstat + ' - ' + time.ctime() |
|---|
| 98 | |
|---|
| 99 | while jobstat != 'COMPLETED' and jobstat != 'ERROR': |
|---|
| 100 | time.sleep(refreshRate) |
|---|
| 101 | jobinfo = ag.applications.getExecutionInformation(eid) |
|---|
| 102 | jobstat = jobinfo['status'] |
|---|
| 103 | print jobstat + ' - ' + time.ctime() |
|---|
| 104 | if refreshRate < maxRefreshRate: |
|---|
| 105 | refreshRate = refreshRate*2.0 |
|---|
| 106 | |
|---|
| 107 | print '' |
|---|
| 108 | |
|---|
| 109 | if jobstat == 'ERROR': |
|---|
| 110 | print 'CTIP Failed to run correctly!' |
|---|
| 111 | elif jobstat == 'COMPLETED': |
|---|
| 112 | print 'CTIP ran correctly!' |
|---|
| 113 | print 'Your results can be found in '+saveFolder |
|---|
| 114 | else: |
|---|
| 115 | print 'The final job status was - ' + jobstat |
|---|
| 116 | |
|---|
| 117 | print 'The job started at '+str(jobinfo['startTime']) |
|---|
| 118 | print 'and the job finished at '+str(jobinfo['finishTime']) |
|---|