forked from andrejsim/ClimExp-pyapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwps_example.py
More file actions
184 lines (142 loc) · 7.7 KB
/
wps_example.py
File metadata and controls
184 lines (142 loc) · 7.7 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# depricated code
# view simple_ind_correlatefield.py
#
import subprocess
class CorrelatefieldDescriptor( KnmiWebProcessDescriptor ):
'''
Correlatefield function developed for ClimateExplorer
# via terminal
# cd /usr/people/mihajlov/climexp
# ./bin/correlatefield DATA/cru_ts3.22.1901.2013.pre.dat.nc DATA/nino3.nc mon 1:12 ave 3 DATA/out.nc
'''
# override with validation process
def process_execute_function(self , inputs, callback,fileOutPath):
callback(10)
content1 = {}
sourceA = inputs['netcdf_source1'].getValue()
sourceB = inputs['netcdf_source2'].getValue()
ratio = inputs['ratio'].getValue()
freq = inputs['frequency'].getValue()
ave = inputs['average'].getValue()
target = fileOutPath+inputs['netcdf_target'].getValue()
source1 = [sourceA,sourceB]
try:
# cd /usr/people/mihajlov/climexp/bin/correlatefield
#'./bin/correlatefield DATA/cru_ts3.22.1901.2013.pre.dat.nc DATA/nino3.nc mon 1:12 ave 3 DATA/out.nc'
callback(21)
dirscript = os.environ['PYWPS_PROCESSES']
#PYWPS_PROCESSES
# os.environ['PYWPS_PROCESSES']
loc = '/usr/people/mihajlov/climexp'
# script = './climexp/correlatefield '+loc+sourceA+' '+loc+sourceB+' '+freq+' '+ratio+' '+ave+' 3 '+str(target)
# process = Popen(cmd, stdout=PIPE, stderr=PIPE, env=envhpc, shell=True)
script = dirscript+'/climexp/correlatefield '+sourceA+' '+sourceB+' '+freq+' '+ratio+' '+ave+' 3 '+str(target)
callback(22,info=script)
try:
process = subprocess.Popen( script , shell=True).communicate()
callback(23,info=str(process))
except Exception, e:
callback(23,info="Popen process failed")
raise e
#,stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE
#outs, errs = process.communicate()
#callback(24,info="errs: "+errs)
#process.wait()
# /usr/people/mihajlov/climexp/
callback(25,info=target)
netcdf_w = netCDF4.Dataset(target,'a')
''' metadata appended, inspire worthy '''
netcdf_w.setncattr( "title" , "KNMI Climate Explorer correlate field service output" )
netcdf_w.setncattr( "summary" , "KNMI Climate Explorer correlate field service output "+sourceA+" for "+sourceB )
netcdf_w.setncattr( "keywords" , "climate,correlation,wps_knmi" )
netcdf_w.setncattr( "institute_id" , "KNMI" )
netcdf_w.setncattr( "contact" , "oldenborgh@knmi.nl" )
netcdf_w.setncattr( "date_created" , datetime.now().isoformat() )
# for sinspire...
#netcdf_w.setncattr( "time_coverage_start" , " " )
#netcdf_w.setncattr( "time_coverage_end" , " " )
#netcdf_w.setncattr( "geospatial_lat_min" , " " )
#netcdf_w.setncattr( "geospatial_lat_max" , " " )
#netcdf_w.setncattr( "geospatial_lon_min" , " " )
#netcdf_w.setncattr( "geospatial_lon_max" , " " )
#netcdf_w.setncattr( "geospatial_lat_resolution" , "1 m" )
#netcdf_w.setncattr( "geospatial_lon_resolution" , "1 m" )
netcdf_w.setncattr( "knmi_wps" , self.structure["identifier"] )
callback(24,info="creating knmi prov var")
processlib.createKnmiProvVar(netcdf_w)
content1 = generateContent(netcdf_w)
except Exception, e:
content1 = {"copy_error 1264": str(e) , "target":target , "process" : process}
logging.info(netcdf_w)
logging.info(content1)
logging.info(str(e))
raise e
#prov.content.append(content1)
return content1 , source1, netcdf_w
def __init__( self ):
self.structure = {}
self.inputsTuple = []
self.structure["identifier"] = "wps_climexp_correlatefield" # = 'wps_simple_indice', # only mandatary attribute = same file name
self.structure["title"]= "climate explorer correlatefield" # = 'SimpleIndices',
self.structure["abstract"] = "KNMI Climate Explorer: correlatefield function" #'Computes single input indices of temperature TG, TX, TN, TXx, TXn, TNx, TNn, SU, TR, CSU, GD4, FD, CFD, ID, HD17; of rainfal: CDD, CWD, RR, RR1, SDII, R10mm, R20mm, RX1day, RX5day; and of snowfall: SD, SD1, SD5, SD50.'
self.structure["version"] = "1.0.0"
self.structure["storeSupported"] = True
self.structure["statusSupported"] = True
self.structure["grassLocation"] = False
self.structure["metadata"] = "METADATA D4P"
# input tuple describes addLiteralInput, values
self.inputsTuple = [
{
"identifier" : "netcdf_source1" ,
"title" : "Copy input: Input 1 netCDF opendap." ,
"type" : type("String"),
"default" : "http://opendap.knmi.nl/knmi/thredds/dodsC/climate_explorer/cru_ts3.22.1901.2013.pre.dat.nc" ,
"abstract" : "application/netcdf",
"values" : None
} ,
{
"identifier" : "netcdf_source2" ,
"title" : "Copy input: Input 2 netCDF opendap." ,
"type" : type("String"),
"default" : "http://opendap.knmi.nl/knmi/thredds/dodsC/climate_explorer/nino3.nc" ,
"abstract" : "application/netcdf",
"values" : None
} ,
{
"identifier" : "netcdf_target" ,
"title" : "Output netCDF." ,
"type" : type("String"),
"default" : "out.nc",
"values" : None
} ,
{
"identifier" : "frequency" ,
"title" : "Frequency" ,
"type" : type("String"),
"default" : "mon" ,
"values" : None
} ,
{
"identifier" : "ratio" ,
"title" : "Ratio" ,
"type" : type("String"),
"default" : "1:12" ,
"values" : None
} ,
{
"identifier" : "average" ,
"title" : "Average" ,
"type" : type("String"),
"default" : "ave" ,
"values" : None
} ,
{
"identifier" : "tags" ,
"title" : "User Defined Tags CLIPC user tags." ,
"type" : type("String"),
"default" : "provenance_research_knmi",
"values" : None
}
]
self.processExecuteCallback = self.process_execute_function
print self