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.
- shancx/3D/__init__.py +25 -0
- shancx/Algo/Class.py +11 -0
- shancx/Algo/CudaPrefetcher1.py +112 -0
- shancx/Algo/Fake_image.py +24 -0
- shancx/Algo/Hsml.py +391 -0
- shancx/Algo/L2Loss.py +10 -0
- shancx/Algo/MetricTracker.py +132 -0
- shancx/Algo/Normalize.py +66 -0
- shancx/Algo/OptimizerWScheduler.py +38 -0
- shancx/Algo/Rmageresize.py +79 -0
- shancx/Algo/Savemodel.py +33 -0
- shancx/Algo/SmoothL1_losses.py +27 -0
- shancx/Algo/Tqdm.py +62 -0
- shancx/Algo/__init__.py +121 -0
- shancx/Algo/checknan.py +28 -0
- shancx/Algo/iouJU.py +83 -0
- shancx/Algo/mask.py +25 -0
- shancx/Algo/psnr.py +9 -0
- shancx/Algo/ssim.py +70 -0
- shancx/Algo/structural_similarity.py +308 -0
- shancx/Algo/tool.py +704 -0
- shancx/Calmetrics/__init__.py +97 -0
- shancx/Calmetrics/calmetrics.py +14 -0
- shancx/Calmetrics/calmetricsmatrixLib.py +147 -0
- shancx/Calmetrics/rmseR2score.py +35 -0
- shancx/Clip/__init__.py +50 -0
- shancx/Cmd.py +126 -0
- shancx/Config_.py +26 -0
- shancx/Df/DataFrame.py +11 -2
- shancx/Df/__init__.py +17 -0
- shancx/Df/tool.py +0 -0
- shancx/Diffm/Psamples.py +18 -0
- shancx/Diffm/__init__.py +0 -0
- shancx/Diffm/test.py +207 -0
- shancx/Doc/__init__.py +214 -0
- shancx/E/__init__.py +178 -152
- shancx/Fillmiss/__init__.py +0 -0
- shancx/Fillmiss/imgidwJU.py +46 -0
- shancx/Fillmiss/imgidwLatLonJU.py +82 -0
- shancx/Gpu/__init__.py +55 -0
- shancx/H9/__init__.py +126 -0
- shancx/H9/ahi_read_hsd.py +877 -0
- shancx/H9/ahisearchtable.py +298 -0
- shancx/H9/geometry.py +2439 -0
- shancx/Hug/__init__.py +81 -0
- shancx/Inst.py +22 -0
- shancx/Lib.py +31 -0
- shancx/Mos/__init__.py +37 -0
- shancx/NN/__init__.py +235 -106
- shancx/Path1.py +161 -0
- shancx/Plot/GlobMap.py +276 -116
- shancx/Plot/__init__.py +491 -1
- shancx/Plot/draw_day_CR_PNG.py +4 -21
- shancx/Plot/exam.py +116 -0
- shancx/Plot/plotGlobal.py +325 -0
- shancx/{radar_nmc.py → Plot/radarNmc.py} +4 -34
- shancx/{subplots_single_china_map.py → Plot/single_china_map.py} +1 -1
- shancx/Point.py +46 -0
- shancx/QC.py +223 -0
- shancx/RdPzl/__init__.py +32 -0
- shancx/Read.py +72 -0
- shancx/Resize.py +79 -0
- shancx/SN/__init__.py +62 -123
- shancx/Time/GetTime.py +9 -3
- shancx/Time/__init__.py +66 -1
- shancx/Time/timeCycle.py +302 -0
- shancx/Time/tool.py +0 -0
- shancx/Train/__init__.py +74 -0
- shancx/Train/makelist.py +187 -0
- shancx/Train/multiGpu.py +27 -0
- shancx/Train/prepare.py +161 -0
- shancx/Train/renet50.py +157 -0
- shancx/ZR.py +12 -0
- shancx/__init__.py +333 -262
- shancx/args.py +27 -0
- shancx/bak.py +768 -0
- shancx/df2database.py +62 -2
- shancx/geosProj.py +80 -0
- shancx/info.py +38 -0
- shancx/netdfJU.py +231 -0
- shancx/sendM.py +59 -0
- shancx/tensBoard/__init__.py +28 -0
- shancx/wait.py +246 -0
- {shancx-1.8.92.dist-info → shancx-1.9.33.218.dist-info}/METADATA +15 -5
- shancx-1.9.33.218.dist-info/RECORD +91 -0
- {shancx-1.8.92.dist-info → shancx-1.9.33.218.dist-info}/WHEEL +1 -1
- my_timer_decorator/__init__.py +0 -10
- shancx/Dsalgor/__init__.py +0 -19
- shancx/E/DFGRRIB.py +0 -30
- shancx/EN/DFGRRIB.py +0 -30
- shancx/EN/__init__.py +0 -148
- shancx/FileRead.py +0 -44
- shancx/Gray2RGB.py +0 -86
- shancx/M/__init__.py +0 -137
- shancx/MN/__init__.py +0 -133
- shancx/N/__init__.py +0 -131
- shancx/Plot/draw_day_CR_PNGUS.py +0 -206
- shancx/Plot/draw_day_CR_SVG.py +0 -275
- shancx/Plot/draw_day_pre_PNGUS.py +0 -205
- shancx/Plot/glob_nation_map.py +0 -116
- shancx/Plot/radar_nmc.py +0 -61
- shancx/Plot/radar_nmc_china_map_compare1.py +0 -50
- shancx/Plot/radar_nmc_china_map_f.py +0 -121
- shancx/Plot/radar_nmc_us_map_f.py +0 -128
- shancx/Plot/subplots_compare_devlop.py +0 -36
- shancx/Plot/subplots_single_china_map.py +0 -45
- shancx/S/__init__.py +0 -138
- shancx/W/__init__.py +0 -132
- shancx/WN/__init__.py +0 -132
- shancx/code.py +0 -331
- shancx/draw_day_CR_PNG.py +0 -200
- shancx/draw_day_CR_PNGUS.py +0 -206
- shancx/draw_day_CR_SVG.py +0 -275
- shancx/draw_day_pre_PNGUS.py +0 -205
- shancx/makenetCDFN.py +0 -42
- shancx/mkIMGSCX.py +0 -92
- shancx/netCDF.py +0 -130
- shancx/radar_nmc_china_map_compare1.py +0 -50
- shancx/radar_nmc_china_map_f.py +0 -125
- shancx/radar_nmc_us_map_f.py +0 -67
- shancx/subplots_compare_devlop.py +0 -36
- shancx/tool.py +0 -18
- shancx/user/H8mess.py +0 -317
- shancx/user/__init__.py +0 -137
- shancx/user/cinradHJN.py +0 -496
- shancx/user/examMeso.py +0 -293
- shancx/user/hjnDAAS.py +0 -26
- shancx/user/hjnFTP.py +0 -81
- shancx/user/hjnGIS.py +0 -320
- shancx/user/hjnGPU.py +0 -21
- shancx/user/hjnIDW.py +0 -68
- shancx/user/hjnKDTree.py +0 -75
- shancx/user/hjnLAPSTransform.py +0 -47
- shancx/user/hjnMiscellaneous.py +0 -182
- shancx/user/hjnProj.py +0 -162
- shancx/user/inotify.py +0 -41
- shancx/user/matplotlibMess.py +0 -87
- shancx/user/mkNCHJN.py +0 -623
- shancx/user/newTypeRadar.py +0 -492
- shancx/user/test.py +0 -6
- shancx/user/tlogP.py +0 -129
- shancx/util_log.py +0 -33
- shancx/wtx/H8mess.py +0 -315
- shancx/wtx/__init__.py +0 -151
- shancx/wtx/cinradHJN.py +0 -496
- shancx/wtx/colormap.py +0 -64
- shancx/wtx/examMeso.py +0 -298
- shancx/wtx/hjnDAAS.py +0 -26
- shancx/wtx/hjnFTP.py +0 -81
- shancx/wtx/hjnGIS.py +0 -330
- shancx/wtx/hjnGPU.py +0 -21
- shancx/wtx/hjnIDW.py +0 -68
- shancx/wtx/hjnKDTree.py +0 -75
- shancx/wtx/hjnLAPSTransform.py +0 -47
- shancx/wtx/hjnLog.py +0 -78
- shancx/wtx/hjnMiscellaneous.py +0 -201
- shancx/wtx/hjnProj.py +0 -161
- shancx/wtx/inotify.py +0 -41
- shancx/wtx/matplotlibMess.py +0 -87
- shancx/wtx/mkNCHJN.py +0 -613
- shancx/wtx/newTypeRadar.py +0 -492
- shancx/wtx/test.py +0 -6
- shancx/wtx/tlogP.py +0 -129
- shancx-1.8.92.dist-info/RECORD +0 -99
- /shancx/{Dsalgor → Algo}/dsalgor.py +0 -0
- {shancx-1.8.92.dist-info → shancx-1.9.33.218.dist-info}/top_level.txt +0 -0
shancx/user/hjnGIS.py
DELETED
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
from PIL import Image, ImageDraw
|
|
2
|
-
import matplotlib.pyplot as plt
|
|
3
|
-
from hjn.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
|
-
class maskClip():
|
|
13
|
-
def __init__(self,data,latAtt,lonArr,step):
|
|
14
|
-
|
|
15
|
-
self.dem = data
|
|
16
|
-
self.latArr = latAtt
|
|
17
|
-
self.lonArr = lonArr
|
|
18
|
-
|
|
19
|
-
oriStep=np.abs((self.latArr[0]-self.latArr[-1])/(len(self.latArr)-1))
|
|
20
|
-
range=int(np.round(step/oriStep,0))
|
|
21
|
-
self.dem=self.dem[::range,::range]
|
|
22
|
-
|
|
23
|
-
self.ltc = envelope(self.latArr[0], self.latArr[-1], self.lonArr[0], self.lonArr[-1])
|
|
24
|
-
self.step = step
|
|
25
|
-
|
|
26
|
-
def world2Pixel(self,ltc, x, y):
|
|
27
|
-
"""
|
|
28
|
-
Uses a gdal geomatrix (gdal.GetGeoTransform()) to calculate
|
|
29
|
-
the pixel location of a geospatial coordinate
|
|
30
|
-
"""
|
|
31
|
-
ulX = ltc.w
|
|
32
|
-
ulY = ltc.n
|
|
33
|
-
xDist = self.step
|
|
34
|
-
|
|
35
|
-
pixel = int((x - ulX) / xDist)
|
|
36
|
-
line = int((ulY - y) / xDist)
|
|
37
|
-
return (pixel, line)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def getMask(self,geom,minX,maxY,minY,maxX):
|
|
41
|
-
|
|
42
|
-
points = []
|
|
43
|
-
pixels = []
|
|
44
|
-
ulX, ulY = self.world2Pixel(self.ltc, minX, maxY)
|
|
45
|
-
lrX, lrY = self.world2Pixel(self.ltc, maxX, minY)
|
|
46
|
-
|
|
47
|
-
# Calculate the pixel size of the new image
|
|
48
|
-
pxWidth = int(lrX - ulX)
|
|
49
|
-
pxHeight = int(lrY - ulY)
|
|
50
|
-
|
|
51
|
-
ltc1 = copy.copy(self.ltc)
|
|
52
|
-
ltc1.n = maxY
|
|
53
|
-
ltc1.w = minX
|
|
54
|
-
|
|
55
|
-
pts = geom.boundary.xy
|
|
56
|
-
for p in range(len(pts[0])):
|
|
57
|
-
points.append((pts[0][p], pts[1][p]))
|
|
58
|
-
for p in points:
|
|
59
|
-
pixels.append(self.world2Pixel(ltc1, p[0], p[1]))
|
|
60
|
-
rasterPoly = Image.new("L", (pxWidth, pxHeight), 1)
|
|
61
|
-
rasterize = ImageDraw.Draw(rasterPoly)
|
|
62
|
-
if len(pixels) > 1:
|
|
63
|
-
rasterize.polygon(pixels, 0)
|
|
64
|
-
|
|
65
|
-
mask = np.asarray(rasterPoly)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
# plt.imshow(mask)
|
|
69
|
-
# plt.show()
|
|
70
|
-
|
|
71
|
-
latOffset0 = int((self.ltc.n - maxY) / self.step)
|
|
72
|
-
latOffset1 = self.dem.shape[0] - int((self.ltc.n - minY) / self.step)
|
|
73
|
-
lonOffset0 = int((minX - self.ltc.w) / self.step)
|
|
74
|
-
lonOffset1 = self.dem.shape[1] - int((maxX - self.ltc.w) / self.step)
|
|
75
|
-
ndarray = np.pad(mask, ((latOffset0, latOffset1),
|
|
76
|
-
(lonOffset0, lonOffset1)), 'constant', constant_values=(1, 1))
|
|
77
|
-
|
|
78
|
-
clip = copy.copy(self.dem)
|
|
79
|
-
|
|
80
|
-
clip[ndarray != 0] = np.nan
|
|
81
|
-
|
|
82
|
-
return clip
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
def clip(self,shapefile_path,encoding='gb18030'):
|
|
87
|
-
chly = gpd.GeoDataFrame.from_file(shapefile_path, encoding=encoding).geometry
|
|
88
|
-
|
|
89
|
-
minX, maxX, minY, maxY = chly.bounds.min().minx,chly.bounds.max().maxx,chly.bounds.min().miny,chly.bounds.max().maxy
|
|
90
|
-
maskArr=[]
|
|
91
|
-
|
|
92
|
-
for j in range(len(chly)):
|
|
93
|
-
geom = chly[j]
|
|
94
|
-
if geom.geometryType() == 'Polygon':
|
|
95
|
-
clip=self.getMask(geom, minX, maxY, minY, maxX)
|
|
96
|
-
maskArr.append(clip)
|
|
97
|
-
elif geom.geometryType() == "MultiPolygon":
|
|
98
|
-
multiLayer = []
|
|
99
|
-
for i in range(len(geom)):
|
|
100
|
-
geom1 = geom[i]
|
|
101
|
-
clip = self.getMask(geom1, minX, maxY, minY, maxX)
|
|
102
|
-
multiLayer.append(clip)
|
|
103
|
-
|
|
104
|
-
multiLayer= np.asarray(multiLayer)
|
|
105
|
-
clip = np.nanmax(multiLayer,axis=0)
|
|
106
|
-
maskArr.append(clip)
|
|
107
|
-
|
|
108
|
-
return maskArr
|
|
109
|
-
|
|
110
|
-
def getMaskMask(self, geom, minX, maxY, minY, maxX):
|
|
111
|
-
|
|
112
|
-
points = []
|
|
113
|
-
pixels = []
|
|
114
|
-
ulX, ulY = self.world2Pixel(self.ltc, minX, maxY)
|
|
115
|
-
lrX, lrY = self.world2Pixel(self.ltc, maxX, minY)
|
|
116
|
-
|
|
117
|
-
# Calculate the pixel size of the new image
|
|
118
|
-
pxWidth = int(lrX - ulX)
|
|
119
|
-
pxHeight = int(lrY - ulY)
|
|
120
|
-
|
|
121
|
-
ltc1 = copy.copy(self.ltc)
|
|
122
|
-
ltc1.n = maxY
|
|
123
|
-
ltc1.w = minX
|
|
124
|
-
|
|
125
|
-
pt = geom.boundary
|
|
126
|
-
# print(pt)
|
|
127
|
-
|
|
128
|
-
if pt.type == "LineString":
|
|
129
|
-
pts = pt.xy
|
|
130
|
-
for p in range(len(pts[0])):
|
|
131
|
-
points.append((pts[0][p], pts[1][p]))
|
|
132
|
-
for p in points:
|
|
133
|
-
pixels.append(self.world2Pixel(ltc1, p[0], p[1]))
|
|
134
|
-
rasterPoly = Image.new("L", (pxWidth, pxHeight), 1)
|
|
135
|
-
rasterize = ImageDraw.Draw(rasterPoly)
|
|
136
|
-
if len(pixels) > 1:
|
|
137
|
-
rasterize.polygon(pixels, 0)
|
|
138
|
-
|
|
139
|
-
mask = np.asarray(rasterPoly)
|
|
140
|
-
|
|
141
|
-
latOffset0 = int((self.ltc.n - maxY) / self.step)
|
|
142
|
-
latOffset1 = self.dem.shape[0] - int((self.ltc.n - minY) / self.step)
|
|
143
|
-
lonOffset0 = int((minX - self.ltc.w) / self.step)
|
|
144
|
-
lonOffset1 = self.dem.shape[1] - int((maxX - self.ltc.w) / self.step)
|
|
145
|
-
ndarray = np.pad(mask, ((latOffset0, latOffset1),
|
|
146
|
-
(lonOffset0, lonOffset1)), 'constant', constant_values=(1, 1))
|
|
147
|
-
|
|
148
|
-
# clip = copy.copy(self.dem)
|
|
149
|
-
# clip[ndarray != 0] = np.nan
|
|
150
|
-
return mask
|
|
151
|
-
else:
|
|
152
|
-
# return
|
|
153
|
-
masks = []
|
|
154
|
-
|
|
155
|
-
for ptt in pt[:1]:
|
|
156
|
-
pts = ptt.xy
|
|
157
|
-
for p in range(len(pts[0])):
|
|
158
|
-
points.append((pts[0][p], pts[1][p]))
|
|
159
|
-
for p in points:
|
|
160
|
-
pixels.append(self.world2Pixel(ltc1, p[0], p[1]))
|
|
161
|
-
rasterPoly = Image.new("L", (pxWidth, pxHeight), 1)
|
|
162
|
-
rasterize = ImageDraw.Draw(rasterPoly)
|
|
163
|
-
if len(pixels) > 1:
|
|
164
|
-
rasterize.polygon(pixels, 0)
|
|
165
|
-
|
|
166
|
-
mask = np.asarray(rasterPoly)
|
|
167
|
-
masks.append(mask)
|
|
168
|
-
masks = np.asarray(masks)
|
|
169
|
-
masks = np.min(masks, axis=0)
|
|
170
|
-
latOffset0 = int((self.ltc.n - maxY) / self.step)
|
|
171
|
-
latOffset1 = self.dem.shape[0] - int((self.ltc.n - minY) / self.step)
|
|
172
|
-
lonOffset0 = int((minX - self.ltc.w) / self.step)
|
|
173
|
-
lonOffset1 = self.dem.shape[1] - int((maxX - self.ltc.w) / self.step)
|
|
174
|
-
ndarray = np.pad(masks, ((latOffset0, latOffset1),
|
|
175
|
-
(lonOffset0, lonOffset1)), 'constant', constant_values=(1, 1))
|
|
176
|
-
|
|
177
|
-
clip = copy.copy(self.dem)
|
|
178
|
-
clip[ndarray != 0] = np.nan
|
|
179
|
-
return clip
|
|
180
|
-
|
|
181
|
-
def clipMask(self,chlyTable):
|
|
182
|
-
# chlyTable = gpd.GeoDataFrame.from_file(shapefile_path, encoding=encoding)
|
|
183
|
-
chly = chlyTable.geometry
|
|
184
|
-
minX, maxX, minY, maxY = chly.bounds.min().minx,chly.bounds.max().maxx,chly.bounds.min().miny,chly.bounds.max().maxy
|
|
185
|
-
maskArr=[]
|
|
186
|
-
|
|
187
|
-
for j in range(len(chly)):
|
|
188
|
-
geom = chly.iloc[j]
|
|
189
|
-
if geom.geometryType() == 'Polygon':
|
|
190
|
-
clip=self.getMaskMask(geom, minX, maxY, minY, maxX)
|
|
191
|
-
if not clip is None:
|
|
192
|
-
maskArr.append(clip)
|
|
193
|
-
|
|
194
|
-
elif geom.geometryType() == "MultiPolygon":
|
|
195
|
-
multiLayer = []
|
|
196
|
-
for i in range(len(geom)):
|
|
197
|
-
geom1 = geom[i]
|
|
198
|
-
clip = self.getMaskMask(geom1, minX, maxY, minY, maxX)
|
|
199
|
-
multiLayer.append(clip)
|
|
200
|
-
|
|
201
|
-
multiLayer= np.asarray(multiLayer)
|
|
202
|
-
clip = np.nanmin(multiLayer,axis=0)
|
|
203
|
-
if not clip is None:
|
|
204
|
-
maskArr.append(clip)
|
|
205
|
-
|
|
206
|
-
return maskArr
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
class slope_aspect():
|
|
210
|
-
def __init__(self,gridNew,dx, dy):
|
|
211
|
-
self.gridNew = gridNew
|
|
212
|
-
self.dx = dx
|
|
213
|
-
self.dy = dy
|
|
214
|
-
self.Sx, self.Sy = self.calcFiniteSlopes(gridNew, self.dx, self.dy)
|
|
215
|
-
# 计算dx,dy
|
|
216
|
-
def calcFiniteSlopes(self,elevGrid, dx, dy):
|
|
217
|
-
Zbc = np.pad(elevGrid, ((1, 1), (1, 1)), "edge")
|
|
218
|
-
Sx = (Zbc[1:-1, :-2] - Zbc[1:-1, 2:]) / (2 * dx) # WE方向
|
|
219
|
-
Sy = (Zbc[2:, 1:-1] - Zbc[:-2, 1:-1]) / (2 * dy) # NS方向
|
|
220
|
-
return Sx, Sy
|
|
221
|
-
|
|
222
|
-
def calcFiniteAspect(self,Sx, Sy):
|
|
223
|
-
|
|
224
|
-
Sx = Sx.astype(np.float)
|
|
225
|
-
Sy = Sy.astype(np.float)
|
|
226
|
-
aspect = np.degrees(np.arctan2(Sy, Sx))
|
|
227
|
-
aspect1 = copy.copy(aspect)
|
|
228
|
-
aspect1[aspect < 0] = 90 - aspect[aspect < 0]
|
|
229
|
-
aspect1[aspect > 90] = 360.0 - aspect[aspect > 90] + 90.0
|
|
230
|
-
aspect1[np.logical_and(aspect <= 90, aspect >= 0)] = 90.0 - aspect[np.logical_and(aspect <= 90, aspect >= 0)]
|
|
231
|
-
aspect1[np.logical_and(Sx == 0, Sy == 0)] = -1
|
|
232
|
-
return aspect1
|
|
233
|
-
|
|
234
|
-
def getSlop(self):
|
|
235
|
-
return np.degrees(np.arctan(np.sqrt(self.Sx ** 2 + self.Sy ** 2)))
|
|
236
|
-
|
|
237
|
-
def getAspect(self):
|
|
238
|
-
return self.calcFiniteAspect(self.Sx, self.Sy)
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
def Polygonize(mask,latArr,lonArr,outshp,EPSG=4326):
|
|
242
|
-
driver = gdal.GetDriverByName("GTiff")
|
|
243
|
-
im_bands = 1
|
|
244
|
-
dataset = driver.Create("./tmp.tiff", mask.shape[1], mask.shape[0], im_bands, gdal.GDT_UInt16)
|
|
245
|
-
im_geotrans = (lonArr[0], lonArr[1]-lonArr[0], 0, latArr[0], 0, latArr[1]-latArr[0])
|
|
246
|
-
dataset.SetGeoTransform(im_geotrans)
|
|
247
|
-
prj = osr.SpatialReference()
|
|
248
|
-
prj.ImportFromEPSG(EPSG)
|
|
249
|
-
dataset.SetProjection(prj.ExportToWkt())
|
|
250
|
-
dataset.GetRasterBand(1).WriteArray(mask)
|
|
251
|
-
inband = dataset.GetRasterBand(1)
|
|
252
|
-
mkDir(outshp)
|
|
253
|
-
drv = ogr.GetDriverByName("ESRI Shapefile")
|
|
254
|
-
if os.path.exists(outshp):
|
|
255
|
-
drv.DeleteDataSource(outshp)
|
|
256
|
-
Polygon = drv.CreateDataSource(outshp)
|
|
257
|
-
Poly_layer = Polygon.CreateLayer(outshp, srs=prj,
|
|
258
|
-
geom_type=ogr.wkbMultiPolygon)
|
|
259
|
-
newField = ogr.FieldDefn('value', ogr.OFTReal)
|
|
260
|
-
Poly_layer.CreateField(newField)
|
|
261
|
-
gdal.FPolygonize(inband, None, Poly_layer, 0)
|
|
262
|
-
Polygon.SyncToDisk()
|
|
263
|
-
del Polygon
|
|
264
|
-
os.remove("./tmp.tiff")
|
|
265
|
-
|
|
266
|
-
def Polylinize(mask, latArr, lonArr, outshp, EPSG=4326):
|
|
267
|
-
driver = gdal.GetDriverByName("GTiff")
|
|
268
|
-
im_bands = 1
|
|
269
|
-
dataset = driver.Create("./tmp.tiff", mask.shape[1], mask.shape[0], im_bands, gdal.GDT_UInt16)
|
|
270
|
-
im_geotrans = (lonArr[0], lonArr[1]-lonArr[0], 0, latArr[0], 0, latArr[1]-latArr[0])
|
|
271
|
-
dataset.SetGeoTransform(im_geotrans)
|
|
272
|
-
prj = osr.SpatialReference()
|
|
273
|
-
prj.ImportFromEPSG(EPSG)
|
|
274
|
-
dataset.SetProjection(prj.ExportToWkt())
|
|
275
|
-
dataset.GetRasterBand(1).WriteArray(mask)
|
|
276
|
-
inband = dataset.GetRasterBand(1)
|
|
277
|
-
mkDir(outshp)
|
|
278
|
-
drv = ogr.GetDriverByName("ESRI Shapefile")
|
|
279
|
-
if os.path.exists(outshp):
|
|
280
|
-
drv.DeleteDataSource(outshp)
|
|
281
|
-
Polygon = drv.CreateDataSource(outshp)
|
|
282
|
-
Poly_layer = Polygon.CreateLayer(outshp, srs=prj,
|
|
283
|
-
geom_type=ogr.wkbLineString)
|
|
284
|
-
newField = ogr.FieldDefn('value', ogr.OFTReal)
|
|
285
|
-
Poly_layer.CreateField(newField)
|
|
286
|
-
gdal.FPolygonize(inband, None, Poly_layer, 0)
|
|
287
|
-
Polygon.SyncToDisk()
|
|
288
|
-
del Polygon
|
|
289
|
-
os.remove("./tmp.tiff")
|
|
290
|
-
|
|
291
|
-
def polygon2polyline(shpFile, tolerance= 0.001):
|
|
292
|
-
gdf = gpd.read_file(shpFile)
|
|
293
|
-
lat0, lat1, lon1, lon0 = gdf.total_bounds
|
|
294
|
-
|
|
295
|
-
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)
|
|
296
|
-
mask_clip = gpd.clip(gdf, area).explode(index_parts=False)
|
|
297
|
-
new_gdf = gpd.GeoDataFrame([], columns=mask_clip.columns, crs=gdf.crs)
|
|
298
|
-
for i in set(mask_clip["value"]):
|
|
299
|
-
tmpDF = mask_clip[mask_clip["value"] == i]
|
|
300
|
-
aa = shapely.ops.linemerge(list(tmpDF.geometry))
|
|
301
|
-
tmp = gpd.GeoDataFrame([[i,aa]], columns=mask_clip.columns, crs=gdf.crs)
|
|
302
|
-
new_gdf = new_gdf.append(tmp)
|
|
303
|
-
|
|
304
|
-
new_gdf.reset_index(inplace=True,drop=True)
|
|
305
|
-
mask_clip = new_gdf.explode(index_parts=False)
|
|
306
|
-
|
|
307
|
-
new_gdf = gpd.GeoDataFrame([],columns=mask_clip.columns,crs=gdf.crs)
|
|
308
|
-
mask_clip = list(mask_clip.values)
|
|
309
|
-
while len(mask_clip)>0:
|
|
310
|
-
tmp = [mask_clip.pop()]
|
|
311
|
-
for j in range(1,len(mask_clip)):
|
|
312
|
-
if j>=len(mask_clip):
|
|
313
|
-
continue
|
|
314
|
-
if tmp[0][1].equals(mask_clip[j][1]):
|
|
315
|
-
tmp.append(mask_clip.pop(j))
|
|
316
|
-
gpdtmp = gpd.GeoDataFrame(tmp, columns=["value", "geometry"], crs=gdf.crs)
|
|
317
|
-
gpdtmp.sort_values("value",ascending=False,inplace=True)
|
|
318
|
-
new_gdf = new_gdf.append(gpdtmp.iloc[0])
|
|
319
|
-
return new_gdf
|
|
320
|
-
|
shancx/user/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/user/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/user/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))
|
shancx/user/hjnLAPSTransform.py
DELETED
|
@@ -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
|
-
|