Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Affine scale factor is included in fitting parameters #314

Open
mccarthy677 opened this issue Jan 24, 2024 · 0 comments
Open

Affine scale factor is included in fitting parameters #314

mccarthy677 opened this issue Jan 24, 2024 · 0 comments

Comments

@mccarthy677
Copy link
Collaborator

I built a signal processor that includes an affine shear and scale transformation. When I use make_LMFIT_params, the affine scale factor is included in the fit parameters, but this parameter is not one that should be fitted for. Can we change the default behavior to exclude this parameter from the list, or change it to not vary by default?

To Reproduce

Sample code:

from mrsimulator import Site, SpinSystem, Simulator
from mrsimulator import Method, SpectralDimension
from mrsimulator.method import SpectralEvent
from mrsimulator import signal_processor as sp
import numpy as np

mqmas = Method(
    channels=["87Rb"],
    magnetic_flux_density = 9.373412440496665, #in T
    rotor_frequency= np.inf, # in Hz
    spectral_dimensions= [
        SpectralDimension(
            count = 1079,
            spectral_width = 12500,
            reference_offset = -12931.260000005364,
            origin_offset = 131077732.42,
            label="3Q",
            events=[
                SpectralEvent(transition_queries = [{"ch1": {"P": [-3], "D":[0]}}])
            ]
        ),
        SpectralDimension(
            count = 1024,
            spectral_width = 25000,
            reference_offset = -4310.420000001788,
            origin_offset = 131077732.42,
            label="1Q",
            events=[
                SpectralEvent(transition_queries = [{"ch1":{"P":[-1], "D":[0]}}])
            ]
        )
    ],
)
site1 = Site(
    isotope="87Rb",
    isotropic_chemical_shift=-31,  # ppm
    quadrupolar={"Cq": 1.7e6, "eta": 0.58},  # Cq in Hz
)
sites = [site1]
RbNO3_spin_systems = [SpinSystem(sites=[s]) for s in sites]
sim = Simulator(spin_systems=RbNO3_spin_systems, methods=[mqmas])

processor = sp.SignalProcessor(operations=[
    # broadening and scaling
    sp.IFFT(dim_index=(0, 1)),
    sp.apodization.Gaussian(FWHM="0.05 kHz", dim_index=0),
    sp.apodization.Gaussian(FWHM="0.1 kHz", dim_index=1),
    sp.FFT(dim_index=(0, 1)),
    sp.Scale(factor=5e8),
    # first shear
    sp.IFFT(dim_index=1),
    sp.affine.Shear(factor='-21/27', dim_index=0, parallel=1), #applying to zero
    sp.IFFT(dim_index=0),  
    sp.affine.Scale(factor=48/27, dim_index=1),
    sp.FFT(dim_index=0),
    sp.FFT(dim_index=1),
    ]
)

from mrsimulator.utils import spectral_fitting as sf

fit_parameters = sf.make_LMFIT_params(sim, processor)
print(fit_parameters.pretty_print(columns=["value", "min", "max", "vary", "expr"]))

Desktop (please complete the following information):

  • OS: Windows
  • Python version: 3.9.18
  • mrsimulator version: 0.8.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant