Exemplo n.º 1
0
def test_2D_area():
    data = np.zeros((256, 128), dtype=float)
    data[128, 64] = 1.0
    csdm_obj = cp.as_csdm(data)

    # test00
    PS = [
        sp.IFFT(dim_index=(0, 1)),
        sp.apodization.Gaussian(FWHM="35", dim_index=0),
        sp.apodization.Gaussian(FWHM="55", dim_index=1),
        sp.FFT(dim_index=(0, 1)),
    ]

    post_sim = sp.SignalProcessor(operations=PS)
    data_new = post_sim.apply_operations(data=csdm_obj.copy())
    _, __, y1 = data_new.to_list()

    assert np.allclose(y1.sum(), data.sum())

    # test01
    PS = [
        sp.IFFT(dim_index=(0, 1)),
        sp.apodization.Gaussian(FWHM="35", dim_index=0),
        sp.apodization.Exponential(FWHM="55", dim_index=1),
        sp.FFT(dim_index=(0, 1)),
    ]

    post_sim = sp.SignalProcessor(operations=PS)
    data_new = post_sim.apply_operations(data=csdm_obj.copy())
    _, __, y1 = data_new.to_list()

    assert np.allclose(y1.sum(), data.sum())
def setup_sim_and_processor():
    site = Site(isotope="1H", shielding_symmetric={"zeta": -100, "eta": 0.3})
    spin_sys = SpinSystem(sites=[site, site], abundance=45)

    method = BlochDecaySpectrum(channels=["1H"])
    sim = Simulator(spin_systems=[spin_sys, spin_sys],
                    methods=[method, method])

    sim.run(method_index=0)

    processor = sp.SignalProcessor(operations=[
        sp.IFFT(),
        sp.apodization.Exponential(FWHM="2500 Hz"),
        sp.FFT(),
        sp.Scale(factor=20),
    ])
    processors = [processor] * 2

    application = {
        "com.github.DeepanshS.mrsimulator": {
            "foo": "This is some metadata"
        },
        "com.github.DeepanshS.mrsimulator-app": {
            "params": "The JSON string of params"
        },
    }

    return sim, processors, application
Exemplo n.º 3
0
def test_serialization_and_parse():
    processor = sp.SignalProcessor(operations=[
        sp.IFFT(dim_index=1),
        sp.affine.Shear(factor="-1 K/s", dim_index=1, parallel=0),
        sp.FFT(dim_index=1),
    ])
    serialize = processor.json()

    expected = {
        "operations": [
            {
                "dim_index": 1,
                "function": "IFFT"
            },
            {
                "dim_index": 1,
                "factor": "-1.0 K / s",
                "function": "affine",
                "parallel": 0,
                "type": "Shear",
            },
            {
                "dim_index": 1,
                "function": "FFT"
            },
        ],
    }

    assert serialize == expected

    recovered = sp.SignalProcessor.parse_dict_with_units(serialize)
    assert recovered == processor
Exemplo n.º 4
0
def test_Gaussian():
    FWHM = 200 * 2.354820045030949
    PS_2 = [
        sp.IFFT(dim_index=0),
        sp.apodization.Gaussian(FWHM=f"{FWHM} Hz",
                                dim_index=0,
                                dv_index=[0, 1]),
        sp.FFT(dim_index=0),
    ]

    PS_3 = [
        sp.IFFT(dim_index=0),
        sp.apodization.Gaussian(FWHM=f"{FWHM} Hz", dim_index=0, dv_index=None),
        sp.FFT(dim_index=0),
    ]

    post_sim = sp.SignalProcessor(operations=PS_2)
    data = post_sim.apply_operations(data=sim.methods[0].simulation.copy())
    _, y0, y1, _ = data.to_list()

    sigma = 200
    test = (1 /
            (sigma * np.sqrt(2 * np.pi))) * np.exp(-((freqHz / sigma)**2) / 2)

    assert np.allclose(y0, y1), "Gaussian apodization on two dv are not equal."

    assert np.allclose(test / test.sum(), y0 / y0.sum(),
                       atol=1e-04), "Gaussian apodization amplitude failed"

    # test None for dv_index
    post_sim = sp.SignalProcessor(operations=PS_3)
    data = post_sim.apply_operations(data=sim.methods[0].simulation.copy())
    _, y0, y1, y2 = data.to_list()

    assert np.allclose(
        y0, y1), "Gaussian apodization on dv at 0 and 1 are unequal."
    assert np.allclose(
        y0, y2), "Gaussian apodization on dv at 0 and 2 are unequal."
    assert np.allclose(test / test.sum(), y0 / y0.sum(),
                       atol=1e-04), "Gaussian apodization amplitude failed"
Exemplo n.º 5
0
def test_shear_01():
    processor = sp.SignalProcessor(operations=[
        sp.IFFT(dim_index=1),
        af.Shear(factor="-1 K/s", dim_index=1, parallel=0),
        sp.FFT(dim_index=1),
    ])

    shear_data = processor.apply_operations(data=csdm_object)
    index = np.where(
        shear_data.dependent_variables[0].components[0] > 0.99999999)

    a = np.arange(40)
    assert np.allclose(index, [a, a])

    # complex_fft dim=0 to false
    csdm_object.dimensions[0].complex_fft = False
    csdm_object.dimensions[1].complex_fft = True
    shear_data = processor.apply_operations(data=csdm_object)
    index = np.where(
        shear_data.dependent_variables[0].components[0] > 0.99999999)

    a1 = np.arange(20)
    b1 = a1 + 20
    b = np.append(b1, a1)
    assert np.allclose(index, [a, b])

    # complex_fft dim=1 to false
    csdm_object.dimensions[0].complex_fft = True
    csdm_object.dimensions[1].complex_fft = False
    shear_data = processor.apply_operations(data=csdm_object)
    index = np.where(
        shear_data.dependent_variables[0].components[0] > 0.99999999)

    b = np.arange(40)
    b[1:] = a[::-1][:-1]
    assert np.allclose(index, [a, b])

    # both complex_fft set to false
    csdm_object.dimensions[0].complex_fft = False
    csdm_object.dimensions[1].complex_fft = False
    shear_data = processor.apply_operations(data=csdm_object)
    index = np.where(
        shear_data.dependent_variables[0].components[0] > 0.99999999)

    a1 = np.arange(21)[::-1]
    b1 = a1[1:-1] + 20
    b = np.append(a1, b1)
    assert np.allclose(index, [a, b])
def setup_signal_processor():
    op_list1 = [
        sp.IFFT(dim_index=0),
        sp.apodization.Exponential(FWHM=100),
        sp.apodization.Gaussian(FWHM=200),
        sp.FFT(dim_index=0),
        sp.Scale(factor=10),
        sp.baseline.ConstantOffset(offset=43.1),
        sp.Linear(amplitude=32.9, offset=13.4),
    ]
    op_list2 = [
        sp.Scale(factor=20),
        sp.baseline.ConstantOffset(offset=-43.1),
        sp.Linear(amplitude=1.2, offset=0.4),
    ]
    return [sp.SignalProcessor(operations=op) for op in [op_list1, op_list2]]
Exemplo n.º 7
0
def test_SkewedGaussian():
    # TODO: update this test for multiple skewes and using npp.convolve
    skew = 2
    FWHM = 200 * 2.354820045030949
    PS_2 = [
        sp.IFFT(dim_index=0),
        sp.apodization.SkewedGaussian(skew=skew,
                                      FWHM=f"{FWHM} Hz",
                                      dim_index=0,
                                      dv_index=[0, 1]),
        sp.FFT(dim_index=0),
    ]

    post_sim = sp.SignalProcessor(operations=PS_2)
    data = post_sim.apply_operations(data=sim.methods[0].simulation.copy())
    _, y0, y1, _ = data.to_list()

    assert np.allclose(y0, y1), "Gaussian apodization on two dv are not equal."
Exemplo n.º 8
0
def setup():
    site = Site(isotope="1H", shielding_symmetric={"zeta": -100, "eta": 0.3})
    spin_sys = SpinSystem(sites=[site, site], abundance=45)

    method = BlochDecaySpectrum(channels=["1H"])
    sim = Simulator(spin_systems=[spin_sys, spin_sys],
                    methods=[method, method])

    sim.run(method_index=0)

    processor = sp.SignalProcessor(operations=[
        sp.IFFT(),
        sp.apodization.Exponential(FWHM="2500 Hz"),
        sp.FFT(),
        sp.Scale(factor=20),
    ])
    processors = [processor] * 2

    return sim, processors
Exemplo n.º 9
0
def test_Lorentzian():
    PS_1 = [
        sp.IFFT(dim_index=0),
        sp.apodization.Exponential(FWHM="200 Hz", dim_index=0, dv_index=0),
        sp.FFT(dim_index=0),
    ]
    post_sim = sp.SignalProcessor(operations=PS_1)
    data = post_sim.apply_operations(data=sim.methods[0].simulation.copy())
    _, y0, y1, y2 = data.to_list()

    FWHM = 200
    test = (FWHM / 2) / (np.pi * (freqHz**2 + (FWHM / 2)**2))

    assert np.allclose(y1, y2)
    assert np.all(y0 != y1)
    assert np.allclose(test / test.sum(), y0 / y0.sum(),
                       atol=1e-04), "Lorentzian apodization amplitude failed"
    assert np.allclose(
        y1.sum(), y0.sum()), "Area not conserved after Lorentzian apodization"
def test_01():
    post_sim = sp.SignalProcessor()
    operations = [
        sp.IFFT(),
        sp.apodization.Gaussian(FWHM="12 K", dim_index=0, dv_index=0),
        sp.FFT(),
    ]

    post_sim.operations = operations

    with pytest.raises(ValueError, match="The data must be a CSDM object."):
        post_sim.apply_operations([])

    data = cp.as_csdm(np.arange(20))
    data.x[0] = cp.LinearDimension(count=20, increment="10 K")
    post_sim.apply_operations(data)

    # to dict with units
    dict_ = post_sim.json()
    assert dict_ == {
        "operations": [
            {
                "dim_index": 0,
                "function": "IFFT"
            },
            {
                "function": "apodization",
                "type": "Gaussian",
                "FWHM": "12.0 K",
                "dim_index": 0,
                "dv_index": 0,
            },
            {
                "dim_index": 0,
                "function": "FFT"
            },
        ],
    }

    # parse dict with units
    post_sim_2 = sp.SignalProcessor.parse_dict_with_units(dict_)

    assert post_sim.operations == post_sim_2.operations
Exemplo n.º 11
0
def test_Mask():
    one_mask = np.zeros(shape=len(freqHz))

    PS_5 = [
        sp.IFFT(dim_index=0),
        sp.apodization.Mask(mask=one_mask, dim_index=0, dv_index=[0, 1]),
        sp.FFT(dim_index=0),
    ]

    post_sim = sp.SignalProcessor(operations=PS_5)
    data = post_sim.apply_operations(data=sim.methods[0].simulation.copy())
    _, y0, y1, _ = data.to_list()

    _, test_y0, test_y1, _ = sim.methods[0].simulation.to_list()

    nonzero_y0 = np.count_nonzero(y0)
    nonzero_y1 = np.count_nonzero(y1)

    assert np.allclose(y0, y1), "Mask on two dv are not equal."

    assert np.allclose(nonzero_y0, nonzero_y1,
                       atol=1e-04), "Mask apodization amplitude failed"
def test_7():
    site = Site(isotope="23Na")
    sys = SpinSystem(sites=[site], abundance=50)
    sim = Simulator()
    sim.spin_systems = [sys, sys]
    sim.methods = [BlochDecayCTSpectrum(channels=["23Na"])]
    sim.methods[0].experiment = cp.as_csdm(np.zeros(1024))

    processor = sp.SignalProcessor(operations=[
        sp.IFFT(dim_index=0),
        sp.apodization.Gaussian(FWHM="0.2 kHz", dim_index=0),
        sp.FFT(dim_index=0),
    ])

    def test_array():
        sim.run()
        data = processor.apply_operations(sim.methods[0].simulation)

        data_sum = 0
        for dv in data.y:
            data_sum += dv.components[0]

        params = sf.make_LMFIT_params(sim, processor)
        a = sf.LMFIT_min_function(params, sim, processor)
        np.testing.assert_almost_equal(-a, data_sum, decimal=8)

        dat = sf.add_csdm_dvs(data.real)
        fits = sf.bestfit(sim, processor)
        assert sf.add_csdm_dvs(fits[0]) == dat

        res = sf.residuals(sim, processor)
        assert res[0] == -dat

    test_array()

    sim.config.decompose_spectrum = "spin_system"
    test_array()
Exemplo n.º 13
0
ax = plt.subplot(projection="csdm")
cb = ax.imshow(data / data.max(), aspect="auto", cmap="gist_ncar_r")
plt.colorbar(cb)
ax.invert_xaxis()
ax.invert_yaxis()
plt.tight_layout()
plt.show()

# %%
# Add post-simulation signal processing.
processor = sp.SignalProcessor(operations=[
    # Gaussian convolution along both dimensions.
    sp.IFFT(dim_index=(0, 1)),
    sp.apodization.Gaussian(FWHM="0.3 kHz", dim_index=0),
    sp.apodization.Gaussian(FWHM="0.15 kHz", dim_index=1),
    sp.FFT(dim_index=(0, 1)),
])
processed_data = processor.apply_operations(data=data)
processed_data /= processed_data.max()

# %%
# The plot of the simulation after signal processing.
plt.figure(figsize=(4.25, 3.0))
ax = plt.subplot(projection="csdm")
cb = ax.imshow(processed_data.real, cmap="gist_ncar_r", aspect="auto")
plt.colorbar(cb)
ax.invert_xaxis()
ax.invert_yaxis()
plt.tight_layout()
plt.show()
Exemplo n.º 14
0
    experiment=synthetic_experiment,  # add the measurement to the method.
)

# %%
# **Step 3:** Create the Simulator object, add the method and spin system objects, and
# run the simulation.
sim = Simulator(spin_systems=[spin_system], methods=[MAS])
sim.run()

# %%
# **Step 4:** Create a SignalProcessor class and apply post simulation processing.
processor = sp.SignalProcessor(
    operations=[
        sp.IFFT(),  # inverse FFT to convert frequency based spectrum to time domain.
        sp.apodization.Exponential(FWHM="200 Hz"),  # apodization of time domain signal.
        sp.FFT(),  # forward FFT to convert time domain signal to frequency spectrum.
        sp.Scale(factor=3),  # scale the frequency spectrum.
    ]
)
processed_data = processor.apply_operations(data=sim.methods[0].simulation).real

# %%
# **Step 5:** The plot the spectrum. We also plot the synthetic dataset for comparison.
plt.figure(figsize=(4.25, 3.0))
ax = plt.subplot(projection="csdm")
ax.plot(synthetic_experiment, "k", linewidth=1, label="Experiment")
ax.plot(processed_data, "r", alpha=0.75, linewidth=1, label="guess spectrum")
ax.set_xlim(50, -200)
plt.legend()
plt.grid()
plt.tight_layout()
Exemplo n.º 15
0
# %%
# **Step 4:** Simulate the spectrum.
sim.run()

# The plot of the simulation before signal processing.
ax = plt.subplot(projection="csdm")
ax.plot(sim.methods[0].simulation.real, color="black", linewidth=1)
ax.invert_xaxis()
plt.tight_layout()
plt.show()

# %%
# **Step 5:** Add post-simulation signal processing.
processor = sp.SignalProcessor(
    operations=[sp.IFFT(), apo.Exponential(
        FWHM="10 Hz"), sp.FFT()])
processed_data = processor.apply_operations(data=sim.methods[0].simulation)

# The plot of the simulation after signal processing.
ax = plt.subplot(projection="csdm")
ax.plot(processed_data.real, color="black", linewidth=1)
ax.invert_xaxis()
plt.tight_layout()
plt.show()

# %%
# .. [#f3] Moudrakovski, I., Lang, S., Patchkovskii, S., and Ripmeester, J. High field
#       :math:`^{33}\text{S}` solid state NMR and first-principles calculations in
#       potassium sulfates. J. Phys. Chem. A, 2010, **114**, *1*, 309–316.
#       `DOI: 10.1021/jp908206c <https://doi.org/10.1021/jp908206c>`_
Exemplo n.º 16
0
# %%
# **Step 5:** Simulate the spectrum.
sim.run()

# The plot of the simulation before signal processing.
ax = plt.subplot(projection="csdm")
ax.plot(sim.methods[0].simulation.real, color="black", linewidth=1)
ax.invert_xaxis()
plt.tight_layout()
plt.show()

# %%
# **Step 6:** Add post-simulation signal processing.
processor = sp.SignalProcessor(
    operations=[sp.IFFT(), apo.Exponential(
        FWHM="70 Hz"), sp.FFT()])
processed_data = processor.apply_operations(data=sim.methods[0].simulation)

# The plot of the simulation after signal processing.
ax = plt.subplot(projection="csdm")
ax.plot(processed_data.real, color="black", linewidth=1)
ax.invert_xaxis()
plt.tight_layout()
plt.show()

# %%
# .. [#f1] Hansen, M. R., Jakobsen, H. J., Skibsted, J., :math:`^{29}\text{Si}`
#       Chemical Shift Anisotropies in Calcium Silicates from High-Field
#       :math:`^{29}\text{Si}` MAS NMR Spectroscopy, Inorg. Chem. 2003,
#       **42**, *7*, 2368-2377.
#       `DOI: 10.1021/ic020647f <https://doi.org/10.1021/ic020647f>`_
Exemplo n.º 17
0
    sys.transition_pathways = PASS.get_transition_pathways(sys)

# %%
# **Guess Spectrum**

# Simulation
# ----------
sim = Simulator(spin_systems=spin_systems, methods=[PASS])
sim.run()

# Post Simulation Processing
# --------------------------
processor = sp.SignalProcessor(
    operations=[
        # Lorentzian convolution along the isotropic dimensions.
        sp.FFT(axis=0),
        sp.apodization.Exponential(FWHM="50 Hz"),
        sp.IFFT(axis=0),
        sp.Scale(factor=60),
    ]
)
processed_data = processor.apply_operations(data=sim.methods[0].simulation).real

# Plot of the guess Spectrum
# --------------------------
plt.figure(figsize=(8, 3.5))
ax = plt.subplot(projection="csdm")
ax.contour(mat_data, colors="k", **options)
ax.contour(processed_data, colors="r", linestyles="--", **options)
ax.set_xlim(180, 15)
plt.grid()
Exemplo n.º 18
0
# Run the simulation.
sim.run()

# Get the simulation data from the respective methods.
data_13C = sim.methods[
    0].simulation  # method at index 0 is 13C Bloch decay method.
data_15N = sim.methods[
    1].simulation  # method at index 1 is 15N Bloch decay method.

# %%
# Add post-simulation signal processing.
processor = sp.SignalProcessor(
    operations=[sp.IFFT(),
                sp.apodization.Exponential(FWHM="10 Hz"),
                sp.FFT()])
# apply post-simulation processing to data_13C
processed_data_13C = processor.apply_operations(data=data_13C).real

# apply post-simulation processing to data_15N
processed_data_15N = processor.apply_operations(data=data_15N).real

# %%
# The plot of the simulation after signal processing.
fig, ax = plt.subplots(1,
                       2,
                       subplot_kw={"projection": "csdm"},
                       sharey=True,
                       figsize=(9, 4))

ax[0].plot(processed_data_13C, color="black", linewidth=0.5)
Exemplo n.º 19
0
# %%
# **Step 5:** Simulate the spectrum.
sim.run()

# The plot of the simulation before signal processing.
plt.figure(figsize=(4.25, 3.0))
ax = plt.subplot(projection="csdm")
ax.plot(sim.methods[0].simulation.real, color="black", linewidth=1)
ax.invert_xaxis()
plt.tight_layout()
plt.show()

# %%
# **Step 6:** Add post-simulation signal processing.
processor = sp.SignalProcessor(
    operations=[sp.IFFT(), sp.apodization.Exponential(FWHM="70 Hz"), sp.FFT()]
)
processed_data = processor.apply_operations(data=sim.methods[0].simulation)

# The plot of the simulation after signal processing.
plt.figure(figsize=(4.25, 3.0))
ax = plt.subplot(projection="csdm")
ax.plot(processed_data.real, color="black", linewidth=1)
ax.invert_xaxis()
plt.tight_layout()
plt.show()

# %%
# .. [#f1] Hansen, M. R., Jakobsen, H. J., Skibsted, J., :math:`^{29}\text{Si}`
#       Chemical Shift Anisotropies in Calcium Silicates from High-Field
#       :math:`^{29}\text{Si}` MAS NMR Spectroscopy, Inorg. Chem. 2003,
# %%
# **Guess Spectrum**

# Simulation
# ----------
sim = Simulator(spin_systems=spin_systems, methods=[shifting_d])
sim.config.integration_volume = "hemisphere"
sim.run()

# Post Simulation Processing
# --------------------------
processor = sp.SignalProcessor(operations=[
    # Gaussian convolution along both dimensions.
    sp.IFFT(dim_index=0),
    sp.apodization.Gaussian(FWHM="10 kHz", dim_index=0),  # along dimension 0
    sp.FFT(dim_index=0),
    sp.Scale(factor=5e8),
])
processed_data = processor.apply_operations(
    data=sim.methods[0].simulation).real

# Plot of the guess Spectrum
# --------------------------
plt.figure(figsize=(4.25, 3.0))
ax = plt.subplot(projection="csdm")
ax.contour(experiment, colors="k", **options)
ax.contour(processed_data, colors="r", linestyles="--", **options)
ax.set_xlim(2500, -1500)
ax.set_ylim(2000, -2200)
plt.grid()
plt.tight_layout()
# ----------
# Add the spin systems and the three methods to the simulator object.
sim = Simulator(spin_systems=spin_systems, methods=[MAS1, MAS2, MAS3])
sim.config.decompose_spectrum = "spin_system"
sim.run()

# Post Simulation Processing
# --------------------------
# Add signal processing to simulation dataset from the three methods.

# Processor for dataset 1
processor1 = sp.SignalProcessor(operations=[
    sp.IFFT(),
    sp.apodization.Exponential(FWHM="20 Hz", dv_index=0),  # spin system 0
    sp.apodization.Exponential(FWHM="200 Hz", dv_index=1),  # spin system 1
    sp.FFT(),
    sp.Scale(factor=10),  # dataset is scaled independently using scale factor.
])

# Processor for dataset 2
processor2 = sp.SignalProcessor(operations=[
    sp.IFFT(),
    sp.apodization.Exponential(FWHM="30 Hz", dv_index=0),  # spin system 0
    sp.apodization.Exponential(FWHM="300 Hz", dv_index=1),  # spin system 1
    sp.FFT(),
    sp.Scale(
        factor=100),  # dataset is scaled independently using scale factor.
])

# Processor for dataset 3
processor3 = sp.SignalProcessor(operations=[
Exemplo n.º 22
0
def test_MQMAS():
    site = Site(
        isotope="87Rb",
        isotropic_chemical_shift=-9,
        shielding_symmetric={
            "zeta": 100,
            "eta": 0
        },
        quadrupolar={
            "Cq": 3.5e6,
            "eta": 0.36,
            "beta": 70 / 180 * np.pi
        },
    )
    spin_system = SpinSystem(sites=[site])

    method = Method2D(
        channels=["87Rb"],
        magnetic_flux_density=9.4,
        spectral_dimensions=[
            {
                "count": 128,
                "spectral_width": 20000,
                "events": [{
                    "transition_query": [{
                        "P": [-3],
                        "D": [0]
                    }]
                }],
            },
            {
                "count": 128,
                "spectral_width": 20000,
                "events": [{
                    "transition_query": [{
                        "P": [-1],
                        "D": [0]
                    }]
                }],
            },
        ],
    )

    sim = Simulator()
    sim.spin_systems = [spin_system]
    sim.methods = [method]
    sim.config.integration_volume = "hemisphere"
    sim.run()

    # process
    k = 21 / 27  # shear factor
    processor = sp.SignalProcessor(operations=[
        sp.IFFT(dim_index=1),
        aft.Shear(factor=-k, dim_index=1, parallel=0),
        aft.Scale(factor=1 + k, dim_index=1),
        sp.FFT(dim_index=1),
    ])
    processed_data = processor.apply_operations(
        data=sim.methods[0].simulation).real

    # Since there is a single site, after the shear and scaling transformations, there
    # should be a single perak along the isotropic dimension at index 70.
    # The isotropic coordinate of this peak is given by
    # w_iso = (17.8)*iso_shift + 1e6/8 * (vq/v0)^2 * (eta^2 / 3 + 1)
    # ref: D. Massiot et al. / Solid State Nuclear Magnetic Resonance 6 (1996) 73-83
    iso_slice = processed_data[40, :]
    assert np.argmax(iso_slice.y[0].components[0]) == 70

    # calculate the isotropic coordinate
    spin = method.channels[0].spin
    w0 = method.channels[0].gyromagnetic_ratio * 9.4 * 1e6
    wq = 3 * 3.5e6 / (2 * spin * (2 * spin - 1))
    w_iso = -9 * 17 / 8 + 1e6 / 8 * (wq / w0)**2 * ((0.36**2) / 3 + 1)

    # the coordinate from spectrum
    w_iso_spectrum = processed_data.x[1].coordinates[70].value
    np.testing.assert_almost_equal(w_iso, w_iso_spectrum, decimal=2)

    # The projection onto the  MAS dimension should be the 1D block decay central
    # transition spectrum
    mas_slice = processed_data.sum(axis=1).y[0].components[0]

    # MAS spectrum
    method = BlochDecayCTSpectrum(
        channels=["87Rb"],
        magnetic_flux_density=9.4,
        rotor_frequency=1e9,
        spectral_dimensions=[{
            "count": 128,
            "spectral_width": 20000
        }],
    )

    sim = Simulator()
    sim.spin_systems = [spin_system]
    sim.methods = [method]
    sim.config.integration_volume = "hemisphere"
    sim.run()

    data = sim.methods[0].simulation.y[0].components[0]
    np.testing.assert_almost_equal(data / data.max(),
                                   mas_slice / mas_slice.max(),
                                   decimal=2,
                                   err_msg="not equal")
Exemplo n.º 23
0
for sys in spin_systems:
    sys.transition_pathways = MAS_CT.get_transition_pathways(sys)

# %%
# **Step 3:** Create the Simulator object and add the method and spin system objects.
sim = Simulator(spin_systems=spin_systems, methods=[MAS_CT])
sim.config.decompose_spectrum = "spin_system"
sim.run()

# %%
# **Step 4:** Create a SignalProcessor class object and apply the post-simulation
# signal processing operations.
processor = sp.SignalProcessor(operations=[
    sp.IFFT(),
    sp.apodization.Gaussian(FWHM="100 Hz"),
    sp.FFT(),
    sp.Scale(factor=200.0),
])
processed_data = processor.apply_operations(
    data=sim.methods[0].simulation).real

# %%
# **Step 5:** The plot of the data and the guess spectrum.
plt.figure(figsize=(4.25, 3.0))
ax = plt.subplot(projection="csdm")
ax.plot(experiment, color="black", linewidth=0.5, label="Experiment")
ax.plot(processed_data, linewidth=2, alpha=0.6)
ax.set_xlim(100, -50)
plt.legend()
plt.grid()
plt.tight_layout()
Exemplo n.º 24
0
# Add the methods to the Simulator object and run the simulation

# Add the methods.
sim.methods = [method_13C, method_15N]

# Run the simulation.
sim.run()

# Get the simulation data from the respective methods.
data_13C = sim.methods[0].simulation  # method at index 0 is 13C Bloch decay method.
data_15N = sim.methods[1].simulation  # method at index 1 is 15N Bloch decay method.

# %%
# Add post-simulation signal processing.
processor = sp.SignalProcessor(
    operations=[sp.IFFT(), apo.Exponential(FWHM="10 Hz"), sp.FFT()]
)
# apply post-simulation processing to data_13C
processed_data_13C = processor.apply_operations(data=data_13C).real

# apply post-simulation processing to data_15N
processed_data_15N = processor.apply_operations(data=data_15N).real

# %%
# The plot of the simulation after signal processing.
fig, ax = plt.subplots(1, 2, subplot_kw={"projection": "csdm"}, sharey=True)

ax[0].plot(processed_data_13C, color="black", linewidth=0.5)
ax[0].invert_xaxis()

ax[1].plot(processed_data_15N, color="black", linewidth=0.5)