def fitFunction(x, *tmp_params):

            model = load_model(equation)

            data = empty_data1D(x)
            param_dict = dict(zip(param_names, tmp_params))

            model_wrapper = Model(model, **param_dict)
            if value_ranges is not None:
                for name, values in value_ranges.items():
                    model_wrapper.__dict__[name].range(values[0], values[1])
            func_wrapper = Experiment(data=data, model=model_wrapper)

            return func_wrapper.theory()
Beispiel #2
0
kernel = load_model(name, dtype="single")
cutoff = 1e-3

if name == "ellipsoid":
    model = Model(
        kernel,
        scale=0.08,
        background=35,
        radius_polar=15,
        radius_equatorial=800,
        sld=.291,
        sld_solvent=7.105,
        theta=theta,
        phi=phi,
        theta_pd=0,
        theta_pd_n=0,
        theta_pd_nsigma=3,
        phi_pd=0,
        phi_pd_n=20,
        phi_pd_nsigma=3,
        radius_polar_pd=0.222296,
        radius_polar_pd_n=1,
        radius_polar_pd_nsigma=0,
        radius_equatorial_pd=.000128,
        radius_equatorial_pd_n=1,
        radius_equatorial_pd_nsigma=0,
    )

    # SET THE FITTING PARAMETERS
    model.radius_polar.range(15, 1000)
    model.radius_equatorial.range(15, 1000)
Beispiel #3
0
datasets = load_data('latex_smeared.xml', index='all')
#[print(data) for data in datasets]

# A single sphere model to share between the datasets.  We will use
# FreeVariables below to set the parameters that are independent between
# the datasets.
kernel = load_model('sphere')
pars = dict(
    scale=0.01,
    background=0.0,
    sld=5.0,
    sld_solvent=0.0,
    radius=1500.,
    #radius_pd=0.1, radius_pd_n=35,
)
model = Model(kernel, **pars)

# radius and polydispersity (if any) are shared
model.radius.range(0, inf)
#model.radius_pd.range(0, 1)

# Contrast and dilution are the same for both measurements, but are not
# separable with a single measurement (i.e., I(q) ~ F(q) contrast^2 Vf),
# so fit one of scale, sld or solvent sld.  With absolute scaling from
# data reduction, can use the same parameter for both datasets.
model.scale.range(0, inf)
#model.sld.range(-inf, inf)
#model.sld_solvent.range(-inf, inf)

# Background is different for sans and usans so set it as a free variable
# in the model.
Beispiel #4
0
from sasmodels.bumps_model import Model, Experiment
from sasmodels.data import load_data, set_beam_stop, set_top

""" IMPORT THE DATA USED """
radial_data = load_data('DEC07267.DAT')
set_beam_stop(radial_data, 0.00669, outer=0.025)
set_top(radial_data, -.0185)

kernel = load_model("ellipsoid")

model = Model(kernel,
    scale=0.08,
    radius_polar=15, radius_equatorial=800,
    sld=.291, sld_solvent=7.105,
    background=0,
    theta=90, phi=0,
    theta_pd=15, theta_pd_n=40, theta_pd_nsigma=3,
    radius_polar_pd=0.222296, radius_polar_pd_n=1, radius_polar_pd_nsigma=0,
    radius_equatorial_pd=.000128, radius_equatorial_pd_n=1, radius_equatorial_pd_nsigma=0,
    phi_pd=0, phi_pd_n=20, phi_pd_nsigma=3,
    )

# SET THE FITTING PARAMETERS
model.radius_polar.range(15, 1000)
model.radius_equatorial.range(15, 1000)
model.theta_pd.range(0, 360)
model.background.range(0,1000)
model.scale.range(0, 10)

#cutoff = 0     # no cutoff on polydisperisity loops
#cutoff = 1e-5  # default cutoff
Beispiel #5
0
def scat_model(data, label):

    if label == "ellipsoid":
        pars = dict(
            scale=1.0,
            background=0.001,
        )
        kernel = load_model(label)
        model = Model(kernel, **pars)

        # SET THE FITTING PARAMETERS
        model.radius_polar.range(0.0, 1000.0)
        model.radius_equatorial.range(0.0, 1000.0)
        model.sld.range(-0.56, 8.00)
        model.sld_solvent.range(-0.56, 6.38)
        model.radius_polar_pd.range(0, 0.11)
        experiment = Experiment(data=data, model=model)
        problem = FitProblem(experiment)
        result = fit(problem, method='dream')
        chisq = problem.chisq()

    if label == "shell":
        label = "core_shell_sphere"
        pars = dict(
            scale=1.0,
            background=0.001,
        )
        kernel = load_model(label)
        model = Model(kernel, **pars)

        # SET THE FITTING PARAMETERS
        model.radius.range(0.0, 1000.0)
        model.thickness.range(0.0, 100.0)
        model.sld_core.range(-0.56, 8.00)
        model.sld_shell.range(-0.56, 8.00)
        model.sld_solvent.range(-0.56, 6.38)
        model.radius_pd.range(0.1, 0.11)
        experiment = Experiment(data=data, model=model)
        problem = FitProblem(experiment)
        result = fit(problem, method='dream')
        chisq = problem.chisq()

    if label == "cylinder":
        pars = dict(
            scale=1.0,
            background=0.001,
        )
        kernel = load_model(label)
        model = Model(kernel, **pars)

        # SET THE FITTING PARAMETERS
        model.radius.range(0, 1000.0)
        model.length.range(0, 1000.0)
        model.sld.range(-0.56, 8.00)
        model.sld_solvent.range(-0.56, 6.38)
        model.radius_pd.range(0, 0.11)
        experiment = Experiment(data=data, model=model)
        problem = FitProblem(experiment)
        result = fit(problem, method='dream')
        chisq = problem.chisq()

    if label == "sphere":
        pars = dict(
            scale=1.0,
            background=0.001,
        )
        kernel = load_model(label)
        model = Model(kernel, **pars)

        # SET THE FITTING PARAMETERS
        model.radius.range(0.0, 3200.0)
        model.sld.range(-0.56, 8.00)
        model.sld_solvent.range(-0.56, 6.38)
        model.radius_pd.range(0.1, 0.11)
        experiment = Experiment(data=data, model=model)
        problem = FitProblem(experiment)
        result = fit(problem, method='dream')
        chisq = problem.chisq()

    return np.round(chisq, 3)
Beispiel #6
0
usans.oriented = True
#print sans.dxl, usans.dxl
#import pprint; pprint.pprint(sans.__dict__)

kernel = load_model("ellipsoid")

model = Model(
    kernel,
    scale=0.08,
    background=0,
    sld=.291,
    sld_solvent=7.105,
    r_polar=1800,
    r_polar_pd=0.222296,
    r_polar_pd_n=0,
    r_equatorial=2600,
    r_equatorial_pd=0.28,
    r_equatorial_pd_n=0,
    theta=60,
    theta_pd=0,
    theta_pd_n=0,
    phi=60,
    phi_pd=0,
    phi_pd_n=0,
)

# SET THE FITTING PARAMETERS
model.r_polar.range(1000, 10000)
model.r_equatorial.range(1000, 10000)
model.theta.range(0, 360)
model.phi.range(0, 360)
Beispiel #7
0
section = "radial" if len(sys.argv) < 3 else sys.argv[2]
if section not in ("radial","tangential","both"):
    raise ValueError("section %r should be 'radial', 'tangential' or 'both'"
            % section)
data = radial_data if section != "tangential" else tan_data
phi = 0 if section != "tangential" else 90
kernel = load_model(name, dtype="single")
cutoff = 1e-3

if name == "ellipsoid":
    model = Model(kernel,
        scale=0.08,
        r_polar=15, r_equatorial=800,
        sld=.291, sld_solvent=7.105,
        background=0,
        theta=90, phi=phi,
        theta_pd=15, theta_pd_n=40, theta_pd_nsigma=3,
        r_polar_pd=0.222296, r_polar_pd_n=1, r_polar_pd_nsigma=0,
        r_equatorial_pd=.000128, r_equatorial_pd_n=1, r_equatorial_pd_nsigma=0,
        phi_pd=0, phi_pd_n=20, phi_pd_nsigma=3,
        )


    # SET THE FITTING PARAMETERS
    model.r_polar.range(15, 1000)
    model.r_equatorial.range(15, 1000)
    model.theta_pd.range(0, 360)
    model.background.range(0,1000)
    model.scale.range(0, 10)

def fit_function(key, sans_data, usans_data, actual_vol, actual_stdev_vol,
                 backgrounds, avg_scale, avg_rg, ps_s, ps_porod_exp, slds, cps,
                 matrix):

    #np.savetxt('Sample_'+str(key)+'.txt', np.array(['Fitting']), fmt='%s')
    kernel = load_model("guinier_porod+ellipsoid")

    # loading the data
    sans = sans_data[key]
    sans.dx = sans.dx - sans.dx  # removing smearing from sans segment
    usans = usans_data[key]

    vol = actual_vol[key] / 100  # cp volume fraction from uv-vis
    vol_stdev = actual_stdev_vol[key] / 100

    # initial parameter values

    scale = Parameter(1, name=str(key) + 'scale')
    background = Parameter(backgrounds[key][0], name=str(key) + 'background')

    A_scale = Parameter(avg_scale * (1 - vol), name=str(key) + ' PS scale')
    A_rg = Parameter(avg_rg, name=str(key) + ' PS rg')
    A_s = Parameter(ps_s, name=str(key) + ' PS s')
    A_porod_exp = Parameter(ps_porod_exp, name=str(key) + ' PS porod_exp')

    B_scale_normal = bumps.bounds.Normal(mean=vol, std=vol_stdev)
    B_scale = Parameter(vol,
                        name=str(key) + ' sphere scale',
                        bounds=B_scale_normal)

    B_sld = Parameter(slds[cps[key]], name=str(key) + ' PS sld')
    B_sld_solvent = Parameter(slds[matrix[key]], name=str(key) + ' PS solvent')

    B_radius_polar = Parameter(1000,
                               limits=[0, inf],
                               name=str(key) + ' ellipsoid polar radius')
    B_radius_polar_pd = Parameter(0.5,
                                  name=str(key) + ' ellipsoid polar radius pd')
    B_radius_polar_pd_n = Parameter(200,
                                    name=str(key) +
                                    ' ellipsoid polar radius pd n')
    B_radius_polar_pd_nsigma = Parameter(8,
                                         name=str(key) +
                                         ' ellipsoid polar radius pd nsigma')

    B_radius_equatorial = Parameter(1000,
                                    limits=[0, inf],
                                    name=str(key) +
                                    ' ellipsoid equatorial radius')
    B_radius_equatorial_pd = Parameter(0.5,
                                       name=str(key) +
                                       ' ellipsoid equatorial radius pd')
    B_radius_equatorial_pd_n = Parameter(200,
                                         name=str(key) +
                                         ' ellipsoid equatorial radius pd n')
    B_radius_equatorial_pd_nsigma = Parameter(
        8, name=str(key) + ' ellipsoid equatorial radius pd nsigma')

    # setting up the combined model for fitting
    sans_model = Model(
        model=kernel,
        scale=scale,
        background=background,
        A_scale=A_scale,
        A_rg=A_rg,
        A_s=A_s,
        A_porod_exp=A_porod_exp,
        B_scale=B_scale,
        B_sld=B_sld,
        B_sld_solvent=B_sld_solvent,
        B_radius_polar=B_radius_polar,
        B_radius_polar_pd_type='lognormal',
        B_radius_polar_pd=B_radius_polar_pd,
        B_radius_polar_pd_n=B_radius_polar_pd_n,
        B_radius_polar_pd_nsigma=B_radius_polar_pd_nsigma,
        B_radius_equatorial=B_radius_equatorial,
        B_radius_equatorial_pd_type='lognormal',
        B_radius_equatorial_pd=B_radius_equatorial_pd,
        B_radius_equatorial_pd_n=B_radius_equatorial_pd_n,
        B_radius_equatorial_pd_nsigma=B_radius_equatorial_pd_nsigma,
    )

    # setting parameter ranges as needed

    sans_model.B_radius_polar.range(0, 200000)
    sans_model.B_radius_equatorial.range(0, 200000)

    sans_experiment = Experiment(data=sans, model=sans_model)
    usans_experiment = Experiment(data=usans, model=sans_model)

    usans_smearing = sasmodels.resolution.Slit1D(usans.x, 0.117)
    usans_experiment.resolution = usans_smearing

    experiment = [sans_experiment, usans_experiment]

    problem = FitProblem(experiment)

    result = fit(problem,
                 method='dream',
                 samples=1e6,
                 steps=1000,
                 verbose=True)
    result.state.save(
        '../data/sans/Sample_Fitting/fitting_results/ps_ellipsoid_match/CMW' +
        str(key) + '_ps_ellipsoid_state')
Beispiel #9
0
        theta=theta,
        phi=phi,
        theta_pd=0,
        theta_pd_n=0,
        theta_pd_nsigma=3,
        phi_pd=0,
        phi_pd_n=20,
        phi_pd_nsigma=3,
        radius_polar_pd=0.222296,
        radius_polar_pd_n=1,
        radius_polar_pd_nsigma=0,
        radius_equatorial_pd=.000128,
        radius_equatorial_pd_n=1,
        radius_equatorial_pd_nsigma=0,
    )
    model = Model(kernel, **pars)

    # SET THE FITTING PARAMETERS
    model.radius_polar.range(15, 1000)
    model.radius_equatorial.range(15, 1000)
    #model.theta.range(0, 90)
    #model.theta_pd.range(0,10)
    model.phi_pd.range(0, 20)
    model.phi.range(0, 180)
    model.background.range(0, 1000)
    model.scale.range(0, 10)

elif name == "lamellar":
    pars = dict(
        scale=0.08,
        background=0.003,