dara.xrd module#

Load and process XRD data files (.xrdml, .xy, .rasx).

class RASXFile(angles, intensities, binary_data=None)[source]#

Bases: XRDData

Load Rigaku RASX file data format.

property binary_data: bytes | None#

Binary data.

classmethod from_file(path)[source]#

Load data from a RASX file.

Return type:

RASXFile

to_rasx_file(fn='xrd_data.rasx')[source]#

Save as a RASX file.

Parameters:

fn (str | Path) – filename to save to. Defaults to “xrd_data.rasx”.

Return type:

None

class RawFile(angles, intensities, binary_data=None)[source]#

Bases: XRDData

Load Rigaku RAW file data format.

property binary_data: bytes | None#

Binary data.

classmethod from_file(path)[source]#

Load data from a raw file.

Return type:

RawFile

to_raw_file(fn='xrd_data.raw')[source]#

Save as a raw file.

Parameters:

fn (str | Path) – filename to save to. Defaults to “xrd_data.raw”.

Return type:

None

class XRDData(angles, intensities, errors=None)[source]#

Bases: MSONable

General XRD data class; this is the base class for XRDMLFile, XYFile and other XRD data formats. This class ensures that all XRD data can be serialized.

property angles: ndarray#

2-theta values.

property errors: ndarray | None#

Errors in intensity values.

classmethod from_file(path)[source]#

Load data from file. To be implemented in subclasses.

property intensities: ndarray#

Intensity values (counts).

plot(style='line', ax=None, **kwargs)[source]#

Plot XRD data.

Parameters:
  • ax – existing matplotlib axis to plot on

  • style – either “points” or “line”

  • kwargs – keyword arguments to pass to matplotlib.pyplot.plot

Returns:

matplotlib axis

to_xy_file(fn='xrd_data.xy')[source]#

Save as a .xy file.

Parameters:

fn (str | Path) – filename to save to. Defaults to “xrd_data.xy”.

Return type:

None

Returns:

filename of saved file

class XRDMLFile(angles, intensities, xrdml_dict=None)[source]#

Bases: XRDData

XRDML file class, useful for loading .xrdml data. This is the file type used by the Aeris instrument.

classmethod from_file(path)[source]#

Load data from an XRDML file.

Return type:

XRDMLFile

to_xrdml_file(fn='xrd_data.xrdml')[source]#

Save as an XRDML file.

Parameters:

fn (str | Path) – filename to save to. Defaults to “xrd_data.xrdml”.

Return type:

None

property xrdml_dict: dict | None#

Dictionary representation of the XRDML file.

class XYFile(angles, intensities, errors=None)[source]#

Bases: XRDData

XY file class, useful for loading .xy data.

classmethod from_file(path)[source]#

Load data from a .xy file.

Return type:

XYFile

get_xrdml_data(xrd_dict)[source]#

Get angles and intensities from an XRDML dictionary.

Return type:

tuple[ndarray, ndarray]

hex2float(hex_string)[source]#
Return type:

float

hex2int(hex_string)[source]#
Return type:

int

load_rasx(file)[source]#

Convert RASX file to xy data.

RASX files are ZIP archives containing: - root.xml file - Data*/ folders with Profile*.txt files (scan_angle, intensity, attenuation) - MesurementConditions*.xml files (note: typo in original format)

This function extracts the first scan’s data from the first Profile file found.

Return type:

tuple[tuple[ndarray, ndarray], bytes]

Returns:

Tuple of ((angles, intensities), content) where content is the raw ZIP bytes. The content is kept for potential round-trip saving, though it’s rarely used.

load_raw(file)[source]#

Convert raw file to xy data.

Return type:

tuple[tuple[ndarray, ndarray], bytes]

load_xrdml(file)[source]#

Load an XRDML file and returns a dictionary using xmltodict.

Return type:

dict

rasx2xy(fn, target_folder=None)[source]#

Convert .rasx file to .xy file (and save).

Return type:

Path

raw2xy(fn, target_folder=None)[source]#

Convert .raw file to .xy file (and save).

Return type:

Path

xrdml2xy(fn, target_folder=None)[source]#

Convert .xrdml file to .xy file (and save).

Return type:

Path