# Path: concert/coroutines/base.py
# def background(coroutine):
#     """Same as :func:`.start`, just meant to be used as a decorator."""
#     @functools.wraps(coroutine)
#     def inner(*args, **kwargs):
#         return start(coroutine(*args, **kwargs))
# 
#     return inner
# 
# def run_in_executor(func, *args):
#     """Run a blocking function *func* with signature func(\*args) in an executor."""
#     # Leave this here for now, if there are problems with the normal run_in_executor returning a
#     # future then let's re-visit
#     # """Run a blocking function *func* with signature func(*args) in an executor, wrap the future
#     # into a real coroutine and return it.
#     # """
#     # async def make_coro():
#     #     loop = asyncio.get_running_loop()
#     #     future = loop.run_in_executor(None, func, *args)
#     #
#     #     try:
#     #         return await future
#     #     except asyncio.CancelledError:
#     #         # Wait for the future to finish even if we are cancelled.
#     #         LOG.log(AIODEBUG, f'{func.__name__} waiting for concurrent.Future')
#     #         return await future
#     # return make_coro()
#     loop = asyncio.get_event_loop()
# 
#     return loop.run_in_executor(None, func, *args)
# 
# Path: concert/quantities.py



import asyncio
import numpy as np
import logging
from scipy.signal import fftconvolve
from concert.coroutines.base import background, run_in_executor
from concert.quantities import q
        from skimage.filters import threshold_otsu
        from skimage.morphology import dilation, disk, convex_hull_image, label
    from scipy.ndimage import gaussian_filter1d
    from numpy.fft import fft2, ifft2, fftshift
        from skimage.filters import sobel
        from skimage.transform import resize
        return (image, mask, not _touches_border(mask))

    coros = []
    masks = []
    images = []
    found_completely_in_fov = False
    async for image in producer:
        coros.append(run_in_executor(_process_one, image))

    results = await asyncio.gather(*coros)

    for i, (image, mask, in_fov) in enumerate(results):
        images.append(image)
        masks.append(mask)
        if in_fov:
            a = image
            found_completely_in_fov = True
            LOG.debug('Sphere completely in FOV in image %d', i)

    if not found_completely_in_fov:
        nonzero = [np.count_nonzero(msk) for msk in masks]
        i = np.argmax(nonzero)
        LOG.debug("No sphere commpletely in FOV, largest portion in image %d", i)
        a = images[i]

    center_a = np.mean(np.where(segment_convex_object(a)), axis=1)
    shifts = np.array([correlate(a, b, supersampling=supersampling)[:2] for b in images])
    if correlation_threshold:
        r = np.empty(len(shifts))
        for (i, (dy, dx)) in enumerate(shifts):

# Path: concert/coroutines/base.py
# def background(coroutine):
#     """Same as :func:`.start`, just meant to be used as a decorator."""
#     @functools.wraps(coroutine)
#     def inner(*args, **kwargs):
#         return start(coroutine(*args, **kwargs))
# 
#     return inner
# 
# def run_in_executor(func, *args):
#     """Run a blocking function *func* with signature func(\*args) in an executor."""
#     # Leave this here for now, if there are problems with the normal run_in_executor returning a
#     # future then let's re-visit
#     # """Run a blocking function *func* with signature func(*args) in an executor, wrap the future
#     # into a real coroutine and return it.
#     # """
#     # async def make_coro():
#     #     loop = asyncio.get_running_loop()
#     #     future = loop.run_in_executor(None, func, *args)
#     #
#     #     try:
#     #         return await future
#     #     except asyncio.CancelledError:
#     #         # Wait for the future to finish even if we are cancelled.
#     #         LOG.log(AIODEBUG, f'{func.__name__} waiting for concurrent.Future')
#     #         return await future
#     # return make_coro()
#     loop = asyncio.get_event_loop()
# 
#     return loop.run_in_executor(None, func, *args)
# 
# Path: concert/quantities.py



# Path: concert/imageprocessing.py
import asyncio
import numpy as np
import logging
from scipy.signal import fftconvolve
from concert.coroutines.base import background, run_in_executor
from concert.quantities import q
        from skimage.filters import threshold_otsu
        from skimage.morphology import dilation, disk, convex_hull_image, label
    from scipy.ndimage import gaussian_filter1d
    from numpy.fft import fft2, ifft2, fftshift
        from skimage.filters import sobel
        from skimage.transform import resize

        return (image, mask, not _touches_border(mask))

    coros = []
    masks = []
    images = []
    found_completely_in_fov = False
    async for image in producer:
        coros.append(run_in_executor(_process_one, image))

    results = await asyncio.gather(*coros)

    for i, (image, mask, in_fov) in enumerate(results):
        images.append(image)
        masks.append(mask)
        if in_fov:
            a = image
            found_completely_in_fov = True
            LOG.debug('Sphere completely in FOV in image %d', i)

    if not found_completely_in_fov:
        nonzero = [np.count_nonzero(msk) for msk in masks]
        i = np.argmax(nonzero)
        LOG.debug("No sphere commpletely in FOV, largest portion in image %d", i)
        a = images[i]

    center_a = np.mean(np.where(segment_convex_object(a)), axis=1)
    shifts = np.array([correlate(a, b, supersampling=supersampling)[:2] for b in images])
    if correlation_threshold:
        r = np.empty(len(shifts))
        for (i, (dy, dx)) in enumerate(shifts):

            r[i] = await run_in_executor(compute_pearson_correlation_coefficient,