<jupyter_start><jupyter_text>OpenPIV tutorial 2Demonstrates the use of the multiprocessing run<jupyter_code>from openpiv import tools, scaling, pyprocess, validation, filters
import os
import numpy as np

def func( args ):
    """A function to process each image pair."""

    # this line is REQUIRED for multiprocessing to work
    # always use it in your custom function

    file_a, file_b, counter = args


    #####################
    # Here goes you code
    #####################

    # read images into numpy arrays
    frame_a  = tools.imread( os.path.join(path,file_a) )
    frame_b  = tools.imread( os.path.join(path,file_b) )

    frame_a = (frame_a*1024).astype(np.int32)
    frame_b = (frame_b*1024).astype(np.int32)


    # process image pair with extended search area piv algorithm.
    u, v, sig2noise = pyprocess.extended_search_area_piv( frame_a, frame_b, \
        window_size=64, overlap=32, dt=0.02, search_area_size=128, sig2noise_method='peak2peak')
    u, v, mask = validation.sig2noise_val( u, v, sig2noise, threshold = 1.5 )
    u, v = filters.replace_outliers( u, v, method='localmean', max_iter=10, kernel_size=2)
    # get window centers coordinates
    x, y = pyprocess.get_coordinates( image_size=frame_a.shape, search_area_size=128, overlap=32 )
    # save to a file
    tools.save(x, y, u, v, mask, 'test2_%03d.txt' % counter)
    tools.display_vector_field('test2_%03d.txt' % counter)


path = '../test2/'
task = tools.Multiprocesser( data_dir = path, pattern_a='2image_*0.tif', pattern_b='2image_*1.tif' )
task.run( func = func, n_cpus=1 )<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13636363636363635, 'fraction_numerical': 0.031133250311332503, 'mean_word_length': 4.1506410256410255, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '246277', 'license': 'MIT', 'n_tokens_mistral': 602, 'n_tokens_neox': 555, 'n_words': 143, 'path': 'notebooks/tutorial2.ipynb', 'repo_name': 'OpenPIV/openpiv-python-examples', 'size': '1606'}