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/hjnGIS.py DELETED
@@ -1,330 +0,0 @@
1
- from PIL import Image, ImageDraw
2
- import matplotlib.pyplot as plt
3
- from hjnwtx.mkNCHJN import envelope,mkDir
4
- import numpy as np
5
- import netCDF4 as nc
6
- import copy
7
- import geopandas as gpd
8
- from osgeo import gdal, ogr, osr
9
- import os
10
- import shapely
11
-
12
-
13
- import random
14
- import string
15
-
16
-
17
-
18
- class maskClip():
19
- def __init__(self,data,latAtt,lonArr,step):
20
-
21
- self.dem = data
22
- self.latArr = latAtt
23
- self.lonArr = lonArr
24
-
25
- oriStep=np.abs((self.latArr[0]-self.latArr[-1])/(len(self.latArr)-1))
26
- range=int(np.round(step/oriStep,0))
27
- self.dem=self.dem[::range,::range]
28
-
29
- self.ltc = envelope(self.latArr[0], self.latArr[-1], self.lonArr[0], self.lonArr[-1])
30
- self.step = step
31
-
32
- def world2Pixel(self,ltc, x, y):
33
- """
34
- Uses a gdal geomatrix (gdal.GetGeoTransform()) to calculate
35
- the pixel location of a geospatial coordinate
36
- """
37
- ulX = ltc.w
38
- ulY = ltc.n
39
- xDist = self.step
40
-
41
- pixel = int((x - ulX) / xDist)
42
- line = int((ulY - y) / xDist)
43
- return (pixel, line)
44
-
45
-
46
- def getMask(self,geom,minX,maxY,minY,maxX):
47
-
48
- points = []
49
- pixels = []
50
- ulX, ulY = self.world2Pixel(self.ltc, minX, maxY)
51
- lrX, lrY = self.world2Pixel(self.ltc, maxX, minY)
52
-
53
- # Calculate the pixel size of the new image
54
- pxWidth = int(lrX - ulX)
55
- pxHeight = int(lrY - ulY)
56
-
57
- ltc1 = copy.copy(self.ltc)
58
- ltc1.n = maxY
59
- ltc1.w = minX
60
-
61
- pts = geom.boundary.xy
62
- for p in range(len(pts[0])):
63
- points.append((pts[0][p], pts[1][p]))
64
- for p in points:
65
- pixels.append(self.world2Pixel(ltc1, p[0], p[1]))
66
- rasterPoly = Image.new("L", (pxWidth, pxHeight), 1)
67
- rasterize = ImageDraw.Draw(rasterPoly)
68
- if len(pixels) > 1:
69
- rasterize.polygon(pixels, 0)
70
-
71
- mask = np.asarray(rasterPoly)
72
-
73
-
74
- # plt.imshow(mask)
75
- # plt.show()
76
-
77
- latOffset0 = int((self.ltc.n - maxY) / self.step)
78
- latOffset1 = self.dem.shape[0] - int((self.ltc.n - minY) / self.step)
79
- lonOffset0 = int((minX - self.ltc.w) / self.step)
80
- lonOffset1 = self.dem.shape[1] - int((maxX - self.ltc.w) / self.step)
81
- ndarray = np.pad(mask, ((latOffset0, latOffset1),
82
- (lonOffset0, lonOffset1)), 'constant', constant_values=(1, 1))
83
-
84
- clip = copy.copy(self.dem)
85
-
86
- clip[ndarray != 0] = np.nan
87
-
88
- return clip
89
-
90
-
91
-
92
- def clip(self,shapefile_path,encoding='gb18030'):
93
- chly = gpd.GeoDataFrame.from_file(shapefile_path, encoding=encoding).geometry
94
-
95
- minX, maxX, minY, maxY = chly.bounds.min().minx,chly.bounds.max().maxx,chly.bounds.min().miny,chly.bounds.max().maxy
96
- maskArr=[]
97
-
98
- for j in range(len(chly)):
99
- geom = chly[j]
100
- if geom.geometryType() == 'Polygon':
101
- clip=self.getMask(geom, minX, maxY, minY, maxX)
102
- maskArr.append(clip)
103
- elif geom.geometryType() == "MultiPolygon":
104
- multiLayer = []
105
- for i in range(len(geom)):
106
- geom1 = geom[i]
107
- clip = self.getMask(geom1, minX, maxY, minY, maxX)
108
- multiLayer.append(clip)
109
-
110
- multiLayer= np.asarray(multiLayer)
111
- clip = np.nanmax(multiLayer,axis=0)
112
- maskArr.append(clip)
113
-
114
- return maskArr
115
-
116
- def getMaskMask(self, geom, minX, maxY, minY, maxX):
117
-
118
- points = []
119
- pixels = []
120
- ulX, ulY = self.world2Pixel(self.ltc, minX, maxY)
121
- lrX, lrY = self.world2Pixel(self.ltc, maxX, minY)
122
-
123
- # Calculate the pixel size of the new image
124
- pxWidth = int(lrX - ulX)
125
- pxHeight = int(lrY - ulY)
126
-
127
- ltc1 = copy.copy(self.ltc)
128
- ltc1.n = maxY
129
- ltc1.w = minX
130
-
131
- pt = geom.boundary
132
- # print(pt)
133
-
134
- if pt.type == "LineString":
135
- pts = pt.xy
136
- for p in range(len(pts[0])):
137
- points.append((pts[0][p], pts[1][p]))
138
- for p in points:
139
- pixels.append(self.world2Pixel(ltc1, p[0], p[1]))
140
- rasterPoly = Image.new("L", (pxWidth, pxHeight), 1)
141
- rasterize = ImageDraw.Draw(rasterPoly)
142
- if len(pixels) > 1:
143
- rasterize.polygon(pixels, 0)
144
-
145
- mask = np.asarray(rasterPoly)
146
-
147
- latOffset0 = int((self.ltc.n - maxY) / self.step)
148
- latOffset1 = self.dem.shape[0] - int((self.ltc.n - minY) / self.step)
149
- lonOffset0 = int((minX - self.ltc.w) / self.step)
150
- lonOffset1 = self.dem.shape[1] - int((maxX - self.ltc.w) / self.step)
151
- ndarray = np.pad(mask, ((latOffset0, latOffset1),
152
- (lonOffset0, lonOffset1)), 'constant', constant_values=(1, 1))
153
-
154
- # clip = copy.copy(self.dem)
155
- # clip[ndarray != 0] = np.nan
156
- return mask
157
- else:
158
- # return
159
- masks = []
160
-
161
- for ptt in pt[:1]:
162
- pts = ptt.xy
163
- for p in range(len(pts[0])):
164
- points.append((pts[0][p], pts[1][p]))
165
- for p in points:
166
- pixels.append(self.world2Pixel(ltc1, p[0], p[1]))
167
- rasterPoly = Image.new("L", (pxWidth, pxHeight), 1)
168
- rasterize = ImageDraw.Draw(rasterPoly)
169
- if len(pixels) > 1:
170
- rasterize.polygon(pixels, 0)
171
-
172
- mask = np.asarray(rasterPoly)
173
- masks.append(mask)
174
- masks = np.asarray(masks)
175
- masks = np.min(masks, axis=0)
176
- latOffset0 = int((self.ltc.n - maxY) / self.step)
177
- latOffset1 = self.dem.shape[0] - int((self.ltc.n - minY) / self.step)
178
- lonOffset0 = int((minX - self.ltc.w) / self.step)
179
- lonOffset1 = self.dem.shape[1] - int((maxX - self.ltc.w) / self.step)
180
- ndarray = np.pad(masks, ((latOffset0, latOffset1),
181
- (lonOffset0, lonOffset1)), 'constant', constant_values=(1, 1))
182
-
183
- clip = copy.copy(self.dem)
184
- clip[ndarray != 0] = np.nan
185
- return clip
186
-
187
- def clipMask(self,chlyTable):
188
- # chlyTable = gpd.GeoDataFrame.from_file(shapefile_path, encoding=encoding)
189
- chly = chlyTable.geometry
190
- minX, maxX, minY, maxY = chly.bounds.min().minx,chly.bounds.max().maxx,chly.bounds.min().miny,chly.bounds.max().maxy
191
- maskArr=[]
192
-
193
- for j in range(len(chly)):
194
- geom = chly.iloc[j]
195
- if geom.geometryType() == 'Polygon':
196
- clip=self.getMaskMask(geom, minX, maxY, minY, maxX)
197
- if not clip is None:
198
- maskArr.append(clip)
199
-
200
- elif geom.geometryType() == "MultiPolygon":
201
- multiLayer = []
202
- for i in range(len(geom)):
203
- geom1 = geom[i]
204
- clip = self.getMaskMask(geom1, minX, maxY, minY, maxX)
205
- multiLayer.append(clip)
206
-
207
- multiLayer= np.asarray(multiLayer)
208
- clip = np.nanmin(multiLayer,axis=0)
209
- if not clip is None:
210
- maskArr.append(clip)
211
-
212
- return maskArr
213
-
214
-
215
- class slope_aspect():
216
- def __init__(self,gridNew,dx, dy):
217
- self.gridNew = gridNew
218
- self.dx = dx
219
- self.dy = dy
220
- self.Sx, self.Sy = self.calcFiniteSlopes(gridNew, self.dx, self.dy)
221
- # 计算dx,dy
222
- def calcFiniteSlopes(self,elevGrid, dx, dy):
223
- Zbc = np.pad(elevGrid, ((1, 1), (1, 1)), "edge")
224
- Sx = (Zbc[1:-1, :-2] - Zbc[1:-1, 2:]) / (2 * dx) # WE方向
225
- Sy = (Zbc[2:, 1:-1] - Zbc[:-2, 1:-1]) / (2 * dy) # NS方向
226
- return Sx, Sy
227
-
228
- def calcFiniteAspect(self,Sx, Sy):
229
-
230
- Sx = Sx.astype(np.float)
231
- Sy = Sy.astype(np.float)
232
- aspect = np.degrees(np.arctan2(Sy, Sx))
233
- aspect1 = copy.copy(aspect)
234
- aspect1[aspect < 0] = 90 - aspect[aspect < 0]
235
- aspect1[aspect > 90] = 360.0 - aspect[aspect > 90] + 90.0
236
- aspect1[np.logical_and(aspect <= 90, aspect >= 0)] = 90.0 - aspect[np.logical_and(aspect <= 90, aspect >= 0)]
237
- aspect1[np.logical_and(Sx == 0, Sy == 0)] = -1
238
- return aspect1
239
-
240
- def getSlop(self):
241
- return np.degrees(np.arctan(np.sqrt(self.Sx ** 2 + self.Sy ** 2)))
242
-
243
- def getAspect(self):
244
- return self.calcFiniteAspect(self.Sx, self.Sy)
245
-
246
-
247
- def Polygonize(mask,latArr,lonArr,outshp,EPSG=4326):
248
- driver = gdal.GetDriverByName("GTiff")
249
- im_bands = 1
250
- random_letters = ''.join(random.choices(string.ascii_letters, k=5))
251
- tmpPath = f"./tmp_{random_letters}.tiff"
252
- dataset = driver.Create(tmpPath, mask.shape[1], mask.shape[0], im_bands, gdal.GDT_UInt16)
253
- im_geotrans = (lonArr[0], lonArr[1]-lonArr[0], 0, latArr[0], 0, latArr[1]-latArr[0])
254
- dataset.SetGeoTransform(im_geotrans)
255
- prj = osr.SpatialReference()
256
- prj.ImportFromEPSG(EPSG)
257
- dataset.SetProjection(prj.ExportToWkt())
258
- dataset.GetRasterBand(1).WriteArray(mask)
259
- inband = dataset.GetRasterBand(1)
260
- mkDir(outshp)
261
- drv = ogr.GetDriverByName("ESRI Shapefile")
262
- if os.path.exists(outshp):
263
- drv.DeleteDataSource(outshp)
264
- Polygon = drv.CreateDataSource(outshp)
265
- Poly_layer = Polygon.CreateLayer(outshp, srs=prj,
266
- geom_type=ogr.wkbMultiPolygon)
267
- newField = ogr.FieldDefn('value', ogr.OFTReal)
268
- Poly_layer.CreateField(newField)
269
- gdal.FPolygonize(inband, None, Poly_layer, 0)
270
- Polygon.SyncToDisk()
271
- del Polygon
272
- os.remove(tmpPath)
273
-
274
- def Polylinize(mask, latArr, lonArr, outshp, EPSG=4326):
275
- driver = gdal.GetDriverByName("GTiff")
276
- im_bands = 1
277
- random_letters = ''.join(random.choices(string.ascii_letters, k=5))
278
- tmpPath = f"./tmp_{random_letters}.tiff"
279
- dataset = driver.Create(tmpPath, mask.shape[1], mask.shape[0], im_bands, gdal.GDT_UInt16)
280
- im_geotrans = (lonArr[0], lonArr[1]-lonArr[0], 0, latArr[0], 0, latArr[1]-latArr[0])
281
- dataset.SetGeoTransform(im_geotrans)
282
- prj = osr.SpatialReference()
283
- prj.ImportFromEPSG(EPSG)
284
- dataset.SetProjection(prj.ExportToWkt())
285
- dataset.GetRasterBand(1).WriteArray(mask)
286
- inband = dataset.GetRasterBand(1)
287
- mkDir(outshp)
288
- drv = ogr.GetDriverByName("ESRI Shapefile")
289
- if os.path.exists(outshp):
290
- drv.DeleteDataSource(outshp)
291
- Polygon = drv.CreateDataSource(outshp)
292
- Poly_layer = Polygon.CreateLayer(outshp, srs=prj,
293
- geom_type=ogr.wkbLineString)
294
- newField = ogr.FieldDefn('value', ogr.OFTReal)
295
- Poly_layer.CreateField(newField)
296
- gdal.FPolygonize(inband, None, Poly_layer, 0)
297
- Polygon.SyncToDisk()
298
- del Polygon
299
- os.remove(tmpPath)
300
-
301
- def polygon2polyline(shpFile, tolerance= 0.001):
302
- gdf = gpd.read_file(shpFile)
303
- lat0, lat1, lon1, lon0 = gdf.total_bounds
304
-
305
- area = gpd.GeoSeries([shapely.geometry.Polygon([(lon0+tolerance,lat0-tolerance),(lon0+tolerance,lat1+tolerance),(lon1-tolerance,lat1+tolerance),(lon1-tolerance,lat0-tolerance)])],crs=gdf.crs)
306
- mask_clip = gpd.clip(gdf, area).explode(index_parts=False)
307
- new_gdf = gpd.GeoDataFrame([], columns=mask_clip.columns, crs=gdf.crs)
308
- for i in set(mask_clip["value"]):
309
- tmpDF = mask_clip[mask_clip["value"] == i]
310
- aa = shapely.ops.linemerge(list(tmpDF.geometry))
311
- tmp = gpd.GeoDataFrame([[i,aa]], columns=mask_clip.columns, crs=gdf.crs)
312
- new_gdf = new_gdf.append(tmp)
313
-
314
- new_gdf.reset_index(inplace=True,drop=True)
315
- mask_clip = new_gdf.explode(index_parts=False)
316
-
317
- new_gdf = gpd.GeoDataFrame([],columns=mask_clip.columns,crs=gdf.crs)
318
- mask_clip = list(mask_clip.values)
319
- while len(mask_clip)>0:
320
- tmp = [mask_clip.pop()]
321
- for j in range(1,len(mask_clip)):
322
- if j>=len(mask_clip):
323
- continue
324
- if tmp[0][1].equals(mask_clip[j][1]):
325
- tmp.append(mask_clip.pop(j))
326
- gpdtmp = gpd.GeoDataFrame(tmp, columns=["value", "geometry"], crs=gdf.crs)
327
- gpdtmp.sort_values("value",ascending=False,inplace=True)
328
- new_gdf = new_gdf.append(gpdtmp.iloc[0])
329
- return new_gdf
330
-
shancx/wtx/hjnGPU.py DELETED
@@ -1,21 +0,0 @@
1
- from gpuinfo import GPUInfo
2
- import numpy as np
3
- import time
4
-
5
- def findGPU(waitS=2):
6
- """get ID of GPUS
7
- :param num_gpu: num of GPUs to use
8
- :return: gpu_id: ID of allocated GPUs
9
- """
10
- gpu_id = None
11
- waitSec = np.random.uniform(0,waitS)
12
- time.sleep(waitSec)
13
- available_device=GPUInfo.check_empty()
14
- if not available_device is None:
15
- if len(available_device)>0:
16
- idx = np.random.randint(0,len(available_device))
17
- gpu_id=available_device[idx]
18
-
19
- return gpu_id
20
-
21
-
shancx/wtx/hjnIDW.py DELETED
@@ -1,68 +0,0 @@
1
- # Author : bb
2
- # Time : 2020/11/18 16:59
3
- # -*- coding: utf-8 -*-
4
-
5
- import numpy as np
6
- from sklearn.neighbors import KDTree
7
- np.seterr(divide='ignore',invalid='ignore')
8
-
9
- class IDW():
10
- def __init__(self, y, x, candidate=15):
11
- self.disMat = None
12
- self.idMat = None
13
- self.disPoint = None
14
- self.idPoint = None
15
- self.x = x
16
- self.y = y
17
- self.resultMat = None
18
- self.resultPont = None
19
- self.candidate = candidate
20
-
21
- def initDictMat(self,ltc,resolution=0.01):
22
- self.evn = ltc
23
- self.resolution = resolution
24
- self.latRange = int((self.evn.n - self.evn.s + 10e-10) // self.resolution) + 1
25
- self.lonRange = int((self.evn.e - self.evn.w + 10e-10) // self.resolution) + 1
26
- self.latArr = np.linspace(self.evn.n, self.evn.s, self.latRange)
27
- self.lonArr = np.linspace(self.evn.w, self.evn.e, self.lonRange)
28
- latArr = np.linspace(self.evn.n, self.evn.s, self.latRange)
29
- lonArr = np.linspace(self.evn.w, self.evn.e, self.lonRange)
30
- lonMat, latMat = np.meshgrid(lonArr, latArr)
31
- tree = KDTree(np.c_[self.y, self.x])
32
- xyMesh = np.c_[latMat.reshape(-1), lonMat.reshape(-1)]
33
- dist, ind = tree.query(xyMesh, k=self.candidate)
34
- self.disMat = dist.reshape([len(latArr), len(lonArr), self.candidate])
35
- self.idMat = ind.reshape([len(latArr), len(lonArr), self.candidate])
36
-
37
- def getMat(self,z):
38
- valMat = z[self.idMat]
39
- disAll = np.sum(1 / np.power(self.disMat, 2), axis=2)
40
- dataAll = np.sum(valMat / np.power(self.disMat, 2), axis=2)
41
- self.resultMat = dataAll / disAll
42
- self.resultMat[self.disMat[:, :, 0] == 0] = valMat[self.disMat[:, :, 0] == 0, 0]
43
- return self.resultMat
44
-
45
- def initDictPoints(self,yP, xP):
46
- tree = KDTree(np.c_[self.y, self.x])
47
- xyMesh = np.c_[yP, xP]
48
- dist, ind = tree.query(xyMesh, k=self.candidate)
49
- self.disPoint = dist
50
- self.idPoint = ind
51
- print()
52
-
53
- def getPoint(self, z):
54
- valPont = z[self.idPoint]
55
- disAll = np.sum(1 / np.power(self.disPoint, 2),axis=1)
56
- dataAll = np.sum(valPont / np.power(self.disPoint, 2),axis=1)
57
- self.resultPont = dataAll / disAll
58
- self.resultPont[self.disPoint[:,0] == 0] = valPont[self.disPoint[:,0] == 0, 0]
59
- return self.resultPont
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
shancx/wtx/hjnKDTree.py DELETED
@@ -1,75 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- from collections import namedtuple
4
- from operator import itemgetter
5
- from pprint import pformat
6
- import numpy as np
7
-
8
-
9
- class Node(namedtuple('Node', 'location left_child right_child')):
10
- def __repr__(self):
11
- return pformat(tuple(self))
12
-
13
-
14
- class KDTree():
15
- def __init__(self, points):
16
- self.tree = self._make_kdtree(points)
17
- if len(points) > 0:
18
- self.k = len(points[0])
19
- else:
20
- self.k = None
21
-
22
- def _make_kdtree(self, points, depth=0):
23
- if not points:
24
- return None
25
-
26
- k = len(points[0])
27
- axis = depth % k
28
-
29
- points.sort(key=itemgetter(axis))
30
- median = len(points) // 2
31
-
32
- return Node(
33
- location=points[median],
34
- left_child=self._make_kdtree(points[:median], depth + 1),
35
- right_child=self._make_kdtree(points[median + 1:], depth + 1))
36
-
37
- def find_nearest(self,
38
- point,
39
- root=None,
40
- axis=0,
41
- dist_func=lambda x, y: np.linalg.norm(x - y)):
42
-
43
- if root is None:
44
- root = self.tree
45
- self._best = None
46
-
47
- # 若不是叶节点,则继续向下走
48
- if root.left_child or root.right_child:
49
- new_axis = (axis + 1) % self.k
50
- if point[axis] < root.location[axis] and root.left_child:
51
- self.find_nearest(point, root.left_child, new_axis)
52
- elif root.right_child:
53
- self.find_nearest(point, root.right_child, new_axis)
54
-
55
- # 回溯:尝试更新 best
56
- dist = dist_func(root.location, point)
57
- if self._best is None or dist < self._best[0]:
58
- self._best = (dist, root.location)
59
-
60
- # 若超球与另一边超矩形相交
61
- if abs(point[axis] - root.location[axis]) < self._best[0]:
62
- new_axis = (axis + 1) % self.k
63
- if root.left_child and point[axis] >= root.location[axis]:
64
- self.find_nearest(point, root.left_child, new_axis)
65
- elif root.right_child and point[axis] < root.location[axis]:
66
- self.find_nearest(point, root.right_child, new_axis)
67
-
68
- return self._best
69
-
70
- if __name__ == '__main__':
71
- point_list = [(2, 3), (5, 4), (9, 6), (4, 7), (8, 1), (7, 2)]
72
- kdtree = KDTree(point_list)
73
-
74
- point = np.array([5, 5])
75
- print(kdtree.find_nearest(point))
@@ -1,47 +0,0 @@
1
- # -*- coding:utf-8 -*-
2
- # Author:hujunnan
3
-
4
- import numpy as np
5
-
6
- # p = Proj("+proj=lcc +lat_0=30 +lon_0= 102 +lat_1=30 +lat_2=60")
7
-
8
- class LAPSTransfrom():
9
- def __init__(self,p,lonMat, latMat,env=None,step=0.03):
10
- xMat, yMat = p(lonMat, latMat)
11
- x0 = np.min(xMat)
12
- y0 = np.max(yMat)
13
- if env is None:
14
- n,s,w,e = np.max(latMat),np.min(latMat),np.min(lonMat),np.max(lonMat)
15
- lat0 = n
16
- lat1 = s
17
- lon0 = w
18
- lon1 = e
19
- else:
20
- lat0 = env.n
21
- lat1 = env.s
22
- lon0 = env.w
23
- lon1 = env.e
24
- self.step = step
25
- self.rangeLat = int(np.ceil(((lat0 - lat1) / step))) + 1
26
- self.rangeLon = int(np.ceil(((lon1 - lon0) / step))) + 1
27
- self.latArr = np.asarray([lat0 - i*step for i in range(self.rangeLat)],np.float64)
28
- self.lonArr = np.asarray([lon0 + i*step for i in range(self.rangeLon)],np.float64)
29
- latMatCHN = np.repeat([self.latArr], self.rangeLon, axis=0).T
30
- lonMatCHN = np.repeat([self.lonArr], self.rangeLat, axis=0)
31
- latMatCHNArr = latMatCHN.reshape(-1)
32
- lonMatCHNArr = lonMatCHN.reshape(-1)
33
- x, y = p(lonMatCHNArr, latMatCHNArr)
34
- self.latIdx = ((y0 - y) / (step*100000) + 0.5).astype(int)
35
- self.lonIdx = ((x - x0) / (step*100000) + 0.5).astype(int)
36
- self.latMaskValid = np.logical_or(self.latIdx < 0, self.latIdx >= latMat.shape[0])
37
- self.lonMaskValid = np.logical_or(self.lonIdx < 0, self.lonIdx >= latMat.shape[1])
38
- self.latIdx[self.latMaskValid] = 0
39
- self.lonIdx[self.lonMaskValid] = 0
40
-
41
- def LambertToLatLon(self,t):
42
- lambertMat = t[self.latIdx, self.lonIdx]
43
- lambertMat = lambertMat.reshape([self.rangeLat, self.rangeLon])
44
- lambertMat[self.latMaskValid.reshape([self.rangeLat, self.rangeLon])] = np.nan
45
- lambertMat[self.lonMaskValid.reshape([self.rangeLat, self.rangeLon])] = np.nan
46
- return lambertMat
47
-
shancx/wtx/hjnLog.py DELETED
@@ -1,78 +0,0 @@
1
- import datetime
2
- import os
3
- import time
4
- import traceback
5
- import logging
6
-
7
- class waitHJN():
8
-
9
- def __init__(self,logger,sepSec,timeoutSec):
10
-
11
- if not isinstance(logger,logging.Logger):
12
- self.logger=self.initLog()
13
- else:
14
- self.logger=logger
15
- self.sepSec=sepSec
16
- self.timeoutSec=timeoutSec
17
-
18
- def initLog(self):
19
- logger = logging.getLogger("hjn_example")
20
- logger.setLevel(logging.DEBUG)
21
- # 建立一个streamhandler来把日志打在CMD窗口上,级别为error以上
22
- ch = logging.StreamHandler()
23
- ch.setLevel(logging.INFO)
24
- # 设置日志格式
25
- formatter = logging.Formatter('%(asctime)s|%(levelname)8s|%(process)d|%(filename)16s[:%(lineno)d]|%(message)s')
26
- ch.setFormatter(formatter)
27
- # 将相应的handler添加在logger对象中
28
- logger.addHandler(ch)
29
- return logger
30
-
31
-
32
-
33
- def action(self,path):
34
- pass
35
-
36
- def wait(self,path,debug=False):
37
- t0 = datetime.datetime.now()
38
- t1 = datetime.datetime.now()
39
- flag= True
40
- while flag:
41
- if (t1-t0).total_seconds()>self.timeoutSec:
42
- flag =False
43
- break
44
- else:
45
- if os.path.exists(path):
46
- try:
47
- self.action(path)
48
- flag =False
49
- return True
50
- except Exception as e:
51
- self.logger.error(traceback.format_exc())
52
- self.logger.error(f"wrong data{path}")
53
-
54
- if not debug:
55
- self.logger.info(f"{path} missing waiting {self.sepSec}s {int(self.timeoutSec-(t1-t0).total_seconds())}s remain")
56
- time.sleep(self.sepSec)
57
- else:
58
- self.logger.info(f"{path} missing break")
59
- return False
60
- t1 = datetime.datetime.now()
61
-
62
- if not flag:
63
- return False
64
- else:
65
- return True
66
-
67
-
68
- class wait1(waitHJN):
69
-
70
- def action(self,path):
71
- os.path.exists(path)
72
-
73
-
74
-
75
- if __name__ == '__main__':
76
-
77
- a = wait1("",2,10)
78
- print(a.wait("./test.csv"))