def __init__(self, params): self.cpt = 0 self.params = params self.works_surface_tracking = [] self.nameFrame = None self.path = params.images.path self.path_ref = params.images.path_ref self.verify_process = False self.ref_film = None self.filmName = None self.save_png = True # self.treshold = 0.16 self.xmin = self.params.surface_tracking.xmin self.xmax = self.params.surface_tracking.xmax self.ymin = self.params.surface_tracking.ymin self.ymax = self.params.surface_tracking.ymax self.distance_lens = self.params.surface_tracking.distance_lens self.distance_object = self.params.surface_tracking.distance_object self.pix_size = self.params.surface_tracking.pix_size self.startref_frame = self.params.surface_tracking.startref_frame self.lastref_frame = self.params.surface_tracking.lastref_frame self.sur = self.params.surface_tracking.sur self.k_x = self.params.surface_tracking.k_x self.k_y = self.params.surface_tracking.k_y self.slicer = self.params.surface_tracking.slicer self.red_factor = self.params.surface_tracking.red_factor self.n_frames_stock = self.params.surface_tracking.n_frames_stock self.plot_reduction_factor = 10 self.l_x = self.xmax - self.xmin self.l_y = self.ymax - self.ymin self.wave_proj = 1 / (self.k_x / self.l_x / self.pix_size) # wave_proj_pix = self.wave_proj / self.pix_size self.kslicer = 2 * self.k_x self.kx = np.arange(-self.l_x / 2, self.l_x / 2) / self.l_x self.ky = np.arange(-self.l_y / 2, self.l_y / 2) / self.l_y refserie = SerieOfArraysFromFiles(params.images.path_ref, params.images.str_slice_ref) k_x = self.compute_kx(refserie) logger.warning("Value of kx computed = " + str(k_x)) self.kxx = self.kx / self.pix_size self.gain, self.filt = self.set_gain_filter(k_x, self.l_y, self.l_x, self.slicer) self.a1_tmp = None
def fill_queue_paths(self, input_queue, output_queues): assert input_queue is None queue_paths = output_queues[0] queue_couples_of_names = output_queues[1] serie = self.serie if len(serie) == 0: logger.warning("add 0 image. No image to process.") return names = serie.get_name_arrays() for name in names: path_im_output = self.path_dir_result / name path_im_input = str(self.path_dir_src / name) if self.how_saving == "complete": if not path_im_output.exists(): queue_paths[name] = path_im_input else: queue_paths[name] = path_im_input if len(names) == 0: if self.how_saving == "complete": logger.warning( 'topology in mode "complete" and work already done.') else: logger.warning("Nothing to do") return nb_names = len(names) logger.info(f"Add {nb_names} images to compute.") logger.info("First files to process: " + str(names[:4])) logger.debug("All files: " + str(names)) series = self.series if not series: logger.warning("add 0 couple. No phase to correct.") return nb_series = len(series) logger.info(f"Add {nb_series} phase to correct.") for iserie, serie in enumerate(series): if iserie > 1: break logger.info("Files of serie {}: {}".format( iserie, serie.get_name_arrays())) # for the first corrected angle : corrected_angle = angle ind_serie, serie = next(series.items()) name = serie.get_name_arrays()[0] queue_couples_of_names[ind_serie - 1] = (name, name) for ind_serie, serie in series.items(): queue_couples_of_names[ind_serie] = serie.get_name_arrays()
def compute_kx(self, serie): if len(serie) == 0: logger.warning("0 ref image. Use of default k_x = 70.75.") return 70.75 names = serie.get_name_arrays() ref = np.zeros((self.ymax - self.ymin, self.xmax - self.xmin)) ii = 0 for name in names: array = imread(str(Path(self.path_ref) / name)) frame = array[self.ymin:self.ymax, self.xmin:self.xmax].astype(float) frame = self.frame_normalize(frame) ref = ref + frame ii += 1 ref = ref / ii return self.wave_vector(ref, self.ymin, self.ymax, self.xmin, self.xmax, self.sur)
def fill_couples_of_names_and_paths(self, input_queue, output_queues): """Fill the two first queues""" assert input_queue is None queue_couples_of_names = output_queues[0] queue_paths = output_queues[1] series = self.series if not series: logger.warning("add 0 couple. No PIV to compute.") return if self.how_saving == "complete": index_series = [] for ind_serie, serie in self.series.items(): name_piv = get_name_piv(serie, prefix="piv") if not (self.path_dir_result / name_piv).exists(): index_series.append(ind_serie) if not index_series: logger.warning( 'topology in mode "complete" and work already done.') return series.set_index_series(index_series) if logger.isEnabledFor(DEBUG): logger.debug( repr([serie.get_name_arrays() for serie in series])) nb_series = len(series) logger.info(f"Add {nb_series} PIV fields to compute.") for iserie, serie in enumerate(series): if iserie > 1: break logger.info("Files of serie {}: {}".format( iserie, serie.get_name_arrays())) for ind_serie, serie in series.items(): queue_couples_of_names[ind_serie] = serie.get_name_arrays() for name, path in serie.get_name_path_arrays(): queue_paths[name] = path
def fill_queue_paths(self, input_queue, output_queue): """Fill the first queue (paths)""" assert input_queue is None serie = self.serie if not serie: logger.warning("add 0 image. No image to process.") return names = serie.get_name_arrays() for name in names: path_im_output = self.path_dir_result / name path_im_input = str(self.path_dir_src / name) if self.how_saving == "complete": if not path_im_output.exists(): output_queue[name] = path_im_input else: output_queue[name] = path_im_input if not names: if self.how_saving == "complete": logger.warning( 'topology in mode "complete" and work already done.') else: logger.warning("Nothing to do") return nb_names = len(names) logger.info(f"Add {nb_names} images to compute.") logger.info(f"First files to process: {names[:4]}") logger.debug(f"All files: {names}")
def init_series(self) -> List[str]: """Initializes the SeriesOfArrays object `self.series` based on input parameters.""" series = self.series if not series: logger.warning( "encountered empty series. No images to preprocess.") return if self.how_saving == "complete": index_subsets = [] for ind_subset, subset in self.series.items(): names_serie = subset.get_name_arrays() name_preproc = get_name_preproc( subset, names_serie, ind_subset, series.nb_series, self.params.saving.format, ) if not (self.path_dir_result / name_preproc).exists(): index_subsets.append(ind_subset) series.set_index_series(index_subsets) if logger.isEnabledFor(DEBUG): logger.debug( repr([subset.get_name_arrays() for subset in series])) nb_subsets = len(series) if nb_subsets == 0: logger.warning( 'topology in mode "complete" and work already done.') return elif nb_subsets == 1: plurial = "" else: plurial = "s" logger.info(f"Add {nb_subsets} image serie{plurial} to compute.")
def add_series(self, series): if len(series) == 0: logger.warning("add 0 couple. No PIV to compute.") return if self.how_saving == "complete": names = [] index_series = [] for i, serie in enumerate(series): name_piv = get_name_piv(serie, prefix="piv") if os.path.exists(os.path.join(self.path_dir_result, name_piv)): continue for name in serie.get_name_arrays(): if name not in names: names.append(name) index_series.append(i * series.ind_step + series.ind_start) if len(index_series) == 0: logger.warning( 'topology in mode "complete" and work already done.') return series.set_index_series(index_series) logger.debug(repr(names)) logger.debug(repr([serie.get_name_arrays() for serie in series])) else: names = series.get_name_all_arrays() nb_series = len(series) print("Add {} PIV fields to compute.".format(nb_series)) for i, serie in enumerate(series): if i > 1: break print("Files of serie {}: {}".format(i, serie.get_name_arrays())) self.wq0.add_name_files(names) self.wq_images.add_series(series) k, o = self.wq0.popitem() im = self.wq0.work(o) self.wq0.fill_destination(k, im) # a little bit strange, to apply mask... try: params_mask = self.params.mask except AttributeError: params_mask = None couple = ArrayCouple(names=("", ""), arrays=(im, im), params_mask=params_mask) im, _ = couple.get_arrays() self.piv_work._prepare_with_image(im)