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_adaptive_vs_linear():
    ### Instantiate a transformer
    sqtadapt = SqtTransformer.load_from_dict(**STANDARD_SQT.export_to_dict())
    sqtlinear = SqtTransformer.load_from_dict(**STANDARD_SQT.export_to_dict())
    sqtlinear.update_params(ne=50000, integ_mode="linear")

    ### Values for transformation
    taus = logspace(-4, 1, 81)
    freqs = MIEZE_DeltaFreq_from_time(taus * 1.0e-9, 3.43, 6.0)

    ### perform transformation
    from time import time
    startt = time()
    adaptvals = array([sqtadapt(freq) for freq in freqs])
    intermedt = time()
    linearvals = array([sqtlinear(freq) for freq in freqs])
    stopt = time()

    print(f"Adaptive integration took: {intermedt - startt:.1f}")
    print(f"Linear integration took  : {stopt - intermedt:.1f}")