I have a large grid of 1km square cells covering an the area around the Atlantic Ocean around the Atlantic Provinces of Canada from Labrador to Greenland south to the US Canada border. In all it is about 4.3 million cells. I have 400k tracks representing shipping; about 10Gb of data. I am trying to overlay the grid onto the tracks to generate statistics for each cell. I have been passing it to the multiprocessing objects with various results using methods such as using numpy array_split to break the tracks and the grid into smaller chunks which worked for a small sample set but didn't for the whole dataset. I even tried doing it to one cell at a time which was working but was taking too long. I started looking into other methods like...
def cell_calc(df1, df2):
applied_df1 = df1.apply(lambda row: gpoverlay(df1, df2).groupby(by='grid_id').size().reset_index(name='ALL').fillna(0), gpoverlay(df1, df2, how='intersection')
[gpoverlay(df1, df2)
['type']=='CARGO'].groupby(by='grid_id').size().reset_index(name='CARGO').fillna(0))
return concat(df1, applied_df1)
partialTask = ft.partial(cell_calc, df1=GRIDGDF, df2=TRACKSGDF)
with mp.Pool() as pool:
count = 0
stime = ttime()
results_gdf = pool.apply(partialTask)
pool.close()
print(results_gdf)
Which returned TypeError: 'DataFrame' objects are mutable, thus they cannot be hashed
and...
partialTask = ft.partial(gp.overlay, df1=GRIDGDF, df2=TRACKSGDF, how='intersection')
with Pool() as pool:
results = pool.apply(partialTask)
pool.close()
print(results)
Of which works on a test sample but when applied to the whole dataset it runs, then all the processes go to 0% excepts for one which sits at 6% to 7% and it never seems to come out of it.
Simply put, what methods work to speed up the application of geopandas overlay on large datasets and what are some working examples for applying them?