sas.sascalc.calculator package

Submodules

sas.sascalc.calculator.BaseComponent module

Provide base functionality for all model components

class sas.sascalc.calculator.BaseComponent.BaseComponent[source]

Bases: object

Basic model component

Since version 0.5.0, basic operations are no longer supported.

calculate_ER()[source]

Calculate effective radius

calculate_VR()[source]

Calculate volume fraction ratio

clone()[source]

Returns a new object identical to the current object

evalDistribution(qdist)[source]

Evaluate a distribution of q-values.

  • For 1D, a numpy array is expected as input:

    evalDistribution(q)
    

    where q is a numpy array.

  • For 2D, a list of numpy arrays are expected: [qx_prime,qy_prime], where 1D arrays,

    qx_prime = [ qx[0], qx[1], qx[2], ....]
    

    and

    qy_prime = [ qy[0], qy[1], qy[2], ....]
    

Then get

q = np.sqrt(qx_prime^2+qy_prime^2)

that is a qr in 1D array;

q = [q[0], q[1], q[2], ....]

Note

Due to 2D speed issue, no anisotropic scattering is supported for python models, thus C-models should have their own evalDistribution methods.

The method is then called the following way:

evalDistribution(q)

where q is a numpy array.

Parameters:qdist – ndarray of scalar q-values or list [qx,qy] where qx,qy are 1D ndarrays
getDispParamList()[source]

Return a list of all available parameters for the model

getParam(name)[source]

Set the value of a model parameter :param name: name of the parameter

getParamList()[source]

Return a list of all available parameters for the model

getParamListWithToken(token, member)[source]

get Param List With Token

getParamWithToken(name, token, member)[source]

get Param With Token

getProfile()[source]

Get SLD profile

: return: (z, beta) where z is a list of depth of the transition points
beta is a list of the corresponding SLD values
is_fittable(par_name)[source]

Check if a given parameter is fittable or not

Parameters:par_name – the parameter name to check
run(x)[source]

run 1d

runXY(x)[source]

run 2d

setParam(name, value)[source]

Set the value of a model parameter

Parameters:
  • name – name of the parameter
  • value – value of the parameter
setParamWithToken(name, value, token, member)[source]

set Param With Token

set_dispersion(parameter, dispersion)[source]

model dispersions

sas.sascalc.calculator.geni module

Compute scattering from a set of points.

For 1-D scattering use Iq(q, x, y, z, sld, vol, is_avg)

sas.sascalc.calculator.geni.Iq(q, x, y, z, sld, vol, is_avg=False)[source]

Computes 1D isotropic.

Isotropic: Assumes all slds are real (no magnetic)

Also assumes there is no polarization: No dependency on spin.

All values must be numpy vectors of the correct size.

Returns I(q)

sas.sascalc.calculator.geni.Iqxy(qx, qy, x, y, z, sld, vol, mx, my, mz, in_spin, out_spin, s_theta)[source]

Computes 2D anisotropic.

in_spin and out_spin indicate portion of polarizer and analyzer transmission that are spin up. s_theta is the polarization direction.

All other values must be numpy vectors of the correct size.

Returns I(qx, qy)

sas.sascalc.calculator.geni.njit(*args, **kw)[source]

sas.sascalc.calculator.instrument module

This module is a small tool to allow user to control instrumental parameters

class sas.sascalc.calculator.instrument.Aperture[source]

Bases: object

An object class that defines the aperture variables

set_sample_distance(distance=[])[source]

Set the sample aperture distance

set_sample_size(size=[])[source]

Set the sample aperture size

set_source_size(size=[])[source]

Set the source aperture size

class sas.sascalc.calculator.instrument.Detector[source]

Bases: object

An object class that defines the detector variables

set_distance(distance=[])[source]

Set the detector distance

set_pix_size(size=[])[source]

Set the detector pix_size

set_size(size=[])[source]

Set the detector size

class sas.sascalc.calculator.instrument.Neutron[source]

Bases: object

An object that defines the wavelength variables

get_band()[source]

To get the wavelength band

get_default_spectrum()[source]

get default spectrum

get_intensity()[source]

To get the value of intensity

get_mass()[source]

To get the neutron mass

get_ramdom_value()[source]

To get the value of wave length

get_spectrum()[source]

To get the wavelength spectrum

get_wavelength()[source]

To get the value of wavelength

get_wavelength_spread()[source]

To get the value of wavelength spread

plot_spectrum()[source]

To plot the wavelength spactrum : requirement: matplotlib.pyplot

set_band(band=[])[source]

To set the wavelength band

Parameters:band – array of [min, max]
set_full_band()[source]

set band to default value

set_intensity(intensity=368428)[source]

Sets the intensity in counts/sec

set_mass(mass=1.67492729e-24)[source]

Sets the wavelength

set_spectrum(spectrum)[source]

Set spectrum

Parameters:spectrum – numpy array
set_wavelength(wavelength=6.0)[source]

Sets the wavelength

set_wavelength_spread(spread=0.125)[source]

Sets the wavelength spread

setup_spectrum()[source]

To set the wavelength spectrum, and intensity, assumes wavelength is already within the spectrum

class sas.sascalc.calculator.instrument.Sample[source]

Bases: object

An object class that defines the sample variables

set_distance(distance=[])[source]

Set the sample distance

set_size(size=[])[source]

Set the sample size

set_thickness(thickness=0.0)[source]

Set the sample thickness

class sas.sascalc.calculator.instrument.TOF[source]

Bases: sas.sascalc.calculator.instrument.Neutron

TOF: make list of wavelength and wave length spreads

get_intensity_list()[source]

get list of the intensity wrt wavelength_list

get_wave_list()[source]

Get wavelength and wavelength_spread list

set_wave_list(wavelength=[])[source]

Set wavelength list

Parameters:wavelength – list of wavelengths
set_wave_spread_list(wavelength_spread=[])[source]

Set wavelength_spread list

Parameters:wavelength_spread – list of wavelength spreads
sas.sascalc.calculator.instrument.validate(value=None)[source]

Check if the value is folat > 0.0

Return value:True / False

sas.sascalc.calculator.kiessig_calculator module

This module is a small tool to allow user to quickly determine the size value in real space from the fringe width in q space.

class sas.sascalc.calculator.kiessig_calculator.KiessigThicknessCalculator[source]

Bases: object

compute thickness from the fringe width of data

compute_thickness()[source]

Calculate thickness.

Returns:the thickness.
get_deltaq()[source]

return deltaQ value in 1/A unit

get_thickness_unit()[source]
Returns:the thickness unit.
set_deltaq(dq=None)[source]

Receive deltaQ value

Parameters:dq – q fringe width in 1/A unit

sas.sascalc.calculator.resolution_calculator module

This object is a small tool to allow user to quickly determine the variance in q from the instrumental parameters.

class sas.sascalc.calculator.resolution_calculator.ResolutionCalculator[source]

Bases: object

compute resolution in 2D

compute(wavelength, wavelength_spread, qx_value, qy_value, coord='cartesian', tof=False)[source]

Compute the Q resoltuion in || and + direction of 2D : qx_value: x component of q : qy_value: y component of q

compute_and_plot(qx_value, qy_value, qx_min, qx_max, qy_min, qy_max, coord='cartesian')[source]

Compute the resolution : qx_value: x component of q : qy_value: y component of q

get_all_instrument_params()[source]

Get all instrumental parameters

get_default_spectrum()[source]

Get default_spectrum

get_detector_pix_size()[source]

Get detector pixel size

get_detector_qrange()[source]

get max detector q ranges

: return: qx_min, qx_max, qy_min, qy_max tuple

get_detector_size()[source]

Get detector size

get_image(qx_value, qy_value, sigma_1, sigma_2, sigma_r, qx_min, qx_max, qy_min, qy_max, coord='cartesian', full_cal=True)[source]

Get the resolution in polar coordinate ready to plot : qx_value: qx_value value : qy_value: qy_value value : sigma_1: variance in r direction : sigma_2: variance in phi direction : coord: coordinate system of image, ‘polar’ or ‘cartesian’

get_intensity()[source]

Get intensity

get_intensity_list()[source]

Set wavelength spread

get_neutron_mass()[source]

Get Neutron mass

get_sample2detector_distance()[source]

Get detector sample2detector_distance

get_sample2sample_distance()[source]

Get detector sampleslitsample_distance

get_sample_aperture_size()[source]

Get sample aperture size

get_source2sample_distance()[source]

Get detector source2sample_distance

get_source_aperture_size()[source]

Get source aperture size

get_spectrum()[source]

Get _spectrum

get_variance(size=[], distance=0, phi=0, comp='radial')[source]

Get the variance when the slit/pinhole size is given : size: list that can be one(diameter for circular) or two components(lengths for rectangular) : distance: [z, x] where z along the incident beam, x // qx_value : comp: direction of the sigma; can be ‘phi’, ‘y’, ‘x’, and ‘radial’

: return variance: sigma^2

get_variance_gravity(s_distance, d_distance, wavelength, spread, phi, comp='radial', switch='on')[source]

Get the variance from gravity when the wavelength spread is given

: s_distance: source to sample distance : d_distance: sample to detector distance : wavelength: wavelength : spread: wavelength spread (ratio) : comp: direction of the sigma; can be ‘phi’, ‘y’, ‘x’, and ‘radial’

: return variance: sigma^2

get_variance_wave(A_value, radius, distance, spread, phi, comp='radial', switch='on')[source]

Get the variance when the wavelength spread is given

: radius: the radial distance from the beam center to the pix of q : distance: sample to detector distance : spread: wavelength spread (ratio) : comp: direction of the sigma; can be ‘phi’, ‘y’, ‘x’, and ‘radial’

: return variance: sigma^2 for 2d, sigma^2 for 1d [tuple]

get_wave_list()[source]

Set wavelength spread

get_wavelength()[source]

Get wavelength

get_wavelength_spread()[source]

Get wavelength spread

plot_image(image)[source]

Plot image using pyplot : image: 2d resolution image

: return plt: pylab object

reset_image()[source]

Reset image to default (=[])

set_detector_pix_size(size)[source]

Set detector pixel size

set_detector_size(size)[source]

Set detector size in number of pixels : param size: [pixel_nums] or [x_pix_num, yx_pix_num]

set_intensity(intensity)[source]

Set intensity

set_neutron_mass(mass)[source]

Set Neutron mass

set_sample2detector_distance(distance)[source]

Set detector sample2detector_distance

: param distance: [distance, x_offset]

set_sample2sample_distance(distance)[source]

Set detector sample_slit2sample_distance

: param distance: [distance, x_offset]

set_sample_aperture_size(size)[source]

Set sample aperture size

: param size: [dia_value] or [xheight_value, yheight_value]

set_source2sample_distance(distance)[source]

Set detector source2sample_distance

: param distance: [distance, x_offset]

set_source_aperture_size(size)[source]

Set source aperture size

: param size: [dia_value] or [x_value, y_value]

set_spectrum(spectrum)[source]

Set spectrum

set_wave(wavelength)[source]

Set wavelength list or wavelength

set_wave_list(wavelength_list, wavelengthspread_list)[source]

Set wavelength and its spread list

set_wave_spread(wavelength_spread)[source]

Set wavelength spread or wavelength spread

set_wavelength(wavelength)[source]

Set wavelength

set_wavelength_spread(wavelength_spread)[source]

Set wavelength spread

setup_tof(wavelength, wavelength_spread)[source]

Setup all parameters in instrument

: param ind: index of lambda, etc

sas.sascalc.calculator.sas_gen module

SAS generic computation and sld file readers.

Calculation checked by sampling from an ellipsoid and comparing Iq with the 1D, 2D oriented and 2D oriented magnetic analytical model from sasmodels.

class sas.sascalc.calculator.sas_gen.GenSAS[source]

Bases: object

Generic SAS computation Model based on sld (n & m) arrays

calculate_Iq(qx, qy=None)[source]

Evaluate the function :Param x: array of x-values :Param y: array of y-values :return: function value

evalDistribution(qdist)[source]

Evaluate a distribution of q-values.

Parameters:qdist – ndarray of scalar q-values (for 1D) or list [qx,qy] where qx,qy are 1D ndarrays (for 2D).
getProfile()[source]

Get SLD profile : return: sld_data

run(x=0.0)[source]

Evaluate the model :param x: simple value :return: (I value)

runXY(x=0.0)[source]

Evaluate the model :param x: simple value :return: I value :Use this runXY() for the computation

set_is_avg(is_avg=False)[source]

Sets is_avg: [bool]

set_pixel_volumes(volume)[source]

Set the volume of a pixel in (A^3) unit :Param volume: pixel volume [float]

set_sld_data(sld_data=None)[source]

Sets sld_data

class sas.sascalc.calculator.sas_gen.MagSLD(pos_x, pos_y, pos_z, sld_n=None, sld_mx=None, sld_my=None, sld_mz=None, vol_pix=None)[source]

Bases: object

Magnetic SLD.

get_sldn()[source]

Returns nuclear sld

pos_x = None
pos_y = None
pos_z = None
set_conect_lines(line_x, line_y, line_z)[source]

Set bonding line data if taken from pdb

set_nodes()[source]

Set xnodes, ynodes, and znodes

set_pix_type(pix_type)[source]

Set pixel type :Param pix_type: string, ‘pixel’ or ‘atom’

set_pixel_symbols(symbol='pixel')[source]

Set pixel :Params pixel: str; pixel or atomic symbol, or array of strings

set_pixel_volumes(vol)[source]

Set pixel volumes :Params pixel: str; pixel or atomic symbol, or array of strings

set_sldms(sld_mx, sld_my, sld_mz)[source]

Sets mx, my, mz and abs(m).

set_sldn(sld_n)[source]

Sets neutron SLD.

Warning: if sld_n is a scalar and attribute is_data is True, then only pixels with non-zero magnetism will be set.

set_stepsize()[source]

Set xtepsize, ystepsize, and zstepsize

sld_mx = None
sld_my = None
sld_mz = None
sld_n = None
class sas.sascalc.calculator.sas_gen.OMF2SLD[source]

Bases: object

Convert OMFData to MAgData

get_magsld()[source]

return MagSLD

get_omfdata()[source]

Return all data

get_output()[source]

Return output

remove_null_points(remove=False, recenter=False)[source]

Removes any mx, my, and mz = 0 points

set_data(omfdata, shape='rectangular')[source]

Set all data

class sas.sascalc.calculator.sas_gen.OMFData[source]

Bases: object

OMF Data.

set_m(mx, my, mz)[source]

Set the Mx, My, Mz values

class sas.sascalc.calculator.sas_gen.OMFReader[source]

Bases: object

Class to load omf/ascii files (3 columns w/header).

ext = ['.omf', '.OMF']
read(path)[source]

Load data file :param path: file path :return: x, y, z, sld_n, sld_mx, sld_my, sld_mz

type = ['OMF files (*.OMF, *.omf)|*.omf']
type_name = 'OMF ASCII'
class sas.sascalc.calculator.sas_gen.PDBReader[source]

Bases: object

PDB reader class: limited for reading the lines starting with ‘ATOM’

ext = ['.pdb', '.PDB']
read(path)[source]

Load data file

Parameters:path – file path
Returns:MagSLD
Raises:RuntimeError – when the file can’t be opened
type = ['pdb files (*.PDB, *.pdb)|*.pdb']
type_name = 'PDB'
write(path, data)[source]

Write

class sas.sascalc.calculator.sas_gen.SLDReader[source]

Bases: object

SLD reader for text files.

7 columns: x, y, z, sld, mx, my, mz 8 columns: x, y, z, sld, mx, my, mz, volume

ext = ['.sld', '.SLD', '.txt', '.TXT', '.*']
read(path)[source]

Load data file :param path: file path :return MagSLD: x, y, z, sld_n, sld_mx, sld_my, sld_mz :raise RuntimeError: when the file can’t be loaded

type = ['sld files (*.SLD, *.sld)|*.sld', 'txt files (*.TXT, *.txt)|*.txt', 'all files (*.*)|*.*']
type_name = 'SLD ASCII'
write(path, data)[source]

Write sld file :Param path: file path :Param data: MagSLD data object

sas.sascalc.calculator.sas_gen.compare(obj, qx, qy=None, plot_points=False, theory=None)[source]

Compare GenSAS calculator obj to old C and sasmodels versions.

theory is the I(q) value for the shape, if known.

sas.sascalc.calculator.sas_gen.decode(s)[source]
sas.sascalc.calculator.sas_gen.demo()[source]

Run a GenSAS operation demo.

sas.sascalc.calculator.sas_gen.demo_load()[source]

Check loading of coordinate data.

sas.sascalc.calculator.sas_gen.demo_oommf()[source]

Calculate theory from saved OOMMF magnetic data.

sas.sascalc.calculator.sas_gen.demo_pdb(is_avg=False)[source]

Calculation I(q) for object in pdb file.

sas.sascalc.calculator.sas_gen.demo_save()[source]

Check saving of coordinate data.

sas.sascalc.calculator.sas_gen.demo_shape(shape='ellip', samples=2000, nq=100, view=(60, 30, 0), qmax=0.5, use_2d=False, **kw)[source]

Sample from shape with analytic model.

shape is one of the shapes from sasmodels/explore/realspace.py

samples is the number of sample points

view is the rotation angle for the shape

qmax is the max q value

use_2d produces a 2D shape rather

Remaining keywords are specific to the shape. See def build_SHAPE(…) in realspace.py for details.

sas.sascalc.calculator.sas_gen.mag2sld(mag, v_unit=None)[source]

Convert magnetization to magnatic SLD sldm = Dm * mag where Dm = gamma * classical elec. radius/(2*Bohr magneton) Dm ~ 2.853E-12 [A^(-2)] ==> Shouldn’t be 2.90636E-12 [A^(-2)]???

sas.sascalc.calculator.sas_gen.realspace_Iq(self, qx, qy)[source]

Compute Iq for GenSAS object using sasmodels/explore/realspace.py

sas.sascalc.calculator.sas_gen.sas_gen_c(self, qx, qy=None)[source]

C interface to sas_gen, for comparison to new python interface.

Note: this requires the old C implementation which may have already been removed from the repository.

sas.sascalc.calculator.sas_gen.set_axis_equal_3D(ax)[source]

Set equal axes on a 3D plot.

sas.sascalc.calculator.sas_gen.test()[source]

Check that the GenSAS can load coordinates and compute I(q).

sas.sascalc.calculator.sas_gen.transform_center(pos_x, pos_y, pos_z)[source]

re-center :return: posx, posy, posz [arrays]

sas.sascalc.calculator.slit_length_calculator module

This module is a small tool to allow user to quickly determine the slit length value of data.

class sas.sascalc.calculator.slit_length_calculator.SlitlengthCalculator[source]

Bases: object

compute slit length from SAXSess beam profile (1st col. Q , 2nd col. I , and 3rd col. dI.: don’t need the 3rd)

calculate_slit_length()[source]

Calculate slit length.

Returns:the slit length calculated value.
get_slit_length_unit()[source]
Returns:the slit length unit.
set_data(x=None, y=None)[source]
Receive two vector x, y and prepare the slit calculator for computation.
Parameters:
  • x – array
  • y – array

Module contents