sasdata.dataloader.readers.cansas_reader module¶
- class sasdata.dataloader.readers.cansas_reader.Reader(xml=None, schema=None)¶
Bases:
XMLreader
- allow_all = True¶
- base_ns = '{cansas1d/1.1}'¶
- cansas_defaults = None¶
- cansas_version = '1.1'¶
- current_data1d = None¶
- data = None¶
- errors = {}¶
- ext = ['.xml', '.svs']¶
- frm = ''¶
- get_file_contents()¶
Reader specific class to access the contents of the file All reader classes that inherit from FileReader must implement
- invalid = True¶
- is_cansas(ext: str | None = 'xml')¶
Checks to see if the XML file is a CanSAS file
- Parameters:
ext – The file extension of the data file
- Raises:
FileContentsException – Raised if XML file isn’t valid CanSAS
- load_file_and_schema(xml_file: str, schema_path: str | None = '') bool ¶
- logging = None¶
- names = None¶
- ns_list = None¶
- process_1d_data_object(tagname: str, data_point: float, unit: str, attr: dict)¶
Assign a 1D data variable to the appropriate plottable value :param tagname: Name of the XML tag :param data_point: Data to be assigned :param unit: Unit of the data_point :param attr: Extra attributes :return: None
- process_2d_data_object(tagname: str, data_point: float, unit: str)¶
Assign a 2D data variable to the appropriate plottable value :param tagname: Name of the XML tag :param data_point: Data to be assigned :param unit: Unit of the data_point :return: None
- process_collimation_data_object(tagname: str, data_point: float, unit: str)¶
Assign a collimation variable to the appropriate Collimation value :param tagname: Name of the XML tag :param data_point: Data to be assigned :param unit: Unit of the data_point :return: None
- process_detector_data_object(tagname: str, data_point: float, unit: str)¶
Assign a detector variable to the appropriate Detector value :param tagname: Name of the XML tag :param data_point: Data to be assigned :param unit: Unit of the data_point :return: None
- process_meta_data(tagname: str, data_point: float)¶
Any unrecognized tag should still be loaded - add to meta_data :param tagname: Name of the XML tag :param data_point: Data to be assigned :return: None
- process_process_data_object(tagname: str, data_point: float, attr: dict)¶
Assign a process variable to the appropriate Process value :param tagname: Name of the XML tag :param data_point: Data to be assigned :param attr: XML attributes :return: None
- process_sample_data_object(tagname: str, data_point: float, unit: str)¶
Assign a sample data variable to the appropriate Sample value :param tagname: Name of the XML tag :param data_point: Data to be assigned :param unit: Unit of the data_point :return: None
- process_source_data_object(tagname: str, data_point: float, unit: str)¶
Assign a source variable to the appropriate Source value :param tagname: Name of the XML tag :param data_point: Data to be assigned :param unit: Unit of the data_point :return: None
- process_trans_spec_data_object(tagname: str, data_point: float, unit: str)¶
Assign a transmission spectrum data variable to the appropriate datainfo value :param tagname: Name of the XML tag :param data_point: Data to be assigned :param unit: Unit of the data_point :return: None
- 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
- set_default_schema()¶
- type = ['XML files (*.xml)|*.xml', 'SasView Save Files (*.svs)|*.svs']¶
- type_name = 'canSAS'¶
- write(filename: str, datainfo: Data1D | Data2D)¶
Write the content of a Data1D as a CanSAS XML file
- Parameters:
filename – name of the file to write
datainfo – Data1D object
- write_node(parent: ElementTree, name: str, value: float | str, attr: dict | None = None) bool ¶
- Parameters:
doc – document DOM
parent – parent node
name – tag of the element
value – value of the child text node
attr – attribute dictionary
- Returns:
True if something was appended, otherwise False
- sasdata.dataloader.readers.cansas_reader.get_content(location, node)¶
Get the first instance of the content of a xpath location.
- Parameters:
location – xpath location
node – node to start at
- Returns:
Element, or None
- sasdata.dataloader.readers.cansas_reader.getattrchain(obj, chain, default=None)¶
Like getattr, but the attr may contain multiple parts separated by ‘.’
- sasdata.dataloader.readers.cansas_reader.setattrchain(obj, chain, value)¶
Like setattr, but the attr may contain multiple parts separated by ‘.’
- sasdata.dataloader.readers.cansas_reader.write_node(doc, parent, name, value, attr=None)¶
- Parameters:
doc – document DOM
parent – parent node
name – tag of the element
value – value of the child text node
attr – attribute dictionary
- Returns:
True if something was appended, otherwise False