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
Get all project datasets.
Check if the project has datasets.
Check if the project has models.
Check if the project has parameters.
Check if the project has results.
Get all project models.
Get all project parameters.
Get all project results.
Methods Summary
Create a new project folder and file.
Create a scheme for optimization.
Generate a model.
Generate parameters for a model.
Get the path to a result with name
name
.Get the path to the model directory of the project.
Get the path to the parameter directory of the project.
Get the path to a result with name
name
.Import a dataset by saving it as an .nc file in the project's data folder.
Load a dataset, with SVD data if
add_svd
isTrue
.Load a result.
Load a model.
Load parameters.
Load a result.
Format the project as a markdown text.
Open a new project.
Optimize a model.
Show model definition file content with syntax highlighting.
Show parameters definition file content with syntax highlighting.
Check that the model is valid, list all issues in the model if there are any.
Methods Documentation
- static create(folder: str | Path, allow_overwrite: bool = False) Project [source]
Create a new project folder and file.
- Parameters:
- Returns:
The created project.
- Return type:
- 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, data_lookup_override: Mapping[str, LoadableDataset] | None = None) 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.
data_lookup_override (Mapping[str, LoadableDataset] | None) – Allows to bypass the default dataset lookup in the project
data
folder and use a different dataset for the optimization without changing the model. This is especially useful when working with preprocessed data. Defaults toNone
.
- Returns:
The created scheme.
- Return type:
- property data: Mapping[str, Path]
Get all project datasets.
- Returns:
The models of the datasets.
- Return type:
Mapping[str, Path]
- 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) 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() 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() 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) Path [source]
Get the path to a result with name
name
.- Parameters:
- 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:
- property has_models: bool
Check if the project has models.
- Returns:
Whether the project has models.
- Return type:
- property has_parameters: bool
Check if the project has parameters.
- Returns:
Whether the project has parameters.
- Return type:
- property has_results: bool
Check if the project has results.
- Returns:
Whether the project has results.
- Return type:
- import_data(dataset: LoadableDataset | Mapping[str, LoadableDataset], dataset_name: str | None = None, allow_overwrite: bool = False, ignore_existing: bool = True)[source]
Import a dataset by saving it as an .nc file in the project’s data folder.
- Parameters:
dataset (LoadableDataset) – Dataset instance or path to a dataset.
dataset_name (str | None) – The name of the dataset (needs to be provided when dataset is an xarray instance). Defaults to None.
allow_overwrite (bool) – Whether to overwrite an existing dataset.
ignore_existing (bool) – Whether to skip import if the dataset already exists and allow_overwrite is False. Defaults to
True
.
- load_data(dataset_name: str, *, add_svd: bool = False, lsv_dim: Hashable = 'time', rsv_dim: Hashable = 'spectral') xr.Dataset [source]
Load a dataset, with SVD data if
add_svd
isTrue
.- Parameters:
- Returns:
The loaded dataset, with SVD data if
add_svd
isTrue
.- Return type:
xr.Dataset
- Raises:
ValueError – Raised if the dataset does not exist.
- load_latest_result(result_name: str) Result [source]
Load a result.
- Parameters:
result_name (str) – The name of the result.
- Returns:
The loaded result.
- Return type:
- Raises:
ValueError – Raised if result does not exist.
- load_model(model_name: str) Model [source]
Load a model.
- Parameters:
model_name (str) – The name of the model.
- Returns:
The loaded model.
- Return type:
- Raises:
ValueError – Raised if the model does not exist.
- load_parameters(parameters_name: str) Parameters [source]
Load parameters.
- Parameters:
parameters_name (str) – The name of the parameters.
- Raises:
ValueError – Raised if parameters do not exist.
- Returns:
The loaded parameters.
- Return type:
- load_result(result_name: str, *, latest: bool = False) Result [source]
Load a result.
- Parameters:
- Returns:
The loaded result.
- Return type:
- Raises:
ValueError – Raised if result does not exist.
- markdown() MarkdownStr [source]
Format the project as a markdown text.
- Returns:
MarkdownStr – The markdown string.
- Return type:
- property models: Mapping[str, Path]
Get all project models.
- Returns:
The models of the project.
- Return type:
Mapping[str, Path]
- classmethod open(project_folder_or_file: str | Path, create_if_not_exist: bool = True) Project [source]
Open a new project.
- Parameters:
- Returns:
The project instance.
- Return type:
- 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, data_lookup_override: Mapping[str, LoadableDataset] | None = None) Result [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.
data_lookup_override (Mapping[str, LoadableDataset] | None) – Allows to bypass the default dataset lookup in the project
data
folder and use a different dataset for the optimization without changing the model. This is especially useful when working with preprocessed data. Defaults toNone
.
- Returns:
Result of the optimization.
- Return type:
- property parameters: Mapping[str, Path]
Get all project parameters.
- Returns:
The parameters of the project.
- Return type:
Mapping[str, Path]
- property results: Mapping[str, Path]
Get all project results.
- Returns:
The results of the project.
- Return type:
Mapping[str, Path]
- show_model_definition(model_name: str, syntax: str | None = None) MarkdownStr [source]
Show model definition file content with syntax highlighting.
- Parameters:
- Returns:
Model definition file content with syntax highlighting to render in ipython.
- Return type:
- show_parameters_definition(parameters_name: str, syntax: str | None = None, *, as_dataframe: bool | None = None) MarkdownStr | DataFrame [source]
Show parameters definition file content with syntax highlighting.
- Parameters:
parameters_name (str) – The name of the parameters.
syntax (str | None) – Syntax used for syntax highlighting. Defaults to None which means that the syntax is inferred based on the file extension. Pass the value
""
to deactivate syntax highlighting.as_dataframe (bool | None) – Whether or not to show the
Parameters
definition as pandas.DataFrame (mostly useful for non string formats). Defaults to None which means that it will be inferred toTrue
for known non string formats likexlsx
.
- Returns:
Parameters definition file content with syntax highlighting to render in ipython.
- Return type:
MarkdownStr | pd.DataFrame
- validate(model_name: str, parameters_name: str | None = None) MarkdownStr [source]
Check that the model is valid, list all issues in the model if there are any.
If
parameters_name
also consider theParameters
when validating.- Parameters:
- Returns:
Text indicating if the model is valid or not.
- Return type: