shancx 1.9.33.176__py3-none-any.whl → 1.9.33.178__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/QC.py +154 -0
- shancx/geosProj.py +1 -1
- {shancx-1.9.33.176.dist-info → shancx-1.9.33.178.dist-info}/METADATA +1 -1
- {shancx-1.9.33.176.dist-info → shancx-1.9.33.178.dist-info}/RECORD +6 -6
- {shancx-1.9.33.176.dist-info → shancx-1.9.33.178.dist-info}/WHEEL +0 -0
- {shancx-1.9.33.176.dist-info → shancx-1.9.33.178.dist-info}/top_level.txt +0 -0
shancx/QC.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import cv2
|
|
2
2
|
import numpy as np
|
|
3
|
+
from numba import jit
|
|
3
4
|
def removeSmallPatches(binary_mask, min_pixels=50, min_area=40):
|
|
4
5
|
binary_mask = (binary_mask > 0).astype(np.uint8)
|
|
5
6
|
num_labels, labels, stats, centroids = cv2.connectedComponentsWithStats(
|
|
@@ -66,4 +67,157 @@ mask = removeSmallPatches(b, min_pixels=50, min_area=40)
|
|
|
66
67
|
data = np.where(mask, data, 0)
|
|
67
68
|
filtered_data = np.full([256,256],0)
|
|
68
69
|
filtered_data[mask] = e[mask]
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
import cv2
|
|
73
|
+
import numpy as np
|
|
74
|
+
from numba import jit, prange
|
|
75
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
76
|
+
def removeSmallPatches_optimized(binary_mask, min_pixels=50, min_area=40):
|
|
77
|
+
binary_mask = (binary_mask > 0).astype(np.uint8)
|
|
78
|
+
num_labels, labels, stats, _ = cv2.connectedComponentsWithStats(binary_mask, connectivity=8)
|
|
79
|
+
output_mask = np.zeros_like(binary_mask)
|
|
80
|
+
valid_labels = [i for i in range(1, num_labels) if stats[i, cv2.CC_STAT_AREA] >= min_pixels]
|
|
81
|
+
for i in valid_labels:
|
|
82
|
+
contour_mask = (labels == i).astype(np.uint8)
|
|
83
|
+
contours, _ = cv2.findContours(contour_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
|
84
|
+
|
|
85
|
+
if contours and cv2.contourArea(contours[0]) >= min_area:
|
|
86
|
+
output_mask[labels == i] = 255
|
|
87
|
+
|
|
88
|
+
return output_mask
|
|
89
|
+
|
|
90
|
+
@jit(nopython=True, parallel=True, nogil=True)
|
|
91
|
+
def numba_filter_components(labels, stats, min_pixels, min_area):
|
|
92
|
+
height, width = labels.shape
|
|
93
|
+
output = np.zeros((height, width), dtype=np.uint8)
|
|
94
|
+
for i in prange(1, stats.shape[0]):
|
|
95
|
+
if stats[i, 4] >= min_pixels: # stats[i, 4] 对应 cv2.CC_STAT_AREA
|
|
96
|
+
for y in range(height):
|
|
97
|
+
for x in range(width):
|
|
98
|
+
if labels[y, x] == i:
|
|
99
|
+
output[y, x] = 255
|
|
100
|
+
return output
|
|
101
|
+
def removeSmallPatches_numba(binary_mask, min_pixels=50, min_area=40):
|
|
102
|
+
binary_mask = (binary_mask > 0).astype(np.uint8)
|
|
103
|
+
num_labels, labels, stats, _ = cv2.connectedComponentsWithStats(binary_mask, connectivity=8)
|
|
104
|
+
output_mask = numba_filter_components(labels, stats, min_pixels, min_area)
|
|
105
|
+
if min_area > 0:
|
|
106
|
+
num_labels2, labels2, stats2, _ = cv2.connectedComponentsWithStats(output_mask, connectivity=8)
|
|
107
|
+
final_output = np.zeros_like(output_mask)
|
|
108
|
+
for i in range(1, num_labels2):
|
|
109
|
+
contour_mask = (labels2 == i).astype(np.uint8)
|
|
110
|
+
contours, _ = cv2.findContours(contour_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
|
111
|
+
if contours and cv2.contourArea(contours[0]) >= min_area:
|
|
112
|
+
final_output[labels2 == i] = 255
|
|
113
|
+
return final_output
|
|
114
|
+
return output_mask
|
|
115
|
+
def process_block_optimized_v2(args):
|
|
116
|
+
block, coords, min_pixels, min_area = args
|
|
117
|
+
num_labels, labels, stats, _ = cv2.connectedComponentsWithStats(block, connectivity=8)
|
|
118
|
+
result = np.zeros_like(block)
|
|
119
|
+
valid_labels = []
|
|
120
|
+
for i in range(1, num_labels):
|
|
121
|
+
if stats[i, cv2.CC_STAT_AREA] >= min_pixels:
|
|
122
|
+
valid_labels.append(i)
|
|
123
|
+
for i in valid_labels:
|
|
124
|
+
component_indices = (labels == i)
|
|
125
|
+
if component_indices.any():
|
|
126
|
+
component_mask = component_indices.astype(np.uint8)
|
|
127
|
+
contours, _ = cv2.findContours(component_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
|
128
|
+
if contours and cv2.contourArea(contours[0]) >= min_area:
|
|
129
|
+
result[component_indices] = 255
|
|
130
|
+
return result, coords
|
|
131
|
+
def removeSmallPatches_fast_v2(binary_mask, min_pixels=100, min_area=40, num_workers=4):
|
|
132
|
+
binary_mask = (binary_mask > 0).astype(np.uint8)
|
|
133
|
+
h, w = binary_mask.shape
|
|
134
|
+
optimal_block_size = max(500, min(2000, (h * w) // (num_workers * 10000)))
|
|
135
|
+
output = np.zeros_like(binary_mask)
|
|
136
|
+
blocks = []
|
|
137
|
+
for y in range(0, h, optimal_block_size):
|
|
138
|
+
for x in range(0, w, optimal_block_size):
|
|
139
|
+
y_end, x_end = min(y + optimal_block_size, h), min(x + optimal_block_size, w)
|
|
140
|
+
block = binary_mask[y:y_end, x:x_end].copy()
|
|
141
|
+
blocks.append((block, (y, x, y_end, x_end), min_pixels, min_area))
|
|
142
|
+
actual_workers = min(num_workers, len(blocks))
|
|
143
|
+
with ThreadPoolExecutor(max_workers=actual_workers) as executor:
|
|
144
|
+
for result, (y, x, y_end, x_end) in executor.map(process_block_optimized_v2, blocks):
|
|
145
|
+
output[y:y_end, x:x_end] = result
|
|
146
|
+
return output
|
|
147
|
+
def get_optimal_function(binary_mask, min_pixels=50, min_area=40):
|
|
148
|
+
h, w = binary_mask.shape
|
|
149
|
+
total_pixels = h * w
|
|
150
|
+
if total_pixels < 1000000: # 小于100万像素
|
|
151
|
+
return removeSmallPatches_optimized
|
|
152
|
+
if min_area <= 0:
|
|
153
|
+
return removeSmallPatches_numba
|
|
154
|
+
return removeSmallPatches_fast_v2
|
|
155
|
+
def auto_remove_small_patches(binary_mask, min_pixels=50, min_area=40):
|
|
156
|
+
optimal_func = get_optimal_function(binary_mask, min_pixels, min_area)
|
|
157
|
+
return optimal_func(binary_mask, min_pixels, min_area)
|
|
158
|
+
"""
|
|
159
|
+
try:
|
|
160
|
+
result = auto_remove_small_patches(binary_mask, min_pixels=50, min_area=40)
|
|
161
|
+
except Exception as e:
|
|
162
|
+
from original_module import removeSmallPatches
|
|
163
|
+
result = removeSmallPatches(binary_mask, min_pixels=50, min_area=40)
|
|
164
|
+
removeSmallPatches_numba optimum performance min_area <= 0
|
|
165
|
+
removeSmallPatches_fast_v2 area
|
|
166
|
+
"""
|
|
167
|
+
@jit(nopython=True, parallel=True, nogil=True)
|
|
168
|
+
def QC_simple_numba(mat, dbzTH = 10.0, areaTH=20):
|
|
169
|
+
# Create a copy of the matrix
|
|
170
|
+
mat1 = np.copy(mat)
|
|
171
|
+
rows, cols = mat1.shape
|
|
172
|
+
|
|
173
|
+
# Create binary mask based on threshold
|
|
174
|
+
mask = np.zeros((rows, cols), dtype=np.uint8)
|
|
175
|
+
for i in range(rows):
|
|
176
|
+
for j in range(cols):
|
|
177
|
+
if mat1[i, j] > dbzTH:
|
|
178
|
+
mask[i, j] = 1
|
|
179
|
+
# Simple 8-connectivity region labeling (flood fill algorithm)
|
|
180
|
+
labels = np.zeros((rows, cols), dtype=np.int32)
|
|
181
|
+
current_label = 1
|
|
182
|
+
region_areas = []
|
|
183
|
+
for i in range(rows):
|
|
184
|
+
for j in range(cols):
|
|
185
|
+
# If current pixel is foreground and not yet labeled
|
|
186
|
+
if mask[i, j] == 1 and labels[i, j] == 0:
|
|
187
|
+
# Start flood fill
|
|
188
|
+
stack = [(i, j)]
|
|
189
|
+
labels[i, j] = current_label
|
|
190
|
+
area = 0
|
|
191
|
+
|
|
192
|
+
while stack:
|
|
193
|
+
x, y = stack.pop()
|
|
194
|
+
area += 1
|
|
195
|
+
|
|
196
|
+
# Check 8 surrounding pixels
|
|
197
|
+
for dx in [-1, 0, 1]:
|
|
198
|
+
for dy in [-1, 0, 1]:
|
|
199
|
+
nx, ny = x + dx, y + dy
|
|
200
|
+
# Check bounds and conditions
|
|
201
|
+
if (0 <= nx < rows and 0 <= ny < cols and
|
|
202
|
+
mask[nx, ny] == 1 and labels[nx, ny] == 0):
|
|
203
|
+
labels[nx, ny] = current_label
|
|
204
|
+
stack.append((nx, ny))
|
|
205
|
+
|
|
206
|
+
region_areas.append(area)
|
|
207
|
+
current_label += 1
|
|
208
|
+
|
|
209
|
+
# Apply area threshold filtering
|
|
210
|
+
for i in range(rows):
|
|
211
|
+
for j in range(cols):
|
|
212
|
+
if labels[i, j] > 0 and region_areas[labels[i, j] - 1] < areaTH:
|
|
213
|
+
mat1[i, j] = 0
|
|
214
|
+
return mat1
|
|
215
|
+
def QC_ref_numba(mat, dbzTH = 10, areaTH=20):
|
|
216
|
+
for i in range(len(mat)):
|
|
217
|
+
mat[i] = QC_simple_numba(mat[i], dbzTH, areaTH)
|
|
218
|
+
return mat
|
|
219
|
+
"""
|
|
220
|
+
CR = subset["CR"].data[0].copy()
|
|
221
|
+
CR[CR < 6] = 0
|
|
222
|
+
CR = QC_ref_numba(CR[None], areaTH=15)[0]
|
|
69
223
|
"""
|
shancx/geosProj.py
CHANGED
|
@@ -58,7 +58,7 @@ class goesProjMSG10():
|
|
|
58
58
|
self.CFAC=FAC[resolution]
|
|
59
59
|
self.LFAC=FAC[resolution]
|
|
60
60
|
|
|
61
|
-
def transform(self,latD,lonDe,ROC
|
|
61
|
+
def transform(self,latD,lonDe,ROC=-10,ROL=-30):
|
|
62
62
|
lat=np.radians(latD)
|
|
63
63
|
lon=np.radians(lonDe)
|
|
64
64
|
ba2=np.square(self.eb/self.ea)
|
|
@@ -3,7 +3,7 @@ shancx/Inst.py,sha256=Q8dULK2djqBU0JFyhMAf1mhWzFDwx9SaAJuTIO0AWig,751
|
|
|
3
3
|
shancx/Lib.py,sha256=GUAspllSxk39mvj-F1Q8Ys0EcY_lQfZPRGPE7L3x4SE,977
|
|
4
4
|
shancx/Path1.py,sha256=vX4A5RgdwVyIVVNZRocl18rOu1Z8YMLfDb0B92-0bE8,5334
|
|
5
5
|
shancx/Point.py,sha256=gyIomOVbNoz6SOcAhhTS26NHBeJ0TOwB-ljNsBWN1ZE,1909
|
|
6
|
-
shancx/QC.py,sha256=
|
|
6
|
+
shancx/QC.py,sha256=MFxbPMEwrnk5l0sTFMrx13wPlXJ5WI5TovzaiBoEr0E,9848
|
|
7
7
|
shancx/Read.py,sha256=xX4ciDoWhL9KAsN3cWvaFAOMlSVwR56AR3dSB-SBnLI,3139
|
|
8
8
|
shancx/ZR.py,sha256=5APchqVoI1G2MkrN9YJSWCwfLUygcSFIsUXSo9aq1Qg,341
|
|
9
9
|
shancx/__init__.py,sha256=2SJt6zlJTlXt_b81qnQOg2DAhRUnLW8DXdu2qjIa1hM,19766
|
|
@@ -11,7 +11,7 @@ shancx/args.py,sha256=Nr80vgQpT3m31_crKGf5DvofCxyERJFbqJ1sHb1BIqs,1042
|
|
|
11
11
|
shancx/bak.py,sha256=eKe2o1Yq7LCldoA-LXi14s_QNf1BkQsDsWJ7pDoscrw,25428
|
|
12
12
|
shancx/cmp.py,sha256=cIQv-QTl-22FJa6tmHyBu_IQmMq5LnsQGGFK5jc5hMA,893
|
|
13
13
|
shancx/df2database.py,sha256=h9_n9tZBWKyGKnpGPRHPSZgMn5kylX0sV5APwmi2SHM,3315
|
|
14
|
-
shancx/geosProj.py,sha256=
|
|
14
|
+
shancx/geosProj.py,sha256=JMmtj3kV8rtFkKbmwvTKuDWlC8AkgLG8JvCPzkn8Dfs,2685
|
|
15
15
|
shancx/getResponse.py,sha256=QmJfa4czGCOiKb8RuCLXKE7AAKVADAptNiwn7v1tfbM,1055
|
|
16
16
|
shancx/info.py,sha256=0rk_L8Z5uj9RliaZrzT-CArH9ZObmdmcp-1RxAItL08,1122
|
|
17
17
|
shancx/netdfJU.py,sha256=96KR9NMLr2Kcs_OOMpX7QPujdWUj0GCEUIZ7_4_pBxw,7741
|
|
@@ -84,7 +84,7 @@ shancx/Train/multiGpu.py,sha256=D_oZeiSc7VWktpnVDwrFOC1CYZSt9rxOKY5lngE5vFg,820
|
|
|
84
84
|
shancx/Train/prepare.py,sha256=vL_8UOA66oZCBIwCICtihsGibivtNgaVJGulJxfNdn8,6793
|
|
85
85
|
shancx/Train/renet50.py,sha256=wEhYk1X96WE5zuqHqVxWLJa-A5jDNkz4z6edORNufnA,6428
|
|
86
86
|
shancx/tensBoard/__init__.py,sha256=ga2C5YyJITvvQA1ocpxna_KNFnNRJVwkTjLoIglLZUQ,993
|
|
87
|
-
shancx-1.9.33.
|
|
88
|
-
shancx-1.9.33.
|
|
89
|
-
shancx-1.9.33.
|
|
90
|
-
shancx-1.9.33.
|
|
87
|
+
shancx-1.9.33.178.dist-info/METADATA,sha256=V0mQKvomKiJ8EGg9GVYK_nSlUD2a_vb5YFkmAFsxXa4,644
|
|
88
|
+
shancx-1.9.33.178.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
89
|
+
shancx-1.9.33.178.dist-info/top_level.txt,sha256=akfCS1vKWz3pNmEN_yN9ZiGp-60IQY5ET38mRx_i_-4,7
|
|
90
|
+
shancx-1.9.33.178.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|