-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain_evaluate.py
More file actions
executable file
·78 lines (65 loc) · 3.05 KB
/
main_evaluate.py
File metadata and controls
executable file
·78 lines (65 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# ==============================================================================
# Copyright 2021 Technical University of Denmark
# Author: Nikolas Borrel-Jensen
#
# All Rights Reserved.
#
# Licensed under the MIT License.
# ==============================================================================
import tensorflow as tf
import os
from pathlib import Path
from setup.settings import Settings
from setup.setup_nn import setupPinnModelFromWeights
import utils.utils as utils
from utils.validations import validateData
from utils.evaluate import evaluatePlotIR_TF, evaluatePlotAtReceiverPositions, evaluatePlotWaveSideBySide, evaluatePlotAccumulators, evaluateAnimateWave
import setup.configurations as configs
import setup.parsers as parsers
from models.datastructures import BoundaryType
import datahandlers.data_reader_writer as rw
### SETTINGS ###
id_dir = 'neumann_srcs3_sine_3_256_7sources'
settings_filename = 'settings_srcs.json'
base_dir = "/Users/nikolasborrel/data/pinn"
do_plots_for_paper = True
do_animations = True
do_side_by_side_plot = True
### SETUP ###
configs.setupPlotParams(do_plots_for_paper)
settings_path = os.path.join(base_dir, f"results/{id_dir}/{settings_filename}")
settings_dict = parsers.parseSettings(settings_path)
settings = Settings(settings_dict, base_dir=base_dir)
settings.dirs.createDirs(False)
validateData(settings)
c_phys = settings.physics.c_phys
# LOAD REFERENCE GRID
grid,_,_,_,_ = rw.loadDataFromH5(settings.dirs.data_path, tmax=settings.domain.tmax)
r0 = utils.calcSourcePositions(grid,settings.domain)
checkpoint_path = os.path.join(settings.dirs.models_dir, 'LossType.PINN')
latest = tf.train.latest_checkpoint(checkpoint_path)
if latest == None:
raise FileNotFoundError(f'Weights not found: %s', checkpoint_path)
m, funcs, accum = setupPinnModelFromWeights(latest, settings)
# PLOT
if do_plots_for_paper:
configs.setupPlotParams(True)
figs_paper_dir = os.path.join(settings.dirs.figs_dir, "paper"); Path(figs_paper_dir).mkdir(parents=True, exist_ok=True)
evaluatePlotAtReceiverPositions(m,funcs,settings,r0,figs_dir=figs_paper_dir)
evaluatePlotIR_TF(m,funcs,settings,r0,c_phys=settings.physics.c_phys,figs_dir=figs_paper_dir)
if do_animations:
configs.setupPlotParams(False)
if settings.domain.boundary_cond.type == BoundaryType.IMPEDANCE_FREQ_DEP:
title = 'Boundary condition: Frequency-Dependent Impedance'
elif settings.domain.boundary_cond.type == BoundaryType.IMPEDANCE_FREQ_INDEP:
title = 'Boundary condition: Frequency-Independent Impedance'
elif settings.domain.boundary_cond.type == BoundaryType.NEUMANN:
title = 'Boundary condition: Reflective Walls (Neumann)'
else:
title = ''
evaluateAnimateWave(m, funcs, settings, r0, settings.physics.c_phys, title=title)
if do_side_by_side_plot:
configs.setupPlotParams(False)
evaluatePlotWaveSideBySide(m,funcs,settings,tag='TRAINED')
if settings.domain.boundary_cond.type == BoundaryType.IMPEDANCE_FREQ_DEP:
evaluatePlotAccumulators(m,funcs,accum,settings,tag='TRAINED',do_animations=do_animations)