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

__dict__ = mappingproxy({'__module__': 'sasdata.dataloader.data_info', 'name': None, 'type': None, 'size_name': None, 'size': None, 'size_unit': 'mm', 'distance': None, 'distance_unit': 'mm', '__init__': <function Aperture.__init__>, '__dict__': <attribute '__dict__' of 'Aperture' objects>, '__weakref__': <attribute '__weakref__' of 'Aperture' objects>, '__doc__': None, '__annotations__': {}})
__doc__ = None
__init__()
__module__ = 'sasdata.dataloader.data_info'
__weakref__

list of weak references to the 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

__dict__ = mappingproxy({'__module__': 'sasdata.dataloader.data_info', '__doc__': '\n    Class to hold collimation information\n    ', 'name': None, 'length': None, 'length_unit': 'mm', 'aperture': None, '__init__': <function Collimation.__init__>, '__str__': <function Collimation.__str__>, '__dict__': <attribute '__dict__' of 'Collimation' objects>, '__weakref__': <attribute '__weakref__' of 'Collimation' objects>, '__annotations__': {}})
__doc__ = '\n    Class to hold collimation information\n    '
__init__()
__module__ = 'sasdata.dataloader.data_info'
__str__()

Return str(self).

__weakref__

list of weak references to the object

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

__doc__ = '\n    1D data class\n    '
__init__(x=None, y=None, dx=None, dy=None, lam=None, dlam=None, isSesans=False)

Initialization

__module__ = 'sasdata.dataloader.data_info'
__str__()

Nice printout

_perform_operation(other, operation)
_perform_union(other)
_validity_check(other)

Checks that the data lengths are compatible. Checks that the x vectors are compatible. Returns errors vectors equal to original errors vectors if they were present or vectors of zeros when none was found.

Parameters:

other – other data set for operation

Returns:

dy for self, dy for other [numpy arrays]

Raises:

ValueError – when lengths are not compatible

_validity_check_union(other)

Checks that the data lengths are compatible. Checks that the x vectors are compatible. Returns errors vectors equal to original errors vectors if they were present or vectors of zeros when none was found.

Parameters:

other – other data set for operation

Returns:

bool

Raises:

ValueError – when data types are not compatible

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'
__annotations__ = {}
__doc__ = '\n    2D data class\n    '
__init__(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)

Initialization

__module__ = 'sasdata.dataloader.data_info'
__str__()

Return str(self).

_perform_operation(other, operation)

Perform 2D operations between data sets

Parameters:
  • other – other data set

  • operation – function defining the operation

_perform_union(other)

Perform 2D operations between data sets

Parameters:
  • other – other data set

  • operation – function defining the operation

_validity_check(other)

Checks that the data lengths are compatible. Checks that the x vectors are compatible. Returns errors vectors equal to original errors vectors if they were present or vectors of zeros when none was found.

Parameters:

other – other data set for operation

Returns:

dy for self, dy for other [numpy arrays]

Raises:

ValueError – when lengths are not compatible

static _validity_check_union(self, other)

Checks that the data lengths are compatible. Checks that the x vectors are compatible. Returns errors vectors equal to original errors vectors if they were present or vectors of zeros when none was found.

Parameters:

other – other data set for operation

Returns:

bool

Raises:

ValueError – when data types are not compatible

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

Add two data sets

Parameters:

other – data set to add to the current one

Returns:

new data set

Raises:

ValueError – raised when two data sets are incompatible

__annotations__ = {}
__dict__ = mappingproxy({'__module__': 'sasdata.dataloader.data_info', '__doc__': '\n    Class to hold the data read from a file.\n    It includes four blocks of data for the\n    instrument description, the sample description,\n    the data itself and any other meta data.\n    ', 'title': '', 'run': None, 'run_name': None, 'filename': '', 'notes': None, 'process': None, 'instrument': '', 'detector': None, 'sample': None, 'source': None, 'collimation': None, 'trans_spectrum': None, 'meta_data': None, 'errors': None, 'isSesans': None, '__init__': <function DataInfo.__init__>, 'append_empty_process': <function DataInfo.append_empty_process>, 'add_notes': <function DataInfo.add_notes>, '__str__': <function DataInfo.__str__>, '_perform_operation': <function DataInfo._perform_operation>, '_perform_union': <function DataInfo._perform_union>, '__add__': <function DataInfo.__add__>, '__radd__': <function DataInfo.__radd__>, '__sub__': <function DataInfo.__sub__>, '__rsub__': <function DataInfo.__rsub__>, '__mul__': <function DataInfo.__mul__>, '__rmul__': <function DataInfo.__rmul__>, '__truediv__': <function DataInfo.__truediv__>, '__div__': <function DataInfo.__truediv__>, '__rtruediv__': <function DataInfo.__rtruediv__>, '__rdiv__': <function DataInfo.__rtruediv__>, '__or__': <function DataInfo.__or__>, '__ror__': <function DataInfo.__ror__>, '__dict__': <attribute '__dict__' of 'DataInfo' objects>, '__weakref__': <attribute '__weakref__' of 'DataInfo' objects>, '__annotations__': {}})
__div__(other)

Divided a data set by another

Parameters:

other – data set that the current one is divided by

Returns:

new data set

Raises:

ValueError – raised when two data sets are incompatible

__doc__ = '\n    Class to hold the data read from a file.\n    It includes four blocks of data for the\n    instrument description, the sample description,\n    the data itself and any other meta data.\n    '
__init__()

Initialization

__module__ = 'sasdata.dataloader.data_info'
__mul__(other)

Multiply two data sets

Parameters:

other – data set to subtract from the current one

Returns:

new data set

Raises:

ValueError – raised when two data sets are incompatible

__or__(other)

Union a data set with another

Parameters:

other – data set to be unified

Returns:

new data set

Raises:

ValueError – raised when two data sets are incompatible

__radd__(other)

Add two data sets

Parameters:

other – data set to add to the current one

Returns:

new data set

Raises:

ValueError – raised when two data sets are incompatible

__rdiv__(other)

Divided a data set by another

Parameters:

other – data set that the current one is divided by

Returns:

new data set

Raises:

ValueError – raised when two data sets are incompatible

__rmul__(other)

Multiply two data sets

Parameters:

other – data set to subtract from the current one

Returns:

new data set

Raises:

ValueError – raised when two data sets are incompatible

__ror__(other)

Union a data set with another

Parameters:

other – data set to be unified

Returns:

new data set

Raises:

ValueError – raised when two data sets are incompatible

__rsub__(other)

Subtract two data sets

Parameters:

other – data set to subtract from the current one

Returns:

new data set

Raises:

ValueError – raised when two data sets are incompatible

__rtruediv__(other)

Divided a data set by another

Parameters:

other – data set that the current one is divided by

Returns:

new data set

Raises:

ValueError – raised when two data sets are incompatible

__str__()

Nice printout

__sub__(other)

Subtract two data sets

Parameters:

other – data set to subtract from the current one

Returns:

new data set

Raises:

ValueError – raised when two data sets are incompatible

__truediv__(other)

Divided a data set by another

Parameters:

other – data set that the current one is divided by

Returns:

new data set

Raises:

ValueError – raised when two data sets are incompatible

__weakref__

list of weak references to the object

_perform_operation(other, operation)

Private method to perform operation. Not implemented for DataInfo, but should be implemented for each data class inherited from DataInfo that holds actual data (ex.: Data1D)

_perform_union(other)

Private method to perform union operation. Not implemented for DataInfo, but should be implemented for each data class inherited from DataInfo that holds actual data (ex.: Data1D)

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

__dict__ = mappingproxy({'__module__': 'sasdata.dataloader.data_info', '__doc__': '\n    Class to hold detector information\n    ', 'name': None, 'distance': None, 'distance_unit': 'mm', 'offset': None, 'offset_unit': 'm', 'orientation': None, 'orientation_unit': 'degree', 'beam_center': None, 'beam_center_unit': 'mm', 'pixel_size': None, 'pixel_size_unit': 'mm', 'slit_length': None, 'slit_length_unit': 'mm', '__init__': <function Detector.__init__>, '__str__': <function Detector.__str__>, '__dict__': <attribute '__dict__' of 'Detector' objects>, '__weakref__': <attribute '__weakref__' of 'Detector' objects>, '__annotations__': {}})
__doc__ = '\n    Class to hold detector information\n    '
__init__()

Initialize class attribute that are objects…

__module__ = 'sasdata.dataloader.data_info'
__str__()

Return str(self).

__weakref__

list of weak references to the object

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.

__dict__ = mappingproxy({'__module__': 'sasdata.dataloader.data_info', '__doc__': '\n    Class that holds information about the processes\n    performed on the data.\n    ', 'name': '', 'date': '', 'description': '', 'term': None, 'notes': None, '__init__': <function Process.__init__>, 'is_empty': <function Process.is_empty>, 'single_line_desc': <function Process.single_line_desc>, '__str__': <function Process.__str__>, '__dict__': <attribute '__dict__' of 'Process' objects>, '__weakref__': <attribute '__weakref__' of 'Process' objects>, '__annotations__': {}})
__doc__ = '\n    Class that holds information about the processes\n    performed on the data.\n    '
__init__()
__module__ = 'sasdata.dataloader.data_info'
__str__()

Return str(self).

__weakref__

list of weak references to the object

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 = ''
__dict__ = mappingproxy({'__module__': 'sasdata.dataloader.data_info', '__doc__': '\n    Class to hold the sample description\n    ', 'name': '', 'ID': '', 'thickness': None, 'thickness_unit': 'mm', 'transmission': None, 'temperature': None, 'temperature_unit': None, 'position': None, 'position_unit': 'mm', 'orientation': None, 'orientation_unit': 'degree', 'details': None, 'zacceptance': (0, ''), 'yacceptance': (0, ''), '__init__': <function Sample.__init__>, '__str__': <function Sample.__str__>, '__dict__': <attribute '__dict__' of 'Sample' objects>, '__weakref__': <attribute '__weakref__' of 'Sample' objects>, '__annotations__': {}})
__doc__ = '\n    Class to hold the sample description\n    '
__init__()
__module__ = 'sasdata.dataloader.data_info'
__str__()

Return str(self).

__weakref__

list of weak references to the object

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

__dict__ = mappingproxy({'__module__': 'sasdata.dataloader.data_info', '__doc__': '\n    Class to hold source information\n    ', 'name': None, 'radiation': None, 'type': None, 'probe': None, 'beam_size_name': None, 'beam_size': None, 'beam_size_unit': 'mm', 'beam_shape': None, 'wavelength': None, 'wavelength_unit': 'A', 'wavelength_min': None, 'wavelength_min_unit': 'nm', 'wavelength_max': None, 'wavelength_max_unit': 'nm', 'wavelength_spread': None, 'wavelength_spread_unit': 'percent', '__init__': <function Source.__init__>, '__str__': <function Source.__str__>, '__dict__': <attribute '__dict__' of 'Source' objects>, '__weakref__': <attribute '__weakref__' of 'Source' objects>, '__annotations__': {}})
__doc__ = '\n    Class to hold source information\n    '
__init__()
__module__ = 'sasdata.dataloader.data_info'
__str__()

Return str(self).

__weakref__

list of weak references to the object

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.

__dict__ = mappingproxy({'__module__': 'sasdata.dataloader.data_info', '__doc__': '\n    Class that holds information about transmission spectrum\n    for white beams and spallation sources.\n    ', 'name': '', 'timestamp': '', 'wavelength': None, 'wavelength_unit': 'A', 'transmission': None, 'transmission_unit': '', 'transmission_deviation': None, 'transmission_deviation_unit': '', '__init__': <function TransmissionSpectrum.__init__>, '__str__': <function TransmissionSpectrum.__str__>, '__dict__': <attribute '__dict__' of 'TransmissionSpectrum' objects>, '__weakref__': <attribute '__weakref__' of 'TransmissionSpectrum' objects>, '__annotations__': {}})
__doc__ = '\n    Class that holds information about transmission spectrum\n    for white beams and spallation sources.\n    '
__init__()
__module__ = 'sasdata.dataloader.data_info'
__str__()

Return str(self).

__weakref__

list of weak references to the object

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

__dict__ = mappingproxy({'__module__': 'sasdata.dataloader.data_info', '__doc__': '\n    Vector class to hold multi-dimensional objects\n    ', 'x': None, 'y': None, 'z': None, '__init__': <function Vector.__init__>, '__str__': <function Vector.__str__>, '__dict__': <attribute '__dict__' of 'Vector' objects>, '__weakref__': <attribute '__weakref__' of 'Vector' objects>, '__annotations__': {}})
__doc__ = '\n    Vector class to hold multi-dimensional objects\n    '
__init__(x=None, y=None, z=None)

Initialization. Components that are not set a set to None by default.

Parameters:
  • x – x component

  • y – y component

  • z – z component

__module__ = 'sasdata.dataloader.data_info'
__str__()

Return str(self).

__weakref__

list of weak references to the object

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.

__annotations__ = {}
__dict__ = mappingproxy({'__module__': 'sasdata.dataloader.data_info', '__doc__': '\n    Data1D is a place holder for 1D plottables.\n    ', 'x': None, 'y': None, 'dx': None, 'dy': None, 'dxl': None, 'dxw': None, 'lam': None, 'dlam': None, '_xaxis': '', '_xunit': '', '_yaxis': '', '_yunit': '', '__init__': <function plottable_1D.__init__>, 'xaxis': <function plottable_1D.xaxis>, 'yaxis': <function plottable_1D.yaxis>, '__dict__': <attribute '__dict__' of 'plottable_1D' objects>, '__weakref__': <attribute '__weakref__' of 'plottable_1D' objects>, '__annotations__': {}})
__doc__ = '\n    Data1D is a place holder for 1D plottables.\n    '
__init__(x, y, dx=None, dy=None, dxl=None, dxw=None, lam=None, dlam=None)
__module__ = 'sasdata.dataloader.data_info'
__weakref__

list of weak references to the object

_xaxis = ''
_xunit = ''
_yaxis = ''
_yunit = ''
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.

__annotations__ = {}
__dict__ = mappingproxy({'__module__': 'sasdata.dataloader.data_info', '__doc__': '\n    Data2D is a place holder for 2D plottables.\n    ', 'xmin': None, 'xmax': None, 'ymin': None, 'ymax': None, 'data': None, 'qx_data': None, 'qy_data': None, 'q_data': None, 'err_data': None, 'dqx_data': None, 'dqy_data': None, 'mask': None, 'x_bins': None, 'y_bins': None, '_xaxis': '', '_xunit': '', '_yaxis': '', '_yunit': '', '_zaxis': '', '_zunit': '', '__init__': <function plottable_2D.__init__>, 'xaxis': <function plottable_2D.xaxis>, 'yaxis': <function plottable_2D.yaxis>, 'zaxis': <function plottable_2D.zaxis>, '__dict__': <attribute '__dict__' of 'plottable_2D' objects>, '__weakref__': <attribute '__weakref__' of 'plottable_2D' objects>, '__annotations__': {}})
__doc__ = '\n    Data2D is a place holder for 2D plottables.\n    '
__init__(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)
__module__ = 'sasdata.dataloader.data_info'
__weakref__

list of weak references to the object

_xaxis = ''
_xunit = ''
_yaxis = ''
_yunit = ''
_zaxis = ''
_zunit = ''
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

__dict__ = mappingproxy({'__module__': 'sasdata.dataloader.filereader', 'type_name': 'ASCII', 'type': ['Text files (*.txt|*.TXT)'], 'ext': ['.txt'], 'allow_all': False, 'has_converter': True, '__init__': <function FileReader.__init__>, 'read': <function FileReader.read>, '_read': <function FileReader._read>, 'reset_state': <function FileReader.reset_state>, 'nextline': <function FileReader.nextline>, 'nextlines': <function FileReader.nextlines>, 'readall': <function FileReader.readall>, 'handle_error_message': <function FileReader.handle_error_message>, 'send_to_output': <function FileReader.send_to_output>, 'sort_data': <function FileReader.sort_data>, '_reorder_1d_array': <staticmethod(<function FileReader._reorder_1d_array>)>, '_remove_nans_in_data': <staticmethod(<function FileReader._remove_nans_in_data>)>, 'set_default_1d_units': <staticmethod(<function FileReader.set_default_1d_units>)>, 'set_default_2d_units': <staticmethod(<function FileReader.set_default_2d_units>)>, 'convert_data_units': <function FileReader.convert_data_units>, 'format_unit': <function FileReader.format_unit>, 'set_all_to_none': <function FileReader.set_all_to_none>, 'data_cleanup': <function FileReader.data_cleanup>, 'remove_empty_q_values': <function FileReader.remove_empty_q_values>, 'reset_data_list': <function FileReader.reset_data_list>, 'splitline': <staticmethod(<function FileReader.splitline>)>, 'get_file_contents': <function FileReader.get_file_contents>, '__dict__': <attribute '__dict__' of 'FileReader' objects>, '__weakref__': <attribute '__weakref__' of 'FileReader' objects>, '__doc__': None, '__annotations__': {}})
__doc__ = None
__init__()
__module__ = 'sasdata.dataloader.filereader'
__weakref__

list of weak references to the object

_read(file_handler: CustomFileOpen) List[Data1D | Data2D]

Private method to handle file loading

Parameters:
  • file_handler – A CustomFileOpen instance used to handle file operations

  • f_pos – The initial file position to start the read from

Returns:

A list of Data1D and Data2D objects

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

Remove data points where nan is loaded :param data: 1D or 2D data object :return: data with nan points removed

static _reorder_1d_array(array: array, ind: int) array

Reorders a 1D array based on the indices passed as ind :param array: Array to be reordered :param ind: Indices used to reorder array :return: reordered array

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.

__call__(file_path_list: List[str]) List[Data1D | Data2D]

Allow direct calls to the loader system for transient file loader systems. :param file_path_list: A list of string representations of file paths. Each item can either be a local file path

or a URI.

Returns:

A list of loaded Data1D/2D objects.

__dict__ = mappingproxy({'__module__': 'sasdata.dataloader.loader', '__doc__': '\n    Utility class to use the Registry as a singleton.\n    ', '_Loader__registry': <sasdata.dataloader.loader.Registry object>, 'associate_file_type': <function Loader.associate_file_type>, 'associate_file_reader': <function Loader.associate_file_reader>, 'load': <function Loader.load>, 'save': <function Loader.save>, '_get_registry_creation_time': <function Loader._get_registry_creation_time>, 'find_plugins': <function Loader.find_plugins>, 'get_wildcards': <function Loader.get_wildcards>, '__call__': <function Loader.__call__>, '__dict__': <attribute '__dict__' of 'Loader' objects>, '__weakref__': <attribute '__weakref__' of 'Loader' objects>, '__annotations__': {}})
__doc__ = '\n    Utility class to use the Registry as a singleton.\n    '
__module__ = 'sasdata.dataloader.loader'
__registry = <sasdata.dataloader.loader.Registry object>
__weakref__

list of weak references to the object

_get_registry_creation_time() float

Internal method used to test the uniqueness of the registry object

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.

__annotations__ = {}
__doc__ = '\n    Registry class for file format extensions.\n    Readers and writers are supported.\n    '
__init__()
__module__ = 'sasdata.dataloader.loader'
_identify_plugin(module: ModuleType)

Look into a module to find whether it contains a Reader class. If so, add it to readers and (potentially) to the list of writers. :param module: module object :returns: True if successful

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