zacel pisati skripto z NGW algoritmom

master
Andrej 2021-05-06 10:57:42 +02:00
parent 48e46e3e61
commit ed89c89b35
2 changed files with 38 additions and 0 deletions

BIN
.s2eps.py.swp 100644

Binary file not shown.

38
s2eps.py 100644
View File

@ -0,0 +1,38 @@
#!/usr/bin/python3
import numpy as np
from operator import itemgetter
def s2p_to_narray(file):
""" prebere s2p file v narray. STOLPCI --> VRSTICE!!! """
return np.loadtxt(file, comments=('!','#')).T
def narray_to_s(narray):
""" prebran s2p narray posortiram po s parametrih.
pri tem upostevam vrstni red:
f s11 s21 s12 s22, kjer sta za vsak s parameter
dve vrstici: realni in imaginarni del """
keys = ["s{}{}".format(j,i) for i in range(1,3) for j in range(1,3)]
s = {}
for i in range(4):
s[keys[i]] = narray[(2*i+1),:]+1j*narray[(2*i+2),:]
s['f'] = narray[0,:]
return s
def s_to_eps(s, L):
""" izracunam eps in tand iz s parametrov in dolzin """
s11, s21, s12, s22, f = itemgetter(*s.keys())(s)
X = (s11**2 - s21**2 + 1)/2/s11
G = X + np.sqrt(X**2 - 1)
if np.abs(G) > 1:
G = X - np.sqrt(X**2 - 1)
P = (s11 + s21 - G)/(1-(s11+s21)*G)
Lambda2 = - (1/2/np.pi/L * np.log(1/P))**2 #izmisli resitev za korene kompleksnega logaritma
# argument korena mora biti 2*pi*n, kjer je n=L/lambda_g
return
a=s2p_to_narray('20.s2p')
b = narray_to_s(a)
s_to_eps(b,0,0,0)