12
12
import pandas as pd
13
13
14
14
from ..utils .generate_soft_colors import generate_soft_color
15
+ from ..utils .jitterrotation .jitterrotator import JitterRotator
15
16
from ..utils .validation import check_random_state
16
- from .Q_blocks import Node , Point
17
+ from .Q_blocks import QNode , QPoint
17
18
18
19
os .environ ["MKL_NUM_THREADS" ] = "1"
19
20
os .environ ["NUMEXPR_NUM_THREADS" ] = "1"
23
24
24
25
25
26
def recursive_subdivide (
26
- node : Node ,
27
+ node : QNode ,
27
28
grid_len_lon_upper_threshold : Union [float , int ],
28
29
grid_len_lon_lower_threshold : Union [float , int ],
29
30
grid_len_lat_upper_threshold : Union [float , int ],
@@ -53,7 +54,7 @@ def recursive_subdivide(
53
54
h_ = float (node .height / 2 )
54
55
55
56
p = contains (node .x0 , node .y0 , w_ , h_ , node .points )
56
- x1 = Node (node .x0 , node .y0 , w_ , h_ , p )
57
+ x1 = QNode (node .x0 , node .y0 , w_ , h_ , p )
57
58
recursive_subdivide (
58
59
x1 ,
59
60
grid_len_lon_upper_threshold ,
@@ -64,7 +65,7 @@ def recursive_subdivide(
64
65
)
65
66
66
67
p = contains (node .x0 , node .y0 + h_ , w_ , h_ , node .points )
67
- x2 = Node (node .x0 , node .y0 + h_ , w_ , h_ , p )
68
+ x2 = QNode (node .x0 , node .y0 + h_ , w_ , h_ , p )
68
69
recursive_subdivide (
69
70
x2 ,
70
71
grid_len_lon_upper_threshold ,
@@ -75,7 +76,7 @@ def recursive_subdivide(
75
76
)
76
77
77
78
p = contains (node .x0 + w_ , node .y0 , w_ , h_ , node .points )
78
- x3 = Node (node .x0 + w_ , node .y0 , w_ , h_ , p )
79
+ x3 = QNode (node .x0 + w_ , node .y0 , w_ , h_ , p )
79
80
recursive_subdivide (
80
81
x3 ,
81
82
grid_len_lon_upper_threshold ,
@@ -86,7 +87,7 @@ def recursive_subdivide(
86
87
)
87
88
88
89
p = contains (node .x0 + w_ , node .y0 + h_ , w_ , h_ , node .points )
89
- x4 = Node (node .x0 + w_ , node .y0 + h_ , w_ , h_ , p )
90
+ x4 = QNode (node .x0 + w_ , node .y0 + h_ , w_ , h_ , p )
90
91
recursive_subdivide (
91
92
x4 ,
92
93
grid_len_lon_upper_threshold ,
@@ -204,17 +205,12 @@ def add_lon_lat_data(self, indexes: Sequence, x_array: Sequence, y_array: Sequen
204
205
if not len (x_array ) == len (y_array ) or not len (x_array ) == len (indexes ):
205
206
raise ValueError ("input longitude and latitude and indexes not in same length!" )
206
207
207
- data = np .array ([x_array , y_array ]).T
208
- angle = self .rotation_angle
209
- r = angle / 360
210
- theta = r * np .pi * 2
211
- rotation_matrix = np .array ([[np .cos (theta ), - np .sin (theta )], [np .sin (theta ), np .cos (theta )]])
212
- data = data @ rotation_matrix
213
- lon_new = (data [:, 0 ] + self .calibration_point_x_jitter ).tolist ()
214
- lat_new = (data [:, 1 ] + self .calibration_point_y_jitter ).tolist ()
208
+ lon_new , lat_new = JitterRotator .rotate_jitter (
209
+ x_array , y_array , self .rotation_angle , self .calibration_point_x_jitter , self .calibration_point_y_jitter
210
+ )
215
211
216
212
for index , lon , lat in zip (indexes , lon_new , lat_new ):
217
- self .points .append (Point (index , lon , lat ))
213
+ self .points .append (QPoint (index , lon , lat ))
218
214
219
215
def generate_gridding_params (self ):
220
216
"""generate the gridding params after data are added
@@ -233,15 +229,15 @@ def generate_gridding_params(self):
233
229
234
230
self .left_bottom_point = (left_bottom_point_x , left_bottom_point_y )
235
231
if self .lon_lat_equal_grid is True :
236
- self .root = Node (
232
+ self .root = QNode (
237
233
left_bottom_point_x ,
238
234
left_bottom_point_y ,
239
235
max (self .grid_length_x , self .grid_length_y ),
240
236
max (self .grid_length_x , self .grid_length_y ),
241
237
self .points ,
242
238
)
243
239
elif self .lon_lat_equal_grid is False :
244
- self .root = Node (
240
+ self .root = QNode (
245
241
left_bottom_point_x , left_bottom_point_y , self .grid_length_x , self .grid_length_y , self .points
246
242
)
247
243
else :
@@ -272,58 +268,37 @@ def graph(self, scatter: bool = True, ax=None):
272
268
273
269
c = find_children (self .root )
274
270
275
- # areas = set()
276
- # width_set = set()
277
- # height_set = set()
278
- # for el in c:
279
- # areas.add(el.width * el.height)
280
- # width_set.add(el.width)
281
- # height_set.add(el.height)
282
-
283
- theta = - (self .rotation_angle / 360 ) * np .pi * 2
284
- rotation_matrix = np .array ([[np .cos (theta ), - np .sin (theta )], [np .sin (theta ), np .cos (theta )]])
285
-
286
271
for n in c :
287
- xy0_trans = np .array ([[n .x0 , n .y0 ]])
288
- if self .calibration_point_x_jitter :
289
- new_x = xy0_trans [:, 0 ] - self .calibration_point_x_jitter
290
- else :
291
- new_x = xy0_trans [:, 0 ]
292
-
293
- if self .calibration_point_y_jitter :
294
- new_y = xy0_trans [:, 1 ] - self .calibration_point_y_jitter
295
- else :
296
- new_y = xy0_trans [:, 1 ]
297
- new_xy = np .array ([[new_x [0 ], new_y [0 ]]]) @ rotation_matrix
298
- new_x = new_xy [:, 0 ]
299
- new_y = new_xy [:, 1 ]
272
+ old_x , old_y = JitterRotator .inverse_jitter_rotate (
273
+ [n .x0 ], [n .y0 ], self .rotation_angle , self .calibration_point_x_jitter , self .calibration_point_y_jitter
274
+ )
300
275
301
276
if ax is None :
302
277
plt .gcf ().gca ().add_patch (
303
278
patches .Rectangle (
304
- (new_x , new_y ), n .width , n .height , fill = False , angle = self .rotation_angle , color = the_color
279
+ (old_x , old_y ), n .width , n .height , fill = False , angle = self .rotation_angle , color = the_color
305
280
)
306
281
)
307
282
else :
308
283
ax .add_patch (
309
284
patches .Rectangle (
310
- (new_x , new_y ), n .width , n .height , fill = False , angle = self .rotation_angle , color = the_color
285
+ (old_x , old_y ), n .width , n .height , fill = False , angle = self .rotation_angle , color = the_color
311
286
)
312
287
)
313
288
314
- x = np .array ([point .x for point in self .points ]) - self .calibration_point_x_jitter
315
- y = np .array ([point .y for point in self .points ]) - self .calibration_point_y_jitter
316
-
317
- data = np .array ([x , y ]).T @ rotation_matrix
318
289
if scatter :
290
+ old_x , old_y = JitterRotator .inverse_jitter_rotate (
291
+ [point .x for point in self .points ],
292
+ [point .y for point in self .points ],
293
+ self .rotation_angle ,
294
+ self .calibration_point_x_jitter ,
295
+ self .calibration_point_y_jitter ,
296
+ )
297
+
319
298
if ax is None :
320
- plt .scatter (
321
- data [:, 0 ].tolist (), data [:, 1 ].tolist (), s = 0.2 , c = "tab:blue" , alpha = 0.7
322
- ) # plots the points as red dots
299
+ plt .scatter (old_x , old_y , s = 0.2 , c = "tab:blue" , alpha = 0.7 ) # plots the points as red dots
323
300
else :
324
- ax .scatter (
325
- data [:, 0 ].tolist (), data [:, 1 ].tolist (), s = 0.2 , c = "tab:blue" , alpha = 0.7
326
- ) # plots the points as red dots
301
+ ax .scatter (old_x , old_y , s = 0.2 , c = "tab:blue" , alpha = 0.7 ) # plots the points as red dots
327
302
return
328
303
329
304
def get_final_result (self ) -> pandas .core .frame .DataFrame :
@@ -333,21 +308,21 @@ def get_final_result(self) -> pandas.core.frame.DataFrame:
333
308
results (DataFrame): A pandas dataframe containing the gridding information
334
309
"""
335
310
all_grids = find_children (self .root )
336
- point_indexes_list = []
311
+ # point_indexes_list = []
337
312
point_grid_width_list = []
338
313
point_grid_height_list = []
339
314
point_grid_points_number_list = []
340
315
calibration_point_list = []
341
316
for grid in all_grids :
342
- point_indexes_list .append ([point .index for point in grid .points ])
317
+ # point_indexes_list.append([point.index for point in grid.points])
343
318
point_grid_width_list .append (grid .width )
344
319
point_grid_height_list .append (grid .height )
345
320
point_grid_points_number_list .append (len (grid .points ))
346
321
calibration_point_list .append ((round (grid .x0 , 6 ), round (grid .y0 , 6 )))
347
322
348
323
result = pd .DataFrame (
349
324
{
350
- "checklist_indexes" : point_indexes_list ,
325
+ # "checklist_indexes": point_indexes_list,
351
326
"stixel_indexes" : list (range (len (point_grid_width_list ))),
352
327
"stixel_width" : point_grid_width_list ,
353
328
"stixel_height" : point_grid_height_list ,
0 commit comments