From 859da1a847c646f6c0a529f280668b24c6c690be Mon Sep 17 00:00:00 2001 From: Laurent FAINSIN Date: Fri, 14 Apr 2023 13:09:44 +0200 Subject: [PATCH] feat: dirty script to compare recenter generated blades --- compare_samples.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 compare_samples.py diff --git a/compare_samples.py b/compare_samples.py new file mode 100644 index 0000000..e98c22a --- /dev/null +++ b/compare_samples.py @@ -0,0 +1,37 @@ +from pathlib import Path + +import numpy as np +import pyvista as pv + +VTKFILE_NOMINAL = Path("~/data/stage-laurent-f/datasets/Rotor37/processed/nominal_blade_rotated.vtk") + +# load nominal blade +nominal = pv.read(VTKFILE_NOMINAL) + +# for each generated/sampled blade +gen_files = Path.cwd().glob("gen*.txt") +for gen_file in gen_files: + # load numpy txt + blade = np.loadtxt(gen_file) + + # get top and bottom index (filter outliers a bit) + top = int(blade.shape[0] * 0.001) + bot = int(blade.shape[0] * 0.999) + + # sort blade coordinates + sorted_blade = np.sort(blade, axis=0) + + # get center of blade + center = (sorted_blade[bot, :] + sorted_blade[top, :]) / 2 + + # translate blade to world origin + blade -= center + + # save to txt + np.savetxt(f"test_{gen_file.stem}.txt", blade) + + # swap nominal points to blade points + nominal.points = blade + + # save altered blade to vtk + nominal.save(f"test_{gen_file.stem}.vtk")