├── OWZ_Documentation_v1,1.docx
├── README.md
├── data_info_file
├── input_thresh_NH
├── input_thresh_SH
├── owdata_1979010100_NH.nc
├── owdata_1979010100_SH.nc
├── owdata_1979010112_NH.nc
├── owdata_1979010112_SH.nc
├── owz_tracker.py
├── thrsh.py
├── thrsh.pyc
├── topog
├── topogNH.nc
└── topogSH.nc
├── tracker.py
└── tracker.pyc
/OWZ_Documentation_v1,1.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/savinchand/owz_python/a9dbece7903889d0221d528a986463e319310200/OWZ_Documentation_v1,1.docx
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # owz_python
--------------------------------------------------------------------------------
/data_info_file:
--------------------------------------------------------------------------------
1 | 1.0 !dlon = Longitude increment (degrees)
2 | 1.0 !dlat = Latitude increment (degrees)
3 | 12.0 !dtim = Time increment (hours)
4 | 2 !e_min= Minimum number of neighbouring events for a clump to be considered
5 | 5 !TC_min= Minimum number of True links before TC declared
6 | 2 !sea_min= Minimum number of sea points to make a land influenced clump True
7 | 0.09 !land_lim= Topography value above which grid point is considered land (m)
8 | 550.0 !srch_rad= Search factor to determine links in CT strings (km)
9 | 550.0 !clmp_rad= Clump radius, distance in which two clumps are to be combined
10 | 60.0 !TH_OWZ850 = Overiding thresholds
11 | 50.0 !TH_OWZ500
12 | 85.0 !TH_rh950
13 | 70.0 !TH_rh700
14 | 12.5 !TH_wsh
15 | 14.0 !TH_sh950
16 |
--------------------------------------------------------------------------------
/input_thresh_NH:
--------------------------------------------------------------------------------
1 | -5.0 ! -60.0 Min latitude for output window
2 | 60.0 ! 5.0 Max latitude for output window
3 | 20.0 ! 20.0 Min longitude for output window
4 | 350.0 ! 350.0 Max longitude for output window
5 | 3 ! Number of smoothing operations for windshear
6 | False ! Write threshold array to NetCDF file if TRUE
7 | True ! Write lat/lon of thrsh=1.0 locations if TRUE
8 | 1 ! Number of threshld combinations
9 | 50.0, 40.0, 70.0, 50.0, 25.0, 10.0, ! 850 OWZ, 500 OWZ, 950RH, 700 RH, 850-200 shear, SH 950
10 |
--------------------------------------------------------------------------------
/input_thresh_SH:
--------------------------------------------------------------------------------
1 | -60.0 ! -60.0 Min latitude for output window
2 | 5.0 ! 5.0 Max latitude for output window
3 | 20.0 ! 20.0 Min longitude for output window
4 | 350.0 ! 350.0 Max longitude for output window
5 | 3 ! Number of smoothing operations for windshear
6 | False ! Write threshold array to NetCDF file if TRUE
7 | True ! Write lat/lon of thrsh=1.0 locations if TRUE
8 | 1 ! Number of threshld combinations
9 | 50.0, 40.0, 70.0, 50.0, 25.0, 10.0, ! 850 OWZ, 500 OWZ, 950RH, 700 RH, 850-200 shear, SH 950
10 |
--------------------------------------------------------------------------------
/owdata_1979010100_NH.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/savinchand/owz_python/a9dbece7903889d0221d528a986463e319310200/owdata_1979010100_NH.nc
--------------------------------------------------------------------------------
/owdata_1979010100_SH.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/savinchand/owz_python/a9dbece7903889d0221d528a986463e319310200/owdata_1979010100_SH.nc
--------------------------------------------------------------------------------
/owdata_1979010112_NH.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/savinchand/owz_python/a9dbece7903889d0221d528a986463e319310200/owdata_1979010112_NH.nc
--------------------------------------------------------------------------------
/owdata_1979010112_SH.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/savinchand/owz_python/a9dbece7903889d0221d528a986463e319310200/owdata_1979010112_SH.nc
--------------------------------------------------------------------------------
/owz_tracker.py:
--------------------------------------------------------------------------------
1 | import os, fnmatch
2 | from calendar import monthrange
3 | import thrsh as Threshold
4 | import tracker as Tracker
5 | import sys, getopt
6 |
7 | indir = "/var/climatenas/ERA5/OWZ_Tracker/data"
8 | outdir = ""
9 | var1="rh"
10 | var2="mrsh"
11 | var3="temp"
12 | var4="uwnd"
13 | var5="vwnd"
14 |
15 |
16 | #
17 | # Index number of level in netcdf file
18 | # Change this index number according to the data
19 | # e.g. ERA5 data have levels in assending order 200, 500,700,850,950
20 | # So I have set the index values accoring to the data
21 | #
22 | #
23 | # The script will rearrange the data in following format during preprocessing stage:
24 | # 950, 850, 700, 500, 200
25 | LVL200 = 1
26 | LVL500 = 2
27 | LVL700 = 3
28 | LVL850 = 4
29 | LVL950 = 5
30 |
31 |
32 | topog_NH="topog/topogNH.nc"
33 | topog_SH="topog/topogSH.nc"
34 |
35 | #os.system("ls")
36 |
37 | #**
38 | # - convert variable name to the name expected by threshold algorithm
39 | # - extract levels data (950,850,700, 500, 200) for specified date for 00 and 12
40 | # module assumes that levels are in sequence 200, 500, 700, 850, 950
41 | # input :
42 | # varName - Name of the the variable
43 | # timestamp - yyymmddhh format
44 | # timeIndex - index value of 0 hour
45 | # inputFile - name of input file
46 | # output: Temporary output file will generated with extrated data
47 | ##
48 | def extractLevelData(varName, timestamp,timeIndex,inputFile):
49 | print("ncks -O -F -v "+ varName + " -d time,"+str(timeIndex)+" -d lvl,"+str(LVL200)+" "+indir+"/"+inputFile+" "+varName+"200_"+str(timestamp)+"_tmp.nc")
50 | os.system("ncks -O -F -v "+ varName + " -d time,"+str(timeIndex)+" -d lvl,"+str(LVL200)+" "+indir+"/"+inputFile+" "+varName+"200_"+str(timestamp)+"_tmp.nc")
51 | os.system("ncks -O -F -v "+ varName + " -d time,"+str(timeIndex)+" -d lvl,"+str(LVL500)+" "+indir+"/"+inputFile+" "+varName+"500_"+str(timestamp)+"_tmp.nc")
52 | os.system("ncks -O -F -v "+ varName + " -d time,"+str(timeIndex)+" -d lvl,"+str(LVL700)+" "+indir+"/"+inputFile+" "+varName+"700_"+str(timestamp)+"_tmp.nc")
53 | os.system("ncks -O -F -v "+ varName + " -d time,"+str(timeIndex)+" -d lvl,"+str(LVL850)+" "+indir+"/"+inputFile+" "+varName+"850_"+str(timestamp)+"_tmp.nc")
54 | os.system("ncks -O -F -v "+ varName + " -d time,"+str(timeIndex)+" -d lvl,"+str(LVL950)+" "+indir+"/"+inputFile+" "+varName+"950_"+str(timestamp)+"_tmp.nc")
55 |
56 | #Merge levels in sequence 950 to 200 for timestamp
57 | os.system("cdo merge "+varName+"950_"+timestamp+"_tmp.nc "+varName+"850_"+timestamp+"_tmp.nc "+varName+"700_"+timestamp+"_tmp.nc "+varName+"500_"+timestamp+"_tmp.nc "+varName+"200_"+timestamp+"_tmp.nc "+varName+"_"+timestamp+".nc")
58 | os.system("rm *_tmp.nc")
59 |
60 |
61 |
62 | #
63 | # Append all variables into a single file
64 | #
65 | def appendFiles(timestamp):
66 | print("appending Files " + timestamp)
67 | #Append all variables of 00:00 hr into a single file
68 | os.system("ncks -A "+var2+"_"+timestamp+".nc "+ var1+"_"+timestamp+".nc")
69 | os.system("ncks -A "+var3+"_"+timestamp+".nc "+ var1+"_"+timestamp+".nc")
70 | os.system("ncks -A "+var4+"_"+timestamp+".nc "+ var1+"_"+timestamp+".nc")
71 | os.system("ncks -A "+var5+"_"+timestamp+".nc "+ var1+"_"+timestamp+".nc")
72 |
73 | os.system("rm "+var2+"_"+timestamp+".nc")
74 | os.system("rm "+var3+"_"+timestamp+".nc")
75 | os.system("rm "+var4+"_"+timestamp+".nc")
76 | os.system("rm "+var5+"_"+timestamp+".nc")
77 |
78 |
79 |
80 | #
81 | # Split NH and SH data and save in separate files for further processing
82 | #
83 | def split_NH_SH_data(timestamp):
84 | print("split_NH_SH_data Files " + timestamp)
85 |
86 | #NH
87 | os.system("ncks -F -d lon,21,351 -d lat,86,151 "+var1+"_"+timestamp+".nc "+ var1+"_"+timestamp+"NH_tmp.nc")
88 |
89 | #SH
90 | os.system("ncks -F -d lon,21,351 -d lat,31,96 "+var1+"_"+timestamp+".nc "+ var1+"_"+timestamp+"SH_tmp.nc")
91 |
92 | os.system("rm "+var1+"_"+timestamp+".nc")
93 |
94 |
95 |
96 | #
97 | # Append togography data to NH and SH files
98 | #
99 | def appendTopography(timestamp):
100 | print("appendTopography Files " + timestamp)
101 |
102 | #NH
103 | os.system("ncks -A "+topog_NH+" "+var1+"_"+timestamp+"NH_tmp.nc")
104 | #rename file
105 | os.system("mv "+var1+"_"+timestamp+"NH_tmp.nc owdata_"+timestamp+"_NH.nc")
106 |
107 | #SH
108 | os.system("ncks -A "+topog_SH+" "+var1+"_"+timestamp+"SH_tmp.nc")
109 | #rename file
110 | os.system("mv "+var1+"_"+timestamp+"SH_tmp.nc owdata_"+timestamp+"_SH.nc")
111 |
112 |
113 |
114 | #
115 | # Concat individual theshold data of individual days of year into single file (OWZ2)
116 | # This file will be used as an input for the OWZ Tracker
117 | #
118 | def concatThresholdFiles(year):
119 |
120 | #Remove Old OWZ and SubJ Files
121 | os.system("rm OWZ2tracker_"+str(year)+"*.txt")
122 | os.system("rm SubJ_"+str(year)+"*.txt")
123 |
124 |
125 | #Concat TH files for this year to singlge OWZ2 file which will be used for tracking
126 | os.system("cat TH_001_"+str(year)+"*_NH*.txt >OWZ2tracker_"+str(year)+"_NH.txt")
127 | os.system("cat STJ_"+str(year)+"*_NH*.txt >SubJ_"+str(year)+"_NH.txt")
128 |
129 | os.system("cat TH_001_"+str(year)+"*_SH*.txt >OWZ2tracker_"+str(year)+"_SH.txt")
130 | os.system("cat STJ_"+str(year)+"*_SH*.txt >SubJ_"+str(year)+"_SH.txt")
131 |
132 | os.system("rm STJ* TH*")
133 |
134 | #
135 | # Run threshold detector with preprocessed files for NH and SH
136 | #
137 | def runThresholdDetector(date,time, hem,file):
138 |
139 | timestamp = date+time
140 |
141 | if hem != "both":
142 | Threshold.process(file,date,time,hem)
143 | else:
144 | #NH
145 | Threshold.process("owdata_"+timestamp+"_NH.nc",date,time,"NH")
146 |
147 | #SH
148 | Threshold.process("owdata_"+timestamp+"_SH.nc",date,time,"SH")
149 | # END OF runThresholdDetector
150 |
151 |
152 |
153 |
154 | #
155 | # Run tracker on the threshold from OWZ2 file and save output in Clump, S_CT, S_CT2 and S_CT3
156 | #
157 | def runTracker(year,hem):
158 | Tracker.start("OWZ2tracker_"+str(year)+"_"+hem+".txt")
159 | os.system("mv Clump_out_py.txt "+outdir+"Clump_out_"+str(year)+"_"+hem+".txt")
160 | os.system("mv S_CT_out_py.txt "+outdir+"S_CT_out_"+str(year)+"_"+hem+".txt")
161 | os.system("mv S_CT_out2_py.txt "+outdir+"S_CT_out2_"+str(year)+"_"+hem+".txt")
162 | os.system("mv S_CT_out3_py.txt "+outdir+"S_CT_out3_"+str(year)+"_"+hem+".txt")
163 | # END OF runTracker
164 |
165 |
166 |
167 |
168 |
169 |
170 | #
171 | #
172 | #
173 | def preprocessData(fromYear, toYear):
174 |
175 | time00 = 1
176 | time12 = 2
177 | for year in range(fromYear,toYear+1) :
178 | for month in range(1,13):
179 | mm = '{:02d}'.format(month)
180 | for day in range(1,monthrange(year, month)[1]+1):
181 | dd = '{:02d}'.format(day)
182 |
183 | timestamp00= str(year)+mm+dd+"00"
184 | timestamp12= str(year)+mm+dd+"12"
185 | #Extract RH
186 | extractLevelData(var1,timestamp00,time00,"RH_"+str(year)+".nc")
187 | extractLevelData(var1,timestamp12,time12,"RH_"+str(year)+".nc")
188 |
189 | #Extract SPFH
190 | extractLevelData(var2,timestamp00,time00,"SPFH_"+str(year)+".nc")
191 | extractLevelData(var2,timestamp12,time12,"SPFH_"+str(year)+".nc")
192 |
193 | #Extract TEMP
194 | extractLevelData(var3,timestamp00,time00,"TEMP_"+str(year)+".nc")
195 | extractLevelData(var3,timestamp12,time12,"TEMP_"+str(year)+".nc")
196 |
197 | #Extract UWIND
198 | extractLevelData(var4,timestamp00,time00,"UWND_"+str(year)+".nc")
199 | extractLevelData(var4,timestamp12,time12,"UWND_"+str(year)+".nc")
200 |
201 | #Extract VWIND
202 | extractLevelData(var5,timestamp00,time00,"VWND_"+str(year)+".nc")
203 | extractLevelData(var5,timestamp12,time12,"VWND_"+str(year)+".nc")
204 |
205 | #Append all variables in single file for timestamp
206 | appendFiles(timestamp00)
207 | appendFiles(timestamp12)
208 |
209 |
210 | #Extract NH and SH data from source file
211 | split_NH_SH_data(timestamp00)
212 | split_NH_SH_data(timestamp12)
213 |
214 | #Append topography data to NH and SH
215 | appendTopography(timestamp00)
216 | appendTopography(timestamp12)
217 |
218 | #Detect threshold for NH and SH
219 | runThresholdDetector(str(year)+mm+dd,"00","both","")
220 | runThresholdDetector(str(year)+mm+dd,"12","both","")
221 |
222 |
223 | time00=time00 + 2
224 | time12=time12 + 2
225 |
226 | concatThresholdFiles(year)
227 | runTracker(year,"NH")
228 | runTracker(year,"SH")
229 |
230 |
231 |
232 | ##
233 | def processTestData(dataPath):
234 | listOfFiles = os.listdir(dataPath)
235 | years = []
236 | for entry in listOfFiles:
237 | if fnmatch.fnmatch(entry, "*.nc"):
238 | timestamp = entry.split("_")[1]
239 | year = timestamp[0:4]
240 | if(year not in years):
241 | years.append(year)
242 | date = timestamp[0:8]
243 | time = str(timestamp[-2:])
244 | hem = entry.split("_")[2].split(".")[0]
245 | path = ""
246 | if path != ".":
247 | path = dataPath
248 | if path[-1] != "/":
249 | path += "/"
250 |
251 | path = path+entry
252 | print path,timestamp,date,time,hem
253 | runThresholdDetector(date,time,hem,path)
254 |
255 | runTrackerOnTestData(years)
256 |
257 | def runTrackerOnTestData(years):
258 | for year in years:
259 | concatThresholdFiles(year)
260 | runTracker(year,"NH")
261 | runTracker(year,"SH")
262 |
263 |
264 |
265 |
266 |
267 |
268 | def main(argv):
269 | global indir, outdir
270 | indir = ''
271 | outdir = ''
272 | yearFrom = 0
273 | yearTo = 0
274 | test = False
275 | testFiles = []
276 | if len(argv) == 0:
277 | print 'usage: owz_tracker.py -i -o