1212import itertools
1313import numpy as np
1414import pandas as pd
15+ import os
1516
1617
1718class QMXNLibCalculator (QMCalculator ):
18- def __init__ (self , edges_file_path :str , output_file_path :str , polygon_file_path :str = None ):
19+ def __init__ (self , edges_file_path :str , output_file_path :str , polygon_file_path :str = None , partition_count : int = os . cpu_count () ):
1920 """
2021 Initializes the QMXNLibCalculator class.
2122
@@ -31,6 +32,7 @@ def __init__(self, edges_file_path:str, output_file_path:str, polygon_file_path:
3132 self .default_projection = 'epsg:26910'
3233 self .output_projection = 'epsg:4326'
3334 self .precision = 1e-5
35+ self .partition_count = partition_count
3436
3537 def add_edges_from_linestring (self , graph , linestring , edge_attrs ):
3638 points = list (linestring .coords )
@@ -147,8 +149,8 @@ def calculate_quality_metric(self):
147149 gdf = gdf .to_crs (self .default_projection )
148150 tile_gdf = tile_gdf .to_crs (self .default_projection )
149151 tile_gdf = tile_gdf [['geometry' ]]
150-
151- df_dask = dask_geopandas .from_geopandas (tile_gdf , npartitions = 64 )
152+ no_of_cores = min ( self . partition_count , os . cpu_count ())
153+ df_dask = dask_geopandas .from_geopandas (tile_gdf , npartitions = no_of_cores )
152154
153155 output = df_dask .apply (self .qm_func ,axis = 1 , meta = [
154156 ('geometry' , 'geometry' ),
0 commit comments