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=False)[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
copy_from_datainfo(data1d)[source]

copy values of Data1D of type DataLaoder.Data_info

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, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=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
copy_from_datainfo(data2d)[source]

copy value of Data2D of type DataLoader.data_info

isSesans = False
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
yacceptance = (0, '')
zacceptance = (0, '')
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
probe = None
radiation = None
type = 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
  • datainfo – A DataInfo object to be combined with the plottable
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, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, x_bins=None, y_bins=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
x_bins = None
xaxis(label, unit)[source]

set the x axis label and unit

xmax = None
xmin = None
y_bins = 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.file_reader_base_class module

This is the base file reader class most file readers should inherit from. All generic functionality required for a file loader/reader is built into this class

class sas.sascalc.dataloader.file_reader_base_class.FileReader[source]

Bases: object

allow_all = False
convert_data_units(default_q_unit='1/A')[source]

Converts al; data to the sasview default of units of A^{-1} for Q and cm^{-1} for I. :param default_q_unit: The default Q unit used by Sasview

data_cleanup()[source]

Clean up the data sets and refresh everything :return: None

deprecated_extensions = ['.asc']
ext = ['.txt']
format_unit(unit=None)[source]

Format units a common way :param unit: :return:

get_file_contents()[source]

Reader specific class to access the contents of the file All reader classes that inherit from FileReader must implement

handle_error_message(msg)[source]

Generic error handler to add an error to the current datainfo to propagate the error up the error chain. :param msg: Error message

has_converter = True
nextline()[source]

Returns the next line in the file as a string.

nextlines()[source]

Returns the next line in the file as a string.

read(filepath)[source]

Basic file reader

Parameters:filepath – The full or relative path to a file to be loaded
readall()[source]

Returns the entire file as a string.

remove_empty_q_values()[source]

Remove any point where Q == 0

reset_data_list(no_lines=0)[source]

Reset the plottable_1D object

reset_state()[source]

Resets the class state to a base case when loading a new data file so previous data files do not appear a second time

send_to_output()[source]

Helper that automatically combines the info and set and then appends it to output

set_all_to_none()[source]

Set all mutable values to None for error handling purposes

static set_default_1d_units(data)[source]

Set the x and y axes to the default 1D units :param data: 1D data set :return:

static set_default_2d_units(data)[source]

Set the x and y axes to the default 2D units :param data: 2D data set :return:

sort_data()[source]

Sort 1D data along the X axis for consistency

static splitline(line)[source]

Splits a line into pieces based on common delimiters :param line: A single line of text :return: list of values

type = ['Text files (*.txt|*.TXT)']
type_name = 'ASCII'
sas.sascalc.dataloader.file_reader_base_class.decode(s)[source]

sas.sascalc.dataloader.loader module

File handler to support different file extensions. Uses reflectometer 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 :param ext: file extension [string] :param 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 :param ext: file extension [string] :param module: module object

find_plugins(directory)[source]

Find plugins in a given directory :param 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 :param file: file name (path) :param format: specified format to use (optional) :return: 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 :param ext: file extension [string] :param 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 :param ext: file extension [string] :param 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. :param dir: directory to search into :return: number of readers found

load(path, format=None, debug=False, use_defaults=True)[source]

Call the loader for the file type of path. :param path: file path :param format: explicit extension, to force the use

of a particular reader
Parameters:
  • debug – when True, print the traceback for each loader that fails
  • use_defaults – Flag to use the default readers as a backup if the main reader fails or no reader exists

Defaults to the ascii (multi-column), cansas XML, and cansas NeXuS readers if no reader was registered for the file’s extension.

load_using_generic_loaders(path)[source]

If the expected reader cannot load the file or no known loader exists, attempt to load the file using a few defaults readers :param path: file path :return: List of Data1D and Data2D objects

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.loader_exceptions module

Exceptions specific to loading data.

exception sas.sascalc.dataloader.loader_exceptions.DataReaderException(e=None)[source]

Bases: Exception

Exception for files that were able to mostly load, but had minor issues along the way. Any exceptions of this type should be put into the datainfo.errors

exception sas.sascalc.dataloader.loader_exceptions.DefaultReaderException(e=None)[source]

Bases: Exception

Exception for files with no associated reader. This should be thrown by default readers only to tell Loader to try the next reader.

exception sas.sascalc.dataloader.loader_exceptions.FileContentsException(e=None)[source]

Bases: Exception

Exception for files with an associated reader, but with no loadable data. This is useful for catching loader or file format issues.

exception sas.sascalc.dataloader.loader_exceptions.NoKnownLoaderException(e=None)[source]

Bases: Exception

Exception for files with no associated reader based on the file extension of the loaded file. This exception should only be thrown by loader.py.

sas.sascalc.dataloader.manipulations module

class sas.sascalc.dataloader.manipulations.Binning(min_value, max_value, n_bins, base=None)[source]

Bases: object

This class just creates a binning object either linear or log

get_bin_index(value)[source]

The general formula logarithm binning is: bin = floor(N * (log(x) - log(min)) / (log(max) - log(min)))

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, base=None)[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, base=None)[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_dq_data(data2D)[source]

Get the dq for resolution averaging The pinholes and det. pix contribution present in both direction of the 2D which must be subtracted when converting to 1D: dq_overlap should calculated ideally at q = 0. Note This method works on only pinhole geometry. Extrapolate dqx(r) and dqy(phi) at q = 0, and take an average.

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 This is mainly used by the Readers

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

Module contents