sas.sascalc.file_converter package
Submodules
sas.sascalc.file_converter.FileConverterUtilities module
Module with file loader specific static utilities.
- sas.sascalc.file_converter.FileConverterUtilities.convert_2d_data(dataset, output, metadata)[source]
Wrapper for the NX SAS writer call Sets external metadata on the dataset first.
- sas.sascalc.file_converter.FileConverterUtilities.convert_to_cansas(frame_data, filepath, run_name, single_file)[source]
Saves an array of Data1D objects to a single CanSAS file with multiple <SasData> elements, or to multiple CanSAS files, each with one <SasData> element.
- Parameters:
frame_data – If single_file is true, an array of Data1D objects. If single_file is false, a dictionary of the form {frame_number: Data1D}.
filepath – Where to save the CanSAS file
single_file – If true, array is saved as a single file, if false, each item in the array is saved to it’s own file
- sas.sascalc.file_converter.FileConverterUtilities.extract_ascii_data(filename)[source]
Extracts data from a single-column ASCII file
- Parameters:
filename – The file to load data from
- Returns:
A numpy array containing the extracted data
- sas.sascalc.file_converter.FileConverterUtilities.extract_otoko_data(qfile, ifile)[source]
Extracts data from a 1D OTOKO file
- Parameters:
filename – The OTOKO file to load the data from
- Returns:
A numpy array containing the extracted data
- sas.sascalc.file_converter.FileConverterUtilities.toFloat(text)[source]
Dumb string->float converter
sas.sascalc.file_converter.ascii2d_loader module
ASCII 2D Loader
- class sas.sascalc.file_converter.ascii2d_loader.ASCII2DLoader(data_path)[source]
Bases:
object
- __dict__ = mappingproxy({'__module__': 'sas.sascalc.file_converter.ascii2d_loader', '__init__': <function ASCII2DLoader.__init__>, 'load': <function ASCII2DLoader.load>, '__dict__': <attribute '__dict__' of 'ASCII2DLoader' objects>, '__weakref__': <attribute '__weakref__' of 'ASCII2DLoader' objects>, '__doc__': None, '__annotations__': {}})
- __doc__ = None
- __init__(data_path)[source]
- Parameters:
data_path – The path to the file to load
- __module__ = 'sas.sascalc.file_converter.ascii2d_loader'
- __weakref__
list of weak references to the object (if defined)
- load()[source]
Load the data from the file into a Data2D object
- Returns:
A Data2D instance containing data from the file
- Raises:
ValueError – Raises a ValueError if the file is incorrectly formatted
sas.sascalc.file_converter.bsl_loader module
- class sas.sascalc.file_converter.bsl_loader.BSLLoader(filename)[source]
Bases:
object
Loads 2D SAS data from a BSL file. CLoader is a C extension (found in c_ext/bsl_loader.c)
See http://www.diamond.ac.uk/Beamlines/Soft-Condensed-Matter/small-angle/SAXS-Software/CCP13/BSL.html for more info on the BSL file format.
- __dict__ = mappingproxy({'__module__': 'sas.sascalc.file_converter.bsl_loader', '__doc__': '\n Loads 2D SAS data from a BSL file.\n CLoader is a C extension (found in c_ext/bsl_loader.c)\n\n See http://www.diamond.ac.uk/Beamlines/Soft-Condensed-Matter/small-angle/SAXS-Software/CCP13/BSL.html\n for more info on the BSL file format.\n ', '__init__': <function BSLLoader.__init__>, '_parse_header': <function BSLLoader._parse_header>, 'filename': <property object>, 'n_frames': <property object>, 'n_pixels': <property object>, 'n_rasters': <property object>, 'swap_bytes': <property object>, 'load_frames': <function BSLLoader.load_frames>, 'load_data': <function BSLLoader.load_data>, '__str__': <function BSLLoader.__str__>, '__dict__': <attribute '__dict__' of 'BSLLoader' objects>, '__weakref__': <attribute '__weakref__' of 'BSLLoader' objects>, '__annotations__': {}})
- __doc__ = '\n Loads 2D SAS data from a BSL file.\n CLoader is a C extension (found in c_ext/bsl_loader.c)\n\n See http://www.diamond.ac.uk/Beamlines/Soft-Condensed-Matter/small-angle/SAXS-Software/CCP13/BSL.html\n for more info on the BSL file format.\n '
- __init__(filename)[source]
Parses the BSL header file and sets instance variables apropriately
- Parameters:
filename – Path to the BSL header file
- __module__ = 'sas.sascalc.file_converter.bsl_loader'
- __str__()[source]
Print the objects params.
- Returns:
string description of object parameters.
- __weakref__
list of weak references to the object (if defined)
- _parse_header(header_file, filename, sasdata_filename, folder)[source]
Method that parses the header file and returns the metadata in data_info
- Parameters:
header_file – header file object.
- Returns:
metadata of header file.
- property filename
File to load.
- load_data(frame)[source]
Loads the file named in filename in 4 byte float, in either little or big Endian depending on self.swap_bytes.
- Parameters:
frame – The frame to load.
- Returns:
np array of loaded floats.
- load_frames(frames)[source]
Loads all frames of the BSl file into a Data2D object.
- Parameters:
frames – Number of frames.
- Returns:
Data2D frame_data.
- property n_frames
Number of frames in the file.
- property n_pixels
Number of pixels in the file.
- property n_rasters
Number of rasters in the file.
- property swap_bytes
Whether or not the bytes are in reverse order.
- exception sas.sascalc.file_converter.bsl_loader.BSLParsingError[source]
Bases:
Exception
- __doc__ = None
- __module__ = 'sas.sascalc.file_converter.bsl_loader'
- __weakref__
list of weak references to the object (if defined)
sas.sascalc.file_converter.cansas_writer module
- class sas.sascalc.file_converter.cansas_writer.CansasWriter(xml=None, schema=None)[source]
Bases:
Reader
- __doc__ = None
- __module__ = 'sas.sascalc.file_converter.cansas_writer'
- _to_xml_doc(frame_data, sasentry_attrs=None)[source]
Create an XML document to contain the content of an array of Data1Ds
- Parameters:
frame_data – An array of Data1D objects
- _write_data(datainfo, entry_node)[source]
Writes the I and Q data to the XML file
- Parameters:
datainfo – The Data1D object the information is coming from
entry_node – lxml node ElementTree object to be appended to
- write(filename, frame_data, sasentry_attrs=None)[source]
Write the content of a Data1D as a CanSAS XML file
- Parameters:
filename – name of the file to write
datainfo – Data1D object
sas.sascalc.file_converter.nxcansas_writer module
NXcanSAS 1/2D data reader for writing HDF5 formatted NXcanSAS files.
- class sas.sascalc.file_converter.nxcansas_writer.NXcanSASWriter[source]
Bases:
object
A class for writing in NXcanSAS data files. Any number of data sets may be written to the file. Currently 1D and 2D SAS data sets are supported
NXcanSAS spec: http://download.nexusformat.org/sphinx/classes/contributed_definitions/NXcanSAS.html
- Dependencies:
The NXcanSAS writer requires h5py => v2.5.0 or later.
- __dict__ = mappingproxy({'__module__': 'sas.sascalc.file_converter.nxcansas_writer', '__doc__': '\n A class for writing in NXcanSAS data files. Any number of data sets may be\n written to the file. Currently 1D and 2D SAS data sets are supported\n\n NXcanSAS spec: http://download.nexusformat.org/sphinx/classes/contributed_definitions/NXcanSAS.html\n\n :Dependencies:\n The NXcanSAS writer requires h5py => v2.5.0 or later.\n ', 'write': <function NXcanSASWriter.write>, '_write_1d_data': <function NXcanSASWriter._write_1d_data>, '_write_2d_data': <function NXcanSASWriter._write_2d_data>, '__dict__': <attribute '__dict__' of 'NXcanSASWriter' objects>, '__weakref__': <attribute '__weakref__' of 'NXcanSASWriter' objects>, '__annotations__': {}})
- __doc__ = '\n A class for writing in NXcanSAS data files. Any number of data sets may be\n written to the file. Currently 1D and 2D SAS data sets are supported\n\n NXcanSAS spec: http://download.nexusformat.org/sphinx/classes/contributed_definitions/NXcanSAS.html\n\n :Dependencies:\n The NXcanSAS writer requires h5py => v2.5.0 or later.\n '
- __module__ = 'sas.sascalc.file_converter.nxcansas_writer'
- __weakref__
list of weak references to the object (if defined)
- _write_1d_data(data_obj, data_entry)[source]
Writes the contents of a Data1D object to a SASdata h5py Group
- Parameters:
data_obj – A Data1D object to write to the file
data_entry – A h5py Group object representing the SASdata
- _write_2d_data(data, data_entry)[source]
Writes the contents of a Data2D object to a SASdata h5py Group
- Parameters:
data – A Data2D object to write to the file
data_entry – A h5py Group object representing the SASdata
- write(dataset, filename)[source]
Write an array of Data1d or Data2D objects to an NXcanSAS file, as one SASEntry with multiple SASData elements. The metadata of the first elememt in the array will be written as the SASentry metadata (detector, instrument, sample, etc).
- Parameters:
dataset – A list of Data1D or Data2D objects to write
filename – Where to write the NXcanSAS file
sas.sascalc.file_converter.otoko_loader module
Here we handle loading of “OTOKO” data (for more info about this format see the comment in load_otoko_data). Given the paths of header and data files, we aim to load the data into numpy arrays for use later.
- class sas.sascalc.file_converter.otoko_loader.CStyleStruct(**kwds)[source]
Bases:
object
A nice and easy way to get “C-style struct” functionality.
- __dict__ = mappingproxy({'__module__': 'sas.sascalc.file_converter.otoko_loader', '__doc__': 'A nice and easy way to get "C-style struct" functionality.', '__init__': <function CStyleStruct.__init__>, '__dict__': <attribute '__dict__' of 'CStyleStruct' objects>, '__weakref__': <attribute '__weakref__' of 'CStyleStruct' objects>, '__annotations__': {}})
- __doc__ = 'A nice and easy way to get "C-style struct" functionality.'
- __init__(**kwds)[source]
- __module__ = 'sas.sascalc.file_converter.otoko_loader'
- __weakref__
list of weak references to the object (if defined)
- class sas.sascalc.file_converter.otoko_loader.OTOKOData(q_axis, data_axis)[source]
Bases:
object
- __dict__ = mappingproxy({'__module__': 'sas.sascalc.file_converter.otoko_loader', '__init__': <function OTOKOData.__init__>, '__dict__': <attribute '__dict__' of 'OTOKOData' objects>, '__weakref__': <attribute '__weakref__' of 'OTOKOData' objects>, '__doc__': None, '__annotations__': {}})
- __doc__ = None
- __init__(q_axis, data_axis)[source]
- __module__ = 'sas.sascalc.file_converter.otoko_loader'
- __weakref__
list of weak references to the object (if defined)
- class sas.sascalc.file_converter.otoko_loader.OTOKOLoader(qaxis_path, data_path)[source]
Bases:
object
- __dict__ = mappingproxy({'__module__': 'sas.sascalc.file_converter.otoko_loader', '__init__': <function OTOKOLoader.__init__>, 'load_otoko_data': <function OTOKOLoader.load_otoko_data>, '_load_otoko_axis': <function OTOKOLoader._load_otoko_axis>, '__dict__': <attribute '__dict__' of 'OTOKOLoader' objects>, '__weakref__': <attribute '__weakref__' of 'OTOKOLoader' objects>, '__doc__': None, '__annotations__': {}})
- __doc__ = None
- __init__(qaxis_path, data_path)[source]
- __module__ = 'sas.sascalc.file_converter.otoko_loader'
- __weakref__
list of weak references to the object (if defined)
- _load_otoko_axis(header_path)[source]
Loads an “OTOKO” axis, given the header file path. Essentially, the header file contains information about the data in the form of integer “indicators”, as well as the names of each of the binary files which are assumed to be in the same directory as the header.
- load_otoko_data()[source]
Loads “OTOKO” data, which is a format that stores each axis separately. An axis is represented by a “header” file, which in turn will give details of one or more binary files where the actual data is stored.
Given the paths of two header files, this function will load each axis in turn. If loading is successful then an instance of the OTOKOData class will be returned, else an exception will be raised.
For more information on the OTOKO file format, please see: http://www.diamond.ac.uk/Home/Beamlines/small-angle/SAXS-Software/CCP13/ XOTOKO.html
- exception sas.sascalc.file_converter.otoko_loader.OTOKOParsingError[source]
Bases:
Exception
- __doc__ = None
- __module__ = 'sas.sascalc.file_converter.otoko_loader'
- __weakref__
list of weak references to the object (if defined)