shancx 1.8.92__py3-none-any.whl → 1.9.33.218__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.
Files changed (166) hide show
  1. shancx/3D/__init__.py +25 -0
  2. shancx/Algo/Class.py +11 -0
  3. shancx/Algo/CudaPrefetcher1.py +112 -0
  4. shancx/Algo/Fake_image.py +24 -0
  5. shancx/Algo/Hsml.py +391 -0
  6. shancx/Algo/L2Loss.py +10 -0
  7. shancx/Algo/MetricTracker.py +132 -0
  8. shancx/Algo/Normalize.py +66 -0
  9. shancx/Algo/OptimizerWScheduler.py +38 -0
  10. shancx/Algo/Rmageresize.py +79 -0
  11. shancx/Algo/Savemodel.py +33 -0
  12. shancx/Algo/SmoothL1_losses.py +27 -0
  13. shancx/Algo/Tqdm.py +62 -0
  14. shancx/Algo/__init__.py +121 -0
  15. shancx/Algo/checknan.py +28 -0
  16. shancx/Algo/iouJU.py +83 -0
  17. shancx/Algo/mask.py +25 -0
  18. shancx/Algo/psnr.py +9 -0
  19. shancx/Algo/ssim.py +70 -0
  20. shancx/Algo/structural_similarity.py +308 -0
  21. shancx/Algo/tool.py +704 -0
  22. shancx/Calmetrics/__init__.py +97 -0
  23. shancx/Calmetrics/calmetrics.py +14 -0
  24. shancx/Calmetrics/calmetricsmatrixLib.py +147 -0
  25. shancx/Calmetrics/rmseR2score.py +35 -0
  26. shancx/Clip/__init__.py +50 -0
  27. shancx/Cmd.py +126 -0
  28. shancx/Config_.py +26 -0
  29. shancx/Df/DataFrame.py +11 -2
  30. shancx/Df/__init__.py +17 -0
  31. shancx/Df/tool.py +0 -0
  32. shancx/Diffm/Psamples.py +18 -0
  33. shancx/Diffm/__init__.py +0 -0
  34. shancx/Diffm/test.py +207 -0
  35. shancx/Doc/__init__.py +214 -0
  36. shancx/E/__init__.py +178 -152
  37. shancx/Fillmiss/__init__.py +0 -0
  38. shancx/Fillmiss/imgidwJU.py +46 -0
  39. shancx/Fillmiss/imgidwLatLonJU.py +82 -0
  40. shancx/Gpu/__init__.py +55 -0
  41. shancx/H9/__init__.py +126 -0
  42. shancx/H9/ahi_read_hsd.py +877 -0
  43. shancx/H9/ahisearchtable.py +298 -0
  44. shancx/H9/geometry.py +2439 -0
  45. shancx/Hug/__init__.py +81 -0
  46. shancx/Inst.py +22 -0
  47. shancx/Lib.py +31 -0
  48. shancx/Mos/__init__.py +37 -0
  49. shancx/NN/__init__.py +235 -106
  50. shancx/Path1.py +161 -0
  51. shancx/Plot/GlobMap.py +276 -116
  52. shancx/Plot/__init__.py +491 -1
  53. shancx/Plot/draw_day_CR_PNG.py +4 -21
  54. shancx/Plot/exam.py +116 -0
  55. shancx/Plot/plotGlobal.py +325 -0
  56. shancx/{radar_nmc.py → Plot/radarNmc.py} +4 -34
  57. shancx/{subplots_single_china_map.py → Plot/single_china_map.py} +1 -1
  58. shancx/Point.py +46 -0
  59. shancx/QC.py +223 -0
  60. shancx/RdPzl/__init__.py +32 -0
  61. shancx/Read.py +72 -0
  62. shancx/Resize.py +79 -0
  63. shancx/SN/__init__.py +62 -123
  64. shancx/Time/GetTime.py +9 -3
  65. shancx/Time/__init__.py +66 -1
  66. shancx/Time/timeCycle.py +302 -0
  67. shancx/Time/tool.py +0 -0
  68. shancx/Train/__init__.py +74 -0
  69. shancx/Train/makelist.py +187 -0
  70. shancx/Train/multiGpu.py +27 -0
  71. shancx/Train/prepare.py +161 -0
  72. shancx/Train/renet50.py +157 -0
  73. shancx/ZR.py +12 -0
  74. shancx/__init__.py +333 -262
  75. shancx/args.py +27 -0
  76. shancx/bak.py +768 -0
  77. shancx/df2database.py +62 -2
  78. shancx/geosProj.py +80 -0
  79. shancx/info.py +38 -0
  80. shancx/netdfJU.py +231 -0
  81. shancx/sendM.py +59 -0
  82. shancx/tensBoard/__init__.py +28 -0
  83. shancx/wait.py +246 -0
  84. {shancx-1.8.92.dist-info → shancx-1.9.33.218.dist-info}/METADATA +15 -5
  85. shancx-1.9.33.218.dist-info/RECORD +91 -0
  86. {shancx-1.8.92.dist-info → shancx-1.9.33.218.dist-info}/WHEEL +1 -1
  87. my_timer_decorator/__init__.py +0 -10
  88. shancx/Dsalgor/__init__.py +0 -19
  89. shancx/E/DFGRRIB.py +0 -30
  90. shancx/EN/DFGRRIB.py +0 -30
  91. shancx/EN/__init__.py +0 -148
  92. shancx/FileRead.py +0 -44
  93. shancx/Gray2RGB.py +0 -86
  94. shancx/M/__init__.py +0 -137
  95. shancx/MN/__init__.py +0 -133
  96. shancx/N/__init__.py +0 -131
  97. shancx/Plot/draw_day_CR_PNGUS.py +0 -206
  98. shancx/Plot/draw_day_CR_SVG.py +0 -275
  99. shancx/Plot/draw_day_pre_PNGUS.py +0 -205
  100. shancx/Plot/glob_nation_map.py +0 -116
  101. shancx/Plot/radar_nmc.py +0 -61
  102. shancx/Plot/radar_nmc_china_map_compare1.py +0 -50
  103. shancx/Plot/radar_nmc_china_map_f.py +0 -121
  104. shancx/Plot/radar_nmc_us_map_f.py +0 -128
  105. shancx/Plot/subplots_compare_devlop.py +0 -36
  106. shancx/Plot/subplots_single_china_map.py +0 -45
  107. shancx/S/__init__.py +0 -138
  108. shancx/W/__init__.py +0 -132
  109. shancx/WN/__init__.py +0 -132
  110. shancx/code.py +0 -331
  111. shancx/draw_day_CR_PNG.py +0 -200
  112. shancx/draw_day_CR_PNGUS.py +0 -206
  113. shancx/draw_day_CR_SVG.py +0 -275
  114. shancx/draw_day_pre_PNGUS.py +0 -205
  115. shancx/makenetCDFN.py +0 -42
  116. shancx/mkIMGSCX.py +0 -92
  117. shancx/netCDF.py +0 -130
  118. shancx/radar_nmc_china_map_compare1.py +0 -50
  119. shancx/radar_nmc_china_map_f.py +0 -125
  120. shancx/radar_nmc_us_map_f.py +0 -67
  121. shancx/subplots_compare_devlop.py +0 -36
  122. shancx/tool.py +0 -18
  123. shancx/user/H8mess.py +0 -317
  124. shancx/user/__init__.py +0 -137
  125. shancx/user/cinradHJN.py +0 -496
  126. shancx/user/examMeso.py +0 -293
  127. shancx/user/hjnDAAS.py +0 -26
  128. shancx/user/hjnFTP.py +0 -81
  129. shancx/user/hjnGIS.py +0 -320
  130. shancx/user/hjnGPU.py +0 -21
  131. shancx/user/hjnIDW.py +0 -68
  132. shancx/user/hjnKDTree.py +0 -75
  133. shancx/user/hjnLAPSTransform.py +0 -47
  134. shancx/user/hjnMiscellaneous.py +0 -182
  135. shancx/user/hjnProj.py +0 -162
  136. shancx/user/inotify.py +0 -41
  137. shancx/user/matplotlibMess.py +0 -87
  138. shancx/user/mkNCHJN.py +0 -623
  139. shancx/user/newTypeRadar.py +0 -492
  140. shancx/user/test.py +0 -6
  141. shancx/user/tlogP.py +0 -129
  142. shancx/util_log.py +0 -33
  143. shancx/wtx/H8mess.py +0 -315
  144. shancx/wtx/__init__.py +0 -151
  145. shancx/wtx/cinradHJN.py +0 -496
  146. shancx/wtx/colormap.py +0 -64
  147. shancx/wtx/examMeso.py +0 -298
  148. shancx/wtx/hjnDAAS.py +0 -26
  149. shancx/wtx/hjnFTP.py +0 -81
  150. shancx/wtx/hjnGIS.py +0 -330
  151. shancx/wtx/hjnGPU.py +0 -21
  152. shancx/wtx/hjnIDW.py +0 -68
  153. shancx/wtx/hjnKDTree.py +0 -75
  154. shancx/wtx/hjnLAPSTransform.py +0 -47
  155. shancx/wtx/hjnLog.py +0 -78
  156. shancx/wtx/hjnMiscellaneous.py +0 -201
  157. shancx/wtx/hjnProj.py +0 -161
  158. shancx/wtx/inotify.py +0 -41
  159. shancx/wtx/matplotlibMess.py +0 -87
  160. shancx/wtx/mkNCHJN.py +0 -613
  161. shancx/wtx/newTypeRadar.py +0 -492
  162. shancx/wtx/test.py +0 -6
  163. shancx/wtx/tlogP.py +0 -129
  164. shancx-1.8.92.dist-info/RECORD +0 -99
  165. /shancx/{Dsalgor → Algo}/dsalgor.py +0 -0
  166. {shancx-1.8.92.dist-info → shancx-1.9.33.218.dist-info}/top_level.txt +0 -0
shancx/wtx/mkNCHJN.py DELETED
@@ -1,613 +0,0 @@
1
- # *-* coding=utf8
2
- import numpy as np
3
- import netCDF4 as nc
4
- import datetime
5
- import traceback
6
- from dateutil.relativedelta import relativedelta
7
- import copy
8
- import os
9
- import random
10
- import string
11
-
12
-
13
- class envelope():
14
- def __init__(self,n,s,w,e):
15
- self.n,self.s,self.w,self.e=n,s,w,e
16
- def __str__(self):
17
- return ("n:%s,s:%s,w:%s,e:%s"%(self.n,self.s,self.w,self.e))
18
-
19
-
20
- areaNameDict = {"NEC": "东北","NCN": "华北","CCN": "华中","SCN": "华南","NWC": "西北","SWC": "西南","XJ": "新疆", "XZ": "西藏","CHN":"中国"}
21
- areaIdxDict = {"NEC": 0,"NCN": 1,"CCN": 2,"SCN": 3,"NWC": 4,"SWC": 5,"XJ": 6, "XZ": 7,"CHN":8}
22
- LeftTopCornerCHN = np.asarray([{"area":"CHN", "evn":envelope(55, 15,72, 136), "CHarea":"中国"}])
23
-
24
-
25
- LeftTopCornerPairArr = np.asarray([
26
- # //东北
27
- {"area":"NEC", "evn":envelope(55, 38,109, 136), "CHarea":"东北"},
28
- # //华北
29
- {"area":"NCN", "evn":envelope(43,31, 109,124), "CHarea":"华北"},
30
- # //华中
31
- {"area":"CCN", "evn":envelope(36,22, 108, 124), "CHarea":"华中"},
32
- # //华南
33
- {"area":"SCN", "evn":envelope(27, 15,104, 124), "CHarea":"华南"},
34
- # //西北
35
- {"area":"NWC", "evn":envelope(44,31, 88, 114), "CHarea":"西北"},
36
- # //西南
37
- {"area":"SWC", "evn":envelope(35, 20,96, 111), "CHarea":"西南"},
38
- # //新疆
39
- {"area":"XJ", "evn":envelope(50, 34,72, 97), "CHarea":"新疆"},
40
- # //西藏
41
- {"area":"XZ", "evn":envelope(37,25, 77, 101), "CHarea":"西藏"}])
42
-
43
-
44
- LeftTopCornerPairArrClip = np.asarray([
45
- # //东北
46
- {"area":"NEC", "evn":envelope(55+10e-5, 38+10e-5, 109+10e-5, 136+10e-5), "CHarea":"东北"},
47
- # //华北
48
- {"area":"NCN", "evn":envelope(43+10e-5, 31+10e-5, 109+10e-5, 124+10e-5), "CHarea":"华北"},
49
- # //华中
50
- {"area":"CCN", "evn":envelope(36+10e-5, 22+10e-5, 108+10e-5, 124+10e-5), "CHarea":"华中"},
51
- # //华南
52
- {"area":"SCN", "evn":envelope(27+10e-5, 15+10e-5, 104+10e-5, 124+10e-5), "CHarea":"华南"},
53
- # //西北
54
- {"area":"NWC", "evn":envelope(44+10e-5, 31+10e-5, 88+10e-5, 114+10e-5), "CHarea":"西北"},
55
- # //西南
56
- {"area":"SWC", "evn":envelope(35+10e-5, 20+10e-5, 96+10e-5, 111+10e-5), "CHarea":"西南"},
57
- # //新疆
58
- {"area":"XJ", "evn":envelope(50+10e-5, 34+10e-5, 72+10e-5, 97+10e-5), "CHarea":"新疆"},
59
- # //西藏
60
- {"area":"XZ", "evn":envelope(37+10e-5,25+10e-5, 77+10e-5, 101+10e-5), "CHarea":"西藏"}])
61
-
62
-
63
- LeftTopCornerPairArrSLL = np.asarray([
64
- # //大渡河
65
- {"area":"DDH", "evn":envelope(30.96, 28.96,101.21, 103.21)},
66
- # //贵阳
67
- {"area":"GY", "evn":envelope(27.08,26.08, 106.23,107.23)},
68
- # //长春
69
- {"area":"CC", "evn":envelope(44.4,43.4, 124.72, 125.72)},
70
- # //深圳
71
- {"area":"SZ", "evn":envelope(22.86, 22.38,113.76, 114.63)},
72
- # //天津
73
- {"area":"TJ", "evn":envelope(40.26,38.56, 116.69, 118.06)},
74
- # //黄山
75
- {"area":"HS", "evn":envelope(35, 25,113, 123)},
76
- # //华山
77
- {"area":"HUAS", "evn":envelope(36, 30,105, 115)},
78
- # //武汉
79
- {"area":"WH", "evn":envelope(31.37, 29.96,113.69, 115.08)},
80
- # //潍坊
81
- {"area":"WF", "evn":envelope(37.31, 35.70,118.17,120.0 )},
82
- # //川藏
83
- {"area":"CZ", "evn":envelope(33,28, 90, 105)}])
84
- LeftTopCornerPairArrSLLnew = np.asarray([
85
- # //四川
86
- {"area":"SC", "evn":envelope(36,25,95,110)},
87
- # //吉林
88
- {"area":"JL", "evn":envelope(49,38,121,132)},
89
- # //广东
90
- {"area":"GD", "evn":envelope(27,19,109,118)},
91
- # //京津冀
92
- {"area":"JJJ", "evn":envelope(44,34,112,121)},
93
- # //安徽
94
- {"area":"AH", "evn":envelope(36,29,114,120)},
95
- # //陕西
96
- {"area":"SAX", "evn":envelope(41,31,104,113)},
97
- # //湖北
98
- {"area":"HB", "evn":envelope(35,28,108,117)},
99
- # //山东
100
- {"area":"SD", "evn":envelope(40,33,114,124)}])
101
-
102
- class zClass():
103
- data_ = None
104
- name_ = None
105
- type_ = np.float32
106
- coordinate_ = None
107
- unit_ = None
108
- positive_ = None
109
- def __init__(self, data, name, type_, coordinate, unit,positive):
110
- self.data_, self.name_, self.type_, self.coordinate_, self.unit_, self.positive_ = data, name, type_, coordinate, unit,positive
111
-
112
-
113
-
114
- class dataClass():
115
- data_ = None
116
- name_ = None
117
- long_name_ = None
118
- type_ = np.float32
119
- coordinate_ = None
120
- unit_ = None
121
- valid_range_ = [-999,9999]
122
- missing_value_ = np.nan
123
- scale_factor_ = np.float32(1.0)
124
- add_offset_ = np.float32(0.0)
125
-
126
- def __init__(self,data, name, type_,coordinate, unit,missing_value=np.nan, scale_factor=np.float32(1.0), add_offset=np.float32(0.0),valid_range=[-999,9999],long_name_=""):
127
- self.data_, self.name_, self.type_, self.coordinate_, self.unit_ ,self.missing_value_ ,self.scale_factor_,self.add_offset_,self.valid_range_,self.long_name_= data, name,type_, coordinate, unit,missing_value, scale_factor, add_offset, valid_range, long_name_
128
-
129
- def print(self):
130
- print(self.data_, self.name_, self.type_, self.coordinate_, self.unit_,self.missing_value_,self.scale_factor_,self.add_offset_,self.valid_range_)
131
-
132
- def mkNCCommonUni(output,dateTimeStart,dateTimeArr,isoArr,latArr,lonArr,dataClass4D=[],dataClass3D=[],dataClass2D=[],attributeDict={},format='NETCDF4'):
133
- # 生成大小写字母的字符集
134
- letters = string.ascii_letters
135
- # 生成5位随机大小写字母的字符串
136
- random_string = ''.join(random.choice(letters) for _ in range(5))
137
- outputTmp = output+f".{random_string}"
138
- dataset = nc.Dataset(outputTmp,'w',format=format) #'NETCDF4_CLASSIC')
139
-
140
- try:
141
- if not dateTimeArr is None and not dateTimeStart is None:
142
- dataset.createDimension("time", len(dateTimeArr))
143
- if not isoArr is None:
144
- dataset.createDimension("isobaric", len(isoArr))
145
-
146
- dataset.createDimension("lat", len(latArr))
147
- dataset.createDimension("lon", len(lonArr))
148
-
149
- if not dateTimeArr is None and not dateTimeStart is None:
150
- dataset.createVariable("time", np.float32, ("time"), zlib=True)
151
- if not isoArr is None:
152
- dataset.createVariable("isobaric", np.float32, ("isobaric"), zlib=True)
153
- dataset.createVariable("lat", np.float64, ("lat"), zlib=True)
154
- dataset.createVariable("lon", np.float64, ("lon"), zlib=True)
155
-
156
- for e in dataClass2D:
157
- dataset.createVariable(e.name_, e.type_, tuple(["lat","lon"]), zlib=True)
158
-
159
- for e in dataClass3D:
160
- dataset.createVariable(e.name_, e.type_, tuple(["time","lat","lon"]), zlib=True)
161
-
162
- for e in dataClass4D:
163
- dataset.createVariable(e.name_, e.type_, tuple(["time","isobaric","lat","lon"]), zlib=True)
164
- if not dateTimeArr is None and not dateTimeStart is None:
165
- dataset.variables["time"][:] = dateTimeArr
166
- dataset.variables["time"].units = 'minutes since %s'%(dateTimeStart.strftime("%Y-%m-%d %H:%M:%S"))
167
- dataset.variables["time"].calendar = 'gregorian'
168
-
169
- if not isoArr is None:
170
- dataset.variables["isobaric"][:] = isoArr
171
- dataset.variables["isobaric"].units="hPa"
172
- dataset.variables["isobaric"].positive="up"
173
-
174
- dataset.variables["lat"][:] = latArr
175
- dataset.variables['lat'].units = 'degrees_north'
176
-
177
- dataset.variables["lon"][:] = lonArr
178
- dataset.variables['lon'].units = 'degrees_east'
179
-
180
- for e in dataClass2D:
181
- dataset.variables[e.name_][:] = e.data_
182
- dataset.variables[e.name_].units = e.unit_
183
- dataset.variables[e.name_].valid_range = e.valid_range_
184
- if not "3" in format:
185
- dataset.variables[e.name_].coordinate = e.coordinate_
186
- dataset.variables[e.name_].missing_value = e.missing_value_
187
- dataset.variables[e.name_].long_name = e.long_name_
188
- dataset.variables[e.name_].scale_factor = e.scale_factor_
189
- dataset.variables[e.name_].add_offset = e.add_offset_
190
-
191
- for e in dataClass3D:
192
- dataset.variables[e.name_][:] = e.data_
193
- dataset.variables[e.name_].units = e.unit_
194
- dataset.variables[e.name_].valid_range = e.valid_range_
195
- if not "3" in format:
196
- dataset.variables[e.name_].coordinate = e.coordinate_
197
- dataset.variables[e.name_].missing_value = e.missing_value_
198
- dataset.variables[e.name_].long_name = e.long_name_
199
- dataset.variables[e.name_].scale_factor = e.scale_factor_
200
- dataset.variables[e.name_].add_offset = e.add_offset_
201
-
202
- for e in dataClass4D:
203
- dataset.variables[e.name_][:] = e.data_
204
- dataset.variables[e.name_].units = e.unit_
205
- dataset.variables[e.name_].valid_range = e.valid_range_
206
- if not "3" in format:
207
- dataset.variables[e.name_].coordinate = e.coordinate_
208
- dataset.variables[e.name_].missing_value = e.missing_value_
209
- dataset.variables[e.name_].long_name = e.long_name_
210
- dataset.variables[e.name_].scale_factor = e.scale_factor_
211
- dataset.variables[e.name_].add_offset = e.add_offset_
212
- for k in list(attributeDict.keys()):
213
- setattr(dataset,k,attributeDict[k])
214
- #dataset.close()
215
- except Exception as ex:
216
- print(ex)
217
- print(latArr.shape,lonArr.shape,e.data_.shape)
218
- print(traceback.format_exc())
219
- #dataset.close()
220
- finally:
221
- dataset.close()
222
- os.renames(outputTmp,output)
223
-
224
- def mkNCCommonUni_multiISO(output, dateTimeStart, dateTimeArr, isoArr, latArr, lonArr, dataClass4D=[], dataClass3D=[],
225
- dataClass2D=[], format='NETCDF4'):
226
- dataset = nc.Dataset(output, 'w', format=format) # 'NETCDF4_CLASSIC')
227
-
228
- try:
229
- if not dateTimeArr is None and not dateTimeStart is None:
230
- dataset.createDimension("time", len(dateTimeArr))
231
-
232
-
233
- if not isoArr is None:
234
- for iso in isoArr:
235
- dataset.createDimension(iso.name_, len(iso.data_))
236
-
237
- dataset.createDimension("lat", len(latArr))
238
- dataset.createDimension("lon", len(lonArr))
239
-
240
- if not dateTimeArr is None and not dateTimeStart is None:
241
- dataset.createVariable("time", np.float32, ("time"), zlib=True)
242
-
243
- if not isoArr is None:
244
- for iso in isoArr:
245
- dataset.createVariable(iso.name_, iso.type_, iso.coordinate_, zlib=True)
246
-
247
- dataset.createVariable("lat", np.float64, ("lat"), zlib=True)
248
- dataset.createVariable("lon", np.float64, ("lon"), zlib=True)
249
-
250
- for e in dataClass2D:
251
- dataset.createVariable(e.name_, e.type_, tuple(e.coordinate_), zlib=True)
252
-
253
- for e in dataClass3D:
254
- dataset.createVariable(e.name_, e.type_, tuple(e.coordinate_), zlib=True)
255
-
256
- for e in dataClass4D:
257
- dataset.createVariable(e.name_, e.type_, tuple(e.coordinate_), zlib=True)
258
- if not dateTimeArr is None and not dateTimeStart is None:
259
- dataset.variables["time"][:] = dateTimeArr
260
- dataset.variables["time"].units = 'minutes since %s' % (dateTimeStart.strftime("%Y-%m-%d %H:%M:%S"))
261
- dataset.variables["time"].calendar = 'gregorian'
262
-
263
- if not isoArr is None:
264
- for iso in isoArr:
265
- dataset.variables[iso.name_][:] = iso.data_
266
- dataset.variables[iso.name_].units = iso.unit_
267
- dataset.variables[iso.name_].positive = iso.positive_
268
-
269
- dataset.variables["lat"][:] = latArr
270
- dataset.variables['lat'].units = 'degrees_north'
271
-
272
- dataset.variables["lon"][:] = lonArr
273
- dataset.variables['lon'].units = 'degrees_east'
274
-
275
- for e in dataClass2D:
276
- dataset.variables[e.name_][:] = e.data_
277
- dataset.variables[e.name_].units = e.unit_
278
- dataset.variables[e.name_].valid_range = e.valid_range_
279
- if not "3" in format:
280
- dataset.variables[e.name_].coordinate = e.coordinate_
281
- dataset.variables[e.name_].missing_value = e.missing_value_
282
- dataset.variables[e.name_].scale_factor = e.scale_factor_
283
- dataset.variables[e.name_].add_offset = e.add_offset_
284
-
285
- for e in dataClass3D:
286
- dataset.variables[e.name_][:] = e.data_
287
- dataset.variables[e.name_].units = e.unit_
288
- dataset.variables[e.name_].valid_range = e.valid_range_
289
- if not "3" in format:
290
- dataset.variables[e.name_].coordinate = e.coordinate_
291
- dataset.variables[e.name_].missing_value = e.missing_value_
292
- dataset.variables[e.name_].scale_factor = e.scale_factor_
293
- dataset.variables[e.name_].add_offset = e.add_offset_
294
-
295
- for e in dataClass4D:
296
- dataset.variables[e.name_][:] = e.data_
297
- dataset.variables[e.name_].units = e.unit_
298
- dataset.variables[e.name_].valid_range = e.valid_range_
299
- if not "3" in format:
300
- dataset.variables[e.name_].coordinate = e.coordinate_
301
- dataset.variables[e.name_].missing_value = e.missing_value_
302
- dataset.variables[e.name_].scale_factor = e.scale_factor_
303
- dataset.variables[e.name_].add_offset = e.add_offset_
304
-
305
- # dataset.close()
306
- except Exception as ex:
307
- print(ex)
308
- print(latArr.shape, lonArr.shape, e.data_.shape)
309
- print(traceback.format_exc())
310
- # dataset.close()
311
- finally:
312
- dataset.close()
313
-
314
- def clip(data, ltc, lat0, lon0, step):
315
- latIdx0 = int(np.round((lat0 - ltc.n) / step+ 0.5,3))
316
- latIdx1 = int(np.round((lat0 - ltc.s) / step+ 0.5,3))
317
- lonIdx0 = int(np.round((ltc.w - lon0) / step+ 0.5,3))
318
- if ltc.e<ltc.w:
319
- E = ltc.e+360
320
- lonIdx1 = int(np.round((E - lon0) / step + 0.5,3))
321
- else:
322
- lonIdx1 = int(np.round((ltc.e - lon0) / step+ 0.5,3))
323
- data = data[...,latIdx0:latIdx1+1, lonIdx0:lonIdx1+1]
324
- return data
325
-
326
- def clip2(data, ltc, latArr, lonArr, step,isPad=False):
327
- latIdx0 = int((latArr[0] - ltc.n) / step+ 0.5)
328
- latIdx1 = int((latArr[0] - ltc.s) / step+ 0.5)
329
- lonIdx0 = int((ltc.w - lonArr[0]) / step+ 0.5)
330
- lonIdx1 = int((ltc.e - lonArr[0]) / step+ 0.5)
331
- if isPad:
332
- if latArr[latIdx0]<ltc.n and latIdx0>0:
333
- latIdx0 -=1
334
- if latArr[latIdx1]>ltc.s and latIdx1< (len(latArr)-1):
335
- latIdx1 +=1
336
- if lonArr[lonIdx0] > ltc.w and lonIdx0 > 0:
337
- lonIdx0 -= 1
338
- if lonArr[lonIdx1] < ltc.e and lonIdx1 < (len(lonArr) - 1):
339
- lonIdx1 += 1
340
-
341
- data = data[...,latIdx0:latIdx1+1, lonIdx0:lonIdx1+1]
342
- return data
343
-
344
- def clipLat(data, ltc, step,isPad=False):
345
- latIdx0 = int(np.round((data[0] - ltc.n) / step+ 0.5,3))
346
- latIdx1 = int(np.round((data[0] - ltc.s) / step+ 0.5,3))
347
- if isPad:
348
- if data[latIdx0]<ltc.n and latIdx0>0:
349
- latIdx0 -=1
350
- if data[latIdx1]>ltc.s and latIdx1< (len(data)-1):
351
- latIdx1 +=1
352
- data = data[latIdx0:latIdx1+1]
353
- return data
354
-
355
- def clipLon(data, ltc, step,isPad=False):
356
- lonIdx0 = int(np.round((ltc.w - data[0]) / step+ 0.5,3))
357
- lonIdx1 = int(np.round((ltc.e - data[0]) / step+ 0.5,3))
358
- if isPad:
359
- if data[lonIdx0]>ltc.w and lonIdx0>0:
360
- lonIdx0 -=1
361
- if data[lonIdx1]<ltc.e and lonIdx1< (len(data)-1):
362
- lonIdx1 +=1
363
- data = data[lonIdx0:lonIdx1+1]
364
- return data
365
-
366
- def totalTimes(delta,second):
367
- return (delta.days*24*3600+delta.seconds)//second
368
-
369
- #def timeSeq(start,end,secInter):
370
- # times=totalTimes((end-start),secInter)
371
- # return list(map(lambda x:start+relativedelta(seconds=x*secInter),range(times)))
372
-
373
- def timeSeq(start,end,secInter,endPoint=True):
374
- times=totalTimes((end-start),secInter)
375
- end = 1 if endPoint else 0
376
- return list(map(lambda x:start+relativedelta(seconds=x*secInter),range(times+end)))
377
-
378
- def UV2WSWD(U,V):
379
- ws = np.sqrt(np.square(U) + np.square(V))
380
- wd = (np.degrees(np.arctan2(-U, -V))+ 360)%360
381
- return ws,wd
382
-
383
- def WSWD2UV(ws,wd):
384
- u=- ws*np.sin(np.radians(wd))
385
- v=- ws*np.cos(np.radians(wd))
386
- return u,v
387
-
388
- def test():
389
- print("test")
390
-
391
- def normalNC(data):
392
- mx=np.nanmax(data)
393
- mn = np.nanmin(data)
394
- rangeV=mx-mn
395
- scale = rangeV/254
396
- offset = (mx+mn)/2
397
- data1=(data - offset)/scale
398
- data1[np.isnan(data1)] = -128
399
- return data1,scale,offset
400
-
401
- def SunAngle(UTC, lat, lon, TimeZone = 0):
402
- year, DOY, hour = UTC.timetuple().tm_year, UTC.timetuple().tm_yday, UTC.timetuple().tm_hour
403
- min, second = UTC.timetuple().tm_min, UTC.timetuple().tm_sec
404
- N0 = 79.6764 + 0.2422 * (year - 1985) - int((year - 1985) / 4.0)
405
- sitar = 2 * np.pi * (DOY - N0) / 365.2422
406
- ED1 = 0.3723 + 23.2567 * np.sin(sitar) + 0.1149 * np.sin(2 * sitar) - 0.1712 * np.sin(3 * sitar) - 0.758 * np.cos(sitar) + 0.3656 * np.cos(2 * sitar) + 0.0201 * np.cos(3 * sitar)
407
- ED = ED1 * np.pi / 180
408
- dLon = lon - TimeZone * 15.0
409
- Et = 0.0028 - 1.9857 * np.sin(sitar) + 9.9059 * np.sin(2 * sitar) - 7.0924 * np.cos(
410
- sitar) - 0.6882 * np.cos(2 * sitar)
411
- gtdt1 = hour + min / 60.0 + second / 3600.0 + dLon / 15
412
-
413
- gtdt = gtdt1 + Et / 60.0
414
- dTimeAngle1 = 15.0 * (gtdt - 12)
415
- dTimeAngle = dTimeAngle1 * np.pi / 180
416
-
417
- latitudeArc = lat * np.pi / 180
418
- HeightAngleArc = np.arcsin(np.sin(latitudeArc) * np.sin(ED) + np.cos(latitudeArc) * np.cos(ED) * np.cos(dTimeAngle))
419
- HeightAngle = HeightAngleArc * 180 / np.pi
420
- return HeightAngle
421
-
422
- # calculate sun angle
423
- def calSunAngle(localTime, TimeZone, lat, lonT):
424
- lon = copy.copy(lonT)
425
- lon[lon<0] +=360
426
- year = localTime.year
427
- month = localTime.month
428
- day = localTime.day
429
- hour = localTime.hour
430
- min = localTime.minute
431
- sec = localTime.second
432
- DOY = localTime.timetuple().tm_yday
433
-
434
- N0 = int(79.6764 + 0.2422 * (year - 1985) - ((year - 1985) / 4.0))
435
-
436
- sitar = 2 * np.pi * (DOY - N0) / 365.2422
437
- ED1 = 0.3723 + 23.2567 * np.sin(sitar) + 0.1149 * np.sin(2 * sitar) - 0.1712 * np.sin(3 * sitar) - 0.758 * np.cos(
438
- sitar) + 0.3656 * np.cos(2 * sitar) + 0.0201 * np.cos(3 * sitar)
439
- ED = ED1 * np.pi / 180
440
- # // #ED本身有符号
441
-
442
- dLon = copy.copy(lon)
443
-
444
- dLon[np.logical_and(lon >= 0, TimeZone == -13)] = lon[np.logical_and(lon >= 0, TimeZone == -13)] - (
445
- np.floor((lon[np.logical_and(lon >= 0, TimeZone == -13)] * 10 - 75) / 150) + 1) * 15.0
446
- dLon[np.logical_and(lon >= 0, TimeZone != -13)] = lon[np.logical_and(lon >= 0, TimeZone != -13)] - TimeZone * 15.0
447
-
448
- dLon[np.logical_and(lon < 0, TimeZone == -13)] = (np.floor(
449
- (lon[np.logical_and(lon < 0, TimeZone == -13)] * 10 - 75) / 150) + 1) * 15.0 - lon[
450
- np.logical_and(lon < 0, TimeZone == -13)]
451
- dLon[np.logical_and(lon < 0, TimeZone != -13)] = TimeZone * 15.0 - lon[np.logical_and(lon < 0, TimeZone != -13)]
452
-
453
- # // #时差
454
- Et = 0.0028 - 1.9857 * np.sin(sitar) + 9.9059 * np.sin(2 * sitar) - 7.0924 * np.cos(sitar) - 0.6882 * np.cos(
455
- 2 * sitar)
456
- gtdt1 = hour + min / 60.0 + sec / 3600.0 + dLon / 15
457
- # // #地方时
458
- gtdt = gtdt1 + Et / 60.0
459
- dTimeAngle1 = 15.0 * (gtdt - 12)
460
- dTimeAngle = dTimeAngle1 * np.pi / 180
461
-
462
- latitudeArc = lat * np.pi / 180
463
-
464
- HeightAngleArc = np.arcsin(np.sin(latitudeArc) * np.sin(ED) + np.cos(latitudeArc) * np.cos(ED) * np.cos(dTimeAngle))
465
-
466
- CosAzimuthAngle = (np.sin(HeightAngleArc) * np.sin(latitudeArc) - np.sin(ED)) / np.cos(HeightAngleArc) / np.cos(
467
- latitudeArc)
468
- AzimuthAngleArc = np.arccos(CosAzimuthAngle)
469
- HeightAngle = HeightAngleArc * 180 / np.pi
470
- ZenithAngle = 90 - HeightAngle
471
- AzimuthAngle1 = AzimuthAngleArc * 180 / np.pi
472
-
473
- AzimuthAngle = copy.copy(AzimuthAngle1)
474
- AzimuthAngle[dTimeAngle < 0] = 180 - AzimuthAngle1[dTimeAngle < 0]
475
- AzimuthAngle[dTimeAngle >= 0] = 180 + AzimuthAngle1[dTimeAngle >= 0]
476
-
477
- # // println( s"太阳天顶角(deg):${ZenithAngle} 高度角(deg):${HeightAngle} 方位角(deg):$AzimuthAngle")
478
- return ZenithAngle, HeightAngle, AzimuthAngle
479
-
480
- def mkDir(path):
481
- if "." in path:
482
- os.makedirs(os.path.dirname(path),exist_ok=True)
483
- else:
484
- os.makedirs(path, exist_ok=True)
485
-
486
- def expend(data,latArr,lonArr,dim=2,fill_value=np.nan,areaLtc=None,step=0.01):
487
- if areaLtc is None:
488
- N = LeftTopCornerPairArr[0]["evn"].n
489
- S = LeftTopCornerPairArr[3]["evn"].s
490
- W = LeftTopCornerPairArr[6]["evn"].w
491
- E = LeftTopCornerPairArr[0]["evn"].e
492
- else:
493
- N = areaLtc.n
494
- S = areaLtc.s
495
- W = areaLtc.w
496
- E = areaLtc.e
497
-
498
- latOffset = int(np.round(((N - latArr[0]) / step).astype(np.float64),4))
499
- latOffsetDown = int(np.round(((latArr[-1] - S) / step).astype(np.float64),4))
500
- lonOffset = int(np.round(((lonArr[0] - W) / step).astype(np.float64),4))
501
- lonOffsetRight = int(np.round(((E - lonArr[-1]) / step).astype(np.float64),4))
502
- appendLat = np.asarray(list(map(lambda x: latArr[0] + x * step, range(1, latOffset + 1)))[::-1])
503
- appendLatDown = np.asarray(list(map(lambda x: latArr[-1] - x * step, range(1, latOffsetDown + 1))))
504
- latArr = np.r_[appendLat, latArr]
505
- latArr = np.r_[latArr, appendLatDown]
506
- appendLon = np.asarray(list(map(lambda x: lonArr[0] - x * step, range(1, lonOffset + 1)))[::-1])
507
- appendLonRight = np.asarray(list(map(lambda x: lonArr[-1] + x * step, range(1, lonOffsetRight + 1))))
508
- lonArr = np.r_[appendLon, lonArr]
509
- lonArr = np.r_[lonArr, appendLonRight]
510
-
511
- if latOffset<0:
512
- latOffset=0
513
- if latOffsetDown < 0:
514
- latOffsetDown = 0
515
- if lonOffset < 0:
516
- lonOffset = 0
517
- if lonOffsetRight < 0:
518
- lonOffsetRight = 0
519
-
520
- if dim==2:
521
- data = np.pad(data, ((latOffset , latOffsetDown ), (lonOffset , lonOffsetRight)),constant_values=fill_value)
522
- elif dim==3:
523
- data = np.pad(data, ((0, 0), (latOffset, latOffsetDown), (lonOffset, lonOffsetRight)), constant_values=fill_value)
524
- elif dim==4:
525
- data = np.pad(data, ((0, 0),(0, 0), (latOffset, latOffsetDown), (lonOffset, lonOffsetRight)), constant_values=fill_value)
526
- return data,latArr,lonArr
527
-
528
-
529
- def checkNC(path):
530
- with nc.Dataset(path) as dataNC:
531
- for e in list(dataNC.variables):
532
- dataNC[e][:]
533
-
534
- def cropDF(df,evn):
535
- return df[(df["Lat"]>evn.s)&(df["Lat"]<evn.n)&(df["Lon"]>evn.w)&(df["Lon"]<evn.e)]
536
-
537
-
538
- def clip_patch(dMat,lenO,inter):
539
- lenC = lenO-inter*2
540
- row = int(np.ceil((dMat.shape[-2]-inter*2)/lenC))
541
- col = int(np.ceil((dMat.shape[-1]-inter*2)/lenC))
542
- inputList = []
543
- dMat = np.pad(dMat,((0,0),(inter,inter),(inter,inter)))
544
- for r in range(row):
545
- for c in range(col):
546
- startR = 0 if r==0 else inter*2+lenC*(r+1)-lenO
547
- startC = 0 if c==0 else inter*2+lenC*(c+1)-lenO
548
-
549
- if r==row-1:
550
- startR = dMat.shape[-2]-lenO
551
- endR = dMat.shape[-2]
552
- else:
553
- endR = inter*2+lenC*(r+1)
554
-
555
- if c==col-1:
556
- startC = dMat.shape[-1]-lenO
557
- endC = dMat.shape[-1]
558
- else:
559
- endC = inter*2+lenC*(c+1)
560
- mat = dMat[:,startR:endR,startC:endC]
561
-
562
-
563
- inputList.append(mat)
564
-
565
- inputList = np.asarray(inputList)
566
- return inputList
567
-
568
- def mosaic_patch(preds,lenO,inter,y,x):
569
-
570
- lenC = lenO-inter*2
571
- row = int(np.ceil((y-inter*2)/lenC))
572
- col = int(np.ceil((x-inter*2)/lenC))
573
- matLast = np.full([30,y,x],np.nan)
574
-
575
- for r in range(row):
576
- for c in range(col):
577
- mat = preds[r*col+c][:,inter:-inter,inter:-inter]
578
-
579
- startR = lenC*r
580
- startC = lenC*c
581
-
582
- if r==row-1:
583
- startR = matLast.shape[-2]-lenC
584
- endR = matLast.shape[-2]
585
- else:
586
- endR = lenC*(r+1)
587
-
588
- if c==col-1:
589
- startC = matLast.shape[-1]-lenC
590
- endC = matLast.shape[-1]
591
- else:
592
- endC = lenC*(c+1)
593
-
594
- matLast[:,startR:endR,startC:endC]=mat
595
-
596
- return matLast
597
-
598
- def start_points(size, split_size, overlap=0):
599
- points = [0]
600
- stride = int(split_size * (1-overlap))
601
- counter = 1
602
- while True:
603
- pt = stride * counter
604
- if pt + split_size >= size:
605
- points.append(size - split_size)
606
- break
607
- else:
608
- points.append(pt)
609
- counter += 1
610
- return points
611
-
612
- if __name__ == '__main__':
613
- print(np.round(1))