def test_correctionFactor_dimensionality(): # We need some lines L1 = LorentzianLine(name="Lorentzian1", domain=(-16.0, 16.0), x0=-1.0, width=0.4, c=0.0, weight=1) # Contruct a SqE model sqe = SqE(lines=(L1, ), lam=6.0, dlam=0.12, lSD=3.43, T=20) # Instantiate a detector efficiency corr factor decf = DetectorEfficiencyCorrectionFactor(sqe) # Instantiate a energy cutoff corr factor eccf = EnergyCutOffCorrectionFactor(sqe) ne = 15 nlam = 5 lam = 6.0 * linspace(1 - 0.12 * 1.01, 1 + 0.12 * 1.01, nlam) lams = tile(lam, (ne, 1)) a = -0.99999 * energy_from_lambda(lam) b = 15.0 + a es = linspace(a, b, ne) print(lams) print(es) print(decf.calc(es, lams)) print(eccf.calc(es, lams))
def test_EnergyCutOffCorrectionFactor_vs_arg(): # We need some lines L1 = LorentzianLine(name="Lorentzian1", domain=(-16.0, 16.0), x0=-1.0, width=0.4, c=0.0, weight=1) # Contruct a SqE model sqe = SqE(lines=(L1, ), lam=6.0, dlam=0.12, lSD=3.43, T=20) # Instantiate a energy cutoff corr factor eccf = EnergyCutOffCorrectionFactor(sqe) ne = 15000 nlam = 20 lam = 6.0 * linspace(1 - 0.12 * 1.01, 1 + 0.12 * 1.01, nlam) lams = tile(lam, (ne, 1)) a = -0.99999 * energy_from_lambda(lam) b = 15.0 + a es = linspace(a, b, ne) test_eccf_vals = arg.CutFac_Eint(arg.lorentzian, -1.0, 0.4, 15000, 20, 6.0, 0.12, 1, 0.0, 1.0, 20, 0.5, 0.00001, 350.) eccf_vals = eccf.correction(es, lams) # print(test_eccf_vals.shape) print(test_eccf_vals) # print(eccf_vals.shape) print(eccf_vals)
def test_export_load(): ### Creating a SqE model for transformation # We need some lines L1 = LorentzianLine("Lorentzian1", (-5.0, 5.0), x0=0.0, width=0.00005, c=0.0, weight=0.1) L2 = F_ILine("FI1", (-energy_from_lambda(6.0), 15), x0=-0.01, width=0.008, A=350.0, q=0.02, kappa=0.01, c=0.0, weight=0.9) # Contruct a SqE model sqe = SqE(lines=(L1, L2), lam=6.0, dlam=0.12, lSD=3.43, T=628) # Add the detector efficiency correction decf = DetectorEfficiencyCorrectionFactor(sqe, ne=500, nlam=20) # Add the energycutoff correction eccf = EnergyCutOffCorrectionFactor(sqe, ne=500, nlam=20) ### Instantiate a transformer sqt = SqtTransformer(sqe, corrections=(decf, eccf), nlam=20, ne=500, lSD=3.43, integ_mode="adaptive") ### Export sqt_dict = sqt.export_to_dict() pprint(sqt_dict["corrections"]) sqt.export_to_jsonfile( f"{testdir}/resources/test_transformer_export_load_file.json") print("", "SqE's of the: ", f"- sqe: {sqe}", f"- decf: {decf.sqe}", f"- eccf: {eccf.sqe}", f"- sqt: {sqt.sqemodel}", sep="\n") ### Loading sqt_from_dict = sqt.load_from_dict(**sqt_dict) print("", "Loading successful: ", sqt, sqt_from_dict, sep='\n') sqt_from_file = sqt.load_from_jsonfile( f"{testdir}/resources/test_transformer_export_load_file.json") print("Loading successful: ", sqt, sqt_from_file, sep='\n') print("", "SqE's of the: ", f"- sqe: {sqe}", f"- decf: {sqt_from_dict.corrections[0].sqe}", f"- eccf: {sqt_from_dict.corrections[1].sqe}", f"- sqt: {sqt_from_dict.sqemodel}", sep="\n") print("\n\nThis is the sqt loaded from dict") pprint(sqt_from_file.export_to_dict())
def test_update_params(): ### Creating a SqE model for transformation # We need some lines L1 = LorentzianLine("Lorentzian1", (-5.0, 5.0), x0=0.0, width=0.4, c=0.0, weight=2) L2 = LorentzianLine(name="Lorentzian2", domain=(-5.0, 5.0), x0=-1.0, width=0.4, c=0.0, weight=1) L3 = F_ILine("FI1", (-energy_from_lambda(6.0), 15), x0=-0.1, width=0.008, A=350.0, q=0.02, kappa=0.01, c=0.0, weight=1) # Contruct a SqE model sqe = SqE(lines=(L1, L2, L3), lam=6.0, dlam=0.12, lSD=3.43, T=20) # Add the detector efficiency correction decf = DetectorEfficiencyCorrectionFactor(sqe, ne=10000, nlam=20) # Add the energycutoff correction eccf = EnergyCutOffCorrectionFactor(sqe, ne=10000, nlam=20) ### Instantiate a transformer sqt = SqtTransformer(sqe, corrections=(decf, eccf), nlam=20, ne=10000, lSD=3.43) print("\n\nBefore update:") pprint(sqt.export_to_dict()) tdict = dict(T=30, lam=8.0, x0_Lorentzian2=-0.5, width_Lorentzian2=0.025, weight_Lorentzian1=5, nlam=55, kappa_FI1=1.0, some_wired_param=True) sqt.update_params(**tdict) print("\n\nAfter update:") pprint(sqt.export_to_dict())
def test_EnergyCutoffCorrectionFactor(): # We need some lines L1 = LorentzianLine("Lorentzian1", (-5.0, 5.0), x0=0.0, width=0.4, c=0.0, weight=2) L2 = LorentzianLine(name="Lorentzian2", domain=(-5.0, 5.0), x0=-1.0, width=0.4, c=0.02, weight=1) # Contruct a SqE model sqe = SqE(lines=(L1, L2), lam=6.0, dlam=0.12, lSD=3.43, T=20) new_domain = (-1 * energy_from_lambda(6.0), UPPER_INTEGRATION_LIMIT) sqe.update_domain(new_domain) # init energycutoff eccf = EnergyCutOffCorrectionFactor(sqe, ne=10000, nlam=20) ne = 10000 nlam = 5 lam = 6.0 * linspace(1 - 0.12 * 1.01, 1 + 0.12 * 1.01, nlam) lams = tile(lam, (ne, 1)) a = -0.99999 * energy_from_lambda(lam) b = 15.0 + a es = linspace(a, b, ne) ### Calculate the trapz integral over the S(q,E) # Only over domain (interval length: 15 meV) I_over_dom_only = trapz(sqe(es[:, 2]), es[:, 2]) print("Trapz integration over the domain.") print(f"Interval {a[2]:.4f} - {b[2]:.4f} -> length {b[2]-a[2]:.4f} meV.") print(f"#Steps = {ne}") print(f"Integral value: {I_over_dom_only:.4f}") # plt.plot(es[:,2], sqe(es[:,2]), label="Over domain only") # plt.show() # Beyond domain same array length es_same_length = linspace(-UPPER_INTEGRATION_LIMIT, UPPER_INTEGRATION_LIMIT, ne) I_beyond_dom_same_length = trapz(sqe(es_same_length), es_same_length) print("\nTrapz integration beyond the domain with varrying stepsize.") print( f"Interval {-UPPER_INTEGRATION_LIMIT} - {UPPER_INTEGRATION_LIMIT} -> length {30.0} meV." ) print(f"#Steps = {ne}") print(f"Integral value: {I_beyond_dom_same_length:.4f}") # plt.plot(es_same_length, sqe(es_same_length), ls="--", label="Beyond domain ne=10000") # plt.show() # Beyond domain same step size es_same_stepsize = arange(-UPPER_INTEGRATION_LIMIT, UPPER_INTEGRATION_LIMIT + 0.001, 15e-3) I_beyond_dom_same_stepsize = trapz(sqe(es_same_stepsize), es_same_stepsize) print("\nTrapz integration beyond the domain with varrying stepsize.") print( f"Interval {-UPPER_INTEGRATION_LIMIT} - {UPPER_INTEGRATION_LIMIT} -> length {30.0} meV." ) print(f"#Steps = {30.0 / 0.015}") print(f"Integral value: {I_beyond_dom_same_stepsize:.4f}")