-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
For testing the magnetic calculations it would be useful to have both the dataset and the model that describes it.
Here's an attempt to model the S50 2D magnetic cross sections using sasmodels with bumps. The fit is not particularly good. See discussion on the sasview magnetic widget ticket here
NB: tested with bumps/bumps#324
from bumps.names import FitProblem, FreeVariables
from sasdata import data_path
from sasmodels.bumps_model import Experiment, Model
from sasmodels.core import load_model
from sasmodels.data import load_data
root = data_path / "magnetic_data"
datasets = dict(
up = load_data(root / 'S50_I+_2D.dat'),
down = load_data(root / 'S50_I-_2D.dat'),
unpolarized = load_data(root / 'S50_unpol_2D.dat'),
)
kernel = load_model("core_shell_sphere")
model = Model(
kernel,
scale = 0.0014, # volume fraction = 0.14%
background = 0.025, # near the minimum seen in the data
radius=40,
thickness=6,
sld_core = 7.19,
sld_shell = 7.19, # [email protected] g/cm³
sld_solvent = 5.66, # D8-toluene [email protected] g/cm³
up_frac_i = 0.11, # polarization = 89%, flipping ratio = 99%
up_frac_f = 0.5, # half polarization
up_theta = 0, # horizontal field of 1.5 T
up_phi = 0, # no out of plane field
sld_core_M0 = 1.1, # should match ~ 1.1 shown in fig 3b
sld_core_mtheta = 0, # X => -35° # should match the applied field direction ??
sld_core_mphi = 0, # no out-of-plane magentization
sld_shell_M0 = 0,
sld_solvent_M0 = 0, # non-magnetic shell and solvent
)
# SET THE FITTING PARAMETERS
#model.scale.range(0.0, 1.0)
model.radius.range(38, 42)
model.thickness.range(4, 8)
model.sld_core_mtheta.range(-90, 90)
model.sld_core_M0.range(0.0, 5.0)
free = FreeVariables(
names=[name for name, data in datasets.items()],
background=model.background,
scale=model.scale,
up_frac_i=model.up_frac_i,
)
free.background.range(0, 1)
free.scale.range(0, 2)
free.up_frac_i.values = [0.11, 0.89, 0.5]
models = [Experiment(data=data, model=model, name=name) for name, data in datasets.items()]
problem = FitProblem(models, freevars=free)
if __name__ == "__main__":
from bumps.webview.server.api import params_to_list
pars = problem.model_parameters()
avail = params_to_list(pars, freevars=problem.freevars)
print("=== Model parameters ===")
print(", ".join(p["name"] for p in avail))
#problem.show()
print("=== Fitting parameters ===")
print(problem.summarize())
print(f"χ² = {problem.chisq_str()}")Edit 2025-09-08 PAK: Changed model to half-polarized.
Metadata
Metadata
Assignees
Labels
No labels