-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmet_setup_obs_micaps.py.bak20180722
126 lines (63 loc) · 2.31 KB
/
met_setup_obs_micaps.py.bak20180722
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
# -*- coding: utf-8 -*-
from pylab import *
import os
# import time
#
# import datetime
import global_vars as gv
import pandas as pd
import pdb
# step 1: reading micaps diamond3 file
def setup_data( cdate_utc, cdate_lst ):
# micaps_r24_dir = "H:\\fcst2018\\micaps\\r24\\"
# tempvar = file("sta2513.c8","r").readlines()
surobs = np.loadtxt("sta2513.c8", usecols=(0, 1, 2, 3))
r24fname = cdate_lst[2::] + ".000"
print
print(" Reading Micaps r24-precipitation file : " + gv.micaps_r24_dir + r24fname )
print
r24obs = open( gv.micaps_r24_dir + r24fname).readlines()[11:] # pay attention to global_vars
nobs = len(r24obs)
r24data = np.zeros((nobs, 5))
for i in range(nobs):
tmpdata = r24obs[i].split()
r24data[i, 0] = tmpdata[0] # pay attention!
r24data[i, 1] = float(tmpdata[1])
r24data[i, 2] = float(tmpdata[2])
r24data[i, 3] = float(tmpdata[3])
r24data[i, 4] = float(tmpdata[4])
# r24data = {"name": , "lat":, "lon", lev:, }
# print(sta_id)
# step 2: write data using acii2nc_MET format
f_ascii_name = gv.result_dir + "micaps" + "_r24_" + cdate_utc + ".ascii"
f_nc_name = gv.result_dir + "micaps" + "_r24_" + cdate_utc + ".nc"
print(f_ascii_name + " == > " + f_nc_name )
f_ascii = open(f_ascii_name, "w")
undef = -9999.0
for i in range(nobs):
msg = "ADPSFC"
stid = str(r24data[i, 0]) #
validtime = cdate_utc[0:8] + "_" + cdate_utc[8:10] + "0000" # YYYYMMDD_HH0000 20180620
clat = str(r24data[i, 2])
clon = str(r24data[i, 1])
celev = str(r24data[i, 3])
vartype = "AccPrecip"
level = "24"
hgt = "-9999"
qc = "NA"
obsdata = str(r24data[i, 4])
datarec = [msg, stid, validtime, clat, clon, celev, vartype, level, hgt, qc, obsdata]
# pdb.set_trace()
# print(datarec)
f_ascii.writelines(" ".join(datarec) + "\n")
f_ascii.close()
# step 3: writing data using grads format?
# step 4: writing data use netcdf-format using "ascii2nc" in MET_TOOLS
cmd = " ascii2nc " + f_ascii_name + " " + f_nc_name
print
print(cmd)
print
print(" =================================== ")
print
os.system(cmd)
# pdb.set_trace()