anti-parallel model updated
This commit is contained in:
@ -10,8 +10,16 @@ from models.antiparallel_model import antiparallel2gap
|
|||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
|
|
||||||
UND_PERIOD = 38.0
|
RADIAL_LIMIT = 5.1
|
||||||
REF_MAG_ARRAY = 'TL'
|
UND_PERIOD_PARALLEL = 38.0
|
||||||
|
UND_PERIOD_ANTIPARALLEL = 2 * UND_PERIOD_PARALLEL
|
||||||
|
UNDU_FIRST = 10
|
||||||
|
UNDU_LAST = 22
|
||||||
|
SETPHASE = -50
|
||||||
|
if SETPHASE >= 0.0:
|
||||||
|
REF_MAG_ARRAY = 'TL'
|
||||||
|
else:
|
||||||
|
REF_MAG_ARRAY = 'BL'
|
||||||
|
|
||||||
|
|
||||||
def check_phase(phase):
|
def check_phase(phase):
|
||||||
@ -20,8 +28,8 @@ def check_phase(phase):
|
|||||||
def fix_phase(p):
|
def fix_phase(p):
|
||||||
return ((p + 180) % 360) - 180
|
return ((p + 180) % 360) - 180
|
||||||
|
|
||||||
def convert_phase_to_shift(phase):
|
def convert_phase_to_shift(phase, und_period):
|
||||||
ratio = UND_PERIOD / 360.0
|
ratio = und_period / 360.0
|
||||||
return phase * ratio / 2
|
return phase * ratio / 2
|
||||||
|
|
||||||
|
|
||||||
@ -83,18 +91,20 @@ class UndPhase(Adjustable):
|
|||||||
def set_target_value(self, value):
|
def set_target_value(self, value):
|
||||||
phase = value
|
phase = value
|
||||||
phase = fix_phase(phase)
|
phase = fix_phase(phase)
|
||||||
shift = convert_phase_to_shift(phase)
|
und_period = UND_PERIOD_PARALLEL if self.isparallel else UND_PERIOD_ANTIPARALLEL
|
||||||
|
shift = convert_phase_to_shift(phase, und_period)
|
||||||
|
|
||||||
k = self.totalk.get()
|
k = self.totalk.get()
|
||||||
if self.isparallel:
|
if self.isparallel:
|
||||||
radial = parallel2gap(k, phase, self.params)
|
radial = parallel2gap(k, phase, self.params)
|
||||||
else:
|
else:
|
||||||
radial = antiparallel2gap(k, phase, self.params)
|
#radial = antiparallel2gap(k, phase, self.params)
|
||||||
|
radial = antiparallel_k2rad_fit(k, phase, self.params)
|
||||||
radial = round(radial, 4) #TODO: why?
|
radial = round(radial, 4) #TODO: why?
|
||||||
|
|
||||||
# workaround for safety measure
|
# workaround for safety measure
|
||||||
if self.radial.get_current_value() <= 5.1:
|
if self.radial.get_current_value() <= RADIAL_LIMIT:
|
||||||
self.radial.set_target_value(5.1).wait()
|
self.radial.set_target_value(RADIAL_LIMIT).wait()
|
||||||
self.shift.set_target_value(shift).wait()
|
self.shift.set_target_value(shift).wait()
|
||||||
self.radial.set_target_value(radial).wait()
|
self.radial.set_target_value(radial).wait()
|
||||||
|
|
||||||
@ -228,12 +238,13 @@ if __name__ == "__main__":
|
|||||||
print(__file__)
|
print(__file__)
|
||||||
print(dirname(__file__))
|
print(dirname(__file__))
|
||||||
basedir = dirname(__file__)
|
basedir = dirname(__file__)
|
||||||
#phase = 123
|
if basedir:
|
||||||
phase = 80
|
basedir += '/'
|
||||||
|
phase = SETPHASE
|
||||||
check_phase(phase)
|
check_phase(phase)
|
||||||
und_first = 10
|
und_first = UNDU_FIRST
|
||||||
und_last = 22
|
und_last = UNDU_LAST
|
||||||
und_range = [*range(und_first, und_last+1, 1)]
|
und_range = list(range(und_first, und_last+1, 1))
|
||||||
if 14 in und_range:
|
if 14 in und_range:
|
||||||
und_range.remove(14)
|
und_range.remove(14)
|
||||||
basename1 = 'SATUN'
|
basename1 = 'SATUN'
|
||||||
@ -241,19 +252,19 @@ if __name__ == "__main__":
|
|||||||
print(undus)
|
print(undus)
|
||||||
|
|
||||||
# old Excel parameter file with only legacy fixed polarization parameters
|
# old Excel parameter file with only legacy fixed polarization parameters
|
||||||
params1 = json_load(basedir + "/UE38_all_parallel_parameters.json")
|
params1 = json_load(basedir + "UE38_all_parallel_parameters.json")
|
||||||
print('\n')
|
print('\n')
|
||||||
print(type(params1))
|
print(type(params1))
|
||||||
print(params1.keys())
|
print(params1.keys())
|
||||||
|
|
||||||
# Excel parameter file with only fixed polarization parameters
|
# Excel parameter file with only fixed polarization parameters
|
||||||
params2 = json_load(basedir + "/UE38_all_parameters.json")
|
params2 = json_load(basedir + "UE38_all_parameters.json")
|
||||||
print('\n')
|
print('\n')
|
||||||
print(type(params2))
|
print(type(params2))
|
||||||
print(params2.keys())
|
print(params2.keys())
|
||||||
|
|
||||||
# Pickle parameter file with fixed and full polarization parameters
|
# Pickle parameter file with fixed and full polarization parameters
|
||||||
alldata = unpickle(basedir + '/UE38_meas_and_fit_data.pickle')
|
alldata = unpickle(basedir + 'UE38_meas_and_fit_data.pickle')
|
||||||
params = alldata['fitdata']
|
params = alldata['fitdata']
|
||||||
measdata = alldata['measdata']
|
measdata = alldata['measdata']
|
||||||
print('\n')
|
print('\n')
|
||||||
|
@ -26,30 +26,54 @@ def K2gap(Kval, fitparam):
|
|||||||
|
|
||||||
|
|
||||||
## TODO: implement the proper model:
|
## TODO: implement the proper model:
|
||||||
#def __antiparallel2gap(K, phi, undudict):
|
|
||||||
# if phi >= 0.0:
|
|
||||||
# fullpol2Kfit_app()
|
|
||||||
# else:
|
|
||||||
# return gLH + dgLV * np.sin(0.5 * phi)**2 + dgC * np.sin(phi)**2
|
|
||||||
#
|
|
||||||
#def fullpol2Kfit_apm(shiftlist, amp1, amp2, amp3, KLH, dKLV, dK45):
|
|
||||||
# gLH = K2gap(K, undudict['K-value_LH'])
|
|
||||||
# gLV = K2gap(K, undudict['K-value_LV-'])
|
|
||||||
# gC = K2gap(K, undudict['K-value_C-'])
|
|
||||||
# dgLV = gLV - gLH
|
|
||||||
# dgC = gC - gLH - dgLV/2
|
|
||||||
# return KLH + dKLV * np.sin((0.5 * shiftlist)*ratio)**2 + dK45 * np.sin(shiftlist*ratio)**2 + amp1 * np.sin(2*shiftlist*ratio) + amp2 * np.sin((2.0 * shiftlist)*ratio)**2 + amp3 * np.cos(6*shiftlist*ratio)
|
|
||||||
#
|
|
||||||
#def fullpol2Kfit_app(shiftlist, amp1, amp2, amp3, KLH, dKLV, dK45):
|
|
||||||
# gLH = K2gap(K, undudict['K-value_LH'])
|
|
||||||
# return KLH + dKLV * np.sin((0.5 * shiftlist)*ratio)**2 + dK45 * np.sin(shiftlist*ratio)**2 + amp1 * np.sin(2*shiftlist*ratio) + amp2 * np.sin((2.0 * shiftlist)*ratio)**2 + amp3 * np.cos(8*shiftlist*ratio)
|
|
||||||
|
|
||||||
|
|
||||||
## reference
|
def antiparallel_rad2k_fit(radial, phi_in_degree, undudict):
|
||||||
#def fullpol2Kfit_apm(shiftlist, amp1, amp2, amp3, KLH, dKLV, dK45):
|
phi = math.radians(phi_in_degree)
|
||||||
# return KLH + dKLV * np.sin((0.5 * shiftlist)*ratio)**2 + dK45 * np.sin(shiftlist*ratio)**2 + amp1 * np.sin(2*shiftlist*ratio) + amp2 * np.sin((2.0 * shiftlist)*ratio)**2 + amp3 * np.cos(6*shiftlist*ratio)
|
amp1 = getfit(radial, undudict['fitpars_amp1'])
|
||||||
#
|
amp2 = getfit(radial, undudict['fitpars_amp2'])
|
||||||
#def fullpol2Kfit_app(shiftlist, amp1, amp2, amp3, KLH, dKLV, dK45):
|
amp3 = getfit(radial, undudict['fitpars_amp3'])
|
||||||
# return KLH + dKLV * np.sin((0.5 * shiftlist)*ratio)**2 + dK45 * np.sin(shiftlist*ratio)**2 + amp1 * np.sin(2*shiftlist*ratio) + amp2 * np.sin((2.0 * shiftlist)*ratio)**2 + amp3 * np.cos(8*shiftlist*ratio)
|
KLH = np.exp(getfit(radial, undudict['fitpars_KLH']))
|
||||||
|
KLV = np.exp(getfit(radial, undudict['fitpars_KLV']))
|
||||||
|
K45 = np.exp(getfit(radial, undudict['fitpars_K45']))
|
||||||
|
dKLV = KLV - KLH
|
||||||
|
dK45 = K45 - KLH - dKLV/2
|
||||||
|
#print(radial, phi_in_degree, amp1, amp2, amp3, KLH, dKLV, dK45)
|
||||||
|
if phi >= 0.0:
|
||||||
|
return KLH + dKLV * np.sin(0.5*phi)**2 + dK45 * np.sin(phi)**2 + amp1 * np.sin(2*phi) + amp2 * np.sin(2.0*phi)**2 + amp3 * np.cos(6*phi)
|
||||||
|
else:
|
||||||
|
return KLH + dKLV * np.sin(0.5*phi)**2 + dK45 * np.sin(phi)**2 + amp1 * np.sin(2*phi) + amp2 * np.sin(2.0*phi)**2 + amp3 * np.cos(8*phi)
|
||||||
|
|
||||||
|
|
||||||
|
def getfit(val, fitparam):
|
||||||
|
fit_func = np.poly1d(fitparam)
|
||||||
|
val = float(val)
|
||||||
|
return fit_func(val)
|
||||||
|
|
||||||
|
|
||||||
|
def antiparallel_k2rad_fit(Kval, phi_in_degree, undudict):
|
||||||
|
phi = math.radians(phi_in_degree)
|
||||||
|
amp1 = getfit(Kval, undudict['fitpars_amp1'])
|
||||||
|
amp2 = getfit(Kval, undudict['fitpars_amp2'])
|
||||||
|
amp3 = getfit(Kval, undudict['fitpars_amp3'])
|
||||||
|
RadLH = getfit_inverse(np.log(Kval), undudict['fitpars_KLH'])
|
||||||
|
RadLV = getfit_inverse(np.log(Kval), undudict['fitpars_KLV'])
|
||||||
|
Rad45 = getfit_inverse(np.log(Kval), undudict['fitpars_K45'])
|
||||||
|
dRadLV = RadLV - RadLH
|
||||||
|
dRad45 = Rad45 - RadLH - dRadLV/2
|
||||||
|
#print(radial, phi_in_degree, amp1, amp2, amp3, RadLH, RadLV, Rad45)
|
||||||
|
if phi >= 0.0:
|
||||||
|
return RadLH + dRadLV * np.sin(0.5*phi)**2 + dRad45 * np.sin(phi)**2 + amp1 * np.sin(2*phi) + amp2 * np.sin(2.0*phi)**2 + amp3 * np.cos(6*phi)
|
||||||
|
else:
|
||||||
|
return RadLH + dRadLV * np.sin(0.5*phi)**2 + dRad45 * np.sin(phi)**2 + amp1 * np.sin(2*phi) + amp2 * np.sin(2.0*phi)**2 + amp3 * np.cos(8*phi)
|
||||||
|
|
||||||
|
|
||||||
|
def getfit_inverse(val, fitparam):
|
||||||
|
fit_func = np.poly1d(fitparam)
|
||||||
|
tau_init = 1.0
|
||||||
|
val = float(val)
|
||||||
|
return float(fsolve(val - fit_func, tau_init))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user