Ejemplo n.º 1
0
def main():

    # Make the data and the recipe
    strufile = "data/C60.stru"
    q = numpy.arange(1, 20, 0.05)
    makeData(strufile, q, "C60.iq", 1.0, 100.68, 0.005, 0.13, 2)

    # Make the recipe
    recipe = makeRecipe(strufile, "C60.iq")

    # Optimize
    scipyOptimize(recipe)

    # Generate and print the FitResults
    res = FitResults(recipe)
    # We want to see how much speed-up we get from bringing the scale and
    # background outside of the intensity generator.  Get the number of calls
    # to the residual function from the FitRecipe, and the number of calls to
    # 'iofq' from the IntensityGenerator.
    rescount = recipe.fithooks[0].count
    calcount = recipe.bucky.I.count
    footer = "iofq called %i%% of the time"%int(100.0*calcount/rescount)
    res.printResults(footer = footer)

    # Plot!
    plotResults(recipe)

    return
Ejemplo n.º 2
0
def main():

    # Make the data and the recipe
    strufile = "data/C60.stru"
    q = numpy.arange(1, 20, 0.05)
    makeData(strufile, q, "C60.iq", 1.0, 100.68, 0.005, 0.13, 2)

    # Make the recipe
    recipe = makeRecipe(strufile, "C60.iq")

    # Optimize
    scipyOptimize(recipe)

    # Generate and print the FitResults
    res = FitResults(recipe)
    # We want to see how much speed-up we get from bringing the scale and
    # background outside of the intensity generator.  Get the number of calls
    # to the residual function from the FitRecipe, and the number of calls to
    # 'iofq' from the IntensityGenerator.
    rescount = recipe.fithooks[0].count
    calcount = recipe.bucky.I.count
    footer = "iofq called %i%% of the time"%int(100.0*calcount/rescount)
    res.printResults(footer = footer)

    # Plot!
    plotResults(recipe)

    return
Ejemplo n.º 3
0
def main():

    p = Profile()
    p.loadtxt("data/gaussian.dat")

    # FitContribution operations
    # "|="  -   Union of necessary components.
    # "<<"  -   Inject a parameter value
    c = FitContribution("g1")
    c |= p
    c |= "A * exp(-0.5*(x-x0)**2/sigma**2)"
    c.A << 0.5
    c.x0 << 5
    c.sigma << 1

    # FitRecipe operations
    # "|="  -   Union of necessary components.
    # "+="  -   Add Parameter or create a new one. Each tuple is a set of
    #           arguments for either setVar or addVar.
    # "*="  -   Constrain a parameter. Think of "*" as a push-pin holding one
    #           parameter's value to that of another.
    # "%="  -   Restrain a parameter or equation. Think of "%" as a rope
    #           loosely tying parameters to a value.
    r = FitRecipe()
    r |= c
    r += (c.A, 0.5), (c.x0, 5), "sig"
    r *= c.sigma, "sig"
    r %= c.A, 0.5, 0.5

    from gaussianrecipe import scipyOptimize

    scipyOptimize(r)

    res = FitResults(r)

    # Print the results.
    res.printResults()

    # Plot the results.
    from gaussianrecipe import plotResults

    plotResults(r)

    return
Ejemplo n.º 4
0
def main():
    """The workflow of creating, running and inspecting a fit."""

    # Create the recipe
    recipe = makeRecipe()

    # Refine using the optimizer of your choice
    scipyOptimize(recipe)

    # Get the results.
    res = FitResults(recipe)

    # Print the results
    res.printResults()

    # Plot the results
    plotResults(recipe)

    return
Ejemplo n.º 5
0
def main():
    """The workflow of creating, running and inspecting a fit."""

    # Create the recipe
    recipe = makeRecipe()

    # Refine using the optimizer of your choice
    scipyOptimize(recipe)

    # Get the results.
    res = FitResults(recipe)

    # Print the results
    res.printResults()

    # Plot the results
    plotResults(recipe)

    return
Ejemplo n.º 6
0
def main():

    p = Profile()
    p.loadtxt("data/gaussian.dat")

    # FitContribution operations
    # "|="  -   Union of necessary components.
    # "<<"  -   Inject a parameter value
    c = FitContribution("g1")
    c |= p
    c |= "A * exp(-0.5*(x-x0)**2/sigma**2)"
    c.A << 0.5
    c.x0 << 5
    c.sigma << 1

    # FitRecipe operations
    # "|="  -   Union of necessary components.
    # "+="  -   Add Parameter or create a new one. Each tuple is a set of
    #           arguments for either setVar or addVar.
    # "*="  -   Constrain a parameter. Think of "*" as a push-pin holding one
    #           parameter's value to that of another.
    # "%="  -   Restrain a parameter or equation. Think of "%" as a rope
    #           loosely tying parameters to a value.
    r = FitRecipe()
    r |= c
    r += (c.A, 0.5), (c.x0, 5), 'sig'
    r *= c.sigma, 'sig'
    r %= c.A, 0.5, 0.5

    from gaussianrecipe import scipyOptimize
    scipyOptimize(r)

    res = FitResults(r)

    # Print the results.
    res.printResults()

    # Plot the results.
    from gaussianrecipe import plotResults
    plotResults(r)

    return
Ejemplo n.º 7
0
def fitRecipe(recipe):
    """We refine in stages to help the refinement converge."""

    # Tune SAS.
    recipe.setWeight(recipe.pdf, 0)
    recipe.fix("all")
    recipe.free("radius_a", "radius_b", iqscale = 1e8)
    recipe.constrain('radius_b', 'radius_a')
    scipyOptimize(recipe)
    recipe.unconstrain('radius_b')

    # Tune PDF
    recipe.setWeight(recipe.pdf, 1)
    recipe.setWeight(recipe.sas, 0)
    recipe.fix("all")
    recipe.free("a", "Biso_0", "scale", "delta2")
    scipyOptimize(recipe)

    # Tune all
    recipe.setWeight(recipe.pdf, 1)
    recipe.setWeight(recipe.sas, 1)
    recipe.free("all")
    scipyOptimize(recipe)

    return
Ejemplo n.º 8
0
def main():

    # Make two different data sets, each from the same structure, but with
    # different scale, noise, broadening and background.
    strufile = "data/C60.stru"
    q = numpy.arange(1, 20, 0.05)
    makeData(strufile, q, "C60_1.iq", 8.1, 101.68, 0.008, 0.12, 2, 0.01)
    makeData(strufile, q, "C60_2.iq", 3.2, 101.68, 0.02, 0.003, 0, 1)

    # Make the recipe
    recipe = makeRecipe(strufile, "C60_1.iq", "C60_2.iq")

    # Optimize
    # Since the backgrounds have a large effect on the profile, we will refine
    # them first, but do so separately.
    # To refine the background from the first contribution, we will fix
    # all other parameters and give the second contribution no weight in the
    # fit.
    recipe.fix("all")
    recipe.free("bcoeffs1")
    recipe.setWeight(recipe.bucky2, 0)
    scipyOptimize(recipe)
    # Now do the same for the second background
    recipe.fix("all")
    recipe.free("bcoeffs1")
    recipe.setWeight(recipe.bucky2, 1)
    recipe.setWeight(recipe.bucky1, 0)
    scipyOptimize(recipe)
    # Now refine everything with the structure parameters included
    recipe.free("all")
    recipe.setWeight(recipe.bucky1, 1)
    scipyOptimize(recipe)

    # Generate and print the FitResults
    res = FitResults(recipe)
    res.printResults()

    # Plot!
    plotResults(recipe)

    return
Ejemplo n.º 9
0
def main():

    # Make two different data sets, each from the same structure, but with
    # different scale, noise, broadening and background.
    strufile = "data/C60.stru"
    q = numpy.arange(1, 20, 0.05)
    makeData(strufile, q, "C60_1.iq", 8.1, 101.68, 0.008, 0.12, 2, 0.01)
    makeData(strufile, q, "C60_2.iq", 3.2, 101.68, 0.02, 0.003, 0, 1)

    # Make the recipe
    recipe = makeRecipe(strufile, "C60_1.iq", "C60_2.iq")

    # Optimize
    # Since the backgrounds have a large effect on the profile, we will refine
    # them first, but do so separately.
    # To refine the background from the first contribution, we will fix
    # all other parameters and give the second contribution no weight in the
    # fit.
    recipe.fix("all")
    recipe.free("bcoeffs1")
    recipe.setWeight(recipe.bucky2, 0)
    scipyOptimize(recipe)
    # Now do the same for the second background
    recipe.fix("all")
    recipe.free("bcoeffs1")
    recipe.setWeight(recipe.bucky2, 1)
    recipe.setWeight(recipe.bucky1, 0)
    scipyOptimize(recipe)
    # Now refine everything with the structure parameters included
    recipe.free("all")
    recipe.setWeight(recipe.bucky1, 1)
    scipyOptimize(recipe)

    # Generate and print the FitResults
    res = FitResults(recipe)
    res.printResults()

    # Plot!
    plotResults(recipe)

    return
Ejemplo n.º 10
0
def fitRecipe(recipe):
    """We refine in stages to help the refinement converge."""

    # Tune SAS.
    recipe.setWeight(recipe.pdf, 0)
    recipe.fix("all")
    recipe.free("radius_a", "radius_b", iqscale = 1e8)
    scipyOptimize(recipe)

    # Tune PDF
    recipe.setWeight(recipe.pdf, 1)
    recipe.setWeight(recipe.sas, 0)
    recipe.fix("all")
    recipe.free("a", "Biso_0", "scale", "delta2")
    scipyOptimize(recipe)

    # Tune all
    recipe.setWeight(recipe.pdf, 1)
    recipe.setWeight(recipe.sas, 1)
    recipe.free("all")
    scipyOptimize(recipe)

    return
Ejemplo n.º 11
0
    pylab.plot(nr,ndiff,'g-',label="G(r) neutron diff")
    pylab.plot(nr,ndiffzero,'k-')
    pylab.xlabel("$r (\AA)$")
    pylab.ylabel("$G (\AA^{-2})$")
    pylab.legend(loc=1)

    pylab.show()
    return

if __name__ == "__main__":

    # Make the data and the recipe
    ciffile = "data/ni.cif"
    xdata = "data/ni-q27r60nodg-xray.gr"
    ndata = "data/ni-q27r100-neutron.gr"

    # Make the recipe
    recipe = makeRecipe(ciffile, xdata, ndata)

    # Optimize
    scipyOptimize(recipe)

    # Generate and print the FitResults
    res = FitResults(recipe)
    res.printResults()

    # Plot!
    plotResults(recipe)

# End of file
Ejemplo n.º 12
0
    pylab.plot(r,diffzero,'k-')
    pylab.xlabel("$r (\AA)$")
    pylab.ylabel("$G (\AA^{-2})$")
    pylab.legend(loc=1)

    pylab.show()
    return


if __name__ == "__main__":

    # Make the data and the recipe
    niciffile = "data/ni.cif"
    siciffile = "data/si.cif"
    data = "data/si90ni10-q27r60-xray.gr"

    # Make the recipe
    recipe = makeRecipe(niciffile, siciffile, data)

    # Optimize
    scipyOptimize(recipe)

    # Generate and print the FitResults
    res = FitResults(recipe)
    res.printResults()

    # Plot!
    plotResults(recipe)

# End of file