Blame view

Bin.py/makeRequest.py 4.04 KB
90a0ee4e   Elena.Budnik   python
1
2
3
4
5

# coding: utf-8

# In[1]:

5a1df76c   Elena.Budnik   calcul in future
6
from datetime import datetime, timedelta
90a0ee4e   Elena.Budnik   python
7
8
from lxml import etree
import sys, os
5a1df76c   Elena.Budnik   calcul in future
9
import numpy as np
90a0ee4e   Elena.Budnik   python
10
11
12
13
14
15
16

# In[2]:

def checkArgs(nbArgs, message):
    if len(sys.argv) != nbArgs:
        print(message)
        sys.exit(2)
5a1df76c   Elena.Budnik   calcul in future
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
        
def getMarginDays(tgtName):
	if tgtName == 'mercury':
		distAU = 0.61
	elif tgtName == 'venus':
		distAU = 0.28
	elif tgtName == 'mars':
		distAU = 0.52
	elif tgtName == 'jupiter':
		distAU = 4.21
	elif tgtName == 'saturn':
		distAU = 8.54
	elif tgtName == 'p67':
		distAU = 4.0
	elif tgtName == 'juno':
		distAU = 6.0
	else:
		distAU = 9.0

	return np.ceil( (distAU*150000000)/(200*24*3600)) + 10
90a0ee4e   Elena.Budnik   python
37
38
39
40

# In[3]:

# CHECK ARGS
47081b7a   Elena.Budnik   work
41
checkArgs(5, 'Usage : python makeRequest.py (tgt_vi) (sw_vi) (TaoStopTime) (SwStopTime)')
90a0ee4e   Elena.Budnik   python
42

47081b7a   Elena.Budnik   work
43
44
45
prefix = sys.argv[1].split("_")[0] 
tgtVI = sys.argv[1]
plasmaVI = sys.argv[2] 
90a0ee4e   Elena.Budnik   python
46
47

# In[4]:
47081b7a   Elena.Budnik   work
48
omniStopTime = datetime.strptime(sys.argv[4], '%Y-%m-%dT%H:%M:%S.000Z')
90a0ee4e   Elena.Budnik   python
49
50
51
print  omniStopTime

# In[5]:
47081b7a   Elena.Budnik   work
52
missionStopTime = datetime.strptime(sys.argv[3], '%Y-%m-%dT%H:%M:%S.000Z')
90a0ee4e   Elena.Budnik   python
53
54
55
56
57
print  missionStopTime

# In[6]:

def writeXMLMission(XMLfilename,startTime,stopTime,plasmaVI,tgtVI,tgtRParam,tgtLonParam):
6ed9c6e8   Elena.Budnik   makedir if needed
58
59
60
    if not os.path.exists(os.getenv('REQ')):
	 os.makedirs(os.getenv('REQ'))
		    
90a0ee4e   Elena.Budnik   python
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
    with open(os.getenv('REQ')+'/'+XMLfilename, "w") as xml:
        xml.write('<?xml version="1.0" ?>\n')
        xml.write('<MISSION>\n')
        xml.write('\t<START>'+startTime+'</START>\n')
        xml.write('\t<STOP>'+stopTime+'</STOP>\n')
        xml.write('\t<PLASMA_VI>'+plasmaVI+'</PLASMA_VI>\n')
        xml.write('\t<SOURCE_VI>earth_orb_all</SOURCE_VI>\n')
        xml.write('\t<SOURCE_R_PARAM>R</SOURCE_R_PARAM>\n')
        xml.write('\t<SOURCE_LON_PARAM>LON_HCI</SOURCE_LON_PARAM>\n')
        xml.write('\t<TARGET_VI>'+tgtVI+'</TARGET_VI>\n')
        xml.write('\t<TARGET_R_PARAM>'+tgtRParam+'</TARGET_R_PARAM>\n')
        xml.write('\t<TARGET_LON_PARAM>'+tgtLonParam+'</TARGET_LON_PARAM>\n')
        xml.write('</MISSION>')
    xml.close()


# In[8]:

8bc6888e   Elena.Budnik   R variable name c...
79
80
81
tgtRParam = 'R_HCI'
if tgtVI == 'p67_orb_all':
	tgtRParam = 'R'
45252157   Elena.Budnik   work
82
	
90a0ee4e   Elena.Budnik   python
83
84
85
86
87
88
89
90
91
92
93
94
tgtLonParam = 'LON_HCI'
newMissionStart = missionStopTime
newMissionStop = omniStopTime
print "New mission start : " + newMissionStart.isoformat()
print "New mission stop  : " + newMissionStop.isoformat()

if newMissionStop <= newMissionStart:
    print "Database is on date"
    exit(0)
else:
    print "Database has to be updated"
    
47081b7a   Elena.Budnik   work
95
if newMissionStart.year != newMissionStop.year and plasmaVI != 'ace_swepam_real':
90a0ee4e   Elena.Budnik   python
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
    print "2 files will be producted"
    newMissionxml1Start = datetime(newMissionStart.year,1,1,0,0)
    newMissionxml1Stop = datetime(newMissionStop.year,1,1,0,0)
    newMissionxml2Start = datetime(newMissionStop.year,1,1,0,0)
    newMissionxml2Stop = newMissionStop
    print 'XML 1 Start : ' + newMissionxml1Start.isoformat()
    print 'XML 1 Stop : ' + newMissionxml1Stop.isoformat()
    print 'XML 2 Start : ' + newMissionxml2Start.isoformat()
    print 'XML 2 Stop : ' + newMissionxml2Stop.isoformat()
    XMLfilename = prefix+'_'+str(newMissionxml1Start.year)+'.xml'
    writeXMLMission(XMLfilename,newMissionxml1Start.isoformat(),newMissionxml1Stop.isoformat(),plasmaVI,tgtVI,tgtRParam,tgtLonParam)
    XMLfilename = prefix+'_'+str(newMissionxml2Start.year)+'.xml'
    writeXMLMission(XMLfilename,newMissionxml2Start.isoformat(),newMissionxml2Stop.isoformat(),plasmaVI,tgtVI,tgtRParam,tgtLonParam)
else:
    print "1 file will be producted"
47081b7a   Elena.Budnik   work
111
    if plasmaVI == "ace_swepam_real":
5a1df76c   Elena.Budnik   calcul in future
112
113
114
115
	   newMissionxmlStart = datetime(newMissionStart.year,newMissionStart.month,newMissionStart.day,0,0)
	   # Future !!!
	   tgt = tgtVI.split("_")[0]	   
	   newMissionxmlStop = newMissionStop + timedelta(getMarginDays(tgt))
47081b7a   Elena.Budnik   work
116
117
    else:	    
	   newMissionxmlStart = datetime(newMissionStart.year,1,1,0,0)
5a1df76c   Elena.Budnik   calcul in future
118
119
	   newMissionxmlStop  = newMissionStop
		
90a0ee4e   Elena.Budnik   python
120
121
122
123
    print 'XML Start : ' + newMissionxmlStart.isoformat()
    print 'XML Stop : ' + newMissionxmlStop.isoformat()
    XMLfilename = prefix+'_'+str(newMissionxmlStart.year)+'.xml'
    writeXMLMission(XMLfilename,newMissionxmlStart.isoformat(),newMissionxmlStop.isoformat(),plasmaVI,tgtVI,tgtRParam,tgtLonParam)