Skip to content

Flake8 #117

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

Merged
merged 7 commits into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions doc/examples/crystalpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@
from diffpy.srfit.pdf import PDFGenerator, PDFParser
from diffpy.structure import Structure

####### Example Code
######
# Example Code


def makeRecipe(ciffile, datname):
"""Create a fitting recipe for crystalline PDF data."""

## The Profile
# The Profile
# This will be used to store the observed and calculated PDF profile.
profile = Profile()

Expand All @@ -57,7 +58,7 @@ def makeRecipe(ciffile, datname):
profile.loadParsedData(parser)
profile.setCalculationRange(xmax=20)

## The ProfileGenerator
# The ProfileGenerator
# The PDFGenerator is for configuring and calculating a PDF profile. Here,
# we want to refine a Structure object from diffpy.structure. We tell the
# PDFGenerator that with the 'setStructure' method. All other configuration
Expand All @@ -69,18 +70,18 @@ def makeRecipe(ciffile, datname):
stru.read(ciffile)
generator.setStructure(stru)

## The FitContribution
# The FitContribution
# Here we associate the Profile and ProfileGenerator, as has been done
# before.
contribution = FitContribution("nickel")
contribution.addProfileGenerator(generator)
contribution.setProfile(profile, xname="r")

## Make the FitRecipe and add the FitContribution.
# Make the FitRecipe and add the FitContribution.
recipe = FitRecipe()
recipe.addContribution(contribution)

## Configure the fit variables
# Configure the fit variables

# The PDFGenerator class holds the ParameterSet associated with the
# Structure passed above in a data member named "phase". (We could have
Expand Down
9 changes: 5 additions & 4 deletions doc/examples/crystalpdfall.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
)
from diffpy.srfit.pdf import PDFGenerator, PDFParser

####### Example Code
######
# Example Code


def makeProfile(datafile):
Expand All @@ -56,14 +57,14 @@ def makeRecipe(
):
"""Create a fitting recipe for crystalline PDF data."""

## The Profiles
# The Profiles
# We need a profile for each data set.
xprofile_ni = makeProfile(xdata_ni)
xprofile_si = makeProfile(xdata_si)
nprofile_ni = makeProfile(ndata_ni)
xprofile_sini = makeProfile(xdata_sini)

## The ProfileGenerators
# The ProfileGenerators
# We create one for each phase and share the phases.
xgenerator_ni = PDFGenerator("xG_ni")
stru = loadCrystal(ciffile_ni)
Expand All @@ -84,7 +85,7 @@ def makeRecipe(
xgenerator_sini_si = PDFGenerator("xG_sini_si")
xgenerator_sini_si.setPhase(phase_si)

## The FitContributions
# The FitContributions
# We one of these for each data set.
xcontribution_ni = makeContribution("xnickel", xgenerator_ni, xprofile_ni)
xcontribution_si = makeContribution("xsilicon", xgenerator_si, xprofile_si)
Expand Down
11 changes: 6 additions & 5 deletions doc/examples/crystalpdfobjcryst.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@
)
from diffpy.srfit.pdf import PDFGenerator, PDFParser

####### Example Code
######
# Example Code


def makeRecipe(ciffile, datname):
"""Create a fitting recipe for crystalline PDF data."""

## The Profile
# The Profile
# This will be used to store the observed and calculated PDF profile.
profile = Profile()

Expand All @@ -50,7 +51,7 @@ def makeRecipe(ciffile, datname):
profile.loadParsedData(parser)
profile.setCalculationRange(xmax=20)

## The ProfileGenerator
# The ProfileGenerator
# This time we use the CreateCrystalFromCIF method of pyobjcryst.crystal to
# create a Crystal object. That object is passed to the PDFGenerator as in
# the previous example.
Expand All @@ -59,7 +60,7 @@ def makeRecipe(ciffile, datname):
generator.setStructure(stru)
generator.setQmax(40.0)

## The FitContribution
# The FitContribution
contribution = FitContribution("nickel")
contribution.addProfileGenerator(generator)
contribution.setProfile(profile, xname="r")
Expand All @@ -68,7 +69,7 @@ def makeRecipe(ciffile, datname):
recipe = FitRecipe()
recipe.addContribution(contribution)

## Configure the fit variables
# Configure the fit variables

# As before, we get a handle to the structure parameter set. In this case,
# it is a ObjCrystCrystalParSet instance that was created when we called
Expand Down
9 changes: 5 additions & 4 deletions doc/examples/crystalpdftwodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@
)
from diffpy.srfit.pdf import PDFGenerator, PDFParser

####### Example Code
######
# Example Code


def makeRecipe(ciffile, xdatname, ndatname):
"""Create a fitting recipe for crystalline PDF data."""

## The Profiles
# The Profiles
# We need a profile for each data set. This means that we will need two
# FitContributions as well.
xprofile = Profile()
Expand All @@ -55,7 +56,7 @@ def makeRecipe(ciffile, xdatname, ndatname):
nprofile.loadParsedData(parser)
nprofile.setCalculationRange(xmax=20)

## The ProfileGenerators
# The ProfileGenerators
# We need one of these for the x-ray data.
xgenerator = PDFGenerator("G")
stru = loadCrystal(ciffile)
Expand All @@ -80,7 +81,7 @@ def makeRecipe(ciffile, xdatname, ndatname):
ngenerator = PDFGenerator("G")
ngenerator.setPhase(xgenerator.phase)

## The FitContributions
# The FitContributions
# We associate the x-ray PDFGenerator and Profile in one FitContribution...
xcontribution = FitContribution("xnickel")
xcontribution.addProfileGenerator(xgenerator)
Expand Down
11 changes: 6 additions & 5 deletions doc/examples/crystalpdftwophase.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@
)
from diffpy.srfit.pdf import PDFGenerator, PDFParser

####### Example Code
######
# Example Code


def makeRecipe(niciffile, siciffile, datname):
"""Create a fitting recipe for crystalline PDF data."""

## The Profile
# The Profile
profile = Profile()

# Load data and add it to the profile
Expand All @@ -47,7 +48,7 @@ def makeRecipe(niciffile, siciffile, datname):
profile.loadParsedData(parser)
profile.setCalculationRange(xmax=20)

## The ProfileGenerator
# The ProfileGenerator
# In order to fit two phases simultaneously, we must use two PDFGenerators.
# PDFGenerator is designed to take care of as little information as it
# must. (Don't do too much, and do it well.) A PDFGenerator can generate
Expand All @@ -67,7 +68,7 @@ def makeRecipe(niciffile, siciffile, datname):
stru = loadCrystal(siciffile)
generator_si.setStructure(stru)

## The FitContribution
# The FitContribution
# Add both generators to the FitContribution. Add the Profile. This will
# send the metadata to the generators.
contribution = FitContribution("nisi")
Expand All @@ -85,7 +86,7 @@ def makeRecipe(niciffile, siciffile, datname):
recipe = FitRecipe()
recipe.addContribution(contribution)

## Configure the fit variables
# Configure the fit variables
# Start by configuring the scale factor and resolution factors.
# We want the sum of the phase scale factors to be 1.
recipe.newVar("scale_ni", 0.1)
Expand Down
9 changes: 5 additions & 4 deletions doc/examples/debyemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
500.0 0.03946 0.00250
"""

####### Example Code
######
# Example Code


def makeRecipe():
Expand All @@ -84,7 +85,7 @@ def makeRecipe():
won't do that here.
"""

## The Profile
# The Profile
# Create a Profile to hold the experimental and calculated signal.
profile = Profile()

Expand All @@ -94,7 +95,7 @@ def makeRecipe():
x, y, dy = numpy.hsplit(xydy, 3)
profile.setObservedProfile(x, y, dy)

## The FitContribution
# The FitContribution
# The FitContribution associates the profile with the Debye function.
contribution = FitContribution("pb")
# Tell the contribution about the Profile. We will need to use the
Expand Down Expand Up @@ -127,7 +128,7 @@ def makeRecipe():
# can specify that as well.
contribution.setEquation("debye(T, 207.2, abs(thetaD)) + offset")

## The FitRecipe
# The FitRecipe
# The FitRecipe lets us define what we want to fit. It is where we can
# create variables, constraints and restraints. If we had multiple profiles
# to fit simultaneously, the contribution from each could be added to the
Expand Down
3 changes: 2 additions & 1 deletion doc/examples/debyemodelII.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@

from diffpy.srfit.fitbase import FitRecipe, FitResults

####### Example Code
######
# Example Code


def makeRecipeII():
Expand Down
13 changes: 7 additions & 6 deletions doc/examples/ellipsoidsas.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
)
from diffpy.srfit.sas import SASGenerator, SASParser

####### Example Code
######
# Example Code


def makeRecipe(datname):
"""Create a fitting recipe for ellipsoidal SAS data."""

## The Profile
# The Profile
# This will be used to store the observed and calculated I(Q) data.
profile = Profile()

Expand All @@ -40,7 +41,7 @@ def makeRecipe(datname):
parser.parseFile(datname)
profile.loadParsedData(parser)

## The ProfileGenerator
# The ProfileGenerator
# The SASGenerator is for configuring and calculating a SAS profile. We use
# a sas model to configure and serve as the calculation engine of the
# generator. This allows us to use the full sas model creation
Expand All @@ -52,7 +53,7 @@ def makeRecipe(datname):
model = EllipsoidModel()
generator = SASGenerator("generator", model)

## The FitContribution
# The FitContribution
# Here we associate the Profile and ProfileGenerator, as has been done
# before.
contribution = FitContribution("ellipsoid")
Expand All @@ -65,11 +66,11 @@ def makeRecipe(datname):
# will have on the estimated parameter uncertainties.
contribution.setResidualEquation("log(eq) - log(y)")

## Make the FitRecipe and add the FitContribution.
# Make the FitRecipe and add the FitContribution.
recipe = FitRecipe()
recipe.addContribution(contribution)

## Configure the fit variables
# Configure the fit variables
# The SASGenerator uses the parameters from the params and dispersion
# attributes of the model. These vary from model to model, but are adopted
# as SrFit Parameters within the generator. Whereas the dispersion
Expand Down
11 changes: 6 additions & 5 deletions doc/examples/gaussiangenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
ProfileGenerator,
)

####### Example Code
######
# Example Code


class GaussianGenerator(ProfileGenerator):
Expand Down Expand Up @@ -124,20 +125,20 @@ def makeRecipe():
associate this with a Profile, and use this to define a FitRecipe.
"""

## The Profile
# The Profile
# Create a Profile to hold the experimental and calculated signal.
profile = Profile()

# Load data and add it to the profile. This uses the loadtxt function from
# numpy.
profile.loadtxt("data/gaussian.dat")

## The ProfileGenerator
# The ProfileGenerator
# Create a GaussianGenerator named "g". This will be the name we use to
# refer to the generator from within the FitContribution equation.
generator = GaussianGenerator("g")

## The FitContribution
# The FitContribution
# Create a FitContribution that will associate the Profile with the
# GaussianGenerator. The GaussianGenerator will be accessible as an
# attribute of the FitContribution by its name ("g"). Note that this will
Expand All @@ -146,7 +147,7 @@ def makeRecipe():
contribution.addProfileGenerator(generator)
contribution.setProfile(profile)

## The FitRecipe
# The FitRecipe
# Now we create the FitRecipe and add the FitContribution.
recipe = FitRecipe()
recipe.addContribution(contribution)
Expand Down
9 changes: 5 additions & 4 deletions doc/examples/gaussianrecipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
Profile,
)

####### Example Code
######
# Example Code


def main():
Expand Down Expand Up @@ -95,15 +96,15 @@ def makeRecipe():
optimized. See the 'scipyOptimize' function.
"""

## The Profile
# The Profile
# Create a Profile to hold the experimental and calculated signal.
profile = Profile()

# Load data and add it to the profile. This uses the loadtxt function from
# numpy.
profile.loadtxt("data/gaussian.dat")

## The FitContribution
# The FitContribution
# The FitContribution associates the Profile with a fitting equation. The
# FitContribution also stores the parameters of the fitting equation. We
# give our FitContribution then name "g1". We will be able to access the
Expand Down Expand Up @@ -131,7 +132,7 @@ def makeRecipe():
# attribute. Parameters also have a 'name' attribute.
contribution.A.value = 1.0

## The FitRecipe
# The FitRecipe
# The FitRecipe lets us define what we want to fit. It is where we can
# create variables, constraints and restraints.
recipe = FitRecipe()
Expand Down
3 changes: 2 additions & 1 deletion doc/examples/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
Profile,
)

####### Example Code
######
# Example Code


def main():
Expand Down
Loading
Loading