diffpy.srfit.sas package

Submodules

diffpy.srfit.sas.prcalculator module

Nanoparticle form factor P(r) calculator.

The PrCalculator class wraps a sas.pr.invertor.Invertor object as a Calculator. This is not wrapped as a ProfileGenerator because it will be used to share information between SAS I(Q) to PDF G(r), but it does not use the same profile as the PDF, which is where the calculator will be applied.

class diffpy.srfit.sas.prcalculator.PrCalculator(name)

Bases: diffpy.srfit.fitbase.calculator.Calculator

A class for calculating P(r) from data.

This is provided so that SAS data can be used to calculate a nanoparticle form factor (characteristic function) for nanoparticle PDF refinements. For a crystal-like nanoparticle: Gnano(r) = f(r)Gcrystal(r), where f(r) is the nanoparticle form factor. This is obtained from P(r) as P(r) = 4 pi r**2 f(r).

Attributes: _invertor – sas.pr.invertor.Invertor object. This object is internal,

but can be configured by the user after initialization. Note that the ‘x’, ‘y’ and ‘err’ attributes get overwritten every time the invertor is used.

Managed Parameters: scale – The scale factor (default 1). q – The q-values of the I(q) signal iq – The I(q) signal diq – The uncertainty in I(q)

class diffpy.srfit.sas.prcalculator.CFCalculator(name)

Bases: diffpy.srfit.sas.prcalculator.PrCalculator

A class for calculating the characteristic function (CF) from data.

This calculator produces f(r) = P(r) / 4 pi r**2 which is the nanoparticle form factor scaled by density.

Attributes: _invertor – sas.pr.invertor.Invertor object. This object is internal,

but can be configured by the user after initialization. Note that the ‘x’, ‘y’ and ‘err’ attributes get overwritten every time the invertor is used.

Managed Parameters: scale – The scale factor (default 1). q – The q-values of the I(q) signal iq – The I(q) signal diq – The uncertainty in I(q)

diffpy.srfit.sas.sasgenerator module

SAS profile generator.

The SASGenerator class wraps a sas.models.BaseModel object as a ProfileGenerator.

class diffpy.srfit.sas.sasgenerator.SASGenerator(name, model)

Bases: diffpy.srfit.fitbase.profilegenerator.ProfileGenerator

A class for calculating I(Q) from a scattering type.

Attributes: _model – BaseModel object this adapts.

Managed Parameters: These depend on the parameters of the BaseModel object held by _model. They are created from the ‘params’ attribute of the BaseModel. If a dispersion is set for the BaseModel, the dispersion “width” will be accessible under “<parname>_width”, where <parname> is the name a parameter adjusted by dispersion.

diffpy.srfit.sas.sasparameter module

SAS profile generator.

The SASGenerator class wraps a sas.models.BaseModel object as a ProfileGenerator.

class diffpy.srfit.sas.sasparameter.SASParameter(name, model, parname=None)

Bases: diffpy.srfit.fitbase.parameter.Parameter

Class adapting a sasmodel parameter to srfit Parameter.

Attributes name – A name for this Parameter. const – A flag indicating whether this is considered a constant. _value – The value of the Parameter. Modified with ‘setValue’. value – Property for ‘getValue’ and ‘setValue’. constrained – A flag indicating if the Parameter is constrained

(default False).
bounds – A 2-list defining the bounds on the Parameter. This can be
used by some optimizers when the Parameter is varied. These bounds are unrelated to restraints on a Parameter.

_model – The BaseModel to which the underlying parameter belongs. _parname – The name of the underlying BaseModel parameter.

getValue()

Get the value of the Parameter.

setValue(value)

Set the value of the Parameter.

diffpy.srfit.sas.sasparser module

This module contains parsers for SAS data.

SASParser uses the sas DataLoader class to load data.

class diffpy.srfit.sas.sasparser.SASParser

Bases: diffpy.srfit.fitbase.profileparser.ProfileParser

Class for parsing a sas profile.

This uses a sas DataLoader to load the data. The DataInfo object it returns is held in the metadata under the name “datainfo”.

Attributes

_format – Name of the data format that this parses (string, default
“”). The format string is a unique identifier for the data format handled by the parser.
_banks – The data from each bank. Each bank contains a (x, y, dx, dy)

tuple: x – A numpy array containing the independent

variable read from the file.
y – A numpy array containing the profile
from the file.
dx – A numpy array containing the uncertainty in x
read from the file. This is 0 if the uncertainty cannot be read.
dy – A numpy array containing the uncertainty read
from the file. This is 0 if the uncertainty cannot be read.

_x – Indpendent variable from the chosen bank _y – Profile from the chosen bank _dx – Uncertainty in independent variable from the chosen bank _dy – Uncertainty in profile from the chosen bank _meta – A dictionary containing metadata read from the file.

General Metadata

filename – The name of the file from which data was parsed. This key
will not exist if data was not read from file.

nbanks – The number of banks parsed. bank – The chosen bank number.

Metadata - These may appear in the metadata dictionary

datainfo – The DataInfo object used to do the data parsing.

parseFile(filename)

Parse a file and set the _x, _y, _dx, _dy and _meta variables.

This wipes out the currently loaded data and selected bank number.

Arguments filename – The name of the file to parse

Raises IOError if the file cannot be read Raises ParseError if the file cannot be parsed

parseString(patstring)

Parse a string and set the _x, _y, _dx, _dy and _meta variables.

When _dx or _dy cannot be obtained in the data format it is set to 0.

This wipes out the currently loaded data and selected bank number.

Arguments patstring – A string containing the pattern

Raises ParseError if the string cannot be parsed

diffpy.srfit.sas.sasprofile module

Class for adapting a sas DataInfo objects to the Profile interface.

class diffpy.srfit.sas.sasprofile.SASProfile(datainfo)

Bases: diffpy.srfit.fitbase.profile.Profile

Observed and calculated profile container for SAS data.

This wraps a sas DataInfo object as a Profile object. Use this when you want to use and manipulate a DataProfile before using it with SrFit. Otherwise, use the SASParser class and load the data into a base Profile object.

Attributes

_xobs – A numpy array of the observed independent variable (default
None)

xobs – Read-only property of _xobs. _yobs – A numpy array of the observed signal (default None) yobs – Read-only property of _yobs. _dyobs – A numpy array of the uncertainty of the observed signal (default

None, optional).

dyobs – Read-only property of _dyobs. x – A numpy array of the calculated independent variable (default

None, property for xpar accessors).
y – The profile over the calculation range (default None, property
for ypar accessors).
dy – The uncertainty in the profile over the calculation range
(default None, property for dypar accessors).

ycalc – A numpy array of the calculated signal (default None). xpar – A ProfileParameter that stores x (named “x”). ypar – A ProfileParameter that stores y (named “y”). dypar – A ProfileParameter that stores dy (named “dy”). meta – A dictionary of metadata. This is only set if provided by a

parser.

_datainfo – The DataInfo object this wraps.

setObservedProfile(xobs, yobs, dyobs=None)

Set the observed profile.

This is overloaded to change the value within the datainfo object.

Arguments xobs – Numpy array of the independent variable yobs – Numpy array of the observed signal. dyobs – Numpy array of the uncertainty in the observed signal. If

dyobs is None (default), it will be set to 1 at each observed xobs.

Raises ValueError if len(yobs) != len(xobs) Raises ValueError if dyobs != None and len(dyobs) != len(xobs)

Module contents

SAS calculation tools.

class diffpy.srfit.sas.SASGenerator(name, model)

Bases: diffpy.srfit.fitbase.profilegenerator.ProfileGenerator

A class for calculating I(Q) from a scattering type.

Attributes: _model – BaseModel object this adapts.

Managed Parameters: These depend on the parameters of the BaseModel object held by _model. They are created from the ‘params’ attribute of the BaseModel. If a dispersion is set for the BaseModel, the dispersion “width” will be accessible under “<parname>_width”, where <parname> is the name a parameter adjusted by dispersion.

class diffpy.srfit.sas.SASParser

Bases: diffpy.srfit.fitbase.profileparser.ProfileParser

Class for parsing a sas profile.

This uses a sas DataLoader to load the data. The DataInfo object it returns is held in the metadata under the name “datainfo”.

Attributes

_format – Name of the data format that this parses (string, default
“”). The format string is a unique identifier for the data format handled by the parser.
_banks – The data from each bank. Each bank contains a (x, y, dx, dy)

tuple: x – A numpy array containing the independent

variable read from the file.
y – A numpy array containing the profile
from the file.
dx – A numpy array containing the uncertainty in x
read from the file. This is 0 if the uncertainty cannot be read.
dy – A numpy array containing the uncertainty read
from the file. This is 0 if the uncertainty cannot be read.

_x – Indpendent variable from the chosen bank _y – Profile from the chosen bank _dx – Uncertainty in independent variable from the chosen bank _dy – Uncertainty in profile from the chosen bank _meta – A dictionary containing metadata read from the file.

General Metadata

filename – The name of the file from which data was parsed. This key
will not exist if data was not read from file.

nbanks – The number of banks parsed. bank – The chosen bank number.

Metadata - These may appear in the metadata dictionary

datainfo – The DataInfo object used to do the data parsing.

parseFile(filename)

Parse a file and set the _x, _y, _dx, _dy and _meta variables.

This wipes out the currently loaded data and selected bank number.

Arguments filename – The name of the file to parse

Raises IOError if the file cannot be read Raises ParseError if the file cannot be parsed

parseString(patstring)

Parse a string and set the _x, _y, _dx, _dy and _meta variables.

When _dx or _dy cannot be obtained in the data format it is set to 0.

This wipes out the currently loaded data and selected bank number.

Arguments patstring – A string containing the pattern

Raises ParseError if the string cannot be parsed

class diffpy.srfit.sas.SASProfile(datainfo)

Bases: diffpy.srfit.fitbase.profile.Profile

Observed and calculated profile container for SAS data.

This wraps a sas DataInfo object as a Profile object. Use this when you want to use and manipulate a DataProfile before using it with SrFit. Otherwise, use the SASParser class and load the data into a base Profile object.

Attributes

_xobs – A numpy array of the observed independent variable (default
None)

xobs – Read-only property of _xobs. _yobs – A numpy array of the observed signal (default None) yobs – Read-only property of _yobs. _dyobs – A numpy array of the uncertainty of the observed signal (default

None, optional).

dyobs – Read-only property of _dyobs. x – A numpy array of the calculated independent variable (default

None, property for xpar accessors).
y – The profile over the calculation range (default None, property
for ypar accessors).
dy – The uncertainty in the profile over the calculation range
(default None, property for dypar accessors).

ycalc – A numpy array of the calculated signal (default None). xpar – A ProfileParameter that stores x (named “x”). ypar – A ProfileParameter that stores y (named “y”). dypar – A ProfileParameter that stores dy (named “dy”). meta – A dictionary of metadata. This is only set if provided by a

parser.

_datainfo – The DataInfo object this wraps.

setObservedProfile(xobs, yobs, dyobs=None)

Set the observed profile.

This is overloaded to change the value within the datainfo object.

Arguments xobs – Numpy array of the independent variable yobs – Numpy array of the observed signal. dyobs – Numpy array of the uncertainty in the observed signal. If

dyobs is None (default), it will be set to 1 at each observed xobs.

Raises ValueError if len(yobs) != len(xobs) Raises ValueError if dyobs != None and len(dyobs) != len(xobs)

class diffpy.srfit.sas.PrCalculator(name)

Bases: diffpy.srfit.fitbase.calculator.Calculator

A class for calculating P(r) from data.

This is provided so that SAS data can be used to calculate a nanoparticle form factor (characteristic function) for nanoparticle PDF refinements. For a crystal-like nanoparticle: Gnano(r) = f(r)Gcrystal(r), where f(r) is the nanoparticle form factor. This is obtained from P(r) as P(r) = 4 pi r**2 f(r).

Attributes: _invertor – sas.pr.invertor.Invertor object. This object is internal,

but can be configured by the user after initialization. Note that the ‘x’, ‘y’ and ‘err’ attributes get overwritten every time the invertor is used.

Managed Parameters: scale – The scale factor (default 1). q – The q-values of the I(q) signal iq – The I(q) signal diq – The uncertainty in I(q)

class diffpy.srfit.sas.CFCalculator(name)

Bases: diffpy.srfit.sas.prcalculator.PrCalculator

A class for calculating the characteristic function (CF) from data.

This calculator produces f(r) = P(r) / 4 pi r**2 which is the nanoparticle form factor scaled by density.

Attributes: _invertor – sas.pr.invertor.Invertor object. This object is internal,

but can be configured by the user after initialization. Note that the ‘x’, ‘y’ and ‘err’ attributes get overwritten every time the invertor is used.

Managed Parameters: scale – The scale factor (default 1). q – The q-values of the I(q) signal iq – The I(q) signal diq – The uncertainty in I(q)