sas.sascalc.dataloader package

Submodules

sas.sascalc.dataloader.data_info module

Module that contains classes to hold information read from reduced data files.

A good description of the data members can be found in the CanSAS 1D XML data format:

http://www.smallangles.net/wgwiki/index.php/cansas1d_documentation

class sas.sascalc.dataloader.data_info.Aperture[source]

Bases: object

distance = None
distance_unit = 'mm'
name = None
size = None
size_name = None
size_unit = 'mm'
type = None
class sas.sascalc.dataloader.data_info.Collimation[source]

Bases: object

Class to hold collimation information

aperture = None
length = None
length_unit = 'mm'
name = None
class sas.sascalc.dataloader.data_info.Data1D(x=None, y=None, dx=None, dy=None, lam=None, dlam=None, isSesans=None)[source]

Bases: sas.sascalc.dataloader.data_info.plottable_1D, sas.sascalc.dataloader.data_info.DataInfo

1D data class

clone_without_data(length=0, clone=None)[source]

Clone the current object, without copying the data (which will be filled out by a subsequent operation). The data arrays will be initialized to zero.

Parameters:
  • length – length of the data array to be initialized
  • clone – if provided, the data will be copied to clone
is_slit_smeared()[source]

Check whether the data has slit smearing information :return: True is slit smearing info is present, False otherwise

class sas.sascalc.dataloader.data_info.Data2D(data=None, err_data=None, qx_data=None, qy_data=None, q_data=None, mask=None, dqx_data=None, dqy_data=None)[source]

Bases: sas.sascalc.dataloader.data_info.plottable_2D, sas.sascalc.dataloader.data_info.DataInfo

2D data class

I_unit = '1/cm'
Q_unit = '1/A'
clone_without_data(length=0, clone=None)[source]

Clone the current object, without copying the data (which will be filled out by a subsequent operation). The data arrays will be initialized to zero.

Parameters:
  • length – length of the data array to be initialized
  • clone – if provided, the data will be copied to clone
isSesans = False
x_bins = None
y_bins = None
class sas.sascalc.dataloader.data_info.DataInfo[source]

Bases: object

Class to hold the data read from a file. It includes four blocks of data for the instrument description, the sample description, the data itself and any other meta data.

add_notes(message='')[source]

Add notes to datainfo

append_empty_process()[source]
collimation = None
detector = None
errors = None
filename = ''
instrument = ''
isSesans = None
meta_data = None
notes = None
process = None
run = None
run_name = None
sample = None
source = None
title = ''
trans_spectrum = None
class sas.sascalc.dataloader.data_info.Detector[source]

Bases: object

Class to hold detector information

beam_center = None
beam_center_unit = 'mm'
distance = None
distance_unit = 'mm'
name = None
offset = None
offset_unit = 'm'
orientation = None
orientation_unit = 'degree'
pixel_size = None
pixel_size_unit = 'mm'
slit_length = None
slit_length_unit = 'mm'
class sas.sascalc.dataloader.data_info.Process[source]

Bases: object

Class that holds information about the processes performed on the data.

date = ''
description = ''
is_empty()[source]

Return True if the object is empty

name = ''
notes = None
single_line_desc()[source]

Return a single line string representing the process

term = None
class sas.sascalc.dataloader.data_info.Sample[source]

Bases: object

Class to hold the sample description

ID = ''
details = None
name = ''
orientation = None
orientation_unit = 'degree'
position = None
position_unit = 'mm'
temperature = None
temperature_unit = None
thickness = None
thickness_unit = 'mm'
transmission = None
zacceptance = None
class sas.sascalc.dataloader.data_info.Source[source]

Bases: object

Class to hold source information

beam_shape = None
beam_size = None
beam_size_name = None
beam_size_unit = 'mm'
name = None
radiation = None
wavelength = None
wavelength_max = None
wavelength_max_unit = 'nm'
wavelength_min = None
wavelength_min_unit = 'nm'
wavelength_spread = None
wavelength_spread_unit = 'percent'
wavelength_unit = 'A'
class sas.sascalc.dataloader.data_info.TransmissionSpectrum[source]

Bases: object

Class that holds information about transmission spectrum for white beams and spallation sources.

name = ''
timestamp = ''
transmission = None
transmission_deviation = None
transmission_deviation_unit = ''
transmission_unit = ''
wavelength = None
wavelength_unit = 'A'
class sas.sascalc.dataloader.data_info.Vector(x=None, y=None, z=None)[source]

Bases: object

Vector class to hold multi-dimensional objects

x = None
y = None
z = None
sas.sascalc.dataloader.data_info.combine_data_info_with_plottable(data, datainfo)[source]

A function that combines the DataInfo data in self.current_datainto with a plottable_1D or 2D data object.

Parameters:data – A plottable_1D or plottable_2D data object
Returns:A fully specified Data1D or Data2D object
class sas.sascalc.dataloader.data_info.plottable_1D(x, y, dx=None, dy=None, dxl=None, dxw=None, lam=None, dlam=None)[source]

Bases: object

Data1D is a place holder for 1D plottables.

dlam = None
dx = None
dxl = None
dxw = None
dy = None
lam = None
x = None
xaxis(label, unit)[source]

set the x axis label and unit

y = None
yaxis(label, unit)[source]

set the y axis label and unit

class sas.sascalc.dataloader.data_info.plottable_2D(data=None, err_data=None, qx_data=None, qy_data=None, q_data=None, mask=None, dqx_data=None, dqy_data=None)[source]

Bases: object

Data2D is a place holder for 2D plottables.

data = None
dqx_data = None
dqy_data = None
err_data = None
mask = None
q_data = None
qx_data = None
qy_data = None
xaxis(label, unit)[source]

set the x axis label and unit

xmax = None
xmin = None
yaxis(label, unit)[source]

set the y axis label and unit

ymax = None
ymin = None
zaxis(label, unit)[source]

set the z axis label and unit

sas.sascalc.dataloader.loader module

File handler to support different file extensions. Uses reflectometry’s registry utility.

The default readers are found in the ‘readers’ sub-module and registered by default at initialization time.

To add a new default reader, one must register it in the register_readers method found in readers/__init__.py.

A utility method (find_plugins) is available to inspect a directory (for instance, a user plug-in directory) and look for new readers/writers.

class sas.sascalc.dataloader.loader.Loader[source]

Bases: object

Utility class to use the Registry as a singleton.

associate_file_reader(ext, loader)[source]

Append a reader object to readers

Parameters:
  • ext – file extension [string]
  • module – reader object
associate_file_type(ext, module)[source]

Look into a module to find whether it contains a Reader class. If so, append it to readers and (potentially) to the list of writers for the given extension

Parameters:
  • ext – file extension [string]
  • module – module object
find_plugins(directory)[source]

Find plugins in a given directory

Parameters:dir – directory to look into to find new readers/writers
get_wildcards()[source]

Return the list of wildcards

load(file, format=None)[source]

Load a file

Parameters:
  • file – file name (path)
  • format – specified format to use (optional)
Returns:

DataInfo object

save(file, data, format)[source]

Save a DataInfo object to file :param file: file name (path) :param data: DataInfo object :param format: format to write the data in

class sas.sascalc.dataloader.loader.Registry[source]

Bases: sas.sascalc.data_util.registry.ExtensionRegistry

Registry class for file format extensions. Readers and writers are supported.

associate_file_reader(ext, loader)[source]

Append a reader object to readers

Parameters:
  • ext – file extension [string]
  • module – reader object
associate_file_type(ext, module)[source]

Look into a module to find whether it contains a Reader class. If so, APPEND it to readers and (potentially) to the list of writers for the given extension

Parameters:
  • ext – file extension [string]
  • module – module object
find_plugins(dir)[source]

Find readers in a given directory. This method can be used to inspect user plug-in directories to find new readers/writers.

Parameters:dir – directory to search into
Returns:number of readers found
load(path, format=None)[source]

Call the loader for the file type of path.

Parameters:
  • path – file path
  • format – explicit extension, to force the use of a particular reader

Defaults to the ascii (multi-column) reader if no reader was registered for the file’s extension.

lookup_writers(path)[source]
Returns:the loader associated with the file type of path.
Raises ValueError:
 if file type is not known.
save(path, data, format=None)[source]

Call the writer for the file type of path.

Raises ValueError if no writer is available. Raises KeyError if format is not available. May raise a writer-defined exception if writer fails.

sas.sascalc.dataloader.manipulations module

Data manipulations for 2D data sets. Using the meta data information, various types of averaging are performed in Q-space

class sas.sascalc.dataloader.manipulations.Boxavg(x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0)[source]

Bases: sas.sascalc.dataloader.manipulations.Boxsum

Perform the average of counts in a 2D region of interest.

class sas.sascalc.dataloader.manipulations.Boxcut(x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0)[source]

Bases: object

Find a rectangular 2D region of interest.

class sas.sascalc.dataloader.manipulations.Boxsum(x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0)[source]

Bases: object

Perform the sum of counts in a 2D region of interest.

class sas.sascalc.dataloader.manipulations.CircularAverage(r_min=0.0, r_max=0.0, bin_width=0.0005)[source]

Bases: object

Perform circular averaging on 2D data

The data returned is the distribution of counts as a function of Q

class sas.sascalc.dataloader.manipulations.Ring(r_min=0, r_max=0, center_x=0, center_y=0, nbins=36)[source]

Bases: object

Defines a ring on a 2D data set. The ring is defined by r_min, r_max, and the position of the center of the ring.

The data returned is the distribution of counts around the ring as a function of phi.

Phi_min and phi_max should be defined between 0 and 2*pi in anti-clockwise starting from the x- axis on the left-hand side

class sas.sascalc.dataloader.manipulations.Ringcut(r_min=0, r_max=0, center_x=0, center_y=0)[source]

Bases: object

Defines a ring on a 2D data set. The ring is defined by r_min, r_max, and the position of the center of the ring.

The data returned is the region inside the ring

Phi_min and phi_max should be defined between 0 and 2*pi in anti-clockwise starting from the x- axis on the left-hand side

class sas.sascalc.dataloader.manipulations.SectorPhi(r_min, r_max, phi_min=0, phi_max=6.283185307179586, nbins=20)[source]

Bases: sas.sascalc.dataloader.manipulations._Sector

Sector average as a function of phi. I(phi) is return and the data is averaged over Q.

A sector is defined by r_min, r_max, phi_min, phi_max. The number of bin in phi also has to be defined.

class sas.sascalc.dataloader.manipulations.SectorQ(r_min, r_max, phi_min=0, phi_max=6.283185307179586, nbins=20)[source]

Bases: sas.sascalc.dataloader.manipulations._Sector

Sector average as a function of Q for both symatric wings. I(Q) is return and the data is averaged over phi.

A sector is defined by r_min, r_max, phi_min, phi_max. r_min, r_max, phi_min, phi_max >0. The number of bin in Q also has to be defined.

class sas.sascalc.dataloader.manipulations.Sectorcut(phi_min=0, phi_max=3.141592653589793)[source]

Bases: object

Defines a sector (major + minor) region on a 2D data set. The sector is defined by phi_min, phi_max, where phi_min and phi_max are defined by the right and left lines wrt central line.

Phi_min and phi_max are given in units of radian and (phi_max-phi_min) should not be larger than pi

class sas.sascalc.dataloader.manipulations.SlabX(x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0, bin_width=0.001)[source]

Bases: sas.sascalc.dataloader.manipulations._Slab

Compute average I(Qx) for a region of interest

class sas.sascalc.dataloader.manipulations.SlabY(x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0, bin_width=0.001)[source]

Bases: sas.sascalc.dataloader.manipulations._Slab

Compute average I(Qy) for a region of interest

sas.sascalc.dataloader.manipulations.flip_phi(phi)[source]

Correct phi to within the 0 <= to <= 2pi range

Returns:phi in >=0 and <=2Pi
sas.sascalc.dataloader.manipulations.get_intercept(q, q_0, q_1)[source]

Returns the fraction of the side at which the q-value intercept the pixel, None otherwise. The values returned is the fraction ON THE SIDE OF THE LOWEST Q.

    A           B
+-----------+--------+    <--- pixel size
0                    1
Q_0 -------- Q ----- Q_1   <--- equivalent Q range
if Q_1 > Q_0, A is returned
if Q_1 < Q_0, B is returned
if Q is outside the range of [Q_0, Q_1], None is returned
sas.sascalc.dataloader.manipulations.get_pixel_fraction(qmax, q_00, q_01, q_10, q_11)[source]

Returns the fraction of the pixel defined by the four corners (q_00, q_01, q_10, q_11) that has q < qmax.:

        q_01                q_11
y=1         +--------------+
            |              |
            |              |
            |              |
y=0         +--------------+
        q_00                q_10

            x=0            x=1
sas.sascalc.dataloader.manipulations.get_pixel_fraction_square(x, xmin, xmax)[source]

Return the fraction of the length from xmin to x.:

    A            B
+-----------+---------+
xmin        x         xmax
Parameters:
  • x – x-value
  • xmin – minimum x for the length considered
  • xmax – minimum x for the length considered
Returns:

(x-xmin)/(xmax-xmin) when xmin < x < xmax

sas.sascalc.dataloader.manipulations.get_q(dx, dy, det_dist, wavelength)[source]
Parameters:
  • dx – x-distance from beam center [mm]
  • dy – y-distance from beam center [mm]
Returns:

q-value at the given position

sas.sascalc.dataloader.manipulations.get_q_compo(dx, dy, det_dist, wavelength, compo=None)[source]

This reduces tiny error at very large q. Implementation of this func is not started yet.<–ToDo

sas.sascalc.dataloader.manipulations.reader2D_converter(data2d=None)[source]

convert old 2d format opened by IhorReader or danse_reader to new Data2D format

Parameters:data2d – 2d array of Data2D object
Returns:1d arrays of Data2D object

Module contents