Project

class glotaran.project.project.Project(file: Path, folder: Path | None = None)[source]

Bases: object

A project represents a projectfolder on disk which contains a project file.

A project file is a file in yml format with name project.gta

Attributes Summary

data

Get all project datasets.

folder

has_data

Check if the project has datasets.

has_models

Check if the project has models.

has_parameters

Check if the project has parameters.

has_results

Check if the project has results.

models

Get all project models.

parameters

Get all project parameters.

results

Get all project results.

version

file

Methods Summary

create

Create a new project folder and file.

create_scheme

Create a scheme for optimization.

generate_model

Generate a model.

generate_parameters

Generate parameters for a model.

get_latest_result_path

Get the path to a result with name name.

get_models_directory

Get the path to the model directory of the project.

get_parameters_directory

Get the path to the parameter directory of the project.

get_result_path

Get the path to a result with name name.

import_data

Import a dataset.

load_data

Load a dataset.

load_latest_result

Load a result.

load_model

Load a model.

load_parameters

Load parameters.

load_result

Load a result.

markdown

Format the project as a markdown text.

open

Open a new project.

optimize

Optimize a model.

Methods Documentation

static create(folder: str | Path, allow_overwrite: bool = False) Project[source]

Create a new project folder and file.

Parameters
  • folder (str | Path | None) – The folder where the project will be created. If None, the current work directory will be used.

  • allow_overwrite (bool) – Whether to overwrite an existing project file.

Returns

The created project.

Return type

Project

Raises

FileExistsError – Raised if the project file already exists and allow_overwrite=False.

create_scheme(model_name: str, parameters_name: str, maximum_number_function_evaluations: int | None = None, clp_link_tolerance: float = 0.0) Scheme[source]

Create a scheme for optimization.

Parameters
  • model_name (str) – The model to optimize.

  • parameters_name (str) – The initial parameters.

  • maximum_number_function_evaluations (int | None) – The maximum number of function evaluations.

  • clp_link_tolerance (float) – The CLP link tolerance.

Returns

The created scheme.

Return type

Scheme

property data: dict[str, Path]

Get all project datasets.

Returns

The models of the datasets.

Return type

dict[str, Path]

file: Path
folder: Path | None = None
generate_model(model_name: str, generator_name: str, generator_arguments: dict[str, Any], *, allow_overwrite: bool = False, ignore_existing: bool = False)[source]

Generate a model.

Parameters
  • model_name (str) – The name of the model.

  • generator_name (str) – The generator for the model.

  • generator_arguments (dict[str, Any]) – Arguments for the generator.

  • allow_overwrite (bool) – Whether to overwrite an existing model.

  • ignore_existing (bool) – Whether to ignore generation of a model file if it already exists.

generate_parameters(model_name: str, parameters_name: str | None = None, *, format_name: Literal['yml', 'yaml', 'csv'] = 'csv', allow_overwrite: bool = False, ignore_existing: bool = False)[source]

Generate parameters for a model.

Parameters
  • model_name (str) – The model.

  • parameters_name (str | None) – The name of the parameters. If None it will be <model_name>_parameters.

  • format_name (Literal["yml", "yaml", "csv"]) – The parameter format.

  • allow_overwrite (bool) – Whether to overwrite existing parameters.

  • ignore_existing (bool) – Whether to ignore generation of a parameter file if it already exists.

get_latest_result_path(result_name: str) pathlib.Path[source]

Get the path to a result with name name.

Parameters

result_name (str) – The name of the result.

Returns

The path to the result.

Return type

Path

Raises

ValueError – Raised if result does not exist.

get_models_directory() pathlib.Path[source]

Get the path to the model directory of the project.

Returns

The path to the project’s model directory.

Return type

Path

get_parameters_directory() pathlib.Path[source]

Get the path to the parameter directory of the project.

Returns

The path to the project’s parameter directory.

Return type

Path

get_result_path(result_name: str, *, latest: bool = False) pathlib.Path[source]

Get the path to a result with name name.

Parameters
  • result_name (str) – The name of the result.

  • latest (bool) – Flag to deactivate warning about using latest result. Defaults to False

Returns

The path to the result.

Return type

Path

Raises

ValueError – Raised if result does not exist.

property has_data: bool

Check if the project has datasets.

Returns

Whether the project has datasets.

Return type

bool

property has_models: bool

Check if the project has models.

Returns

Whether the project has models.

Return type

bool

property has_parameters: bool

Check if the project has parameters.

Returns

Whether the project has parameters.

Return type

bool

property has_results: bool

Check if the project has results.

Returns

Whether the project has results.

Return type

bool

import_data(path: str | Path, name: str | None = None, allow_overwrite: bool = False, ignore_existing: bool = False)[source]

Import a dataset.

Parameters
  • path (str | Path) – The path to the dataset.

  • name (str | None) – The name of the dataset.

  • allow_overwrite (bool) – Whether to overwrite an existing dataset.

  • ignore_existing (bool) – Whether to ignore import if the dataset already exists.

load_data(dataset_name: str) xr.Dataset | xr.DataArray[source]

Load a dataset.

Parameters

dataset_name (str) – The name of the dataset.

Returns

The loaded dataset.

Return type

Result

Raises

ValueError – Raised if the dataset does not exist.

load_latest_result(result_name: str) glotaran.project.result.Result[source]

Load a result.

Parameters

result_name (str) – The name of the result.

Returns

The loaded result.

Return type

Result

Raises

ValueError – Raised if result does not exist.

load_model(name: str) glotaran.model.model.Model[source]

Load a model.

Parameters

name (str) – The name of the model.

Returns

The loaded model.

Return type

Model

Raises

ValueError – Raised if the model does not exist.

load_parameters(parameters_name: str) glotaran.parameter.parameter_group.ParameterGroup[source]

Load parameters.

Parameters

parameters_name (str) – The name of the parameters.

Returns

The loaded parameters.

Return type

ParameterGroup

Raises

ValueError – Raised if parameters do not exist.

load_result(result_name: str, *, latest: bool = False) glotaran.project.result.Result[source]

Load a result.

Parameters
  • result_name (str) – The name of the result.

  • latest (bool) – Flag to deactivate warning about using latest result. Defaults to False

Returns

The loaded result.

Return type

Result

Raises

ValueError – Raised if result does not exist.

markdown() glotaran.utils.ipython.MarkdownStr[source]

Format the project as a markdown text.

Returns

MarkdownStr – The markdown string.

Return type

str

property models: dict[str, Path]

Get all project models.

Returns

The models of the project.

Return type

dict[str, Path]

classmethod open(project_folder_or_file: str | Path, create_if_not_exist: bool = True) Project[source]

Open a new project.

Parameters
  • project_folder_or_file (str | Path) – The path to a project folder or file.

  • create_if_not_exist (bool) – Create the project if not existent.

Returns

The project instance.

Return type

Project

Raises

FileNotFoundError – Raised when the project file does not not exist and create_if_not_exist is False.

optimize(model_name: str, parameters_name: str, result_name: str | None = None, maximum_number_function_evaluations: int | None = None, clp_link_tolerance: float = 0.0)[source]

Optimize a model.

Parameters
  • model_name (str) – The model to optimize.

  • parameters_name (str) – The initial parameters.

  • result_name (str | None) – The name of the result.

  • maximum_number_function_evaluations (int | None) – The maximum number of function evaluations.

  • clp_link_tolerance (float) – The CLP link tolerance.

property parameters: dict[str, Path]

Get all project parameters.

Returns

The parameters of the project.

Return type

dict[str, Path]

property results: dict[str, Path]

Get all project results.

Returns

The results of the project.

Return type

dict[str, Path]

version: str