@@ -130,6 +130,7 @@ def __init__(
130
130
# ooc_qt_picklefilename = os.path.join(
131
131
# global_cache, quadtree_pickle_filename)
132
132
ooc_qt_picklefilename = quadtree_pickle_filename
133
+ global_cache = os .path .dirname (ooc_qt_picklefilename )
133
134
else :
134
135
raise ValueError (
135
136
'Both raw_csv_filename and quadtree_pickle_filename'
@@ -138,6 +139,7 @@ def __init__(
138
139
if os .path .isfile (ooc_qt_picklefilename ):
139
140
LOGGER .info (
140
141
'%s quadtree already exists' , ooc_qt_picklefilename )
142
+ ooc_qt_picklefilename = transplant_quadtree (ooc_qt_picklefilename , cache_workspace )
141
143
else :
142
144
LOGGER .info (
143
145
'%s not found, constructing quadtree' , ooc_qt_picklefilename )
@@ -149,6 +151,7 @@ def __init__(
149
151
max_points_per_node , max_depth )
150
152
self .qt_pickle_filename = ooc_qt_picklefilename
151
153
self .local_cache_workspace = os .path .join (cache_workspace , 'local' )
154
+ # self.global_cache_dir = global_cache
152
155
self .min_year = min_year
153
156
self .max_year = max_year
154
157
@@ -283,8 +286,10 @@ def _calc_aggregated_points_in_aoi(
283
286
pud_poly_feature_queue = multiprocessing .Queue (4 )
284
287
n_polytest_processes = multiprocessing .cpu_count ()
285
288
289
+ LOGGER .info (f'OPENING { self .qt_pickle_filename } ' )
286
290
with open (self .qt_pickle_filename , 'rb' ) as qt_pickle :
287
291
global_qt = pickle .load (qt_pickle )
292
+
288
293
aoi_layer = aoi_vector .GetLayer ()
289
294
aoi_extent = aoi_layer .GetExtent ()
290
295
aoi_ref = aoi_layer .GetSpatialRef ()
@@ -1010,3 +1015,32 @@ def _hash_blocks(file_buffer_queue):
1010
1015
if fast_hash :
1011
1016
file_hash += '_fast_hash'
1012
1017
return file_hash
1018
+
1019
+ def transplant_quadtree (qt_pickle_filepath , workspace ):
1020
+ storage_dir = os .path .dirname (qt_pickle_filepath )
1021
+ pickle_filepath = qt_pickle_filepath
1022
+
1023
+ def rename_managers (qt ):
1024
+ if qt .is_leaf :
1025
+ qt .node_data_manager .manager_filename = f'{ qt_pickle_filepath } .db'
1026
+ qt .node_data_manager .manager_directory = os .path .dirname (qt_pickle_filepath )
1027
+ qt .quad_tree_storage_dir = storage_dir
1028
+ else :
1029
+ [rename_managers (qt .nodes [index ]) for index in range (4 )]
1030
+ return qt
1031
+
1032
+ with open (qt_pickle_filepath , 'rb' ) as qt_pickle :
1033
+ global_qt = pickle .load (qt_pickle )
1034
+
1035
+ if global_qt .quad_tree_storage_dir != storage_dir :
1036
+ LOGGER .info (
1037
+ f'setting quadtree node references to the local filesystem '
1038
+ f'{ storage_dir } ' )
1039
+ new_qt = rename_managers (global_qt )
1040
+ pickle_filepath = os .path .join (
1041
+ workspace , f'transplant_{ os .path .basename (qt_pickle_filepath )} ' )
1042
+ LOGGER .info (
1043
+ f'writing new quadtree index to { pickle_filepath } ' )
1044
+ with open (pickle_filepath , 'wb' ) as qt_pickle :
1045
+ pickle .dump (new_qt , qt_pickle )
1046
+ return pickle_filepath
0 commit comments