From 59fe05badb9251f1370bcb09f6deb62a84364c82 Mon Sep 17 00:00:00 2001 From: paugier Date: Fri, 23 Feb 2024 21:38:31 +0100 Subject: [PATCH] Delete unused files --- .../calcul/_try_correl_images_diff_sizes.py | 73 -------- .../calcul/_try_correl_images_same_size.py | 79 --------- .../executors/multi_exec_async_subproc.py | 84 --------- src/fluidimage/postproc/_try_postproc.py | 160 ------------------ 4 files changed, 396 deletions(-) delete mode 100644 src/fluidimage/calcul/_try_correl_images_diff_sizes.py delete mode 100644 src/fluidimage/calcul/_try_correl_images_same_size.py delete mode 100644 src/fluidimage/executors/multi_exec_async_subproc.py delete mode 100644 src/fluidimage/postproc/_try_postproc.py diff --git a/src/fluidimage/calcul/_try_correl_images_diff_sizes.py b/src/fluidimage/calcul/_try_correl_images_diff_sizes.py deleted file mode 100644 index 1cbbdf24..00000000 --- a/src/fluidimage/calcul/_try_correl_images_diff_sizes.py +++ /dev/null @@ -1,73 +0,0 @@ -import matplotlib.pyplot as plt -import numpy as np - -from fluidimage.calcul.correl import CorrelScipySignal -from fluidimage.synthetic import make_synthetic_images - -plt.ion() - - -nx = 64 -ny = 64 - -nx1 = 32 -ny1 = 32 - -displacement_x = 2.0 -displacement_y = 2.0 - -displacements = np.array([displacement_y, displacement_x]) - -nb_particles = (nx // 3) ** 2 - - -print(f"nx: {nx} ; ny: {ny} ; nx1: {nx1} ; ny1: {ny1}") - -im0, im1 = make_synthetic_images( - displacements, - nb_particles, - shape_im0=(ny, nx), - shape_im1=(ny1, nx1), - epsilon=0.0, -) - -# plt.figure() - -# ax0 = plt.subplot(121) -# ax1 = plt.subplot(122) - -# axi0 = ax0.imshow(im0, interpolation='nearest') -# axi1 = ax1.imshow(im1, interpolation='nearest') - - -classes = {"sig": CorrelScipySignal} - - -cs = {} -funcs = {} -for k, cls in classes.items(): - calcul_corr = cls(im0.shape, im1.shape, mode="valid") - funcs[k] = calcul_corr - cs[k], norm = calcul_corr(im0, im1) - - -for k, c in cs.items(): - func = funcs[k] - inds_max = np.array(np.unravel_index(c.argmax(), c.shape)) - if not np.allclose( - displacements.astype("int"), - func.compute_displacement_from_indices(inds_max), - ): - print( - "do not understand " + k, - displacements.astype("int"), - func.compute_displacement_from_indices(inds_max), - ) - -c = cs["sig"] -# plt.figure() - -# ax = plt.gca() -# ax.imshow(c, interpolation='nearest') - -# plt.show() diff --git a/src/fluidimage/calcul/_try_correl_images_same_size.py b/src/fluidimage/calcul/_try_correl_images_same_size.py deleted file mode 100644 index 77a8e2ad..00000000 --- a/src/fluidimage/calcul/_try_correl_images_same_size.py +++ /dev/null @@ -1,79 +0,0 @@ -import matplotlib.pyplot as plt -import numpy as np - -from fluidimage.calcul.correl import ( - CorrelFFTNumpy, - CorrelFFTW, - CorrelScipyNdimage, - CorrelScipySignal, -) -from fluidimage.synthetic import make_synthetic_images - -plt.ion() - - -nx = 32 -ny = 32 -displacement_x = 2.0 -displacement_y = 2.0 - -displacements = np.array([displacement_x, displacement_y]) - -nb_particles = (nx // 3) ** 2 - - -print(f"nx: {nx} ; ny: {ny}") - -im0, im1 = make_synthetic_images( - displacements, nb_particles, shape_im0=(ny, nx), epsilon=0.0 -) - -# plt.figure() - -# ax0 = plt.subplot(121) -# ax1 = plt.subplot(122) - -# axi0 = ax0.imshow(im0, interpolation='nearest') -# axi1 = ax1.imshow(im1, interpolation='nearest') - - -classes = { - "sig": CorrelScipySignal, - "ndimage": CorrelScipyNdimage, - "np.fft": CorrelFFTNumpy, - "fftw": CorrelFFTW, -} - - -cs = {} -correls = {} -for k, cls in classes.items(): - print(k, cls) - correl = cls(im0.shape, im1.shape) - correls[k] = correl - c, norm = correl(im0, im1) - cs[k] = c - - inds_max = np.array(np.unravel_index(c.argmax(), c.shape)) - print(inds_max) - - displacement_computed = correl.compute_displacement_from_indices(inds_max) - print(displacements.astype("int"), displacement_computed) - - if not np.allclose(displacements.astype("int"), displacement_computed): - print( - "do not understand " + k, - displacements.astype("int"), - displacement_computed, - ) - - -# plt.figure() - -# i = 1 -# for k, c in cs.items(): -# ax1 = plt.subplot(2, 2, i) -# ax1.imshow(c, interpolation='nearest') -# i += 1 - -# plt.show() diff --git a/src/fluidimage/executors/multi_exec_async_subproc.py b/src/fluidimage/executors/multi_exec_async_subproc.py deleted file mode 100644 index 00647da4..00000000 --- a/src/fluidimage/executors/multi_exec_async_subproc.py +++ /dev/null @@ -1,84 +0,0 @@ -""" -Multi executors async using subprocesses -======================================== - -.. autoclass:: ExecutorAsyncForMultiSubproc - :members: - :private-members: - -""" - -import sys -from pathlib import Path -from subprocess import Popen - -from fluidimage.util import logger - -from .multi_exec_async import ExecutorAsyncForMulti, MultiExecutorAsync - - -def main(): - """Create an executor and start it in a process""" - - # topology_this_process, path_input, path_output, log_path - - executor = ExecutorAsyncForMulti( - topology_this_process, - path_dir_result, - sleep_time=sleep_time, - log_path=log_path, - logging_level=logging_level, - ) - executor.t_start = t_start - executor.compute() - - -class MultiExecutorAsyncSubproc(MultiExecutorAsync): - - def launch_process(self, topology, ind_process): - """Launch one process""" - - log_path = Path( - str(self._log_path).split(".txt")[0] + f"_multi{ind_process:03}.txt" - ) - - self.log_paths.append(log_path) - - process = Popen( - [ - sys.executable, - "-m", - "fluidimage.executors.multi_exec_async_subproc", - ], - ) - - self.processes.append(process) - - def wait_for_all_processes(self): - """logging + wait for all processes to finish""" - logger.info( - f"logging files: {[log_path.name for log_path in self.log_paths]}" - ) - - # wait until end of all processes - - self.topology.results = results_all = [] - for index, process in enumerate(self.processes): - try: - results = process.connection.recv() - except EOFError: - logger.error(f"EOFError for process {index} ({process})") - results = None - - if results is not None: - results_all.extend(results) - - for process in self.processes: - process.join() - - -Executor = MultiExecutorAsync - - -if __name__ == "__main__": - main() diff --git a/src/fluidimage/postproc/_try_postproc.py b/src/fluidimage/postproc/_try_postproc.py deleted file mode 100644 index 07d7ae19..00000000 --- a/src/fluidimage/postproc/_try_postproc.py +++ /dev/null @@ -1,160 +0,0 @@ -import numpy as np -import pylab -from fluiddyn.util.serieofarrays import SeriesOfArrays -from postproc import PIV_Postproc, PIV_PostProc_serie - -from fluidimage.works.piv import WorkPIV - -# %% -params = WorkPIV.create_default_params() - -# for a very short computation -params.piv0.shape_crop_im0 = 24 -params.piv0.grid.overlap = 0.0 - -params.piv0.method_subpix = "2d_gaussian" -params.piv0.method_correl = "fftw" - -params.multipass.number = 3 -# params.multipass.use_tps = 'last' - -piv = WorkPIV(params=params) - -series = SeriesOfArrays("../../image_samples/Karman/Images", "i+1:i+3") -serie = series.get_serie_from_index(0) - -result = piv.calcul(serie) -result.save() -# result.display() - -lightresult = result.make_light_result() - -lightresult.save() - - -postp = PIV_Postproc(path="piv_Karman01-02_light.h5") - -rot = postp.compute_rot() - -div = postp.compute_div() - -pylab.figure -postp.displayf(X=postp.X, Y=postp.Y, U=postp.U, V=postp.V) - -pylab.figure -postp.displayf(bg=rot) - - -postp = PIV_PostProc_serie(path=["piv_Karman01-02_light.h5"] * 10) -postp.set_time(np.linspace(0, 10, 10)) - -rot = postp.compute_rot() - -div = postp.compute_div() - -postp.compute_temporal_fft() - -pylab.figure -postp.displayf(U=postp.U, V=postp.V, bg=div) - -pylab.figure -postp.displayf(bg=rot) - -pylab.figure -postp.displayf(U=postp.U, V=postp.V) - - -Nt = 100 -postp = PIV_PostProc_serie(path=["piv_Karman01-02_light.h5"] * Nt) - -t = np.linspace(0, 1000, Nt) - -postp.set_time(t) - -kx = 0.05 -ky = 0.17 -omega = 0.02 - -for i in range(np.shape(postp.U)[0]): - postp.U[i] = np.cos(omega * t[i] + kx * postp.X + ky * postp.Y) - postp.V[i] = np.cos(omega * t[i] + kx * postp.X + ky * postp.Y) - - -# FFT temporelle -postp.compute_temporal_fft(parseval=True) -omega = postp.fft.time.omega -psd = postp.fft.time.psdU + postp.fft.time.psdV -pylab.loglog(omega, postp.spatial_average(psd)) - -# FFT spatiale -postp.compute_spatial_fft(parseval=True) -Kx, Ky = np.meshgrid(postp.fft.spatial.kx, postp.fft.spatial.ky) -Kx = Kx.transpose() -Ky = Ky.transpose() -psd = postp.fft.spatial.psdU + postp.fft.spatial.psdV -postp.displayf(X=Kx, Y=Ky, bg=np.log(postp.time_average(psd))) - - -# FFT spatiotemporelle -postp.compute_spatiotemp_fft(parseval=True) -Kx, Ky = np.meshgrid(postp.fft.spatiotemp.kx, postp.fft.spatiotemp.ky) -Kx = Kx.transpose() -Ky = Ky.transpose() -omega = postp.fft.spatiotemp.omega -psd = postp.fft.spatiotemp.psdU + postp.fft.spatiotemp.psdV -psd = psd[0:10:] -postp.displayf(X=Kx, Y=Ky, bg=np.log(psd)) - - -# useful quantities -X = postp.X -Y = postp.Y -dx = X[1][0] - X[0][0] -dy = Y[0][1] - Y[0][0] -Lx = np.max(X) - np.min(X) -Ly = np.max(Y) - np.min(Y) -nx = X.shape[0] -ny = X.shape[1] - -kx = postp.fft.spatiotemp.kx -ky = postp.fft.spatiotemp.ky -dkx = kx[1] - kx[0] -dky = ky[1] - ky[0] -Kx, Ky = np.meshgrid(postp.fft.spatiotemp.kx, postp.fft.spatiotemp.ky) -Kx = Kx.transpose() -Ky = Ky.transpose() - -omega = postp.fft.spatiotemp.omega -domega = omega[1] - omega[0] -dt = postp.t[1] - postp.t[0] -Lt = np.max(postp.t) - np.min(postp.t) - - -# moyenne spatial de fft spatiotemp vs fft temp - -psd = ( - np.sum(postp.fft.spatiotemp.psdU + postp.fft.spatiotemp.psdV, (1, 2)) - * 1.0 - * dkx - * dky -) -pylab.loglog(omega, psd) -psd2 = postp.fft.time.psdU + postp.fft.time.psdV -psd2 = np.sum(psd2, (1, 2)) * 1.0 * (dx * dy) / (Lx * Ly) -pylab.loglog(omega, psd2, "r+") -print(np.mean(((psd2 - psd) ** 2) / psd)) -print(np.max(((psd2 - psd) ** 2) / psd)) - -# moyenne temporelle de fft spatiotemp vs fft spatial -psd = ( - np.sum(postp.fft.spatiotemp.psdU + postp.fft.spatiotemp.psdV, 0) - * 1.0 - * domega -) -pylab.pcolor(Kx, Ky, psd) -psd2 = postp.fft.spatial.psdU + postp.fft.spatial.psdV -psd2 = np.sum(psd2, 0) * 1.0 * dt / Lt -pylab.pcolor(Kx, Ky, psd2) -pylab.pcolor(Kx, Ky, psd2 - psd) -print(np.mean(((psd2 - psd) ** 2) / psd)) -print(np.max(((psd2 - psd) ** 2) / psd))