async def load_images(self, im1, im2): """ load two images and make a couple :param name of im1 :type str :param name of im2 :type str :return: couple """ start = time.time() if self.img_tmp == None: image1 = await self.loop.run_in_executor( None, functools.partial(imread, self.path_images + im1)) else: image1 = self.img_tmp image2 = await self.loop.run_in_executor( None, functools.partial(imread, self.path_images + im2)) params_mask = self.params.mask couple = ArrayCouple(names=(im1, im2), arrays=(image1, image2), params_mask=params_mask) self.img_tmp = image2 end = time.time() logger.info("Loaded Image {} : {}s".format(im1 + " - " + im2, end - start)) return couple
async def load_images(self, im1, im2, serie): """ load two images and make a couple :param name of im1 :type str :param name of im2 :type str :return: couple """ start = time.time() if self.img_tmp is None: image1 = imread(self.path_images + "/" + im1) else: image1 = self.img_tmp image2 = imread(self.path_images + "/" + im2) params_mask = self.params.mask couple = ArrayCouple( names=(im1, im2), arrays=(image1, image2), params_mask=params_mask, serie=serie, ) self.img_tmp = image2 end = time.time() logger.info( "Loaded Image {} : {}s".format(im1 + " - " + im2, end - start) ) return couple
def do_one_shot_job(self): for key, func in reversed(self.funcs.items()): logger.info( "Does one_shot_job key func : {} with function {}".format( key, func ) ) func()
async def process(self, im1, im2): """ Call load_image, compute piv and save_piv with awaits :param name of im1 :type str :param name of im2 :type str :return: none """ start = time.time() couple = await self.load_images(im1, im2) result = await self.compute(couple) end = time.time() logger.info("Computed Image {} : {}s".format(couple.name, end - start)) await self.save_piv(result, im1, im2) end = time.time() logger.info("finished Image {} : {}s".format(im1 + " - " + im2, end - start)) return
async def start_async_works(self): async with trio.open_nursery() as nursery: cond = trio.Condition() for key, af in reversed(self.async_funcs.items()): nursery.start_soon(af, cond) logger.info("Work all done in {}".format(time.time() - self.t_start))