From e90512b9d542022977b9dff0334522302e5bbe6d Mon Sep 17 00:00:00 2001 From: kittel_c Date: Tue, 25 Oct 2022 10:21:50 +0200 Subject: [PATCH] anti-parallel model updated --- phases/full_polarization.py | 43 +++++++++++------- phases/models/antiparallel_model.py | 70 +++++++++++++++++++---------- 2 files changed, 74 insertions(+), 39 deletions(-) diff --git a/phases/full_polarization.py b/phases/full_polarization.py index c90c12b..16dbe5d 100644 --- a/phases/full_polarization.py +++ b/phases/full_polarization.py @@ -10,8 +10,16 @@ from models.antiparallel_model import antiparallel2gap from time import sleep -UND_PERIOD = 38.0 -REF_MAG_ARRAY = 'TL' +RADIAL_LIMIT = 5.1 +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): @@ -20,8 +28,8 @@ def check_phase(phase): def fix_phase(p): return ((p + 180) % 360) - 180 -def convert_phase_to_shift(phase): - ratio = UND_PERIOD / 360.0 +def convert_phase_to_shift(phase, und_period): + ratio = und_period / 360.0 return phase * ratio / 2 @@ -83,18 +91,20 @@ class UndPhase(Adjustable): def set_target_value(self, value): phase = value 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() if self.isparallel: radial = parallel2gap(k, phase, self.params) 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? # workaround for safety measure - if self.radial.get_current_value() <= 5.1: - self.radial.set_target_value(5.1).wait() + if self.radial.get_current_value() <= RADIAL_LIMIT: + self.radial.set_target_value(RADIAL_LIMIT).wait() self.shift.set_target_value(shift).wait() self.radial.set_target_value(radial).wait() @@ -228,12 +238,13 @@ if __name__ == "__main__": print(__file__) print(dirname(__file__)) basedir = dirname(__file__) - #phase = 123 - phase = 80 + if basedir: + basedir += '/' + phase = SETPHASE check_phase(phase) - und_first = 10 - und_last = 22 - und_range = [*range(und_first, und_last+1, 1)] + und_first = UNDU_FIRST + und_last = UNDU_LAST + und_range = list(range(und_first, und_last+1, 1)) if 14 in und_range: und_range.remove(14) basename1 = 'SATUN' @@ -241,19 +252,19 @@ if __name__ == "__main__": print(undus) # 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(type(params1)) print(params1.keys()) # 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(type(params2)) print(params2.keys()) # 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'] measdata = alldata['measdata'] print('\n') diff --git a/phases/models/antiparallel_model.py b/phases/models/antiparallel_model.py index 5d25e14..c2903cd 100644 --- a/phases/models/antiparallel_model.py +++ b/phases/models/antiparallel_model.py @@ -26,30 +26,54 @@ def K2gap(Kval, fitparam): ## 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 fullpol2Kfit_apm(shiftlist, amp1, amp2, amp3, KLH, dKLV, dK45): -# 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): -# 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) +def antiparallel_rad2k_fit(radial, phi_in_degree, undudict): + phi = math.radians(phi_in_degree) + amp1 = getfit(radial, undudict['fitpars_amp1']) + amp2 = getfit(radial, undudict['fitpars_amp2']) + amp3 = getfit(radial, undudict['fitpars_amp3']) + 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)) + +