vibe-sketcherDocumentation

vibesketcher.document.measured_patterns

Measured powder patterns from simple two-column text files (#207).

Only plain text is read: whitespace-separated XY (.xy, .xye, .dat, .txt) and comma- or semicolon-separated CSV (.csv). The x axis must be stated by the caller (two_theta_deg, d_angstrom or q_inv_angstrom), never guessed from the numbers, and so must the intensity unit. Vendor and binary formats (Bruker RAW/BRML, PANalytical XRDML, Rigaku RAS, GSAS, …) are refused with the reason; convert them to XY with the instrument software, which keeps their licensing out of this package.

The provenance of every import is kept: the SHA-256 and size of the original bytes, the file name as given (no directory), the format, the stated axis, intensity unit and wavelength, instrument fields exactly as given, and the file’s own comment lines. A third column is read as the intensity standard uncertainty (esd) when present.

Functions

convert_axis(values, source, target, wavelength)

Convert x values between 2theta (degrees), d (angstrom) and Q = 2 pi / d (1/angstrom).

read_measured(data, filename, settings)

Points and provenance of a measured pattern, or MeasuredPatternRefused.

read_measured_file(path, settings)

read_measured() for a file on disk (bounded read).

Classes

MeasuredSettings(*, axis[, intensity_unit, ...])

What the caller states about a measured file; nothing is inferred.

Exceptions

MeasuredPatternRefused

The file or its stated axis cannot be read faithfully.

exception vibesketcher.document.measured_patterns.MeasuredPatternRefused[source]

Bases: ValueError

The file or its stated axis cannot be read faithfully.

class vibesketcher.document.measured_patterns.MeasuredSettings(*, axis, intensity_unit='counts', wavelength_angstrom=None, format=None, instrument=<factory>, sample=None)[source]

Bases: BaseModel

What the caller states about a measured file; nothing is inferred.

Parameters:
model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

axis: str
intensity_unit: Literal['counts', 'counts_per_second', 'arbitrary']
wavelength_angstrom: float | None

Wavelength of the measurement in angstrom, when known (required to convert a 2theta axis to d or Q, and to overlay in 2theta).

format: str | None

Explicit format; otherwise taken from the file name’s extension.

instrument: dict[str, str]

Instrument fields exactly as given (diffractometer, geometry, slits, …).

sample: str | None
vibesketcher.document.measured_patterns.read_measured(data, filename, settings)[source]

Points and provenance of a measured pattern, or MeasuredPatternRefused.

Parameters:
Return type:

dict[str, Any]

vibesketcher.document.measured_patterns.read_measured_file(path, settings)[source]

read_measured() for a file on disk (bounded read).

Parameters:
Return type:

dict[str, Any]

vibesketcher.document.measured_patterns.convert_axis(values, source, target, wavelength)[source]

Convert x values between 2theta (degrees), d (angstrom) and Q = 2 pi / d (1/angstrom).

Bragg’s law lambda = 2 d sin(theta); a 2theta axis on either side needs the wavelength, and a d or Q beyond the wavelength’s reach is refused.

Parameters:
Return type:

list[float]