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:

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