From fca04ffb536be176d52540370bcef63b8089d0ee Mon Sep 17 00:00:00 2001 From: Tobias Hienzsch Date: Fri, 9 Aug 2024 06:20:56 +0200 Subject: [PATCH] [python] Enable polyscope --- .gitignore | 2 ++ run_3d.sh | 3 ++- src/python/Modes_cpu.py | 6 ++++-- src/python/Modes_model.py | 2 +- src/python/Modes_viz.py | 4 ++-- src/python/Studio_cpu.py | 3 +++ src/python/analysis/response.py | 24 ++++++++++++++---------- src/python/analysis/room_modes.py | 2 +- 8 files changed, 29 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 69f62f3..0f7c319 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,8 @@ a.out /external /CMakeUserPresets.json +.polyscope.ini +imgui.ini /venv __pycache__# Byte-compiled / optimized / DLL files diff --git a/run_3d.sh b/run_3d.sh index b1ef8db..93591a4 100755 --- a/run_3d.sh +++ b/run_3d.sh @@ -15,7 +15,7 @@ model_dir="$root_dir/data/models/$sim_name" materials_dir="$root_dir/data/materials" fmin=20 -fmax=400 +fmax=800 # Delete old sim rm -rf "$sim_dir" @@ -36,6 +36,7 @@ $engine_exe # Post-process cd "$python_dir" python -m sim3d.process_outputs --data_dir="$sim_dir" --fcut_lowpass "$fmax" --N_order_lowpass=8 --symmetric --fcut_lowcut $fmin --N_order_lowcut=4 --air_abs_filter="none" --save_wav --plot +# python -m analysis.response --fmin=$fmin --fmax="$fmax" ../../data/sim_data/$sim_name/cpu/R001_out_normalised.wav # python -m analysis.t60 --fmin=$fmin --fmax="$fmax" --target=0.25 ../../data/sim_data/$sim_name/cpu/R001_out_normalised.wav # python -m analysis.t60 --data_dir="$sim_dir" --fmin=$fmin --fmax="$fmax" --target=0.25 python -m analysis.room_modes --data_dir="$sim_dir" --fmin=$fmin --fmax=$fmax --modes=20 diff --git a/src/python/Modes_cpu.py b/src/python/Modes_cpu.py index 0547dd5..aa66baa 100644 --- a/src/python/Modes_cpu.py +++ b/src/python/Modes_cpu.py @@ -16,9 +16,11 @@ rh=50, fcc_flag=False, PPW=10.5, - fmax=400.0, + fmax=800.0, save_folder='../../data/sim_data/Modes/cpu', save_folder_gpu='../../data/sim_data/Modes/gpu', compress=0, - rot_az_el=[0, 0], + draw_vox=True, + draw_backend='polyscope', + rot_az_el=[15, 15], ) diff --git a/src/python/Modes_model.py b/src/python/Modes_model.py index de1db82..ad9cb02 100644 --- a/src/python/Modes_model.py +++ b/src/python/Modes_model.py @@ -2,7 +2,7 @@ from common.room_builder import RoomBuilder -S = 0.90 +S = 0.9 L = 7.00*S W = 5.19*S H = 3.70*S diff --git a/src/python/Modes_viz.py b/src/python/Modes_viz.py index 2bd201c..fb7bbfd 100644 --- a/src/python/Modes_viz.py +++ b/src/python/Modes_viz.py @@ -21,9 +21,9 @@ save_folder='../../data/sim_data/Modes/viz', # can run python from here compress=0, draw_vox=True, - draw_backend='mayavi', + draw_backend='polyscope', rot_az_el=[0, 0] ) # then run with python and 3D visualization: -# python3 -m sim3d.sim_fdtd --data_dir='../../data/sim_data/Modes/viz' --plot --draw_backend='mayavi' --json_model='../../data/models/Modes/model.json' +# python3 -m sim3d.sim_fdtd --data_dir='../../data/sim_data/Modes/viz' --plot --draw_backend='polyscope' --json_model='../../data/models/Modes/model.json' diff --git a/src/python/Studio_cpu.py b/src/python/Studio_cpu.py index c416b28..ce6e5d9 100644 --- a/src/python/Studio_cpu.py +++ b/src/python/Studio_cpu.py @@ -25,5 +25,8 @@ fmax=800.0, save_folder='../../data/sim_data/Studio/cpu', save_folder_gpu='../../data/sim_data/Studio/gpu', + draw_vox=True, + draw_backend='polyscope', compress=0, + rot_az_el=[0, 0], ) diff --git a/src/python/analysis/response.py b/src/python/analysis/response.py index 3bc4d5c..ff3f026 100644 --- a/src/python/analysis/response.py +++ b/src/python/analysis/response.py @@ -55,8 +55,8 @@ def parse_file_label(filename: str, fallback: str): def main(): parser = argparse.ArgumentParser() parser.add_argument('filename', nargs='*') - parser.add_argument('--fmin', type=float, default=20.0) - parser.add_argument('--fmax', type=float, default=0.0) + parser.add_argument('--fmin', type=float, default=1.0) + parser.add_argument('--fmax', type=float, default=1000.0) parser.add_argument('--label_a', type=str, default='A') parser.add_argument('--label_b', type=str, default='B') parser.add_argument('--smoothing', type=float, default=0.0) @@ -82,13 +82,15 @@ def main(): spectrum_a = np.fft.rfft(buf_a, nfft) spectrum_b = np.fft.rfft(buf_b, nfft) - dB_a = 20*np.log10(np.abs(spectrum_a)+np.spacing(1)) - dB_a -= np.max(dB_a) - dB_a += 75.0 + dB_a = 20*np.log10(np.abs(spectrum_a)/nfft+np.spacing(1)) + dB_b = 20*np.log10(np.abs(spectrum_b)/nfft+np.spacing(1)) - dB_b = 20*np.log10(np.abs(spectrum_b)+np.spacing(1)) - dB_b -= np.max(dB_b) - dB_b += 75.0 + # norm = max(np.max(dB_a), np.max(dB_b)) + # dB_a -= norm + # dB_b -= norm + + # dB_a += 75.0 + # dB_b += 75.0 if args.smoothing > 0.0: smoothing = args.smoothing @@ -109,8 +111,8 @@ def main(): ax[0].set_title('Spectrum') ax[0].set_xlabel('Frequency [Hz]') ax[0].set_ylabel('Amplitude [dB]') - ax[0].set_ylim((10, 80)) - ax[0].set_xlim((args.fmin, fmax)) + # ax[0].set_ylim((-100, -60)) + # ax[0].set_xlim((args.fmin, fmax)) ax[0].xaxis.set_major_formatter(formatter) ax[0].grid(which='minor', color='#DDDDDD', linestyle=':', linewidth=0.5) ax[0].minorticks_on() @@ -122,6 +124,8 @@ def main(): ax[1].set_xlabel('Frequency [Hz]') ax[1].set_ylabel('Amplitude [dB]') ax[1].set_xlim((args.fmin, fmax)) + ax[1].set_ylim((-np.max(np.abs(difference)), np.max(np.abs(difference)))) + ax[1].set_ylim((-30, 30)) ax[1].xaxis.set_major_formatter(formatter) ax[1].grid(which='minor', color='#DDDDDD', linestyle=':', linewidth=0.5) ax[1].minorticks_on() diff --git a/src/python/analysis/room_modes.py b/src/python/analysis/room_modes.py index 0bdf660..88a45e2 100644 --- a/src/python/analysis/room_modes.py +++ b/src/python/analysis/room_modes.py @@ -158,7 +158,7 @@ def main(): dB_max = np.max(dB) peaks, _ = find_peaks(dB, width=2) - print(freqs[peaks][5:10]) + print(freqs[peaks][:10]) plt.plot(freqs, dB, linestyle='-', label=f'{file.stem[:4]}')