feat: 添加测试代码
This commit is contained in:
48
test/test_save_and_reload_model.py
Normal file
48
test/test_save_and_reload_model.py
Normal file
@@ -0,0 +1,48 @@
|
||||
import skrf as rf
|
||||
import os
|
||||
import json
|
||||
from ovf.core.VFManager import VFManager
|
||||
from ovf.core.sample import auto_select_multple_ports
|
||||
from ovf.core.basis.MultiPortOrthonormalBasis import MultiPortOrthonormalBasis
|
||||
|
||||
id = 3000
|
||||
network = rf.Network(f"/tmp/paramer/simulation/3000/3000.s2p")
|
||||
ports = network.nports
|
||||
K = 5
|
||||
|
||||
full_freqences = network.f
|
||||
noised_sampled_points = network.y.reshape(-1,ports,ports)
|
||||
sampled_points = network.y.reshape(-1,ports,ports)
|
||||
|
||||
H,freqs = auto_select_multple_ports(noised_sampled_points,full_freqences,max_points=20)
|
||||
|
||||
def run_capa():
|
||||
vf = VFManager(npoles_cplx=2,freqs=freqs,H=H,model=MultiPortOrthonormalBasis,iterations=K,verbose=False)
|
||||
vf.fit()
|
||||
vf.plot_metrics(show=False,save_path=f"outputs/{id}")
|
||||
model_responses = vf.get_model_responses(full_freqences)
|
||||
vf.plot_model_responses(show=False,save_path=f"outputs/{id}")
|
||||
# vf.export(f"outputs/{id}")
|
||||
vf.write(f"outputs/{id}")
|
||||
|
||||
def load_model():
|
||||
vf = VFManager.load(f"outputs/3000")
|
||||
|
||||
vf.plot_metrics(show=False,save_path=f"outputs/3001")
|
||||
model_responses = vf.get_model_responses(full_freqences)
|
||||
vf.plot_model_responses(show=False,save_path=f"outputs/3001")
|
||||
# vf.export(f"outputs/{id}")
|
||||
vf.write(f"outputs/3001")
|
||||
|
||||
def load_model1():
|
||||
vf = VFManager.load(f"outputs/3001")
|
||||
|
||||
vf.plot_metrics(show=False,save_path=f"outputs/3002")
|
||||
model_responses = vf.get_model_responses(full_freqences)
|
||||
vf.plot_model_responses(show=False,save_path=f"outputs/3002")
|
||||
# vf.export(f"outputs/{id}")
|
||||
vf.write(f"outputs/3002")
|
||||
|
||||
run_capa()
|
||||
load_model()
|
||||
load_model1()
|
||||
Reference in New Issue
Block a user