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

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.

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.
n_frames

Number of frames in the file.

n_pixels

Number of pixels in the file.

n_rasters

Number of rasters in the file.

swap_bytes

Whether or not the bytes are in reverse order.

exception sas.sascalc.file_converter.bsl_loader.BSLParsingError[source]

Bases: Exception

sas.sascalc.file_converter.cansas_writer module

class sas.sascalc.file_converter.cansas_writer.CansasWriter(xml=None, schema=None)[source]

Bases: sas.sascalc.dataloader.readers.cansas_reader.Reader

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: sas.sascalc.dataloader.readers.cansas_reader_HDF5.Reader

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)[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.

class sas.sascalc.file_converter.otoko_loader.OTOKOData(q_axis, data_axis)[source]

Bases: object

class sas.sascalc.file_converter.otoko_loader.OTOKOLoader(qaxis_path, data_path)[source]

Bases: object

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

sas.sascalc.file_converter.red2d_writer module

class sas.sascalc.file_converter.red2d_writer.Red2DWriter[source]

Bases: sas.sascalc.dataloader.readers.red2d_reader.Reader

write(filename, data, thread)[source]

Write to .dat

Parameters:
  • filename – file name to write
  • data – data2D

Module contents