def load_targets(shapefile, targetfield):
"""
Loads the shapefile onto node 0 then distributes it across all
available nodes
"""
if mpiops.chunk_index == 0:
lonlat, vals, othervals = load_shapefile(shapefile, targetfield)
# sort by y then x
ordind = np.lexsort(lonlat.T)
vals = vals[ordind]
lonlat = lonlat[ordind]
for k, v in othervals.items():
othervals[k] = v[ordind]
lonlat = np.array_split(lonlat, mpiops.chunks)
vals = np.array_split(vals, mpiops.chunks)
split_othervals = {k: np.array_split(v, mpiops.chunks)
for k, v in othervals.items()}
othervals = [{k: v[i] for k, v in split_othervals.items()}
for i in range(mpiops.chunks)]
else:
lonlat, vals, othervals = None, None, None
lonlat = mpiops.comm.scatter(lonlat, root=0)
vals = mpiops.comm.scatter(vals, root=0)
othervals = mpiops.comm.scatter(othervals, root=0)
log.info("Node {} has been assigned {} targets".format(mpiops.chunk_index,
lonlat.shape[0]))
targets = Targets(lonlat, vals, othervals=othervals)
return targets
评论列表
文章目录