sasdata.dataloader package

Subpackages

Submodules

sasdata.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 sasdata.dataloader.data_info.Aperture

Bases: object

distance = None
distance_unit = 'mm'
name = None
size = None
size_name = None
size_unit = 'mm'
type = None
class sasdata.dataloader.data_info.Collimation

Bases: object

Class to hold collimation information

aperture = None
length = None
length_unit = 'mm'
name = None
class sasdata.dataloader.data_info.Data1D(x=None, y=None, dx=None, dy=None, lam=None, dlam=None, isSesans=False)

Bases: plottable_1D, DataInfo

1D data class

clone_without_data(length=0, clone=None)

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)

copy values of Data1D of type DataLaoder.Data_info

is_slit_smeared()

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

class sasdata.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)

Bases: plottable_2D, DataInfo

2D data class

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

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)

copy value of Data2D of type DataLoader.data_info

isSesans = False
class sasdata.dataloader.data_info.DataInfo

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='')

Add notes to datainfo

append_empty_process()
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 sasdata.dataloader.data_info.Detector

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 sasdata.dataloader.data_info.Process

Bases: object

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

date = ''
description = ''
is_empty()

Return True if the object is empty

name = ''
notes = None
single_line_desc()

Return a single line string representing the process

term = None
class sasdata.dataloader.data_info.Sample

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 sasdata.dataloader.data_info.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 sasdata.dataloader.data_info.TransmissionSpectrum

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 sasdata.dataloader.data_info.Vector(x=None, y=None, z=None)

Bases: object

Vector class to hold multi-dimensional objects

x = None
y = None
z = None
sasdata.dataloader.data_info.combine_data_info_with_plottable(data, datainfo)

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 sasdata.dataloader.data_info.plottable_1D(x, y, dx=None, dy=None, dxl=None, dxw=None, lam=None, dlam=None)

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)

set the x axis label and unit

y = None
yaxis(label, unit)

set the y axis label and unit

class sasdata.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)

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)

set the x axis label and unit

xmax = None
xmin = None
y_bins = None
yaxis(label, unit)

set the y axis label and unit

ymax = None
ymin = None
zaxis(label, unit)

set the z axis label and unit

sasdata.dataloader.filereader 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 sasdata.dataloader.filereader.FileReader

Bases: object

allow_all = False
convert_data_units(default_q_unit: str = '1/A')

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()

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

ext = ['.txt']
format_unit(unit: str = None) str

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

abstract get_file_contents()

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

handle_error_message(msg: str)

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() str

Returns the next line in the file as a string.

nextlines() str

Returns the next line in the file as a string.

read(filepath: str | Path, file_handler: CustomFileOpen | None = None, f_pos: int | None = 0) List[Data1D | Data2D]

Basic file reader

Parameters:
  • filepath – The string representation of the path to a file to be loaded. This can be a URI or a local file

  • file_handler – A CustomFileOpen instance used to handle file operations

  • f_pos – The initial file position to start reading from

Returns:

A list of Data1D and Data2D objects

readall() str

Returns the entire file as a string.

remove_empty_q_values()

Remove any point where Q == 0

reset_data_list(no_lines: int = 0)

Reset the plottable_1D object

reset_state()

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()

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

set_all_to_none()

Set all mutable values to None for error handling purposes

static set_default_1d_units(data: Data1D | Data2D) Data1D | Data2D

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

static set_default_2d_units(data: Data1D | Data2D) Data1D | Data2D

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

sort_data()

Sort 1D data along the X axis for consistency

static splitline(line: str) List[str]

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'
sasdata.dataloader.filereader.decode(s)

sasdata.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 sasdata.dataloader.loader.Loader

Bases: object

Utility class to use the Registry as a singleton.

associate_file_reader(ext: str, loader) bool

Append a reader object to readers :param ext: file extension [string] :param module: reader object

associate_file_type(ext: str, module: ModuleType) bool

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: str) int

Find plugins in a given directory :param directory: directory to look into to find new readers/writers

get_wildcards()

Return the list of wildcards

load(file_path_list: List[str | Path] | str | Path, format: List[str] | str | None = None) List[Data1D | Data2D]

Load a file or series of files :param file_path_list: String representations of any number of file paths. This can either be a list or a string :param format: specified format to use (optional) :return: a list of DataInfo objects and/or loading exceptions.

save(file: str, data, format: str) bool

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

class sasdata.dataloader.loader.Registry

Bases: ExtensionRegistry

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

associate_file_reader(file_extension, reader)

Append a reader object to readers :param file_extension: file extension [string] :param reader: reader object

associate_file_type(ext: str, module: ModuleType) bool

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: str)

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(file_path_list: List[str | Path] | str | Path, ext: List[str] | str | None = None, debug: bool | None = False, use_defaults: bool | None = True)

Call the loader for the file type of path.

Parameters:
  • file_path_list – A list of pathlib.Path objects and/or string representations of file paths

  • ext – A list of explicit extensions, to force the use of a particular reader for a particular file. Usage If any ext is passed, the length of the ext list should be the same as the length of the file path list. A single extention, as a string or a list of length 1, will apply ext to all files in the file path list. Any other case will result in an error.

  • 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.

lookup_writers(path)
Returns:

the loader associated with the file type of path.

Raises ValueError:

if file type is not known.

save(path: str, data, format: str | None = None)

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.

Module contents