init: 验证robust算法
This commit is contained in:
55
utils.py
Normal file
55
utils.py
Normal file
@@ -0,0 +1,55 @@
|
||||
import requests
|
||||
import time
|
||||
from schemas.paramer import SimulationRequestUnit, SimulationResponseUnit, UuidResponseUnit
|
||||
import skrf as rf
|
||||
from typing import Literal
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
def send_get_request(url):
|
||||
try:
|
||||
response = requests.get(url)
|
||||
response.raise_for_status() # Raise an error for bad responses
|
||||
return response.json()
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"An error occurred: {e}")
|
||||
return None
|
||||
|
||||
def get_network(file_path: str) -> rf.Network:
|
||||
network = rf.Network(file_path)
|
||||
return network
|
||||
|
||||
def get_rms_error(vf: rf.VectorFitting,parameter_type:Literal['s','y','z']):
|
||||
rms_error = []
|
||||
for i in range(vf.network.nports):
|
||||
rms_error_row = []
|
||||
for j in range(vf.network.nports):
|
||||
rms_error = vf.get_rms_error(i, j, parameter_type)
|
||||
rms_error_row.append(rms_error)
|
||||
rms_error.append(rms_error_row)
|
||||
return rms_error
|
||||
|
||||
def show_rms_error(vf: rf.VectorFitting,parameter_type:Literal['s','y','z'],show_plot:bool=True,save_path:str|None=None):
|
||||
freqs = vf.network.f
|
||||
nports = vf.network.nports
|
||||
fig, ax = plt.subplots(nports, nports)
|
||||
fig.set_size_inches(6*nports, 4*nports)
|
||||
for i in range(nports):
|
||||
for j in range(nports):
|
||||
vf.plot("mag",0,1,freqs,ax=ax[i][j],parameter=parameter_type)
|
||||
fig.tight_layout()
|
||||
if show_plot:
|
||||
plt.show()
|
||||
if save_path:
|
||||
plt.savefig(save_path)
|
||||
|
||||
def remove_simulation_with_high_rms_error(simulations:list[rf.VectorFitting],limit:float=0.015,parameter_type:Literal['s','y','z']='s'):
|
||||
nports = simulations[0].network.nports
|
||||
index_of_filtered_simulations = []
|
||||
for res in simulations:
|
||||
for i in range(nports):
|
||||
for j in range(nports):
|
||||
rms_error = res.get_rms_error(i, j, parameter_type)
|
||||
if rms_error > limit:
|
||||
index_of_filtered_simulations.append(i*nports+j)
|
||||
break
|
||||
Reference in New Issue
Block a user