pyFAI.io package

pyFAI.io.image module

Module function to read images.

pyFAI.io.image.read_data(image_path)

Returns a numpy.array image from a file name or a URL.

Parameters

image_path (str) – Path of the image file

Return type

numpy.ndarray regardless the dimention or the content

Raises
  • IOError – if the data is not reachable

  • TypeError – if the data is not an image (wrong size, wrong dimension)

pyFAI.io.image.read_image_data(image_path)

Returns a numpy.array image from a file name or a URL.

Parameters

image_path (str) – Path of the image file

Return type

numpy.ndarray

Raises
  • IOError – if the data is not reachable

  • TypeError – if the data is not an image (wrong size, wrong dimension)

pyFAI.io.integration_config module

Module function to manage poni files.

class pyFAI.io.integration_config.ConfigurationReader(config)

Bases: object

__init__(config)

Initialize self. See help(type(self)) for accurate signature.

pop_detector()

Returns the detector stored in the json configuration.

Return type

pyFAI.detectors.Detector

pop_method(default=None)

Returns a Method from the method field from the json dictionary.

Return type

pyFAI.method_registry.Method

pyFAI.io.integration_config.normalize(config, inplace=False)

Normalize the configuration file to the one supported internally (the last one).

Parameters
  • config (dict) – The configuration dictionary to read

  • inplace (bool) – In true, the dictionary is edited inplace

Raises

ValueError – If the configuration do not match.

pyFAI.io.ponifile module

Module function to manage poni files.

class pyFAI.io.ponifile.PoniFile(data=None)

Bases: object

__init__(data=None)

Initialize self. See help(type(self)) for accurate signature.

as_dict()
property detector
Return type

Union[None,float]

property dist
Return type

Union[None,float]

property poni1
Return type

Union[None,float]

property poni2
Return type

Union[None,float]

read_from_dict(config)

Initialize this object using a dictionary.

Note

The dictionary is versionned.

read_from_duck(duck)

Initialize the object using an object providing the same API.

The duck object must provide dist, poni1, poni2, rot1, rot2, rot3, wavelength, and detector.

read_from_file(filename)
property rot1
Return type

Union[None,float]

property rot2
Return type

Union[None,float]

property rot3
Return type

Union[None,float]

property wavelength
Return type

Union[None,float]

write(fd)

Write this object to an open stream.

Module contents

Module for “high-performance” writing in either 1D with Ascii , or 2D with FabIO or even nD with n varying from 2 to 4 using HDF5

Stand-alone module which tries to offer interface to HDF5 via H5Py and capabilities to write EDF or other formats using fabio.

Can be imported without h5py but then limited to fabio & ascii formats.

TODO:

  • Add monitor to HDF5

class pyFAI.io.AsciiWriter(filename=None, prefix='fai_', extension='.dat')

Bases: pyFAI.io.Writer

Ascii file writer (.xy or .dat)

__init__(filename=None, prefix='fai_', extension='.dat')
init(fai_cfg=None, lima_cfg=None)

Creates the directory that will host the output file(s)

write(data, index=0)

To be implemented

class pyFAI.io.DefaultAiWriter(filename, engine=None)

Bases: pyFAI.io.Writer

__init__(filename, engine=None)

Constructor of the historical writer of azimuthalIntegrator.

Parameters
  • filename – name of the output file

  • ai – integrator, should provide make_headers method.

close()
flush()

To be implemented

init(fai_cfg=None, lima_cfg=None)

Creates the directory that will host the output file(s) :param fai_cfg: configuration for worker :param lima_cfg: configuration for acquisition

make_headers(hdr='#', has_mask=None, has_dark=None, has_flat=None, polarization_factor=None, normalization_factor=None, metadata=None)
Parameters
  • hdr (str) – string used as comment in the header

  • has_dark (bool) – save the darks filenames (default: no)

  • has_flat (bool) – save the flat filenames (default: no)

  • polarization_factor (float) – the polarization factor

Returns

the header

Return type

str

save1D(filename, dim1, I, error=None, dim1_unit='2th_deg', has_mask=None, has_dark=False, has_flat=False, polarization_factor=None, normalization_factor=None, metadata=None)

This method save the result of a 1D integration as ASCII file.

Parameters
  • filename (str) – the filename used to save the 1D integration

  • dim1 (numpy.ndarray) – the x coordinates of the integrated curve

  • I (numpy.mdarray) – The integrated intensity

  • error (numpy.ndarray or None) – the error bar for each intensity

  • dim1_unit (pyFAI.units.Unit) – the unit of the dim1 array

  • has_mask – a mask was used

  • has_dark – a dark-current was applied

  • has_flat – flat-field was applied

  • polarization_factor (float, None) – the polarization factor

  • normalization_factor (float, None) – the monitor value

  • metadata – JSON serializable dictionary containing the metadata

save2D(filename, I, dim1, dim2, error=None, dim1_unit='2th_deg', has_mask=None, has_dark=False, has_flat=False, polarization_factor=None, normalization_factor=None, metadata=None)

This method save the result of a 2D integration.

Parameters
  • filename (str) – the filename used to save the 2D histogram

  • dim1 (numpy.ndarray) – the 1st coordinates of the histogram

  • dim1 – the 2nd coordinates of the histogram

  • I (numpy.mdarray) – The integrated intensity

  • error (numpy.ndarray or None) – the error bar for each intensity

  • dim1_unit (pyFAI.units.Unit) – the unit of the dim1 array

  • has_mask – a mask was used

  • has_dark – a dark-current was applied

  • has_flat – flat-field was applied

  • polarization_factor (float, None) – the polarization factor

  • normalization_factor (float, None) – the monitor value

  • metadata – JSON serializable dictionary containing the metadata

set_filename(filename)

Define the filename while will be used

write(data)

Minimalistic method to limit the overhead.

Parameters

data – array with intensities or tuple (2th,I) or (I,2th,chi) :type data: Integrate1dResult, Integrate2dResult

class pyFAI.io.FabioWriter(filename=None)

Bases: pyFAI.io.Writer

Image file writer based on FabIO

TODO !!!

__init__(filename=None)
init(fai_cfg=None, lima_cfg=None)

Creates the directory that will host the output file(s)

write(data, index=0)

To be implemented

class pyFAI.io.HDF5Writer(filename, hpath=None, entry_template=None, fast_scan_width=None, append_frames=False, mode='error')

Bases: pyFAI.io.Writer

Class allowing to write HDF5 Files.

CONFIG = 'configuration'
DATASET_NAME = 'data'
MODE_APPEND = 'append'
MODE_DELETE = 'delete'
MODE_ERROR = 'error'
MODE_OVERWRITE = 'overwrite'
__init__(filename, hpath=None, entry_template=None, fast_scan_width=None, append_frames=False, mode='error')

Constructor of an HDF5 writer:

Parameters
  • filename (str) – name of the file

  • hpath (str) – Name of the entry group that will contains the NXprocess.

  • entry_template (str) – Formattable template to create a new entry (if hpath is not specified)

  • fast_scan_width (int) – set it to define the width of

close()
flush(radial=None, azimuthal=None)

Update some data like axis units and so on.

Parameters
  • radial – position in radial direction

  • azimuthal – position in azimuthal direction

init(fai_cfg=None, lima_cfg=None)

Initializes the HDF5 file for writing :param fai_cfg: the configuration of the worker as a dictionary

write(data, index=None)

Minimalistic method to limit the overhead. :param data: array with intensities or tuple (2th,I) or (I,2th,chi)

class pyFAI.io.Writer(filename=None, extension=None)

Bases: object

Abstract class for writers.

CONFIG_ITEMS = ['filename', 'dirname', 'extension', 'subdir', 'hpath']
__init__(filename=None, extension=None)

Constructor of the class

flush(*arg, **kwarg)

To be implemented

init(fai_cfg=None, lima_cfg=None)

Creates the directory that will host the output file(s) :param fai_cfg: configuration for worker :param lima_cfg: configuration for acquisition

setJsonConfig(json_config=None)

Sets the JSON configuration

write(data)

To be implemented