PIV computation in parallel with TopologyPIV
#
This minimal example presents how to carry out a simple PIV computation. See
also the documentation of the class
fluidimage.topologies.piv.TopologyPIV
and the work defined in the
subpackage fluidimage.works.piv
.
from fluidimage import get_path_image_samples
from fluidimage.piv import Topology
params = Topology.create_default_params()
params.series.path = get_path_image_samples() / "Karman/Images"
params.mask.strcrop = "50:350, 0:380"
params.piv0.shape_crop_im0 = 32
params.piv0.displacement_max = 5
params.piv0.nb_peaks_to_search = 2
params.fix.correl_min = 0.4
params.fix.threshold_diff_neighbour = 2.0
params.multipass.number = 2
params.multipass.use_tps = "last"
# params.saving.how = 'complete'
params.saving.postfix = "piv_example"
topology = Topology(params, logging_level="info")
# To produce a graph of the topology
# topology.make_code_graphviz('topo.dot')
# Compute in parallel
topology.compute()
# topology.compute("multi_exec_subproc")
# Compute in sequential (for debugging)
# topology.compute(sequential=True)
We now show a similar example but with a simple preprocessing (using a function
im2im
):
from fluidimage import get_path_image_samples
from fluidimage.piv import Topology
params = Topology.create_default_params()
params.series.path = get_path_image_samples() / "Karman/Images"
params.series.ind_start = 1
params.series.ind_step = 2
params.piv0.shape_crop_im0 = 32
params.multipass.number = 2
params.multipass.use_tps = False
params.mask.strcrop = ":, 50:500"
params.saving.how = "recompute"
params.saving.postfix = "piv_im2im_func_example"
# we use the light versatile preprocessing feature:
params.preproc.im2im = "my_example_im2im.im2im"
# Here the "image to image" function will be imported with the statement
# `from my_example_im2im import im2im`
topology = Topology(params, logging_level="info")
# To produce a graph of the topology
topology.make_code_graphviz("topo.dot")
# Compute in parallel
topology.compute()
# Compute in sequential (for debugging)
# topology.compute(sequential=True)
assert len(topology.results) == 1
The file my_example_im2im.py
should be importable (for example in the same
directory than piv_parallel_im2im.py
)
"""This is a very silly example of importable module where we define a
"filter" function im2im.
"""
def im2im(tuple_name_image):
_, im = tuple_name_image
print("in the function im2im...")
return 2 * im
Same thing but the preprocessing is done with a class Im2Im
from fluidimage import get_path_image_samples
from fluidimage.piv import Topology
params = Topology.create_default_params()
params.series.path = get_path_image_samples() / "Karman/Images"
params.series.ind_start = 1
params.series.ind_step = 2
params.piv0.shape_crop_im0 = 32
params.multipass.number = 2
params.multipass.use_tps = False
params.mask.strcrop = ":, 50:500"
params.saving.how = "recompute"
params.saving.postfix = "piv_im2im_cls_example"
# we use the light versatile preprocessing feature:
params.preproc.im2im = "my_example_im2im_class.Im2Im"
params.preproc.args_init = ("arg0", "arg1")
# Here, the class will be imported with the statement
# `from my_example_im2im_class import Im2Im`
topology = Topology(params, logging_level="info")
# To produce a graph of the topology
topology.make_code_graphviz("topo.dot")
# Compute in parallel
topology.compute()
# Compute in sequential (for debugging)
# topology.compute(sequential=True)
assert len(topology.results) == 1
The file my_example_im2im_class.py
should be importable (for example in the
same directory than piv_parallel_im2im_class.py
)
"""This is a very silly example of importable module where we define a
"filter" class Im2Im.
"""
class Im2Im:
def __init__(self, arg0, arg1):
self.arg0 = arg0
self.arg1 = arg1
def calcul(self, tuple_name_image):
_, image = tuple_name_image
print(f"in the function Im2Im.calcul (arg0={self.arg0})...")
return 2 * image