ptyrad.params.parser#

Params files parsing functions

Functions

copy_params_to_dir(params_path, output_dir)

Copies the params file to the output directory if it exists.

load_json_params(file_path)

load_params(file_path[, validate])

load_py_params(file_path)

load_toml_params(file_path)

Load parameters from a TOML file.

load_yml_params(file_path)

normalize_constraint_params(constraint_params)

Convert old constraint param format {freq} (pre v0.1.0b11) to {start_iter, step, end_iter}.

normalize_probe_params(init_params)

Normalize probe params in init_params This includes: - Migrate legacy keys (pre v0.1.0b13) like probe_defocus, probe_c3, probe_c5 into probe_aberrations.

yaml2json(input_filepath, output_filepath)

ptyrad.params.parser.load_params(file_path, validate=True)[source]#
Parameters:
  • file_path (str)

  • validate (bool)

ptyrad.params.parser.load_json_params(file_path)[source]#
ptyrad.params.parser.load_toml_params(file_path)[source]#

Load parameters from a TOML file.

Parameters: file_path (str): The path to the TOML file to be loaded.

Returns: dict: A dictionary containing the parameters loaded from the TOML file.

Raises: FileNotFoundError: If the specified file does not exist. ImportError: If the tomli package is not installed for Python < 3.11.

ptyrad.params.parser.load_yml_params(file_path)[source]#
ptyrad.params.parser.load_py_params(file_path)[source]#
ptyrad.params.parser.normalize_probe_params(init_params)[source]#

Normalize probe params in init_params This includes: - Migrate legacy keys (pre v0.1.0b13) like probe_defocus, probe_c3, probe_c5 into probe_aberrations. - Canonicalizes probe_aberrations into standard Krivanek polar format {‘Cnm’: XX, ‘phinm’: XX}.

Note that the init_params will be normalized before optionally passing into pydantic

Parameters:

init_params (Dict)

Return type:

Dict

ptyrad.params.parser.normalize_constraint_params(constraint_params)[source]#

Convert old constraint param format {freq} (pre v0.1.0b11) to {start_iter, step, end_iter}.

ptyrad.params.parser.copy_params_to_dir(params_path, output_dir, params=None)[source]#

Copies the params file to the output directory if it exists. If the params file does not exist, it dumps the provided params dictionary to a YAML file in the output directory.

Parameters:
  • params_path (str) – Path to the params file (can be None if params are programmatically generated).

  • output_dir (str) – Directory where the params file or YAML dump will be saved.

  • params (dict, optional) – The programmatically generated params dictionary to save if no file exists.

ptyrad.params.parser.yaml2json(input_filepath, output_filepath)[source]#