1 | # |
||
2 | # Common methods for the a2gtrad and a2advrad scripts. |
||
3 | # |
||
4 | # |
||
5 | # |
||
6 | # SOFTWARE HISTORY |
||
7 | # |
||
8 | # Date Ticket# Engineer Description |
||
9 | # ------------ ---------- ----------- -------------------------- |
||
10 | # 08/13/2014 3393 nabowle Initial creation to contain common |
||
11 | # code for a2*radStub scripts. |
||
12 | # 03/15/2015 mjames@ucar Edited/added to awips package as RadarCommon |
||
13 | # |
||
14 | # |
||
15 | |||
16 | |||
17 | def get_datetime_str(record): |
||
18 | """ |
||
19 | Get the datetime string for a record. |
||
20 | |||
21 | Args: |
||
22 | record: the record to get data for. |
||
23 | |||
24 | Returns: |
||
25 | datetime string. |
||
26 | """ |
||
27 | return str(record.getDataTime())[0:19].replace(" ", "_") + ".0" |
||
28 | |||
29 | |||
30 | def get_data_type(azdat): |
||
31 | """ |
||
32 | Get the radar file type (radial or raster). |
||
33 | |||
34 | Args: |
||
35 | azdat: Boolean. |
||
36 | |||
37 | Returns: |
||
38 | Radial or raster. |
||
39 | """ |
||
40 | if azdat: |
||
41 | return "radial" |
||
42 | return "raster" |
||
43 | |||
44 | |||
45 | View Code Duplication | def get_hdf5_data(idra): |
|
0 ignored issues
–
show
Duplication
introduced
by
![]() |
|||
46 | rdat = [] |
||
47 | azdat = [] |
||
48 | depVals = [] |
||
49 | threshVals = [] |
||
50 | if idra: |
||
51 | for item in idra: |
||
52 | if item.getName() == "Data": |
||
53 | rdat = item |
||
54 | elif item.getName() == "Angles": |
||
55 | azdat = item |
||
56 | # dattyp = "radial" |
||
57 | elif item.getName() == "DependentValues": |
||
58 | depVals = item.getShortData() |
||
59 | elif item.getName() == "Thresholds": |
||
60 | threshVals = item.getShortData() |
||
61 | |||
62 | return rdat, azdat, depVals, threshVals |
||
63 | |||
64 | |||
65 | View Code Duplication | def get_header(record, headerFormat, xLen, yLen, azdat, description): |
|
0 ignored issues
–
show
|
|||
66 | # Encode dimensions, time, mapping, description, tilt, and VCP |
||
67 | mytime = get_datetime_str(record) |
||
68 | dattyp = get_data_type(azdat) |
||
69 | |||
70 | if headerFormat: |
||
71 | msg = str(xLen) + " " + str(yLen) + " " + mytime + " " + \ |
||
72 | dattyp + " " + str(record.getLatitude()) + " " + \ |
||
73 | str(record.getLongitude()) + " " + \ |
||
74 | str(record.getElevation()) + " " + \ |
||
75 | str(record.getElevationNumber()) + " " + \ |
||
76 | description + " " + str(record.getTrueElevationAngle()) + " " + \ |
||
77 | str(record.getVolumeCoveragePattern()) + "\n" |
||
78 | else: |
||
79 | msg = str(xLen) + " " + str(yLen) + " " + mytime + " " + \ |
||
80 | dattyp + " " + description + " " + \ |
||
81 | str(record.getTrueElevationAngle()) + " " + \ |
||
82 | str(record.getVolumeCoveragePattern()) + "\n" |
||
83 | |||
84 | return msg |
||
85 | |||
86 | |||
87 | View Code Duplication | def encode_thresh_vals(threshVals): |
|
0 ignored issues
–
show
|
|||
88 | spec = [".", "TH", "ND", "RF", "BI", "GC", "IC", "GR", "WS", "DS", |
||
89 | "RA", "HR", "BD", "HA", "UK"] |
||
90 | nnn = len(threshVals) |
||
91 | j = 0 |
||
92 | msg = "" |
||
93 | while j < nnn: |
||
94 | lo = threshVals[j] % 256 |
||
95 | hi = threshVals[j] / 256 |
||
96 | msg += " " |
||
97 | j += 1 |
||
98 | if hi < 0: |
||
99 | if lo > 14: |
||
100 | msg += "." |
||
101 | else: |
||
102 | msg += spec[lo] |
||
103 | continue |
||
104 | if hi % 16 >= 8: |
||
105 | msg += ">" |
||
106 | elif hi % 8 >= 4: |
||
107 | msg += "<" |
||
108 | if hi % 4 >= 2: |
||
109 | msg += "+" |
||
110 | elif hi % 2 >= 1: |
||
111 | msg += "-" |
||
112 | if hi >= 64: |
||
113 | msg += "%.2f" % (lo*0.01) |
||
114 | elif hi % 64 >= 32: |
||
115 | msg += "%.2f" % (lo*0.05) |
||
116 | elif hi % 32 >= 16: |
||
117 | msg += "%.1f" % (lo*0.1) |
||
118 | else: |
||
119 | msg += str(lo) |
||
120 | msg += "\n" |
||
121 | return msg |
||
122 | |||
123 | |||
124 | def encode_dep_vals(depVals): |
||
125 | nnn = len(depVals) |
||
126 | j = 0 |
||
127 | msg = [] |
||
128 | while j < nnn: |
||
129 | msg.append(str(depVals[j])) |
||
130 | j += 1 |
||
131 | return msg |
||
132 | |||
133 | |||
134 | def encode_radial(azVals): |
||
135 | azValsLen = len(azVals) |
||
136 | j = 0 |
||
137 | msg = [] |
||
138 | while j < azValsLen: |
||
139 | msg.append(azVals[j]) |
||
140 | j += 1 |
||
141 | return msg |
||
142 |