sasdata.dataloader package¶
Subpackages¶
- sasdata.dataloader.readers package
- Submodules
- sasdata.dataloader.readers.abs_reader module
- sasdata.dataloader.readers.anton_paar_saxs_reader module
- sasdata.dataloader.readers.ascii_reader module
- sasdata.dataloader.readers.associations module
- sasdata.dataloader.readers.cansas_constants module
CansasConstantsCansasConstants.ANYCansasConstants.CANSAS_FORMATCansasConstants.CANSAS_NSCansasConstants.RUNCansasConstants.SASDATACansasConstants.SASDATA_IDATACansasConstants.SASDATA_IDATA_DQLCansasConstants.SASDATA_IDATA_DQWCansasConstants.SASDATA_IDATA_ICansasConstants.SASDATA_IDATA_IDEVCansasConstants.SASDATA_IDATA_QCansasConstants.SASDATA_IDATA_QDEVCansasConstants.SASDATA_IDATA_QMEANCansasConstants.SASDATA_IDATA_SHADOWFACTORCansasConstants.SASINSTRCansasConstants.SASINSTR_COLLCansasConstants.SASINSTR_COLL_APERCansasConstants.SASINSTR_COLL_APER_ATTRCansasConstants.SASINSTR_COLL_APER_DISTCansasConstants.SASINSTR_COLL_APER_SIZECansasConstants.SASINSTR_COLL_APER_XCansasConstants.SASINSTR_COLL_APER_YCansasConstants.SASINSTR_COLL_APER_ZCansasConstants.SASINSTR_DETCansasConstants.SASINSTR_DET_BCCansasConstants.SASINSTR_DET_BC_XCansasConstants.SASINSTR_DET_BC_YCansasConstants.SASINSTR_DET_BC_ZCansasConstants.SASINSTR_DET_OFFCansasConstants.SASINSTR_DET_OFF_ATTRCansasConstants.SASINSTR_DET_OFF_XCansasConstants.SASINSTR_DET_OFF_YCansasConstants.SASINSTR_DET_OFF_ZCansasConstants.SASINSTR_DET_ORCansasConstants.SASINSTR_DET_OR_ATTRCansasConstants.SASINSTR_DET_OR_PITCHCansasConstants.SASINSTR_DET_OR_ROLLCansasConstants.SASINSTR_DET_OR_YAWCansasConstants.SASINSTR_DET_PIXELCansasConstants.SASINSTR_DET_PIXEL_XCansasConstants.SASINSTR_DET_PIXEL_YCansasConstants.SASINSTR_DET_PIXEL_ZCansasConstants.SASINSTR_DET_SDDCansasConstants.SASINSTR_DET_SLITCansasConstants.SASINSTR_SRCCansasConstants.SASINSTR_SRC_BEAMSIZECansasConstants.SASINSTR_SRC_BEAMSIZE_ATTRCansasConstants.SASINSTR_SRC_BEAMSIZE_XCansasConstants.SASINSTR_SRC_BEAMSIZE_YCansasConstants.SASINSTR_SRC_BEAMSIZE_ZCansasConstants.SASINSTR_SRC_WLCansasConstants.SASINSTR_SRC_WL_MAXCansasConstants.SASINSTR_SRC_WL_MINCansasConstants.SASINSTR_SRC_WL_SPRCansasConstants.SASNOTECansasConstants.SASPROCESSCansasConstants.SASPROCESS_SASPROCESSNOTECansasConstants.SASPROCESS_TERMCansasConstants.SASSAMPLECansasConstants.SASSAMPLE_ORIENTCansasConstants.SASSAMPLE_ORIENT_ATTRCansasConstants.SASSAMPLE_ORIENT_PITCHCansasConstants.SASSAMPLE_ORIENT_ROLLCansasConstants.SASSAMPLE_ORIENT_YAWCansasConstants.SASSAMPLE_POSCansasConstants.SASSAMPLE_POS_ATTRCansasConstants.SASSAMPLE_POS_XCansasConstants.SASSAMPLE_POS_YCansasConstants.SASSAMPLE_POS_ZCansasConstants.SASSAMPLE_TEMPCansasConstants.SASSAMPLE_THICKCansasConstants.SASSAMPLE_TRANSCansasConstants.SASTRANSSPECCansasConstants.SASTRANSSPEC_TDATACansasConstants.SASTRANSSPEC_TDATA_LAMDBACansasConstants.SASTRANSSPEC_TDATA_TCansasConstants.SASTRANSSPEC_TDATA_TDEVCansasConstants.TITLECansasConstants.formatCansasConstants.get_namespace_map()CansasConstants.iterate_namespace()CansasConstants.names
CurrentLevel
- sasdata.dataloader.readers.cansas_reader module
ReaderReader.allow_allReader.base_nsReader.cansas_defaultsReader.cansas_versionReader.current_data1dReader.dataReader.errorsReader.extReader.frmReader.get_file_contents()Reader.invalidReader.is_cansas()Reader.load_file_and_schema()Reader.loggingReader.namesReader.ns_listReader.process_1d_data_object()Reader.process_2d_data_object()Reader.process_collimation_data_object()Reader.process_detector_data_object()Reader.process_meta_data()Reader.process_process_data_object()Reader.process_sample_data_object()Reader.process_source_data_object()Reader.process_trans_spec_data_object()Reader.reset_state()Reader.set_default_schema()Reader.typeReader.type_nameReader.write()Reader.write_node()
get_content()getattrchain()setattrchain()write_node()
- sasdata.dataloader.readers.cansas_reader_HDF5 module
ReaderReader.add_data_set()Reader.add_intermediate()Reader.allow_allReader.as_list_or_array()Reader.cansas_versionReader.extReader.final_data_cleanup()Reader.get_file_contents()Reader.process_1d_data_object()Reader.process_2d_data_object()Reader.process_aperture()Reader.process_collimation()Reader.process_detector()Reader.process_process()Reader.process_sample()Reader.process_source()Reader.process_trans_spectrum()Reader.read_children()Reader.reset_state()Reader.typeReader.type_nameReader.write()
h5attr()
- sasdata.dataloader.readers.csv_reader module
- sasdata.dataloader.readers.danse_reader module
- sasdata.dataloader.readers.red2d_reader module
- sasdata.dataloader.readers.sesans_reader module
- sasdata.dataloader.readers.tiff_reader module
- sasdata.dataloader.readers.xml_reader module
XMLreaderXMLreader.append()XMLreader.break_processing_instructions()XMLreader.create_element()XMLreader.create_element_from_string()XMLreader.create_tree()XMLreader.ebuilder()XMLreader.encodingXMLreader.find_invalid_xml()XMLreader.parse_schema_and_doc()XMLreader.processing_instructionsXMLreader.reader()XMLreader.return_processing_instructions()XMLreader.schemaXMLreader.schemadocXMLreader.set_encoding()XMLreader.set_processing_instructions()XMLreader.set_schema()XMLreader.set_xml()XMLreader.to_string()XMLreader.validate_xml()XMLreader.write_attribute()XMLreader.write_text()XMLreader.xmlXMLreader.xmldocXMLreader.xmlroot
uri_is_valid()
- Module contents
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:
objectClass 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,DataInfo1D 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,DataInfo2D 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:
objectClass 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:
objectClass 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:
objectClass 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:
objectClass 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:
objectClass 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:
objectClass 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:
objectVector 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:
objectData1D 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:
objectData2D 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:
objectUtility 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:
ExtensionRegistryRegistry 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.