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