Пример #1
0
def test_x_y_to_zeta_eta_distribution():
    inverse_dimension = [
        cp.Dimension(type="linear", count=4, increment="3 kHz"),
        cp.Dimension(type="linear", count=4, increment="3 kHz"),
    ]

    x = np.arange(4) * 3000
    y = np.arange(4) * 3000
    factor_ = 4 / np.pi
    zeta_ = []
    eta_ = []
    for y_ in y:
        for x_ in x:
            z = np.sqrt(x_**2 + y_**2)
            if x_ < y_:
                eta_.append(factor_ * np.arctan(x_ / y_))
                zeta_.append(z)
            elif x_ > y_:
                eta_.append(factor_ * np.arctan(y_ / x_))
                zeta_.append(-z)
            else:
                zeta_.append(z)
                eta_.append(1.0)

    zeta, eta = _x_y_to_zeta_eta_distribution(inverse_dimension,
                                              supersampling=1)

    assert np.allclose(zeta, np.asarray(zeta_))
    assert np.allclose(eta, np.asarray(eta_))
Пример #2
0
def test_dimensionality_of_lineshape_kernel():
    kernel_dimensions = [
        cp.Dimension(type="linear", count=96, increment="208.33 Hz", complex_fft=True)
    ]

    inverse_dimension = [
        cp.Dimension(type="linear", count=25, increment="370 Hz"),
        cp.Dimension(type="linear", count=25, increment="370 m"),
    ]

    error = r"with quantity name `\['frequency', 'dimensionless'\]` is required for "
    with pytest.raises(ValueError, match=f".*{error}.*"):
        ShieldingPALineshape(
            anisotropic_dimension=kernel_dimensions,
            inverse_dimension=inverse_dimension,
            channel="29Si",
            magnetic_flux_density="9.4 T",
            rotor_angle="90 deg",
            rotor_frequency="14 kHz",
            number_of_sidebands=1,
        )

    kernel_dimensions = cp.Dimension(
        type="linear", count=96, increment="208.33 ms", complex_fft=True
    )
    with pytest.raises(ValueError, match=f".*{error}.*"):
        ShieldingPALineshape(
            anisotropic_dimension=kernel_dimensions,
            inverse_dimension=inverse_dimension,
            channel="29Si",
            magnetic_flux_density="9.4 T",
            rotor_angle="90 deg",
            rotor_frequency="14 kHz",
            number_of_sidebands=1,
        )
 def to_csdm_dimension(self) -> cp.Dimension:
     """Return the spectral dimension as a CSDM dimension object."""
     increment = self.spectral_width / self.count
     label = "" if self.label is None else self.label
     description = "" if self.description is None else self.description
     dim = cp.Dimension(
         type="linear",
         count=self.count,
         increment=f"{increment} Hz",
         coordinates_offset=f"{self.reference_offset} Hz",
         label=label,
         description=description,
         complex_fft=True,
         reciprocal={"coordinates_offset": f"{-1/(2*increment)} s"},
     )
     if self.origin_offset is not None:
         dim.origin_offset = f"{self.origin_offset} Hz"
     return dim
Пример #4
0
import csdmpy as cp
import numpy as np

from mrinversion.kernel import T1
from mrinversion.kernel import T2

kernel_dimension = cp.Dimension(type="linear", count=5, increment="20 ms")

count = 10
coords = 10**((np.arange(count) / (count - 1)) * (2 - (-3)) - 3)
inverse_kernel_dimension = cp.as_dimension(array=coords, unit="s")
print(inverse_kernel_dimension)


def test_T2_kernel():
    T2_obj = T2(
        kernel_dimension=kernel_dimension,
        inverse_dimension=dict(
            count=count,
            minimum="1e-3 s",
            maximum="1e2 s",
            scale="log",
            label="log (T2 / s)",
        ),
    )
    K = T2_obj.kernel(supersampling=1)

    x = kernel_dimension.coordinates
    x_inverse = inverse_kernel_dimension.coordinates
    amp = np.exp(np.tensordot(-x, (1 / x_inverse), 0))
    # amp /= amp.max()
Пример #5
0
__author__ = "Deepansh J. Srivastava"
__email__ = "*****@*****.**"

# Creating a test CSDM object.
test_data = np.zeros((40, 40))
test_data[20, :] = 1
csdm_object = cp.CSDM(
    dependent_variables=[cp.as_dependent_variable(test_data)],
    dimensions=[
        cp.LinearDimension(count=40,
                           increment="1 s",
                           label="0",
                           complex_fft=True),
        cp.Dimension(type="linear",
                     count=40,
                     increment="1 K",
                     label="1",
                     complex_fft=True),
    ],
)

csdm_object2 = csdm_object.copy()


def test_shear_01():
    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),
    ])
Пример #6
0
def test_number_of_dimensions_for_lineshape_kernel():
    kernel_dimensions = [
        cp.Dimension(type="linear", count=96, increment="208.33 Hz", complex_fft=True)
    ]

    inverse_dimension = [
        cp.Dimension(type="linear", count=25, increment="370 Hz"),
        cp.Dimension(type="linear", count=25, increment="370 Hz"),
    ]

    error = r"Exactly 2 inverse dimension\(s\) is/are required for the"
    with pytest.raises(ValueError, match=f".*{error}.*"):
        ShieldingPALineshape(
            anisotropic_dimension=kernel_dimensions,
            inverse_dimension=inverse_dimension[0],
            channel="29Si",
            magnetic_flux_density="9.4 T",
            rotor_angle="90 deg",
            rotor_frequency="14 kHz",
            number_of_sidebands=1,
        )

    with pytest.raises(ValueError, match=f".*{error}.*"):
        ShieldingPALineshape(
            anisotropic_dimension=kernel_dimensions,
            inverse_dimension=[inverse_dimension[0]],
            channel="29Si",
            magnetic_flux_density="9.4 T",
            rotor_angle="90 deg",
            rotor_frequency="14 kHz",
            number_of_sidebands=1,
        )

    error = r"Exactly 1 direct dimension\(s\) is/are required for the"
    with pytest.raises(ValueError, match=f".*{error}.*"):
        ShieldingPALineshape(
            anisotropic_dimension=inverse_dimension,
            inverse_dimension=inverse_dimension,
            channel="29Si",
            magnetic_flux_density="9.4 T",
            rotor_angle="90 deg",
            rotor_frequency="14 kHz",
            number_of_sidebands=1,
        )

    kernel_dimension__ = {}
    error = r"The value of the `kernel_dimension` attribute must be one of "
    with pytest.raises(ValueError, match=f".*{error}.*"):
        ShieldingPALineshape(
            anisotropic_dimension=kernel_dimension__,
            inverse_dimension=inverse_dimension,
            channel="29Si",
            magnetic_flux_density="9.4 T",
            rotor_angle="90 deg",
            rotor_frequency="14 kHz",
            number_of_sidebands=1,
        )

    inverse_dimension = ["", ""]
    error = "The element at index 0 of the `inverse_dimension` list must be an"
    with pytest.raises(ValueError, match=f".*{error}.*"):
        ShieldingPALineshape(
            anisotropic_dimension=kernel_dimensions,
            inverse_dimension=inverse_dimension,
            channel="29Si",
            magnetic_flux_density="9.4 T",
            rotor_angle="90 deg",
            rotor_frequency="14 kHz",
            number_of_sidebands=1,
        )

    inverse_kernel_dimension__ = [
        {"type": "linear", "count": 10, "increment": "1 Hz"},
        "string",
    ]
    error = "The element at index 0 of the `inverse_dimension` list must be an"
    with pytest.raises(ValueError, match=f".*{error}.*"):
        ShieldingPALineshape(
            anisotropic_dimension=kernel_dimensions,
            inverse_dimension=inverse_kernel_dimension__,
            channel="29Si",
            magnetic_flux_density="9.4 T",
            rotor_angle="90 deg",
            rotor_frequency="14 kHz",
            number_of_sidebands=1,
        )
Пример #7
0
import csdmpy as cp
import numpy as np
from mrsimulator import Simulator
from mrsimulator import Site
from mrsimulator import SpinSystem
from mrsimulator.methods import BlochDecaySpectrum

from mrinversion.kernel.nmr import MAF
from mrinversion.kernel.nmr import ShieldingPALineshape
from mrinversion.kernel.nmr import SpinningSidebands
from mrinversion.linear_model import TSVDCompression

anisotropic_dimension_Hz_complex_fft = [
    cp.Dimension(type="linear",
                 count=96,
                 increment="208.33 Hz",
                 complex_fft=True)
]

anisotropic_dimension_Hz = [
    cp.Dimension(type="linear",
                 count=96,
                 increment="208.33 Hz",
                 coordinates_offset="-9999.84 Hz")
]
anisotropic_dimension_ppm_complex_fft = cp.Dimension(
    type="linear",
    count=96,
    increment="2.618010581236476 ppm",
    complex_fft=True)