oafuncs 0.0.97.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,186 @@
1
+ #!/usr/bin/env python
2
+ # coding=utf-8
3
+ """
4
+ Author: Liu Kun && 16031215@qq.com
5
+ Date: 2025-03-09 16:31:45
6
+ LastEditors: Liu Kun && 16031215@qq.com
7
+ LastEditTime: 2025-03-09 16:31:45
8
+ FilePath: \\Python\\My_Funcs\\OAFuncs\\oafuncs\\oa_model\\wrf\\little_r.py
9
+ Description:
10
+ EditPlatform: vscode
11
+ ComputerInfo: XPS 15 9510
12
+ SystemInfo: Windows 11
13
+ Python Version: 3.12
14
+ """
15
+
16
+ __all__ = ["header_record", "data_record", "ending_record", "tail_record"]
17
+
18
+ import sys
19
+
20
+
21
+ def header_record(Latitude, Longitude, ID, Platform, Elevation, Bogus, Date, SLP, name):
22
+ """
23
+ Latitude : F20.5 纬度,浮点数,总共20位,小数点后保留5位
24
+ Lontitude : F20.5 经度,浮点数,总共20位,小数点后保留5位
25
+ Platform : A40 FM 编码的浮标编号,总共40位
26
+ Elevation : F20.5 浮标高度,单位为米,浮点数,总共20位,小数点后保留5位
27
+ Bogus : logical 标志数据是否有效,True为无效,False为有效
28
+ Date : A20 日期,总共20位
29
+ """
30
+ # 存放header record的字典
31
+ dict_header = {}
32
+ dict_header["Latitude"] = str_F20p5(Latitude)
33
+ dict_header["Longitude"] = str_F20p5(Longitude)
34
+ dict_header["ID"] = str_A40_Front_Space(ID)
35
+ dict_header["Name"] = str_A40_Front_Space(name)
36
+ dict_header["Platform"] = str_A40_Front_Space(Platform)
37
+ dict_header["Source"] = " N/A" # A40
38
+ dict_header["Elevation"] = str_F20p5(Elevation)
39
+ dict_header["ValidFields"] = " 1" # I10
40
+ dict_header["NumErrors"] = " -888888" # I10
41
+ dict_header["NumWarnings"] = " -888888" # I10
42
+ dict_header["SequenceNumber"] = " 890" # I10
43
+ dict_header["NumDuplicates"] = " -888888" # I10
44
+ dict_header["IsSounding"] = " F" # logical 10
45
+ dict_header["IsBogus"] = str_L10(Bogus)
46
+ dict_header["Discard"] = " F" # logical 10
47
+ dict_header["UnixTime"] = " -888888" # I10
48
+ dict_header["JulianDay"] = " -888888" # I10
49
+ dict_header["Date"] = str_A20_Behind_Space(Date)
50
+ dict_header["SLP-QC"] = str_F13p5(SLP) + " 0" # F13.5 I7
51
+ dict_header["RefPressure-QC"] = "-888888.00000 0" # F13.5 I7
52
+ dict_header["GroundTemp-QC"] = "-888888.00000 0" # F13.5 I7
53
+ dict_header["SST-QC"] = "-888888.00000 0" # F13.5 I7
54
+ dict_header["SFCPressure-QC"] = "-888888.00000 0" # F13.5 I7
55
+ dict_header["Precip-QC"] = "-888888.00000 0" # F13.5 I7
56
+ dict_header["DailyMaxT-QC"] = "-888888.00000 0" # F13.5 I7
57
+ dict_header["DailyMinT-QC"] = "-888888.00000 0" # F13.5 I7
58
+ dict_header["NightMinT-TC"] = "-888888.00000 0" # F13.5 I7
59
+ dict_header["3hrPresChange-QC"] = "-888888.00000 0" # F13.5 I7
60
+ dict_header["24hrChange-QC"] = "-888888.00000 0" # F13.5 I7
61
+ dict_header["CloudCover-QC"] = "-888888.00000 0" # F13.5 I7
62
+ dict_header["Ceiling-QC"] = "-888888.00000 0" # F13.5 I7
63
+ dict_header["PrecipitableWater-QC"] = "-888888.00000 0" # F13.5 I7
64
+
65
+ # 生成文件头的字符串,固定长度为620
66
+ header_str = ""
67
+ for iKey in dict_header.keys():
68
+ header_str = header_str + dict_header[iKey]
69
+ if len(header_str) != 620:
70
+ print("Error: The header record len =", len(header_str), ",The correct length should be 620!")
71
+ sys.exit(1)
72
+ return header_str
73
+
74
+
75
+ def data_record(Pressure, Height, Temperature, DewPoint, WindSpeed, WindDirection, WindU, WindV, RelativeHumidity, Thickness):
76
+ """
77
+ Pressure : F13.5, Pa
78
+ Height : F13.5, m
79
+ Temperature : F13.5, K
80
+ DewPoint : F13.5, K
81
+ WindSpeed : F13.5, m/s
82
+ WindDirection : F13.5, deg
83
+ WindU : F13.5, m/s
84
+ WindV : F13.5, m/s
85
+ RelativeHumidity : F13.5, %
86
+ Thickness : F13.5, m
87
+ """
88
+ dict_data = {}
89
+ dict_data["Pressure"] = str_F13p5(Pressure) # F13.5
90
+ dict_data["QC1"] = " 0" # I7
91
+ dict_data["Height"] = str_F13p5(Height) # F13.5
92
+ dict_data["QC2"] = " 0" # I7
93
+ dict_data["Temperature"] = str_F13p5(Temperature) # F13.5
94
+ dict_data["QC3"] = " 0" # I7
95
+ dict_data["DewPoint"] = str_F13p5(DewPoint) # F13.5
96
+ dict_data["QC4"] = " 0" # I7
97
+ dict_data["WindSpeed"] = str_F13p5(WindSpeed) # F13.5
98
+ dict_data["QC5"] = " 0" # I7
99
+ dict_data["WindDirection"] = str_F13p5(WindDirection) # F13.5
100
+ dict_data["QC6"] = " 0" # I7
101
+ dict_data["WindU"] = str_F13p5(WindU) # F13.5
102
+ dict_data["QC7"] = " 0" # I7
103
+ dict_data["WindV"] = str_F13p5(WindV) # F13.5
104
+ dict_data["QC8"] = " 0" # I7
105
+ dict_data["RelativeHumidity"] = str_F13p5(RelativeHumidity) # F13.5
106
+ dict_data["QC9"] = " 0" # I7
107
+ dict_data["Thickness"] = str_F13p5(Thickness) # F13.5
108
+ dict_data["QC10"] = " 0" # I7
109
+
110
+ # 生成数据记录,固定长度为200
111
+ data_str = ""
112
+ for iKey in dict_data.keys():
113
+ data_str = data_str + dict_data[iKey]
114
+ if len(data_str) != 200:
115
+ print("Error: The data record len =", len(data_str), ",The correct length should be 200!")
116
+ sys.exit(1)
117
+ return data_str
118
+
119
+
120
+ def ending_record():
121
+ ending_str = "-777777.00000 0-777777.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0"
122
+ return ending_str
123
+
124
+
125
+ def tail_record(ValidFields):
126
+ """
127
+ ValidFields : integer
128
+ """
129
+ NumErrors = " 0"
130
+ NumWarnings = " 0"
131
+ tail_str = str_I7(ValidFields) + NumErrors + NumWarnings
132
+ if len(tail_str) != 21:
133
+ print("Error: The tail record len =", len(tail_str), ",The correct length should be 21!")
134
+ sys.exit(1)
135
+ return tail_str
136
+
137
+
138
+ # 将浮点数格式化为长度为13位,小数点后保留5位的字符串,并在前面添加合适的空格
139
+ def str_F13p5(float):
140
+ a = "%.5f" % float
141
+ space = " " * (13 - len(a))
142
+ return space + str(a)
143
+
144
+
145
+ # 将浮点数格式化为长度为20位,小数点后保留5位的字符串,并在前面添加合适的空格
146
+ def str_F20p5(float):
147
+ a = "%.5f" % float
148
+ space = " " * (20 - len(a))
149
+ return space + str(a)
150
+
151
+
152
+ # 将字符串格式化为长度为40位的字符串,并在前面添加合适的空格。如果原始字符串超过了40位,会将其截断为前40位。
153
+ def str_A40_Front_Space(string):
154
+ # valid string in Front of space
155
+ string0 = str(string).strip()
156
+ space = " " * (40 - len(string0))
157
+ return string0 + space
158
+
159
+
160
+ # 将字符串格式化为长度为20位的字符串,并在后面添加合适的空格。如果原始字符串超过了20位,会将其截断为前20位。
161
+ def str_A20_Behind_Space(string):
162
+ # valid string Behind space
163
+ string0 = str(string).strip()
164
+ space = " " * (20 - len(string0))
165
+ return space + string0
166
+
167
+
168
+ # 将整数格式化为长度为10位的字符串,并在前面添加合适的空格
169
+ def str_I10(int0):
170
+ space = " " * (10 - len(int0))
171
+ return space + str(int0)
172
+
173
+
174
+ # 将整数格式化为长度为7位的字符串,并在前面添加合适的空格
175
+ def str_I7(int0):
176
+ space = " " * (7 - len(str(int0)))
177
+ return space + str(int0)
178
+
179
+
180
+ # 将布尔值格式化为长度为10位的字符串,如果为True则返回字符串' T',如果为False则返回字符串' F'
181
+ def str_L10(logical):
182
+ if logical:
183
+ string = " T"
184
+ else:
185
+ string = " F"
186
+ return string