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
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.
- 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
sasdata.file_converter.cansas_writer module¶
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.
- 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.
- class sasdata.file_converter.otoko_loader.OTOKOData(q_axis, data_axis)¶
Bases:
object
- class sasdata.file_converter.otoko_loader.OTOKOLoader(qaxis_path, data_path)¶
Bases:
object
- 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