xrd_tools package
Subpackages
- xrd_tools.plugins package
- Submodules
- xrd_tools.plugins.refinement_profex module
ProfexInterface
ProfexInterface.create_input_data()
ProfexInterface.data
ProfexInterface.dir_refinement
ProfexInterface.encoding
ProfexInterface.file_refinement_input
ProfexInterface.file_refinement_project
ProfexInterface.get_cif_files()
ProfexInterface.get_composition()
ProfexInterface.get_phases()
ProfexInterface.get_refined_data()
ProfexInterface.get_refinement_result()
ProfexInterface.input_data_delimiter
ProfexInterface.input_data_header
ProfexInterface.input_data_suffix
ProfexInterface.measurement_id
ProfexInterface.name_phases
ProfexInterface.open_refinement()
register()
- Module contents
Submodules
xrd_tools.analyse_measurements module
- class xrd_tools.analyse_measurements.AnalyseMeasurements(measurements: list[xrd_tools.measurement.Measurement], _cols: dict[str, str] = <factory>)[source]
Bases:
object
Perform operations and compare multiple measurements.
- Parameters:
measurements (list[Measurement]) – Measurement objects for measurements of interest.
_cols – Dictionary with strings to assign data series internally.
- classmethod from_ids(ids: list[str], m_manager: MeasurementManager = MeasurementManager(measurements_dir='~/XRD_measurements', encoding='utf-8'))[source]
Alternative constructor to initalise instance by list of measurements IDs.
- ids
List of strings with measurements IDs.
- m_manager
MeasurementManager initiated with measurements directory of interest.
- property measurement_ids: list[str]
Returns list of strings with measurement IDs.
- measurements: list[xrd_tools.measurement.Measurement]
- multiplot(norm: bool = True)[source]
Compare measurements for provided sample IDs in a multiplot.
- norm
Flag to indicate if normalised data are plotted, which is the recommended setting since the y-axis are shared between the individual subplots.
- sample_to_df(df: DataFrame, col_name='sample') DataFrame [source]
Inserts column with sample IDs into provided Pandas DataFrame.
- df
Pandas DataFrame containing rows for each measurement.
- col_name
Column name used for the added column.
- property samples: Series
Returns samples
xrd_tools.config module
xrd_tools.database module
- class xrd_tools.database.DBentry(*, measurement_id: str, sample: str, compound: str, description: str, comment: str, ht_mode: bool, processing_state: Optional[str] = None, xrd_datetime: Optional[str] = None, date_added: str)[source]
Bases:
object
A XRD measurement database entry template.
- comment: str
A comment about the measurement.
- Type:
str
- compound: str
The formula of the compound that was measured.
- Type:
str
- date_added: str
The date and time at when the measurement was added to the DB.
- Type:
str
- description: str
A description of the measurement.
- Type:
str
- ht_mode: bool
Whether the measurement was taken in high temperature mode.
- Type:
bool
- measurement_id: str
The ID of the measurement.
- Type:
str
- processing_state: str = None
The processing state of the measurement, expression must be predefined.
- Type:
str
- sample: str
The ID of the sample that was measured.
- Type:
str
- xrd_datetime: str = None
The date and time at which the measurement was taken.
- Type:
str
- class xrd_tools.database.MeasurementDatabase(db_file: str = '/home/cschrein/.local/share/xrdt/measurements.csv', measurements_dir: str = '~/XRD_measurements')[source]
Bases:
object
XRD Measurement database
- Parameters:
db_file (str) – Path to the database file (CSV).
measurements_dir (str) – Path to measurements directory.
- add_measurement(meta_obj: Meta, to_file: bool = True) None [source]
Add a new measurement to the database.
- meta_obj
Meta object of measurement to be added to database.
- db_file: str = '/home/cschrein/.local/share/xrdt/measurements.csv'
- property empty: bool
Returns True if no measurements are registered.
- get_measurement_for_id(measurement_id: str) Measurement [source]
Returns a measurement object for the provided measurement ID.
- get_measurement_for_sample(sample: str) Measurement [source]
Returns a measurement object for the provided sample ID.
- get_measurements_for_compound(compound: str) AnalyseMeasurements [source]
Returns an AnalyseMeasurements object with measurement of the provided compound.
- list_compounds() list[str] [source]
Returns a list with unique compounds registered in the DB (sorted).
- list_measurements_for_db_key(column: str, value: str) list[str] [source]
Returns list of measurement IDs for provided DB column and value(s).
Method can be used to filter the database for a specific data subset, e.g. measurements corresponding to a certain processing state.
- column
Column where value(s) exists (e.g. processing_state).
- value
Value(s) to filter for (e.g. refined).
- measurements_dir: str = '~/XRD_measurements'
xrd_tools.device module
- class xrd_tools.device.BaseDevice(manufacturer: str, model: str, inventory_no: Optional[str] = None)[source]
Bases:
object
Basic device class.
- inventory_no: str = None
- manufacturer: str
- model: str
- quotation(format_type: Optional[str] = None) str [source]
Retrieve a descriptive string to be used in reports.
A format_type can be defined in order to obtain a formatted string. Currently latex and md are supported format_type strings. The latter results e.g. in the following output: *X’Pert Pro* manufactured by *PANanalytical*
- class xrd_tools.device.HTChamber(manufacturer: str, model: str, inventory_no: Optional[str] = None)[source]
Bases:
BaseDevice
High-temperature chamber.
- property device_type: str
Returns string with the type of device.
- class xrd_tools.device.LabDiffractometer(manufacturer: str, model: str, inventory_no: Optional[str] = None)[source]
Bases:
BaseDevice
XRD device.
- property device_type: str
Returns string with the type of device.
xrd_tools.device_factory module
- class xrd_tools.device_factory.Device(*args, **kwargs)[source]
Bases:
Protocol
Basic representation of a device.
- property device_type: str
- manufacturer: str
- model: str
- xrd_tools.device_factory.create(arguments: dict[str, any]) tuple[xrd_tools.device_factory.Device, str] [source]
Create a device of a specific type, given a dictionary of arguments.
xrd_tools.device_manager module
- class xrd_tools.device_manager.DeviceManager(file_path: str = '~/.local/xrdt/devices.json', device_types: dict[str, str] = <factory>, encoding: str = 'utf-8', indent: str | None = 4, separator: str = ': ')[source]
Bases:
object
Manage Devices.
- add_device(device_id: str, dev_obj: Device, to_file: bool = True) None [source]
Add device kwargs to json file.
- device_types: dict[str, str]
- encoding: str = 'utf-8'
- file_path: str = '~/.local/xrdt/devices.json'
- get_creation_function(device_type: str) Callable[[...], Device] [source]
Get creation function for device type.
- get_device_ids(device_type: Optional[str] = None) list[str] [source]
Get a list of device IDs, optionally of a certain type.
- Parameters:
device_type (str) – The type of device IDs to be returned.
- Returns:
- List of all device IDs if no device_type is specified, otherwise
a list with all devices of the corresponding type.
- Return type:
str
- get_devices(device_type: Optional[str] = None) list[xrd_tools.device_factory.Device] [source]
Get a list of devices, optionally of a certain type.
- Parameters:
device_type (str) – The type of devices to be returned.
- Returns:
- List of all devices if no device_type is specified, otherwise
a list with all devices of the corresponding type.
- Return type:
str
- get_id_list(device_type: Optional[str] = None)[source]
Return list of known device IDs.
Filters for specific device type if one is provided.
- get_type(device_id: str) str [source]
Get the type of a registered device.
- Parameters:
device_id (str) – The ID of a registered device whose type is returned.
- Returns:
The device type of the device with specified ID.
- Return type:
str
- indent: str | None = 4
- remove_device(device_id: str, to_file: bool = True) None [source]
Remove a registered device (and write updated devices to file).
- Parameters:
device_id (str) – The ID of the device to be removed.
to_file (bool) – Flag to indicate to write the new devices to the JSON file.
- separator: str = ': '
xrd_tools.measurement module
- class xrd_tools.measurement.Measurement(paths: MeasurementPaths, meta: Meta, data: Optional[Series] = None)[source]
Bases:
object
XRD measurement class.
- Parameter:
- paths:
MeasurementPaths object of the measurements.
- meta:
Metadata object of the measurement.
- data:
Pandas Series containing the x/y data of the measurement as imported. The index represents the 2θ angle.
- create_protocol(author: str, template: str, encoding: str = 'utf-8') None [source]
Create a protocol document for a XRD measurement.
- Parameters:
author (param) – Author of the measurement protocol.
template (param) – Path to a protocol document template file.
encoding (param) – Encoding of the protocol file.
- data: Series = None
- property data_norm
XRD data normalised to maximum intensity.
- Returns:
Series containing the normalised x/y data of the measurement. The index represents the 2θ angle.
- Return type:
pd.Series
- Raises:
ValueError – If no XRD data are registered for the measurement.
- classmethod from_id(measurement_id: str, measurements_dir: str = '~/XRD_measurements')[source]
Alternative constructor to initiate a Measurement instance.
- Parameters:
measurement_id (str) – ID of the measurement to be loaded.
measurements_dir (str) – Path to the measurements directory.
- get_cif_files(to_file=True) None [source]
Copy CIF file of refined phase(s) from refinement directory to results subdirectory.
- get_processing_state() str [source]
Get the measurements’ data processing state.
- Returns:
- Current processing state, one of the following options:
refined
if a refined data file exists.None
is no option listed above is applicable.
- Return type:
str
- get_refined_data(encoding='utf-8', to_file: bool = False) None [source]
Get the refinement results as pandas directory.
The method requires a refinement interface plugin which provides the data.
- Parameters:
encoding (str) – Encoding used in refined data file if it gets written.
to_file (bool) – Refined data are written to the data directory if
True
.
- get_refined_phase(phase: str) RefinedPhase [source]
Get a refined phase object.
Requires the presence of a CIF file for the phase of interest.
- Parameters:
phase (str) – Name of the phase of interest
- Returns:
Object containing the results for the specified refined phase.
- Return type:
- get_refinement_result() RefinementResult [source]
Get a refinement result object.
- Returns:
Object containing the results of the refinement.
- Return type:
- property has_data: bool
Check if XRD measurement data are available.
- Returns:
True if XRD data are available, and False if not.
- Return type:
bool
- property has_refiner: str
Checks if a refinement interface plugin is set for this measurement.
The refinement plugin can be defined via the method ‘set_refinement_interface’.
- Returns:
True if a refinement interface plugin in set, False if not.
- Return type:
bool
- property is_refined: str
Flag that indicated wheter the measurement is refined.
- Returns:
- True if refined data are present in the data subdirectory of the
measurement, False otherwise.
- Return type:
bool
- paths: MeasurementPaths
- plot(norm: bool = False, window_title: Optional[str] = None)[source]
Plot the XRD data.
- Parameters:
norm (bool) – Plot the data normalised to the maximum intensity if True.
window_title (str) – Title for the matplotlib window that will be created.
- Raises:
ValueError – If no XRD data are registered for the measurement.
- refine(to_file: bool = True) None [source]
Refine the measurement with a refinement plugin.
The refinement plugin has to be set via the method set_refinement_interface.
- Raises:
NoRefinerSetError – If no refinement interface plugin is set for the measurement.
AppNotInstalledError – If the refinement application is not installed on the machine.
- set_processing_state(state: Optional[str] = None, to_file: bool = True) str [source]
Set the data processing state as metadata value.
- Parameter:
- state:
Value for new processing state, besides expressions defined in PROCESSING_STATES, the keyword ‘reset’ is accepted in order to bypass a validity check and set the processing state to None. If no state is provided, the state returned by the method get_processing_state is added to the metadata.
- to_file:
Write the metadata to the JSON file if True and the new state does not correspond to the initial state.
- set_refinement_interface(name: str = 'profex', encoding='utf-8') None [source]
Define a refinement interface plugin (default: “profex”).
The refinement interface module must be named with the filename: ‘refinement_<name>.py’, and it has to be stored in the ‘plugins’ directory of this package.
- Raises:
ValueError – If the refinement interface plugin is not registered.
- update_meta(key: str, value: any, to_file: bool = True) None [source]
Assign a value to a key of the measurement metadata.
- Parameters:
key (str) – Name of Meta attribute to be updated.
value – Value to be updated to Meta attribute.
to_file (bool) – Write the metadata to the JSON file if True and the new value does not correspond to the current value.
- exception xrd_tools.measurement.NoRefinerSetError(message="No refinement interface plugin defined for this measurement. Use `set_refinement_interface('name')` to set one.")[source]
Bases:
Exception
Error that is raised if no refinement interface plugin is set.
- Parameters:
message (str) – Error message
- xrd_tools.measurement.get_data(file_path: str, col_angle: str = '2θ / °', col_intensity: str = 'Intensity / counts', encoding: str = 'utf-8') Series [source]
Load XRD data from file.
- Returns:
The series contains the x/y data of the measurement. Its index represents the 2θ angle in °.
- Return type:
pd.Series
xrd_tools.measurement_manager module
- class xrd_tools.measurement_manager.MeasurementManager(measurements_dir: str = '~/XRD_measurements', encoding: str = 'utf-8')[source]
Bases:
object
Measurement manager.
- Encoding:
Encoding used to read from and write to files.
- encoding: str = 'utf-8'
- get_measurement(measurement_id: str) Measurement [source]
Returns Measurement object for measurement_id.
- import_measurement(meta_obj: Meta, source_file: Optional[str] = None, source_type: str = 'ascii', to_file: bool = True, zip_source: bool = True, remove_source: bool = True, force: bool = False, encoding=None) Measurement [source]
Import measurement from ASCII data file.
- Parameter:
- meta_obj:
Meta object for the measurement to be imported.
- source_file:
Path to XRD data source file of the measurement.
- source_type:
Type of data source, currently supported: [ascii].
- to_files:
Write imported data and metadata to files (csv, json).
- zip_source:
Add an archive with the source data to data subdirectory.
- remove_source:
Delete the source data file if set to True.
- force:
Replace the archive if it exists already in data subdirectory.
- list_measurements(sort_reverse=True) list[str] [source]
Returns list of measurements in measurements_dir (sorted).
- measurements_dir: str = '~/XRD_measurements'
xrd_tools.meta module
- class xrd_tools.meta.Meta(measurement_id: str, ht_mode: ~typing.Optional[bool] = None, operator: ~typing.Optional[str] = None, description: ~typing.Optional[str] = None, sample: ~typing.Optional[str] = None, compound: ~typing.Optional[str] = None, temperature: ~typing.Optional[float] = None, pressure: ~typing.Optional[float] = None, atmosphere: ~typing.Optional[str] = None, devices: list[dict[str, any]] = <factory>, xrd_datetime: ~typing.Optional[str] = None, processing_state: ~typing.Optional[str] = None, comment: ~typing.Optional[str] = None)[source]
Bases:
object
Class to store and handle metadata of a XRD measurement.
- Parameters:
measurement_id (str) – The ID of the measurement.
operator (str) – The operator of the measurement.
description (str) – A description of the measurement.
sample (str) – The ID of the sample that was measured.
compound (str) – The formula of the compound that was measured.
temperature (float) – The temperature at which the measurement took place.
pressure (float) – The pressure at which the measurement took place.
atmosphere (str) – The atmosphere in which the measurement took place.
ht_mode (bool) – Whether the measurement was taken in high temperature mode.
devices (list[dict[str, any]]) – A list of dictionaries containing information about the devices used in the measurement. Each dictionary holds the arguments required to initiate the corresponding Device object.
xrd_datetime (str) – The date and time at which the measurement was taken.
processing_state (str) – The processing state of the measurement, expression must be defined in PROCESSING_STATES.
comment (str) – A comment about the measurement.
- atmosphere: str = None
- comment: str = None
- compound: str = None
- description: str = None
- devices: list[dict[str, any]]
- classmethod from_json(file_path: Optional[str] = None, json_str: Optional[str] = None)[source]
Alternative constructor to initiate a Meta object from a JSON string.
- Parameters:
file_path – path to the JSON file to read from
json_str – JSON string containing the Meta attributes
Either the file_path or json_str parameter must be provided. If both are provided, the json_str parameter takes precedence.
- Returns:
Meta object with attributes initialized from the JSON string
- ht_mode: bool = None
- measurement_id: str
- property mode: str
Returns string with measurement mode (‘XRD’ or ‘HT-XRD’).
- operator: str = None
- pressure: float = None
- processing_state: str = None
- sample: str = None
- temperature: float = None
- to_json(file_path: str, indent: int = 4, encoding: str = 'utf-8') None [source]
Writes Meta class dict as JSON string to file.
- update_value(key: str, value: any, file_path: Optional[str] = None) None [source]
Assign value to key of metadata dictionary.
- Parameters:
file_path (str) – Write metadata to JSON file if a path is provided.
- xrd_datetime: str = None
- property xrd_device: LabDiffractometer
Returns diffractometer device object.
xrd_tools.paths module
- class xrd_tools.paths.MeasurementPaths(measurements_dir: str, measurement_id: str, subdir_data: str = 'data', subdir_refined: str = 'refinement', subdir_results: str = 'results', suffix_data: str = '_data', suffix_meta: str = '_meta', suffix_protocol: str = '_protocol', suffix_refined_data: str = '_refined', suffix_refinement_results: str = '_refined', suffix_source_data: str = '_source-data')[source]
Bases:
object
The MeasurementPaths class provides file- and directory-paths relevant for a XRD measurement and is used by other classes and functions of this package.
- Parameter:
- measurements_dir:
Path to the measurements directory
- measurement_id:
ID of the measurement
- subdir_data:
Subdirectory for data
- subdir_refined:
Subdirectory for refined data
- subdir_results:
Subdirectory for result
- suffix_data:
Suffix for scan data file
- suffix_meta:
Suffix for meta data file
- suffix_protocol:
Suffix for measurement protocol file
- suffix_refined_data:
Suffix for refined data file
- suffix_refinement_results:
Suffix for refinement results file
- suffix_source_data:
Suffix for source data file
- property dir_data: str
Returns path to data directory.
- property dir_refinement: str
Returns path to refinement directory.
- property dir_results: str
Returns path to results directory.
- property file_data: str
Returns path to data file (
.csv
).
- property file_log: str
Returns path to log file (
.log
).
- property file_meta: str
Returns path to meta file (
.json
).
- property file_protocol: str
Returns path to protocol file (
.md
).
- property file_refined_data: str
Returns path to refined data file (
.md
).
- property file_refinement_result: str
Returns path to refinement results file (
.json
).
- property file_source_data: str
Returns path to source archive file (
.zip
).
- measurement_id: str
- measurements_dir: str
- subdir_data: str = 'data'
- subdir_refined: str = 'refinement'
- subdir_results: str = 'results'
- suffix_data: str = '_data'
- suffix_meta: str = '_meta'
- suffix_protocol: str = '_protocol'
- suffix_refined_data: str = '_refined'
- suffix_refinement_results: str = '_refined'
- suffix_source_data: str = '_source-data'
xrd_tools.plugin_loader module
A simple plugin loader.
- class xrd_tools.plugin_loader.ModuleInterface[source]
Bases:
object
Represents a xrd-tools plugin interface.
A plugin has a register function, as well as a plugin_type and a plugin_name. The latter have to represent the plugin module filename as follows: <plugin_type>_<plugin_name>.py
Moreover, the module has to be stored in the ‘plugins’ directory of this package.
- xrd_tools.plugin_loader.get_plugins(plugin_type: str) list[str] [source]
Get names for plugins of a certain type.
The plugin file has to be named as follows: <plugin_type>_<plugin_name>.py, and it has to be located in the ‘plugins’ directory within this package.
- Returns:
List of plugin names for provided plugin type.
- Return type:
list[str]
- xrd_tools.plugin_loader.import_module(name: str) ModuleInterface [source]
Imports a module given a name.
xrd_tools.preset_manager module
Module providing tools to handle preset dictionaries, which are stored in a JSON file.
- class xrd_tools.preset_manager.PresetManager(file_path: str, encoding: str = 'utf-8', indent: int = 4)[source]
Bases:
object
Manager to handle preset dictionaries, which are stored in a JSON file.
- Parameters:
file_path (str) – Path to a JSON file containing preset dictionaries.
encoding (str) – Encoding applied when writing to and reading from JSON files.
indent (int) – Indent applied when writing to a JSON file.
- add_preset(name: str, preset_dct: dict[str, any], to_file: bool = True) None [source]
Add a new preset (and write to JSON file).
- Parameters:
name (str) – The name of the preset to be added.
preset_dct (str) – Dictionary containg the preset key/value pairs to be added.
to_file (bool) – Flag to indicate to write the new presets to the JSON file.
- Raises:
ValueError – If the preset name is already registered.
- encoding: str = 'utf-8'
- file_path: str
- get_names() list[str] [source]
Retrieve a list with names of registered presets.
- Returns:
List containg the names of all registered presets.
- Return type:
list[str]
- get_preset(name: str) dict[str, any] [source]
Retrieve a preset dictionary.
- Parameters:
name (str) – The name of the preset to be returned.
- Returns:
Dictionary containg the preset key/value pairs.
- Return type:
dict[str, any]
- property has_preset: bool
Check if registered presets are existing.
- Returns:
True if at least one preset is registered, and False if no preset is registered.
- Return type:
bool
- indent: int = 4
xrd_tools.refinement module
- class xrd_tools.refinement.RefinedPhase(cif_file: Optional[str] = None)[source]
Bases:
object
Class that represents a refined phase.
- property chemical_formula: float
- cif_file: str = None
- classmethod from_name(name: str, paths: MeasurementPaths)[source]
Alternative constructor to initialise instance by phase name.
- property lp: float
- property lp_a: float
- property lp_alpha: float
- property lp_b: float
- property lp_beta: float
- property lp_c: float
- property lp_gamma: float
- class xrd_tools.refinement.RefinementResult(r_wp: Optional[float] = None, r_exp: Optional[float] = None, gof: Optional[float] = None, chi_sqrd: Optional[float] = None, zero_shift: Optional[float] = None, sample_discplacement: Optional[float] = None, composition: Optional[dict[str, float | uncertainties.core.AffineScalarFunc]] = None, software: Optional[str] = None, version: Optional[str] = None)[source]
Bases:
object
Class to represent a refinement results.
- chi_sqrd: float = None
- composition: dict[str, float | uncertainties.core.AffineScalarFunc] = None
- classmethod from_json(file_path: Optional[str] = None, json_str: Optional[str] = None)[source]
Alternative constructor to initiate a RefinementResult object from a JSON string.
- Parameters:
file_path – path to the JSON file to read from
json_str – JSON string containing the Meta attributes
Either the file_path or json_str parameter must be provided. If both are provided, the json_str parameter takes precedence.
- Returns:
RefinementResult object with attributes initialized from the JSON string
- gof: float = None
- r_exp: float = None
- r_wp: float = None
- sample_discplacement: float = None
- software: str = None
- to_json(file_path: str, indent: int = 4, encoding: str = 'utf-8') None [source]
Write RefinementResults as JSON string to file.
- version: str = None
- zero_shift: float = None
xrd_tools.refinement_interface module
Refinement interface module.
- exception xrd_tools.refinement_interface.AppNotInstalledError[source]
Bases:
Exception
Error that is raised if the refinement application is not installed.
- class xrd_tools.refinement_interface.RefinementInterface[source]
Bases:
ABC
Basic representation of a refinement interface.
A refinement interface has the property ‘file_refinement_input’, and the methods ‘create_refinement_input’, ‘get_refinement_properties’, ‘get_refinement_results’ and ‘open_refinement’. The latter checks for the required application and raise an ‘AppNotInstalledError’ if the application is not installed on the machine.
It has to accept the arguments listed below.
- Parameters:
measurement_id (str) – ID of the measurement to be loaded to the plugin.
data (pd.Series) – Series containing the x/y data of the measurement. The index represents the 2theta angle.
project_dir (str) – Path to the refinement project directory.
encoding (str) – Encoding used in data file.
- data: Series
- dir_refinement: str
- encoding: str
- get_cif_files() dict[str, str] [source]
Get a dictionary with the name and the path to the cif files for refined phase(s).
- get_refined_data() DataFrame [source]
Get a pandas DataFrame containing the refined data series.
- Parameters:
i_calc (str) – Column name for the calculated intensities.
i_bg (str) – Column name for the background intensities.
- Returns:
A DataFrame with index set to 2θ and an index name as found in the provided data. The columns correspond to: - I_calc with column name provided as argument, - I_bg with column name provided as argument, and - a further column for each phase refined, named with its name as defined
in profex.
- Return type:
pd.DataFrame
- get_refinement_result() RefinementResult [source]
Get a RefinementResults object for the refinement of the measurement.
- measurement_id: str
- open_refinement() None [source]
Open refinement project with refinement application.
- Raises:
AppNotInstalledError – If the refinement applicaiton is not installed.
xrd_tools.refinement_interface_factory module
Factory to create a refinement interface glugin.
- xrd_tools.refinement_interface_factory.create(arguments: dict[str, Any]) RefinementInterface [source]
Create a plugin of a specific type, given JSON data.
- xrd_tools.refinement_interface_factory.register(name: str, creator_fn: Callable[[...], RefinementInterface]) None [source]
Register a new refinement interface.
xrd_tools.templates module
- class xrd_tools.templates.TemplateManager(template_dir: str = '~/.local/xrdt/templates', default_templates: dict[str, str] = <factory>, separator: str = ': ')[source]
Bases:
object
Class to manage templates used to documentate a measurement.
- Parameters:
templates_dir (str) – The path to the directory containing custom templates.
default_templates – Dictionary with keys of known document types and values specifying the paths of the fallback templates for the corresponding document types.
- Raises:
ValueError – If an unknown document type is provided in any of its methods.
- create_template(name: str, document_type: str, force: bool = False) None [source]
Create a custom template for a certain document type.
- Parameters:
name (str) – The name of the template.
document_type (str) – The type of document that the template will be used for.
force (bool, optional) – Whether to overwrite the template if it already exists. Defaults to False.
- Raises:
FileExistsError – If a template with the same name already exists and ‘force’ is set to False.
- default_templates: dict[str, str]
- get_template(document_type: str, name: str) str [source]
Get the file path of a registered template.
- Parameters:
document_type (str) – The document type of the template to be returned.
name (str) – The name of a registered template that shall be returned.
- Returns:
The path to the template with the provided name and document type.
- Return type:
str
- get_template_dict() dict[str, list[str]] [source]
Get a dictionary with document types as keys and list of names as values.
- get_templates(document_type: str, names: bool = False) list[str] [source]
Get a list to paths (or names) of available templates.
If no custom templates exist, the list will contain the path to the fallback template for the specified document_type, otherwise the fallback template will be excluded. If names are requested, ‘None’ is returned if no custom template is registered for the specified type.
- Parameters:
document_type (str) – The document type of the templates to be considered.
names (bool) – Flag to indicate that template names instead of paths shall be returned.
- Returns:
- A list with paths to or names of available templates for the
specified document type.
- Return type:
list[str]
- get_type(name: str) str [source]
Get the document type of a registered template.
- Parameters:
name (str) – The name of a registered template whose type shall be returned.
- Returns:
The document type of the provided template name.
- Return type:
str
- get_type_name_list() list[str] [source]
Returns list of registered templates and their document type.
- separator: str = ': '
- template_dir: str = '~/.local/xrdt/templates'
- property types
List with known document types
- xrd_tools.templates.get_template_cli(template_manager: TemplateManager, document_type: str, template_name: Optional[str] = None) tuple[str, str] [source]
CLI to get the (name of) and path to a template for the specified document types.
- Parameters:
template_manager (TemplateManager) – TemplateManager instance initiated with the template directory of interest.
document_type (str) – The document type of the template that shall be returned.
template_name (str, optional) – Specify the name of the desired document template.
- Returns:
A tuple containing the (1.) template_name, and the corresponding (2.) file_path.
- Return type:
tuple[str,str]
xrd_tools.utils module
“Helper functions for xrd-tools.
- xrd_tools.utils.ensure_file_exists(file_path) None [source]
Raise a FileNotFoundError if file_path does not exist.
- xrd_tools.utils.make_dirs(file_path) None [source]
Create parent dirs for file path if not existing.
- xrd_tools.utils.raise_file_exists(file_path, force=False) None [source]
Check if the file already exists and raise a FileExistsError if so.
The error message will include instructions on how to overwrite the file if the ‘force’ flag is set to True (default).
- Parameters:
file_path (str) – The file path to check.
force (bool, optional) – Whether to include instructions on how to overwrite the file in the error message using a “force” flag.
- Raises:
FileExistsError – If the specified file already exists.