If we want to do the same thing but in batches per roi to send each job to a separate worker on an HPC cluster:
In [13]:
batch_columns = ["roi"]id_columns = [e for e in id_columns if e notin batch_columns]i =0for name_batch, df_batch in df_imgs.group_by(batch_columns):print(f"Batch {i}:")print(" Batch ID:", dict(zip(batch_columns, name_batch)))for img in df_batch.select(id_columns).rows(named=True):print(" Image ID:", img) i +=1
If there’s even more free resources on the cluster and we’re in a hurry:
In [14]:
batch_columns = ["roi", "m"]id_columns = [e for e in id_columns if e notin batch_columns]i =0for name_batch, df_batch in df_imgs.group_by(batch_columns):print(f"Batch {i}:")print(f" Batch ID:", dict(zip(batch_columns, name_batch)))for img in df_batch.select(id_columns).rows(named=True):print(" Image ID:", img) i +=1
As you can see it is trivial to process the data by walking along the coordinates, and batching can be done flexibly by grouping by the respective columns.