Skip to content

Commit 9b2cf37

Browse files
committed
BugFix: Added check for empty points in DBSCAN clustering function.
1 parent dd3af70 commit 9b2cf37

3 files changed

Lines changed: 20 additions & 216 deletions

File tree

examples/02_Track-Radar-Data/02_Track-Radar-Dataset.ipynb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@
7070
"!python -m pip install -q -U pyfortracc"
7171
]
7272
},
73+
{
74+
"cell_type": "code",
75+
"execution_count": null,
76+
"metadata": {},
77+
"outputs": [],
78+
"source": [
79+
"# Import libraries and check pyfortracc version\n",
80+
"import pyfortracc\n",
81+
"print(f'pyfortracc version: {pyfortracc.__version__}')"
82+
]
83+
},
7384
{
7485
"cell_type": "markdown",
7586
"metadata": {},
@@ -194,8 +205,8 @@
194205
"name_list['input_path'] = 'input/' # path to the input data\n",
195206
"name_list['output_path'] = 'output/' # path to the output data\n",
196207
"name_list['timestamp_pattern'] = 'sbmn_cappi_%Y%m%d_%H%M.nc.gz' # timestamp file pattern\n",
197-
"name_list['thresholds'] = [20,30,35] # in dbz\n",
198-
"name_list['min_cluster_size'] = [3,3,3] # in number of points per cluster\n",
208+
"name_list['thresholds'] = [20, 30, 35] # in dbz\n",
209+
"name_list['min_cluster_size'] = [5,4,3] # in number of points per cluster\n",
199210
"name_list['operator'] = '>=' # '>= * **<=' or '=='\n",
200211
"name_list['delta_time'] = 12 # in minutes\n",
201212
"name_list['min_overlap'] = 20 # Minimum overlap between clusters in percentage\n",
@@ -229,7 +240,7 @@
229240
"import pyfortracc as pf\n",
230241
"\n",
231242
"# Track the clusters\n",
232-
"pf.track(name_list, read_function)"
243+
"pf.track(name_list, read_function, parallel=False)"
233244
]
234245
},
235246
{

examples/WORCAP-Minicourse/4_Sunspots_Tracking/4_Sunspots_Tracking.ipynb

Lines changed: 0 additions & 213 deletions
This file was deleted.

pyfortracc/features_extraction/clustering.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ def dbscan_clustering(data, operator, threshold, min_size, eps=1):
5959
"""
6060
# Segment the data based on the threshold
6161
points = np.argwhere(operator(data, threshold))
62+
# Check if have points after filtering based on operator
63+
if points.size == 0:
64+
# Return empty clusters and labels
65+
clusters = np.zeros(data.shape, dtype=np.int32)
66+
labels = np.empty((0, 3), dtype=np.int32)
67+
return clusters, labels
6268
# Set the dbscan object
6369
dbscan = DBSCAN(algorithm='kd_tree', metric='chebyshev',
6470
eps=eps, min_samples=3)

0 commit comments

Comments
 (0)