Пример #1
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)
    sim.methods[0].simulation._timestamp = None

    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
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]]
Пример #3
0
def test_scale():
    PS_0 = [sp.Scale(factor=10)]
    post_sim = sp.SignalProcessor(operations=PS_0)
    dataset = post_sim.apply_operations(
        dataset=sim.methods[0].simulation.copy())
    _, y0, y1, y2 = sim.methods[0].simulation.to_list()
    _, y0_, y1_, y2_ = dataset.to_list()
    # cast complex dataset
    assert np.allclose(y0_, y0 * 10), "Scaling failed"
    assert np.allclose(y1_, y1 * 10), "Scaling failed"
    assert np.allclose(y2_, y2 * 10), "Scaling failed"
Пример #4
0
def test_scale_class():
    # direct initialization
    a = sp.Scale(factor=200)

    assert a.factor == 200
    assert a.property_units == {}

    # class to dict with units
    dict_ = a.json()

    assert dict_ == {
        "function": "Scale",
        "factor": 200.0,
    }

    # read from dictionary
    b = sp.Scale.parse_dict_with_units(dict_)

    assert a == b
Пример #5
0
# %%
# **Guess Model Spectrum**

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

# Post Simulation Processing
# --------------------------
processor = sp.SignalProcessor(operations=[
    sp.IFFT(),
    sp.apodization.Exponential(FWHM="100 Hz"),
    sp.FFT(),
    sp.Scale(factor=200),
])
processed_dataset = processor.apply_operations(
    dataset=sim.methods[0].simulation).real

# Plot of the guess Spectrum
# --------------------------
plt.figure(figsize=(4.25, 3.0))
ax = plt.subplot(projection="csdm")
ax.plot(experiment, "k", linewidth=1, label="Experiment")
ax.plot(processed_dataset,
        "r",
        alpha=0.75,
        linewidth=1,
        label="guess spectrum")
ax.set_xlim(100, -100)
for sys in spin_systems:
    sys.transition_pathways = MAS.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])
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.Exponential(FWHM="0.3 kHz"),
    sp.FFT(),
    sp.Scale(factor=300),
    sp.baseline.ConstantOffset(offset=-2),
])
processed_dataset = processor.apply_operations(
    dataset=sim.methods[0].simulation).real

# %%
# **Step 5:** The plot of the dataset 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_dataset, linewidth=2, alpha=0.6, label="Guess Spectrum")
ax.set_xlim(150, -150)
plt.legend()
plt.grid()
plt.tight_layout()
Пример #7
0
# Simulation
# ----------
sim = Simulator(spin_systems=spin_systems, methods=[DAS])
sim.config.number_of_sidebands = 1  # no sidebands are required for this dataset.
sim.run()

# Post Simulation Processing
# --------------------------
processor = sp.SignalProcessor(operations=[
    # Gaussian convolution along both dimensions.
    sp.IFFT(dim_index=(0, 1)),
    sp.apodization.Gaussian(FWHM="0.15 kHz", dim_index=0),
    sp.apodization.Gaussian(FWHM="0.1 kHz", dim_index=1),
    sp.FFT(dim_index=(0, 1)),
    sp.Scale(factor=4e7),
])
processed_dataset = processor.apply_operations(
    dataset=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_dataset, colors="r", linestyles="--", **options)
ax.invert_xaxis()
ax.set_ylim(30, -30)
plt.grid()
plt.tight_layout()
plt.show()
Пример #8
0
# **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(dim_index=0),
        sp.apodization.Exponential(FWHM="50 Hz"),
        sp.IFFT(dim_index=0),
        sp.Scale(factor=212260),
    ]
)
processed_dataset = processor.apply_operations(dataset=sim.methods[0].simulation).real

# Plot of the guess Spectrum
# --------------------------
plt.figure(figsize=(8, 3.5))
ax = plt.subplot(projection="csdm")
ax.contour(mat_dataset, colors="k", **options)
ax.contour(processed_dataset, colors="r", linestyles="--", **options)
ax.set_xlim(180, 15)
plt.grid()
plt.tight_layout()
plt.show()
Пример #9
0
# %%
# **Guess Model Spectrum**

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

# Post Simulation Processing
# --------------------------
processor = sp.SignalProcessor(operations=[
    sp.IFFT(),
    sp.apodization.Gaussian(FWHM="3000 Hz"),
    sp.FFT(),
    sp.Scale(factor=4000),
])
processed_dataset = processor.apply_operations(
    dataset=sim.methods[0].simulation).real

# Plot of 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_dataset, linewidth=2, alpha=0.6, label="Guess Spectrum")
ax.set_xlim(200, -200)
plt.grid()
plt.legend()
plt.tight_layout()
plt.show()
Пример #10
0
# %%
# **Guess Model Spectrum**

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

# Post Simulation Processing
# --------------------------
processor = sp.SignalProcessor(operations=[
    sp.IFFT(),
    sp.apodization.Exponential(FWHM="60 Hz"),
    sp.FFT(),
    sp.Scale(factor=140),
])
processed_dataset = processor.apply_operations(
    dataset=sim.methods[0].simulation).real

# Plot of 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_dataset, linewidth=2, alpha=0.6, label="Guess Spectrum")
ax.set_xlim(600, -700)
plt.grid()
plt.legend()
plt.tight_layout()
plt.show()
Пример #11
0
# %%
# **Guess Spectrum**

# Simulation
# ----------
sim = Simulator(spin_systems=spin_systems, methods=[MAS])
sim.config.decompose_spectrum = "spin_system"
sim.run()

# Post Simulation Processing
# --------------------------
processor = sp.SignalProcessor(operations=[
    sp.IFFT(),
    sp.apodization.Gaussian(FWHM="300 Hz"),
    sp.FFT(),
    sp.Scale(factor=50),
])
processed_dataset = processor.apply_operations(
    dataset=sim.methods[0].simulation).real

# Plot of the guess Spectrum
# --------------------------
plt.figure(figsize=(8, 4))
ax = plt.subplot(projection="csdm")
ax.plot(experiment, color="black", linewidth=0.5, label="Experiment")
ax.plot(processed_dataset, linewidth=2, alpha=0.6)
ax.set_xlim(1200, -1200)
plt.grid()
plt.legend()
plt.tight_layout()
plt.show()
# Optimize the script by pre-setting the transition pathways for each spin system from
# the method.
for sys in spin_systems:
    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=[sp.Scale(factor=2000)])
processed_dataset = processor.apply_operations(
    dataset=sim.methods[0].simulation).real

# Plot of the guess Spectrum
# --------------------------
plt.figure(figsize=(4.25, 3.0))
ax = plt.subplot(projection="csdm")
ax.plot(pass_cross_section, color="k", linewidth=1, label="Experiment")
ax.plot(processed_dataset,
        color="r",
        alpha=0.75,
        linewidth=1,
        label="guess spectrum")
plt.grid()
ax.invert_xaxis()
# 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=[
    sp.IFFT(),
Пример #14
0
        "beta": "4.12 rad"
    },
}
CH = {
    "site_index": [0, 1],
    "isotropic_j": "10 Hz",
    "j_symmetric": {
        "zeta": "60 Hz",
        "eta": 0.4
    },
}
op_list = [
    sp.IFFT(dim_index=0),
    sp.apodization.Exponential(FWHM=100, dim_index=0, dv_index=0),
    sp.FFT(dim_index=0),
    sp.Scale(factor=10),
]


def compare_result(params, valuesdict_system, sim):
    valuesdict_proc = {
        "SP_0_operation_1_Exponential_FWHM": 100,
        "SP_0_operation_3_Scale_factor": 10,
    }
    assert params.valuesdict() == {
        **valuesdict_system,
        **valuesdict_proc,
    }, "Parameter creation failed"

    params = sf.make_LMFIT_params(sim)
    assert params.valuesdict(
Пример #15
0
# 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, 1)),
    sp.apodization.Gaussian(FWHM="5 kHz", dim_index=0),  # along dimension 0
    sp.apodization.Gaussian(FWHM="5 kHz", dim_index=1),  # along dimension 1
    sp.FFT(dim_index=(0, 1)),
    sp.Scale(factor=5e8),
])
processed_dataset = processor.apply_operations(
    dataset=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_dataset, colors="r", linestyles="--", **options)
ax.set_xlim(1000, -1000)
ax.set_ylim(1500, -1500)
plt.grid()
plt.tight_layout()
plt.show()
Пример #16
0
# %%
# **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(dim_index=0),
    sp.apodization.Gaussian(FWHM="100 Hz"),
    sp.IFFT(dim_index=0),
    sp.Scale(factor=1e7),
])
processed_dataset = processor.apply_operations(
    dataset=sim.methods[0].simulation).real

# Plot of the guess Spectrum
# --------------------------
plt.figure(figsize=(8, 3.5))
ax = plt.subplot(projection="csdm")
ax.contour(qmat_dataset.T, colors="k", **options)
ax.contour(processed_dataset.T, colors="r", linestyles="--", **options)
ax.set_xlim(200, -200)
ax.set_ylim(75, -120)
plt.grid()
plt.tight_layout()
plt.show()