sasdata.file_converter package

Submodules

sasdata.file_converter.FileConverterUtilities module

Module with file loader specific static utilities.

sasdata.file_converter.FileConverterUtilities.convert_2d_data(dataset, output, metadata)

Wrapper for the NX SAS writer call Sets external metadata on the dataset first.

sasdata.file_converter.FileConverterUtilities.convert_to_cansas(frame_data, filepath, run_name, single_file)

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

sasdata.file_converter.FileConverterUtilities.extract_ascii_data(filename)

Extracts data from a single-column ASCII file

Parameters:

filename – The file to load data from

Returns:

A numpy array containing the extracted data

sasdata.file_converter.FileConverterUtilities.extract_otoko_data(qfile, ifile)

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

sasdata.file_converter.FileConverterUtilities.toFloat(text)

Dumb string->float converter

sasdata.file_converter.ascii2d_loader module

ASCII 2D Loader

class sasdata.file_converter.ascii2d_loader.ASCII2DLoader(data_path)

Bases: object

__dict__ = mappingproxy({'__module__': 'sasdata.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)
Parameters:

data_path – The path to the file to load

__module__ = 'sasdata.file_converter.ascii2d_loader'
__weakref__

list of weak references to the object

load()

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

sasdata.file_converter.bsl_loader module

class sasdata.file_converter.bsl_loader.BSLLoader(filename)

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__': 'sasdata.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)

Parses the BSL header file and sets instance variables apropriately

Parameters:

filename – Path to the BSL header file

__module__ = 'sasdata.file_converter.bsl_loader'
__str__()

Print the objects params.

Returns:

string description of object parameters.

__weakref__

list of weak references to the object

_parse_header(header_file, filename, sasdata_filename, folder)

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)

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)

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 sasdata.file_converter.bsl_loader.BSLParsingError

Bases: Exception

__doc__ = None
__module__ = 'sasdata.file_converter.bsl_loader'
__weakref__

list of weak references to the object

sasdata.file_converter.cansas_writer module

class sasdata.file_converter.cansas_writer.CansasWriter(xml=None, schema=None)

Bases: Reader

__annotations__ = {}
__doc__ = None
__module__ = 'sasdata.file_converter.cansas_writer'
_to_xml_doc(frame_data, sasentry_attrs=None)

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)

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)

Write the content of a Data1D as a CanSAS XML file

Parameters:
  • filename – name of the file to write

  • datainfo – Data1D object

sasdata.file_converter.nxcansas_writer module

NXcanSAS 1/2D data reader for writing HDF5 formatted NXcanSAS files.

class sasdata.file_converter.nxcansas_writer.NXcanSASWriter

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__': 'sasdata.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__ = 'sasdata.file_converter.nxcansas_writer'
__weakref__

list of weak references to the object

_write_1d_data(data_obj, data_entry)

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)

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)

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

sasdata.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 sasdata.file_converter.otoko_loader.CStyleStruct(**kwds)

Bases: object

A nice and easy way to get “C-style struct” functionality.

__dict__ = mappingproxy({'__module__': 'sasdata.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)
__module__ = 'sasdata.file_converter.otoko_loader'
__weakref__

list of weak references to the object

class sasdata.file_converter.otoko_loader.OTOKOData(q_axis, data_axis)

Bases: object

__dict__ = mappingproxy({'__module__': 'sasdata.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)
__module__ = 'sasdata.file_converter.otoko_loader'
__weakref__

list of weak references to the object

class sasdata.file_converter.otoko_loader.OTOKOLoader(qaxis_path, data_path)

Bases: object

__dict__ = mappingproxy({'__module__': 'sasdata.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)
__module__ = 'sasdata.file_converter.otoko_loader'
__weakref__

list of weak references to the object

_load_otoko_axis(header_path)

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

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 sasdata.file_converter.otoko_loader.OTOKOParsingError

Bases: Exception

__doc__ = None
__module__ = 'sasdata.file_converter.otoko_loader'
__weakref__

list of weak references to the object

sasdata.file_converter.red2d_writer module

class sasdata.file_converter.red2d_writer.Red2DWriter

Bases: Reader

__annotations__ = {}
__doc__ = None
__module__ = 'sasdata.file_converter.red2d_writer'
write(filename, data, thread)

Write to .dat

Parameters:
  • filename – file name to write

  • data – data2D

Module contents