annotate netcdf_read.py @ 0:8da8ec7da45f draft default tip

Uploaded
author mnhn65mo
date Thu, 02 Aug 2018 09:24:38 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
1 import netCDF4
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
2 from netCDF4 import Dataset
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
3 import numpy as np
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
4 import matplotlib
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
5 matplotlib.use("Agg")
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
6 import matplotlib.pyplot as plt
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
7 from pylab import *
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
8 import sys
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
9 import os
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
10 from scipy import spatial
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
11 from math import radians, cos, sin, asin, sqrt
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
12 import itertools
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
13
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
14 #####################
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
15 #####################
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
16
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
17 def checklist(dim_list, dim_name, filtre, threshold):
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
18 if not dim_list:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
19 error="Error "+str(dim_name)+" has no value "+str(filtre)+" "+str(threshold)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
20 sys.exit(error)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
21
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
22
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
23 #Return dist in km between two coord
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
24 #Thx to : https://stackoverflow.com/questions/4913349/haversine-formula-in-python-bearing-and-distance-between-two-gps-points
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
25 def haversine(lon1, lat1, lon2, lat2):
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
26 """
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
27 Calculate the great circle distance between two points
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
28 on the earth (specified in decimal degrees)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
29 """
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
30 # convert decimal degrees to radians
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
31 lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
32
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
33 # haversine formula
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
34 dlon = lon2 - lon1
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
35 dlat = lat2 - lat1
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
36 a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
37 c = 2 * asin(sqrt(a))
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
38 r = 6371 # Radius of earth in kilometers. Use 3956 for miles
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
39 return c * r
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
40
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
41
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
42 #Comparison functions, return a list of indexes for the user conditions
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
43 def is_strict_inf(filename, dim_name, threshold):
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
44 list_dim=[]
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
45 for i in range(0,filename.variables[dim_name].size):
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
46 if filename.variables[dim_name][i] < threshold:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
47 list_dim.append(i)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
48 checklist(list_dim,dim_name,"<",threshold)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
49 return list_dim
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
50
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
51 def is_equal_inf(filename, dim_name, threshold):
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
52 list_dim=[]
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
53 for i in range(0,filename.variables[dim_name].size):
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
54 if filename.variables[dim_name][i] <= threshold:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
55 list_dim.append(i)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
56 checklist(list_dim,dim_name,"<=",threshold)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
57 return list_dim
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
58
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
59 def is_equal_sup(filename, dim_name, threshold):
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
60 list_dim=[]
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
61 for i in range(0,filename.variables[dim_name].size):
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
62 if filename.variables[dim_name][i] >= threshold:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
63 list_dim.append(i)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
64 checklist(list_dim,dim_name,">=",threshold)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
65 return list_dim
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
66
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
67 def is_strict_sup(filename, dim_name, threshold):
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
68 list_dim=[]
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
69 for i in range(0,filename.variables[dim_name].size):
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
70 if filename.variables[dim_name][i] > threshold:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
71 list_dim.append(i)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
72 checklist(list_dim,dim_name,">",threshold)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
73 return list_dim
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
74
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
75 def find_nearest(array,value):
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
76 index = (np.abs(array-value)).argmin()
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
77 return index
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
78
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
79 def is_equal(filename, dim_name, value):
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
80 try:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
81 index=filename.variables[dim_name][:].tolist().index(value)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
82 except:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
83 index=find_nearest(filename.variables[dim_name][:],value)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
84 return index
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
85
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
86 def is_between_include(filename, dim_name, threshold1, threshold2):
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
87 list_dim=[]
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
88 for i in range(0,filename.variables[dim_name].size):
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
89 if filename.variables[dim_name][i] >= threshold1 and filename.variables[dim_name][i] <= threshold2:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
90 list_dim.append(i)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
91 checklist(list_dim,dim_name,">=",threshold1)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
92 checklist(list_dim,dim_name,"=<",threshold2)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
93 return list_dim
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
94
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
95 def is_between_exclude(filename, dim_name, threshold1, threshold2):
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
96 list_dim=[]
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
97 for i in range(0,filename.variables[dim_name].size):
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
98 if filename.variables[dim_name][i] > threshold1 and filename.variables[dim_name][i] < threshold2:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
99 list_dim.append(i)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
100 checklist(list_dim,dim_name,">",threshold1)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
101 checklist(list_dim,dim_name,"<",threshold2)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
102 return list_dim
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
103
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
104 #######################
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
105 #######################
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
106
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
107 #Get args
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
108 #Get Input file
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
109 inputfile=Dataset(sys.argv[1])
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
110 var_file_tab=sys.argv[2]
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
111 var=sys.argv[3] #Var chosen by user
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
112
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
113 Coord_bool=False
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
114
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
115
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
116 ######################
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
117 ######################
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
118 #len_threshold=1000000
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
119 len_threshold=7000
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
120 x_percent=0.75
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
121 threshold_latlon=100
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
122
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
123
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
124 #Check if coord is passed as parameter
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
125 arg_n=len(sys.argv)-1
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
126 if(((arg_n-3)%3)!=0):
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
127 Coord_bool=True #Useful to get closest coord
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
128 arg_n=arg_n-4 #Number of arg minus lat & lon
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
129 name_dim_lat=str(sys.argv[-4])
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
130 name_dim_lon=str(sys.argv[-2])
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
131 value_dim_lat=float(sys.argv[-3])
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
132 value_dim_lon=float(sys.argv[-1])
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
133
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
134 #Get all lat & lon
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
135 #try:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
136 if True:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
137 latitude=np.ma.MaskedArray(inputfile.variables[name_dim_lat])
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
138 longitude=np.ma.MaskedArray(inputfile.variables[name_dim_lon])
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
139 lat=latitude;lon=longitude #Usefull to keep the originals lat/lon vect before potentially resize it bellow.
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
140 len_all_coord=len(lat)*len(lon)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
141
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
142 #print("len all coord "+str(len_all_coord)+" threshold "+str(len_threshold))
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
143
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
144 #To avoid case when all_coord is to big and need to much memory
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
145 #If the vector is too big, reduce it to its third in a loop until its < to the threshold
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
146 while len_all_coord > len_threshold:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
147
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
148 if len(lat)<threshold_latlon: #If lat and lon are very different and lon is >> than lat. This way only lon is reduce and not lat.
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
149 x_percent_len_lat=99999999
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
150 else:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
151 x_percent_len_lat=int(x_percent*len(lat))
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
152
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
153 if len(lon)<threshold_latlon: #If lat and lon are very different and lat is >> than lon. This way only lat is reduce and not lon.
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
154 x_percent_len_lon=99999999
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
155 else:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
156 x_percent_len_lon=int(x_percent*len(lon))
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
157
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
158 #print("len(lat) :"+str(len(lat))+" x_percent_len_lat "+str(x_percent_len_lat))
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
159 #print("len(lon) :"+str(len(lon))+" x_percent_len_lon "+str(x_percent_len_lon))
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
160
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
161
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
162 pos_lat_user=find_nearest(lat,value_dim_lat)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
163 pos_lon_user=find_nearest(lon,value_dim_lon)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
164
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
165
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
166 #This part is to avoid having a vector that start bellow 0
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
167 lat_reduced=int(pos_lat_user-x_percent_len_lat/2-1)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
168 if lat_reduced<0:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
169 lat_reduced=0
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
170 lon_reduced=int(pos_lon_user-x_percent_len_lon/2-1)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
171 if lon_reduced<0:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
172 lon_reduced=0
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
173 #Opposite here to avoid having vector with len > to len(vector)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
174 lat_extended=int(pos_lat_user+x_percent_len_lat/2-1)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
175 if lat_extended>len(lat):
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
176 lat_extended=len(lat)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
177 lon_extended=int(pos_lon_user+x_percent_len_lon/2-1)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
178 if lon_extended>len(lon):
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
179 lon_extended=len(lon)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
180
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
181 lat=lat[lat_reduced:lat_extended] #add a test to check if pos_lat_user-x_percent_len_lat/2-1 >0
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
182 lon=lon[lon_reduced:lon_extended]
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
183 #print("latreduced : "+str(lat_reduced)+" latextended "+str(lat_extended))
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
184 #print("lonreduced : "+str(lon_reduced)+" lonextended "+str(lon_extended))
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
185 #print("lat : "+str(lat))
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
186 #print("lon : "+str(lon))
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
187 len_all_coord=len(lat)*len(lon)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
188
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
189 #print ("len_all_coord : "+str(len_all_coord)+". len_lat : "+str(len(lat))+" .len_lon : "+str(len(lon)))
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
190
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
191 else:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
192 #except:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
193 sys.exit("Latitude & Longitude not found")
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
194
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
195 #Set all lat-lon pair avaible in list_coord
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
196 list_coord_dispo=[]
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
197 for i in lat:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
198 for j in lon:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
199 list_coord_dispo.append(i);list_coord_dispo.append(j)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
200
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
201 #Reshape
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
202 all_coord=np.reshape(list_coord_dispo,(lat.size*lon.size,2))
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
203 #np.set_printoptions(threshold='nan')#to print full vec
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
204 #print(str(all_coord))
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
205 noval=True
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
206
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
207
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
208
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
209 #########################
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
210 #########################
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
211
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
212
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
213 #Get the file of variables and number of dims : var.tab
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
214 var_file=open(var_file_tab,"r") #read
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
215 lines=var_file.readlines() #line
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
216 dim_names=[]
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
217 for line in lines: #for every lines
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
218 words=line.split()
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
219 if (words[0]==var): #When line match user input var
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
220 varndim=int(words[1]) #Get number of dim for the var
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
221 for dim in range(2,varndim*2+2,2): #Get dim names
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
222 dim_names.append(words[dim])
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
223 #print ("Chosen var : "+sys.argv[3]+". Number of dimensions : "+str(varndim)+". Dimensions : "+str(dim_names)) #Standard msg
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
224
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
225
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
226 ########################
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
227 ########################
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
228
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
229
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
230 #Use a dictionary to save every lists of indexes
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
231 my_dic={} ##d["string{0}".format(x)]
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
232
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
233 for i in range(4,arg_n,3):
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
234 #print("\nDimension name : "+sys.argv[i]+" action : "+sys.argv[i+1]+" .Value : "+sys.argv[i+2]+"\n") #Standard msg
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
235
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
236 #Check if the dim selected for filtering is present in the var dimensions.
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
237 if (sys.argv[i] not in dim_names):
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
238 print("Warning ! "+sys.argv[i]+" is not a dimension of "+var+".\nThis filter will be skipped\nCheck in the file \"variables\" the dimensions available.\n\n")
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
239 pass
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
240
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
241 my_dic["string{0}".format(i)]="list_index_dim"
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
242 my_dic_index="list_index_dim"+str(sys.argv[i]) #Possible improvement: Check if lon/lat are not parsed again
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
243
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
244 #Apply every user filter. Call function and return list of index wich validate condition for every dim.
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
245 if (sys.argv[i+1]=="l"): #<
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
246 my_dic[my_dic_index]=is_strict_inf(inputfile, sys.argv[i], float(sys.argv[i+2]))
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
247 if (sys.argv[i+1]=="le"): #<=
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
248 my_dic[my_dic_index]=is_equal_inf(inputfile, sys.argv[i], float(sys.argv[i+2]))
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
249 if (sys.argv[i+1]=="g"): #>
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
250 my_dic[my_dic_index]=is_strict_sup(inputfile, sys.argv[i], float(sys.argv[i+2]))
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
251 if (sys.argv[i+1]=="ge"): #>=
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
252 my_dic[my_dic_index]=is_equal_sup(inputfile, sys.argv[i], float(sys.argv[i+2]))
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
253 if (sys.argv[i+1]=="e"): #==
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
254 my_dic[my_dic_index]=is_equal(inputfile, sys.argv[i], float(sys.argv[i+2]))
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
255 if (sys.argv[i+1]==":"): #all
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
256 my_dic[my_dic_index]=np.arange(inputfile.variables[sys.argv[i]].size)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
257 if (sys.argv[i+1]=="be"): #between_exclude
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
258 #Get the 2 thresholds from the arg which looks like "threshold1-threshold2"
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
259 threshold1=sys.argv[i+2].split("-")[0]
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
260 threshold2=sys.argv[i+2].split("-")[1]
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
261 my_dic[my_dic_index]=is_between_exclude(inputfile, sys.argv[i], float(threshold1), float(threshold2))
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
262 if (sys.argv[i+1]=="bi"): #between_include
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
263 #Get the 2 thresholds from the arg which looks like "threshold1-threshold2"
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
264 threshold1=sys.argv[i+2].split("-")[0]
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
265 threshold2=sys.argv[i+2].split("-")[1]
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
266 my_dic[my_dic_index]=is_between_include(inputfile, sys.argv[i], float(threshold1), float(threshold2))
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
267
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
268 #####################
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
269 #####################
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
270
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
271
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
272 #If precise coord given.
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
273 if Coord_bool:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
274 while noval: #While no closest coord with valid values is found
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
275 #Return closest coord avaible
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
276 tree=spatial.KDTree(all_coord)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
277 closest_coord=(tree.query([(value_dim_lat,value_dim_lon)]))
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
278 cc_index=closest_coord[1]
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
279
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
280 closest_lat=float(all_coord[closest_coord[1]][0][0])
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
281 closest_lon=float(all_coord[closest_coord[1]][0][1])
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
282
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
283 #Get coord index into dictionary
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
284 my_dic_index="list_index_dim"+str(name_dim_lat)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
285 my_dic[my_dic_index]=latitude.tolist().index(closest_lat)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
286
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
287 my_dic_index="list_index_dim"+str(name_dim_lon)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
288 my_dic[my_dic_index]=longitude.tolist().index(closest_lon)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
289
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
290
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
291 #All dictionary are saved in the string exec2 which will be exec(). Value got are in vec2
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
292 exec2="vec2=inputfile.variables['"+var+"']["
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
293 first=True
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
294 for i in dim_names: #Every dim are in the right order
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
295 if not first:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
296 exec2=exec2+","
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
297 dimension_indexes="my_dic[\"list_index_dim"+i+"\"]" #new dim, custom name dic
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
298 try: #If some error or no specific user choices; every indexes are used for the selected dim.
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
299 exec(dimension_indexes)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
300 except:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
301 dimension_indexes=":"
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
302 exec2=exec2+dimension_indexes #Concatenate dim
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
303 first=False #Not the first element now
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
304 exec2=exec2+"]"
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
305 #print exec2 #To check integrity of the string
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
306 exec(exec2) #Execution, value are in vec2.
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
307 #print vec2 #Get the value, standard output
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
308
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
309 #Check integrity of vec2. We don't want NA values
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
310 i=0
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
311 #Check every value, if at least one non NA is found vec2 and the current closest coords are validated
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
312 vecsize=vec2.size
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
313 #print (str(vecsize))
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
314 if vecsize>1:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
315 while i<vecsize:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
316 #print (str(vec2))
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
317 if vec2[i]!="nan":
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
318 break
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
319 else:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
320 i=i+1
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
321 else:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
322 if vec2!="nan":
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
323 break
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
324 else:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
325 i=i+1
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
326
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
327 if i<vecsize: #There is at least 1 nonNA value
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
328 noval=False
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
329 else: #If only NA : pop the closest coord and search in the second closest coord in the next loop.
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
330 all_coord=np.delete(all_coord,cc_index,0)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
331
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
332
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
333 #Same as before, dictionary use in exec2. exec(exec2) give vec2 and the values wanted.
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
334 else:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
335 exec2="vec2=inputfile.variables['"+str(sys.argv[3])+"']["
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
336 first=True
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
337 for i in dim_names: #Respect order
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
338 if not first:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
339 exec2=exec2+","
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
340 dimension_indexes="my_dic[\"list_index_dim"+i+"\"]"
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
341 try: #Avoid error and exit
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
342 exec(dimension_indexes)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
343 except:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
344 dimension_indexes=":"
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
345 exec2=exec2+dimension_indexes
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
346 first=False
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
347 exec2=exec2+"]"
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
348 exec(exec2)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
349
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
350
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
351 ########################
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
352 ########################
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
353
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
354
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
355 #This part create the header of every value.
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
356 #Values of every dim from the var is saved in a list : b[].
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
357 #All the lists b are saved in the unique list a[]
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
358 #All the combinations of the dim values inside a[] are the headers of the vec2 values
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
359
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
360 #Also write dim_name into a file to make clear header.
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
361 fo=open("header_names",'w')
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
362
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
363 a=[]
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
364 for i in dim_names:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
365 try: #If it doesn't work here its because my_dic= : so there is no size. Except will direcly take size of the dim.
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
366 size_dim=inputfile[i][my_dic['list_index_dim'+i]].size
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
367 except:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
368 size_dim=inputfile[i].size
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
369 my_dic['list_index_dim'+i]=range(size_dim)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
370
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
371 #print (i,size_dim) #Standard msg
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
372 b=[]
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
373 #Check size is useful since b.append(inputfile[i][my_dic['list_index_dim'+i][0]]) won't work
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
374 if size_dim>1:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
375 for s in range(0,size_dim):
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
376 b.append(inputfile[i][my_dic['list_index_dim'+i][s]])
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
377 #print (i,inputfile[i][my_dic['list_index_dim'+i][s]])
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
378 else:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
379 b.append(inputfile[i][my_dic['list_index_dim'+i]])
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
380 #print (i,inputfile[i][my_dic['list_index_dim'+i]])
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
381
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
382 a.append(b)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
383 fo.write(i+"\t")
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
384 if Coord_bool:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
385 fo.write("input_lat\t"+"input_lon\t")
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
386 fo.write(var+"\n")
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
387 fo.close()
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
388
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
389
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
390 ######################
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
391 ######################
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
392
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
393
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
394 #Write header in file
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
395 fo=open("header",'w')
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
396 for combination in itertools.product(*a):
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
397 if Coord_bool:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
398 fo.write(str(combination)+"_"+str(value_dim_lat)+"_"+str(value_dim_lon)+"\t")
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
399 else:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
400 fo.write(str(combination)+"\t")
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
401 fo.write("\n")
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
402 fo.close()
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
403
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
404
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
405 #Write vec2 in a tabular formated file
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
406 fo=open("sortie.tabular",'w')
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
407 #print(str(vec2))
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
408 try:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
409 vec2.tofile(fo,sep="\t",format="%s")
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
410 except:
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
411 vec3=np.ma.filled(vec2,np.nan)
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
412 vec3.tofile(fo,sep="\t",format="%s")
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
413 fo.close()
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
414
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
415
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
416 ######################
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
417 ######################
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
418
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
419
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
420 #Final sweet msg
8da8ec7da45f Uploaded
mnhn65mo
parents:
diff changeset
421 print (var+" values successffuly extracted from "+sys.argv[1]+" !")