xrdtrace: X-ray diffractogram trace file parser
This module handles the reading and processing of X-ray diffraction data. It loads X-ray diffraction data, determines reasonable uncertainties of the signal intensity (y-axis), and explicitly populates the angle axis (\(2\theta\)), if necessary.
Usage
Available since yadg-4.0
. The parser supports the following parameters:
- pydantic model dgbowl_schemas.yadg.dataschema_5_0.step.XRDTrace
Parser for XRD traces.
Show JSON schema
{ "title": "XRDTrace", "description": "Parser for XRD traces.", "type": "object", "properties": { "tag": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Tag" }, "parser": { "const": "xrdtrace", "title": "Parser" }, "input": { "$ref": "#/$defs/Input" }, "extractor": { "anyOf": [ { "$ref": "#/$defs/Panalytical_xrdml" }, { "$ref": "#/$defs/Panalytical_xy" }, { "$ref": "#/$defs/Panalytical_csv" } ], "title": "Extractor" }, "parameters": { "anyOf": [ { "$ref": "#/$defs/Parameters" }, { "type": "null" } ], "default": null }, "externaldate": { "anyOf": [ { "$ref": "#/$defs/ExternalDate" }, { "type": "null" } ], "default": null } }, "$defs": { "ExternalDate": { "additionalProperties": false, "description": "Supply timestamping information that are external to the processed file.", "properties": { "using": { "anyOf": [ { "$ref": "#/$defs/ExternalDateFile" }, { "$ref": "#/$defs/ExternalDateFilename" }, { "$ref": "#/$defs/ExternalDateISOString" }, { "$ref": "#/$defs/ExternalDateUTSOffset" } ], "title": "Using" }, "mode": { "default": "add", "enum": [ "add", "replace" ], "title": "Mode", "type": "string" } }, "required": [ "using" ], "title": "ExternalDate", "type": "object" }, "ExternalDateFile": { "additionalProperties": false, "description": "Read external date information from file.", "properties": { "file": { "$ref": "#/$defs/dgbowl_schemas__yadg__dataschema_5_0__externaldate__ExternalDateFile__Content" } }, "required": [ "file" ], "title": "ExternalDateFile", "type": "object" }, "ExternalDateFilename": { "additionalProperties": false, "description": "Read external date information from the file name.", "properties": { "filename": { "$ref": "#/$defs/dgbowl_schemas__yadg__dataschema_5_0__externaldate__ExternalDateFilename__Content" } }, "required": [ "filename" ], "title": "ExternalDateFilename", "type": "object" }, "ExternalDateISOString": { "additionalProperties": false, "description": "Read a constant external date using an ISO-formatted string.", "properties": { "isostring": { "title": "Isostring", "type": "string" } }, "required": [ "isostring" ], "title": "ExternalDateISOString", "type": "object" }, "ExternalDateUTSOffset": { "additionalProperties": false, "description": "Read a constant external date using a Unix timestamp offset.", "properties": { "utsoffset": { "title": "Utsoffset", "type": "number" } }, "required": [ "utsoffset" ], "title": "ExternalDateUTSOffset", "type": "object" }, "Input": { "additionalProperties": false, "description": "Specification of input files/folders to be processed by the :class:`Step`.", "properties": { "folders": { "items": { "type": "string" }, "title": "Folders", "type": "array" }, "prefix": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Prefix" }, "suffix": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Suffix" }, "contains": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Contains" }, "exclude": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Exclude" } }, "required": [ "folders" ], "title": "Input", "type": "object" }, "Panalytical_csv": { "additionalProperties": false, "properties": { "filetype": { "const": "panalytical.csv", "title": "Filetype" }, "timezone": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Timezone" }, "locale": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Locale" }, "encoding": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Encoding" } }, "required": [ "filetype" ], "title": "Panalytical_csv", "type": "object" }, "Panalytical_xrdml": { "additionalProperties": false, "properties": { "filetype": { "enum": [ "panalytical.xrdml", "marda:panalytical-xrdml" ], "title": "Filetype", "type": "string" }, "timezone": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Timezone" }, "locale": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Locale" }, "encoding": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Encoding" } }, "required": [ "filetype" ], "title": "Panalytical_xrdml", "type": "object" }, "Panalytical_xy": { "additionalProperties": false, "properties": { "filetype": { "const": "panalytical.xy", "title": "Filetype" }, "timezone": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Timezone" }, "locale": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Locale" }, "encoding": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Encoding" } }, "required": [ "filetype" ], "title": "Panalytical_xy", "type": "object" }, "Parameters": { "additionalProperties": false, "description": "Empty parameters specification with no extras allowed.", "properties": {}, "title": "Parameters", "type": "object" }, "dgbowl_schemas__yadg__dataschema_5_0__externaldate__ExternalDateFile__Content": { "additionalProperties": false, "properties": { "path": { "title": "Path", "type": "string" }, "type": { "title": "Type", "type": "string" }, "match": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Match" } }, "required": [ "path", "type" ], "title": "Content", "type": "object" }, "dgbowl_schemas__yadg__dataschema_5_0__externaldate__ExternalDateFilename__Content": { "additionalProperties": false, "properties": { "format": { "title": "Format", "type": "string" }, "len": { "title": "Len", "type": "integer" } }, "required": [ "format", "len" ], "title": "Content", "type": "object" } }, "additionalProperties": false, "required": [ "parser", "input", "extractor" ] }
- Config:
extra: str = forbid
- field parser: Literal['xrdtrace'] [Required]
- field extractor: Panalytical_xrdml | Panalytical_xy | Panalytical_csv [Required]
Formats
The filetypes
currently supported by the parser are:
PANalytical
xrdml
files (panalytical.xrdml
), seepanalyticalxrdml
PANalytical
csv
files (panalytical.csv
), seepanalyticalcsv
PANalytical
xy
files (panalytical.xy
), seepanalyticalxy
Provides
The raw data is stored, for each timestep, using the following format:
xr.Dataset:
coords:
uts: !!float
angle: !!float # Diffraction angle (deg)
data_vals:
intensity: (uts, angle) # Detector intensity (counts)
- yadg.parsers.xrdtrace.process(*, filetype, **kwargs)
Unified X-ray diffractogram data parser. Forwards
kwargs
to the worker functions based on the suppliedfiletype
.This parser processes XPS scans in signal(energy) format.
- Parameters:
filetype (
str
) – Discriminator used to select the appropriate worker function.- Return type:
Submodules
- yadg.parsers.xrdtrace.common.panalytical_comment(line)
Processes a comments from the file header into a dictionary.
- Parameters:
line (
str
) – A line containing the comment.- Returns:
A dictionary containing the processed comment.
- Return type:
dict
- yadg.parsers.xrdtrace.common.snake_case(s)
Converts Sentence case. and camelCase strings to snake_case.
From https://stackoverflow.com/a/1176023
- Parameters:
s (
str
) – The input string to be converted.- Returns:
The corresponding snake_case string.
- Return type:
str
panalyticalcsv: Processing of PANalytical XRD csv
files
File Structure
These files are split into a [Measurement conditions]
and a [Scan points]
section. The former stores the metadata and the latter all the datapoints.
Uncertainties
The uncertainties of "angle"
are taken from the number of significant figures.
The uncertainties of "intensity"
are taken from the number of significant figures.
Code author: Nicolas Vetsch, Peter Kraus
- yadg.parsers.xrdtrace.panalyticalcsv.process(*, fn, encoding='utf-8', timezone='UTC', **kwargs)
Processes a PANalytical XRD csv file. All information contained in the header of the csv file is stored in the metadata.
- Parameters:
fn (
str
) – The file containing the trace(s) to parse.encoding (
str
) – Encoding offn
, by default “utf-8”.timezone (
str
) – A string description of the timezone. Default is “UTC”.
- Returns:
Data containing the timesteps and metadata. This filetype contains the full date specification.
- Return type:
panalyticalxrdml: Processing of PANalytical XRD xml
files
File Structure
These are xml-formatted files, which we here parse using the xml.etree
library into a Python dict
.
Note
The angle
returned from this parser is based on a linear interpolation of
the start and end point of the scan, and is the \(2\theta\). The values
of \(\omega\) are discarded.
Warning
This parser is fairly new and untested. As a result, the returned metadata contain only a subset of the available metadata in the XML file. If something important is missing, please contact us!
Uncertainties
The uncertainties of in "angle"
are taken as the step-width of
the linearly spaced \(2\theta\) values.
The uncertainties of of "intensity"
are currently set to a constant
value of 1.0 count as all the supported files seem to produce integer values.
Code author: Nicolas Vetsch, Peter Kraus
- yadg.parsers.xrdtrace.panalyticalxrdml.etree_to_dict(e)
Recursively converts an ElementTree.Element into a dictionary.
Element attributes are stored into “@”-prefixed attribute keys. Element text is stored into “#text” for all nodes.
From https://stackoverflow.com/a/10076823.
- Parameters:
e (
Element
) – The ElementTree root Element.- Returns:
ElementTree parsed into a dictionary.
- Return type:
dict
- yadg.parsers.xrdtrace.panalyticalxrdml.process(*, fn, timezone, **kwargs)
Processes a PANalytical xrdml file.
- Parameters:
fn (
str
) – The file containing the trace(s) to parse.timezone (
ZoneInfo
) – A string description of the timezone. Default is “UTC”.
- Returns:
Data containing the timesteps, and metadata. This filetype contains the full date specification.
- Return type:
panalyticalxy: Processing of PANalytical XRD xy
files
File Structure
These files basically just contain the [Scan points]
part of
panalyticalcsv
files. As a consequence, no metadata
is recorded, and the format does not have an associated timestamp.
Uncertainties
The uncertainties of "angle"
are taken from the number of significant figures.
The uncertainties of "intensity"
are taken from the number of significant figures.
Code author: Nicolas Vetsch, Peter Kraus
- yadg.parsers.xrdtrace.panalyticalxy.process(*, fn, encoding, **kwargs)
Processes a PANalytical XRD xy file.
- Parameters:
fn (
str
) – The file containing the trace(s) to parse.encoding (
str
) – Encoding offn
, by default “utf-8”.
- Returns:
Tuple containing the timesteps and metadata. A full timestamp is not available in
.xy
files.- Return type: