esgvoc 0.2.1__py3-none-any.whl → 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of esgvoc might be problematic. Click here for more details.
- esgvoc/__init__.py +3 -1
- esgvoc/api/__init__.py +23 -34
- esgvoc/api/_utils.py +28 -14
- esgvoc/api/data_descriptors/__init__.py +18 -12
- esgvoc/api/data_descriptors/activity.py +8 -45
- esgvoc/api/data_descriptors/area_label.py +6 -0
- esgvoc/api/data_descriptors/branded_suffix.py +5 -0
- esgvoc/api/data_descriptors/branded_variable.py +5 -0
- esgvoc/api/data_descriptors/consortium.py +16 -56
- esgvoc/api/data_descriptors/data_descriptor.py +106 -0
- esgvoc/api/data_descriptors/date.py +3 -46
- esgvoc/api/data_descriptors/directory_date.py +3 -46
- esgvoc/api/data_descriptors/experiment.py +19 -54
- esgvoc/api/data_descriptors/forcing_index.py +3 -45
- esgvoc/api/data_descriptors/frequency.py +6 -43
- esgvoc/api/data_descriptors/grid_label.py +6 -44
- esgvoc/api/data_descriptors/horizontal_label.py +6 -0
- esgvoc/api/data_descriptors/initialisation_index.py +3 -44
- esgvoc/api/data_descriptors/institution.py +11 -54
- esgvoc/api/data_descriptors/license.py +4 -44
- esgvoc/api/data_descriptors/mip_era.py +6 -44
- esgvoc/api/data_descriptors/model_component.py +7 -45
- esgvoc/api/data_descriptors/organisation.py +3 -40
- esgvoc/api/data_descriptors/physic_index.py +3 -45
- esgvoc/api/data_descriptors/product.py +4 -43
- esgvoc/api/data_descriptors/realisation_index.py +3 -44
- esgvoc/api/data_descriptors/realm.py +4 -42
- esgvoc/api/data_descriptors/resolution.py +6 -44
- esgvoc/api/data_descriptors/source.py +18 -53
- esgvoc/api/data_descriptors/source_type.py +3 -41
- esgvoc/api/data_descriptors/sub_experiment.py +3 -41
- esgvoc/api/data_descriptors/table.py +6 -48
- esgvoc/api/data_descriptors/temporal_label.py +6 -0
- esgvoc/api/data_descriptors/time_range.py +3 -27
- esgvoc/api/data_descriptors/variable.py +13 -71
- esgvoc/api/data_descriptors/variant_label.py +3 -47
- esgvoc/api/data_descriptors/vertical_label.py +5 -0
- esgvoc/api/projects.py +187 -171
- esgvoc/api/report.py +21 -12
- esgvoc/api/search.py +3 -1
- esgvoc/api/universe.py +44 -34
- esgvoc/apps/__init__.py +3 -4
- esgvoc/apps/drs/generator.py +166 -161
- esgvoc/apps/drs/report.py +222 -131
- esgvoc/apps/drs/validator.py +103 -105
- esgvoc/cli/drs.py +29 -19
- esgvoc/cli/get.py +26 -25
- esgvoc/cli/install.py +11 -8
- esgvoc/cli/main.py +0 -2
- esgvoc/cli/status.py +5 -5
- esgvoc/cli/valid.py +40 -40
- esgvoc/core/db/models/universe.py +3 -3
- esgvoc/core/db/project_ingestion.py +1 -1
- esgvoc/core/db/universe_ingestion.py +6 -5
- esgvoc/core/logging_handler.py +1 -1
- esgvoc/core/repo_fetcher.py +4 -3
- esgvoc/core/service/__init__.py +37 -5
- esgvoc/core/service/configuration/config_manager.py +188 -0
- esgvoc/core/service/configuration/setting.py +88 -0
- esgvoc/core/service/state.py +49 -32
- {esgvoc-0.2.1.dist-info → esgvoc-0.3.0.dist-info}/METADATA +34 -3
- esgvoc-0.3.0.dist-info/RECORD +78 -0
- esgvoc/cli/config.py +0 -82
- esgvoc/core/service/settings.py +0 -73
- esgvoc/core/service/settings.toml +0 -17
- esgvoc/core/service/settings_default.toml +0 -17
- esgvoc-0.2.1.dist-info/RECORD +0 -73
- {esgvoc-0.2.1.dist-info → esgvoc-0.3.0.dist-info}/WHEEL +0 -0
- {esgvoc-0.2.1.dist-info → esgvoc-0.3.0.dist-info}/entry_points.txt +0 -0
- {esgvoc-0.2.1.dist-info → esgvoc-0.3.0.dist-info}/licenses/LICENSE.txt +0 -0
esgvoc/__init__.py
CHANGED
esgvoc/api/__init__.py
CHANGED
|
@@ -1,38 +1,26 @@
|
|
|
1
|
-
from esgvoc.api.
|
|
2
|
-
from esgvoc.api.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
from esgvoc.api._utils import APIException
|
|
2
|
+
from esgvoc.api.project_specs import (DrsCollection, DrsConstant, DrsPart,
|
|
3
|
+
DrsPartKind, DrsSpecification, DrsType,
|
|
4
|
+
ProjectSpecs)
|
|
5
|
+
from esgvoc.api.projects import (
|
|
6
|
+
find_collections_in_project, find_project,
|
|
7
|
+
find_terms_from_data_descriptor_in_all_projects,
|
|
8
|
+
find_terms_from_data_descriptor_in_project, find_terms_in_all_projects,
|
|
9
|
+
find_terms_in_collection, find_terms_in_project,
|
|
10
|
+
get_all_collections_in_project, get_all_projects,
|
|
11
|
+
get_all_terms_in_all_projects, get_all_terms_in_collection,
|
|
12
|
+
get_all_terms_in_project, valid_term, valid_term_in_all_projects,
|
|
13
|
+
valid_term_in_collection, valid_term_in_project)
|
|
14
|
+
from esgvoc.api.report import (ProjectTermError, UniverseTermError,
|
|
15
|
+
ValidationError, ValidationErrorVisitor,
|
|
16
|
+
ValidationReport)
|
|
17
|
+
from esgvoc.api.search import MatchingTerm, SearchSettings, SearchType
|
|
18
|
+
from esgvoc.api.universe import (find_data_descriptors_in_universe,
|
|
19
|
+
find_terms_in_data_descriptor,
|
|
20
|
+
find_terms_in_universe,
|
|
8
21
|
get_all_data_descriptors_in_universe,
|
|
9
|
-
find_data_descriptors_in_universe,
|
|
10
22
|
get_all_terms_in_data_descriptor,
|
|
11
|
-
|
|
12
|
-
find_terms_in_data_descriptor)
|
|
13
|
-
from esgvoc.api.projects import (get_all_projects,
|
|
14
|
-
find_project,
|
|
15
|
-
get_all_terms_in_all_projects,
|
|
16
|
-
get_all_terms_in_project,
|
|
17
|
-
get_all_collections_in_project,
|
|
18
|
-
find_collections_in_project,
|
|
19
|
-
get_all_terms_in_collection,
|
|
20
|
-
find_terms_in_project,
|
|
21
|
-
find_terms_in_all_projects,
|
|
22
|
-
find_terms_from_data_descriptor_in_all_projects,
|
|
23
|
-
find_terms_from_data_descriptor_in_project,
|
|
24
|
-
find_terms_in_collection,
|
|
25
|
-
valid_term_in_all_projects,
|
|
26
|
-
valid_term_in_project,
|
|
27
|
-
valid_term_in_collection,
|
|
28
|
-
valid_term)
|
|
29
|
-
from esgvoc.api.project_specs import (DrsType,
|
|
30
|
-
DrsPartKind,
|
|
31
|
-
DrsConstant,
|
|
32
|
-
DrsCollection,
|
|
33
|
-
DrsPart,
|
|
34
|
-
DrsSpecification,
|
|
35
|
-
ProjectSpecs)
|
|
23
|
+
get_all_terms_in_universe)
|
|
36
24
|
|
|
37
25
|
__all__ = ["MatchingTerm",
|
|
38
26
|
"SearchType",
|
|
@@ -70,4 +58,5 @@ __all__ = ["MatchingTerm",
|
|
|
70
58
|
"DrsCollection",
|
|
71
59
|
"DrsPart",
|
|
72
60
|
"DrsSpecification",
|
|
73
|
-
"ProjectSpecs"
|
|
61
|
+
"ProjectSpecs",
|
|
62
|
+
"APIException"]
|
esgvoc/api/_utils.py
CHANGED
|
@@ -1,39 +1,53 @@
|
|
|
1
|
-
from typing import
|
|
1
|
+
from typing import Iterable, MutableSequence
|
|
2
2
|
|
|
3
|
+
from sqlmodel import Session
|
|
3
4
|
|
|
4
5
|
import esgvoc.core.constants as api_settings
|
|
6
|
+
import esgvoc.core.service as service
|
|
5
7
|
from esgvoc.api.data_descriptors import DATA_DESCRIPTOR_CLASS_MAPPING
|
|
8
|
+
from esgvoc.api.data_descriptors.data_descriptor import (DataDescriptor,
|
|
9
|
+
DataDescriptorSubSet)
|
|
6
10
|
from esgvoc.core.db.models.project import PTerm
|
|
7
11
|
from esgvoc.core.db.models.universe import UTerm
|
|
8
|
-
from pydantic import BaseModel
|
|
9
|
-
from sqlmodel import Session
|
|
10
12
|
|
|
11
|
-
import esgvoc.core.service as service
|
|
12
|
-
UNIVERSE_DB_CONNECTION = service.state_service.universe.db_connection
|
|
13
13
|
|
|
14
|
+
class APIException(Exception): ...
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
|
|
17
|
+
def get_pydantic_class(data_descriptor_id_or_term_type: str) -> type[DataDescriptor]:
|
|
16
18
|
if data_descriptor_id_or_term_type in DATA_DESCRIPTOR_CLASS_MAPPING:
|
|
17
19
|
return DATA_DESCRIPTOR_CLASS_MAPPING[data_descriptor_id_or_term_type]
|
|
18
20
|
else:
|
|
19
|
-
raise
|
|
21
|
+
raise RuntimeError(f"{data_descriptor_id_or_term_type} pydantic class not found")
|
|
20
22
|
|
|
21
23
|
|
|
22
24
|
def get_universe_session() -> Session:
|
|
23
|
-
|
|
25
|
+
|
|
26
|
+
UNIVERSE_DB_CONNECTION = service.current_state.universe.db_connection
|
|
24
27
|
if UNIVERSE_DB_CONNECTION:
|
|
25
28
|
return UNIVERSE_DB_CONNECTION.create_session()
|
|
26
29
|
else:
|
|
27
30
|
raise RuntimeError('universe connection is not initialized')
|
|
28
31
|
|
|
29
32
|
|
|
30
|
-
def instantiate_pydantic_term(term: UTerm|PTerm
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
def instantiate_pydantic_term(term: UTerm|PTerm,
|
|
34
|
+
selected_term_fields: Iterable[str]|None) -> DataDescriptor:
|
|
35
|
+
type = term.specs[api_settings.TERM_TYPE_JSON_KEY]
|
|
36
|
+
if selected_term_fields:
|
|
37
|
+
subset = DataDescriptorSubSet(id=term.id, type=type)
|
|
38
|
+
for field in selected_term_fields:
|
|
39
|
+
setattr(subset, field, term.specs.get(field, None))
|
|
40
|
+
for field in DataDescriptorSubSet.MANDATORY_TERM_FIELDS:
|
|
41
|
+
setattr(subset, field, term.specs.get(field, None))
|
|
42
|
+
return subset
|
|
43
|
+
else:
|
|
44
|
+
term_class = get_pydantic_class(type)
|
|
45
|
+
return term_class(**term.specs)
|
|
33
46
|
|
|
34
47
|
|
|
35
|
-
def instantiate_pydantic_terms(db_terms:
|
|
36
|
-
list_to_populate:
|
|
48
|
+
def instantiate_pydantic_terms(db_terms: Iterable[UTerm|PTerm],
|
|
49
|
+
list_to_populate: MutableSequence[DataDescriptor],
|
|
50
|
+
selected_term_fields: Iterable[str]|None) -> None:
|
|
37
51
|
for db_term in db_terms:
|
|
38
|
-
term = instantiate_pydantic_term(db_term)
|
|
52
|
+
term = instantiate_pydantic_term(db_term, selected_term_fields)
|
|
39
53
|
list_to_populate.append(term)
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
from esgvoc.api.data_descriptors.directory_date import DirectoryDate
|
|
2
|
-
from pydantic import BaseModel
|
|
3
|
-
|
|
4
1
|
from esgvoc.api.data_descriptors.activity import Activity
|
|
5
2
|
from esgvoc.api.data_descriptors.consortium import Consortium
|
|
3
|
+
from esgvoc.api.data_descriptors.data_descriptor import DataDescriptor
|
|
6
4
|
from esgvoc.api.data_descriptors.date import Date
|
|
5
|
+
from esgvoc.api.data_descriptors.directory_date import DirectoryDate
|
|
7
6
|
from esgvoc.api.data_descriptors.experiment import Experiment
|
|
8
7
|
from esgvoc.api.data_descriptors.forcing_index import ForcingIndex
|
|
9
8
|
from esgvoc.api.data_descriptors.frequency import Frequency
|
|
@@ -26,10 +25,14 @@ from esgvoc.api.data_descriptors.table import Table
|
|
|
26
25
|
from esgvoc.api.data_descriptors.time_range import TimeRange
|
|
27
26
|
from esgvoc.api.data_descriptors.variable import Variable
|
|
28
27
|
from esgvoc.api.data_descriptors.variant_label import VariantLabel
|
|
29
|
-
from esgvoc.api.data_descriptors.
|
|
30
|
-
|
|
28
|
+
from esgvoc.api.data_descriptors.area_label import AreaLabel
|
|
29
|
+
from esgvoc.api.data_descriptors.vertical_label import VerticalLabel
|
|
30
|
+
from esgvoc.api.data_descriptors.horizontal_label import HorizontalLabel
|
|
31
|
+
from esgvoc.api.data_descriptors.temporal_label import TemporalLabel
|
|
32
|
+
from esgvoc.api.data_descriptors.branded_suffix import BrandedSuffix
|
|
33
|
+
from esgvoc.api.data_descriptors.branded_variable import BrandedVariable
|
|
31
34
|
|
|
32
|
-
DATA_DESCRIPTOR_CLASS_MAPPING: dict[str, type[
|
|
35
|
+
DATA_DESCRIPTOR_CLASS_MAPPING: dict[str, type[DataDescriptor]] = {
|
|
33
36
|
"activity": Activity,
|
|
34
37
|
"consortium": Consortium,
|
|
35
38
|
"date": Date,
|
|
@@ -37,9 +40,8 @@ DATA_DESCRIPTOR_CLASS_MAPPING: dict[str, type[BaseModel]] = {
|
|
|
37
40
|
"experiment": Experiment,
|
|
38
41
|
"forcing_index": ForcingIndex,
|
|
39
42
|
"frequency": Frequency,
|
|
40
|
-
"grid": GridLabel
|
|
41
|
-
"
|
|
42
|
-
"grid_label": GridLabel, # DEBUG: the value of the key type for the terms of the DD grid is not consistent.
|
|
43
|
+
"grid": GridLabel,#Universe
|
|
44
|
+
"grid_label": GridLabel, # cmip6, cmip6plus
|
|
43
45
|
"initialisation_index": InitialisationIndex,
|
|
44
46
|
"institution": Institution,
|
|
45
47
|
"license": License,
|
|
@@ -57,7 +59,11 @@ DATA_DESCRIPTOR_CLASS_MAPPING: dict[str, type[BaseModel]] = {
|
|
|
57
59
|
"table" : Table,
|
|
58
60
|
"time_range": TimeRange,
|
|
59
61
|
"variable": Variable,
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
62
|
+
"variant_label": VariantLabel,
|
|
63
|
+
"area_label": AreaLabel,
|
|
64
|
+
"temporal_label": TemporalLabel,
|
|
65
|
+
"vertical_label" : VerticalLabel,
|
|
66
|
+
"horizontal_label" : HorizontalLabel,
|
|
67
|
+
"branded_suffix" : BrandedSuffix,
|
|
68
|
+
"branded_variable" : BrandedVariable
|
|
63
69
|
}
|
|
@@ -1,51 +1,14 @@
|
|
|
1
|
+
from esgvoc.api.data_descriptors.data_descriptor import PlainTermDataDescriptor
|
|
1
2
|
|
|
2
|
-
from __future__ import annotations
|
|
3
|
-
from typing import (
|
|
4
|
-
Optional
|
|
5
|
-
)
|
|
6
|
-
from pydantic.version import VERSION as PYDANTIC_VERSION
|
|
7
|
-
if int(PYDANTIC_VERSION[0])>=2:
|
|
8
|
-
from pydantic import (
|
|
9
|
-
BaseModel,
|
|
10
|
-
ConfigDict,
|
|
11
|
-
Field
|
|
12
|
-
)
|
|
13
|
-
else:
|
|
14
|
-
from pydantic import (
|
|
15
|
-
BaseModel,
|
|
16
|
-
Field
|
|
17
|
-
)
|
|
18
3
|
|
|
19
|
-
|
|
20
|
-
version = "None"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class ConfiguredBaseModel(BaseModel):
|
|
24
|
-
model_config = ConfigDict(
|
|
25
|
-
validate_assignment = True,
|
|
26
|
-
validate_default = True,
|
|
27
|
-
extra = "allow",
|
|
28
|
-
arbitrary_types_allowed = True,
|
|
29
|
-
use_enum_values = True,
|
|
30
|
-
strict = False,
|
|
31
|
-
)
|
|
32
|
-
pass
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
class Activity(ConfiguredBaseModel):
|
|
4
|
+
class Activity(PlainTermDataDescriptor):
|
|
37
5
|
"""
|
|
38
|
-
|
|
6
|
+
An 'activity' refers to a coordinated set of modeling experiments designed to address specific \
|
|
7
|
+
scientific questions or objectives. Each activity is focused on different aspects of climate \
|
|
8
|
+
science and utilizes various models to study a wide range of climate phenomena. \
|
|
9
|
+
Activities are often organized around key research themes and may involve multiple experiments, \
|
|
10
|
+
scenarios, and model configurations.
|
|
39
11
|
"""
|
|
40
|
-
|
|
41
|
-
id: str
|
|
42
|
-
validation_method: str = Field(default = "list")
|
|
43
12
|
name: str
|
|
44
13
|
long_name: str
|
|
45
|
-
|
|
46
|
-
url: Optional[str]
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
# Model rebuild
|
|
50
|
-
# see https://pydantic-docs.helpmanual.io/usage/models/#rebuilding-a-model
|
|
51
|
-
Activity.model_rebuild()
|
|
14
|
+
url: str|None
|
|
@@ -1,66 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
from
|
|
3
|
-
from typing import (
|
|
4
|
-
List,
|
|
5
|
-
Optional,
|
|
6
|
-
Union
|
|
7
|
-
)
|
|
8
|
-
from pydantic.version import VERSION as PYDANTIC_VERSION
|
|
9
|
-
if int(PYDANTIC_VERSION[0])>=2:
|
|
10
|
-
from pydantic import (
|
|
11
|
-
BaseModel,
|
|
12
|
-
ConfigDict,
|
|
13
|
-
Field
|
|
14
|
-
)
|
|
15
|
-
else:
|
|
16
|
-
from pydantic import (
|
|
17
|
-
BaseModel,
|
|
18
|
-
Field
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
metamodel_version = "None"
|
|
22
|
-
version = "None"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
class ConfiguredBaseModel(BaseModel):
|
|
26
|
-
model_config = ConfigDict(
|
|
27
|
-
validate_assignment = True,
|
|
28
|
-
validate_default = True,
|
|
29
|
-
extra = "allow",
|
|
30
|
-
arbitrary_types_allowed = True,
|
|
31
|
-
use_enum_values = True,
|
|
32
|
-
strict = False,
|
|
33
|
-
)
|
|
34
|
-
pass
|
|
1
|
+
from pydantic import Field
|
|
2
|
+
from esgvoc.api.data_descriptors.data_descriptor import PlainTermDataDescriptor, ConfiguredBaseModel
|
|
35
3
|
|
|
36
4
|
|
|
37
5
|
class Dates(ConfiguredBaseModel):
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
to: Union[int,str]
|
|
6
|
+
phase: str
|
|
7
|
+
from_: int = Field(...,alias="from") # Cause from is a keyword
|
|
8
|
+
to: int|str
|
|
42
9
|
|
|
43
10
|
|
|
44
11
|
class Member(ConfiguredBaseModel):
|
|
45
|
-
|
|
46
12
|
type : str
|
|
47
|
-
institution
|
|
48
|
-
dates
|
|
49
|
-
membership_type
|
|
13
|
+
institution: str # id
|
|
14
|
+
dates: list[Dates] = Field(default_factory=list)
|
|
15
|
+
membership_type: str # prior, current
|
|
50
16
|
|
|
51
|
-
class Consortium(ConfiguredBaseModel):
|
|
52
17
|
|
|
53
|
-
|
|
18
|
+
class Consortium(PlainTermDataDescriptor):
|
|
54
19
|
validation_method: str = Field(default = "list")
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
# Model rebuild
|
|
65
|
-
# see https://pydantic-docs.helpmanual.io/usage/models/#rebuilding-a-model
|
|
66
|
-
Consortium.model_rebuild()
|
|
20
|
+
name: str|None = None
|
|
21
|
+
status: str|None = None
|
|
22
|
+
changes: str|None
|
|
23
|
+
members: list[Member] = Field(default_factory=list)
|
|
24
|
+
url: str|None
|
|
25
|
+
# TODO: remove default value when all json will have their description.
|
|
26
|
+
description: str = Field(default = "")
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
from typing import Protocol, Any, ClassVar
|
|
2
|
+
from abc import ABC, abstractmethod
|
|
3
|
+
from pydantic import BaseModel, ConfigDict
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ConfiguredBaseModel(BaseModel):
|
|
7
|
+
model_config = ConfigDict(
|
|
8
|
+
validate_assignment = True,
|
|
9
|
+
validate_default = True,
|
|
10
|
+
extra = "allow",
|
|
11
|
+
arbitrary_types_allowed = True,
|
|
12
|
+
use_enum_values = True,
|
|
13
|
+
strict = False,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class DataDescriptorVisitor(Protocol):
|
|
18
|
+
"""
|
|
19
|
+
The specifications for a term visitor.
|
|
20
|
+
"""
|
|
21
|
+
def visit_sub_set_term(self, term: "DataDescriptorSubSet") -> Any:
|
|
22
|
+
"""Visit a sub set of the information of a term."""
|
|
23
|
+
pass
|
|
24
|
+
def visit_plain_term(self, term: "PlainTermDataDescriptor") -> Any:
|
|
25
|
+
"""Visit a plain term."""
|
|
26
|
+
pass
|
|
27
|
+
def visit_pattern_term(self, term: "PatternTermDataDescriptor") -> Any:
|
|
28
|
+
"""Visit a pattern term."""
|
|
29
|
+
pass
|
|
30
|
+
def visit_composite_term(self, term: "CompositeTermDataDescriptor") -> Any:
|
|
31
|
+
"""Visit a composite term."""
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class DataDescriptor(ConfiguredBaseModel, ABC):
|
|
35
|
+
"""
|
|
36
|
+
Generic class for the data descriptor classes.
|
|
37
|
+
"""
|
|
38
|
+
id: str
|
|
39
|
+
"""The identifier of the terms."""
|
|
40
|
+
type: str
|
|
41
|
+
"""The data descriptor to which the term belongs."""
|
|
42
|
+
|
|
43
|
+
@abstractmethod
|
|
44
|
+
def accept(self, visitor: DataDescriptorVisitor) -> Any:
|
|
45
|
+
"""
|
|
46
|
+
Accept an term visitor.
|
|
47
|
+
|
|
48
|
+
:param visitor: The term visitor.
|
|
49
|
+
:type visitor: DataDescriptorVisitor
|
|
50
|
+
:return: Depending on the visitor.
|
|
51
|
+
:rtype: Any
|
|
52
|
+
"""
|
|
53
|
+
pass
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class DataDescriptorSubSet(DataDescriptor):
|
|
57
|
+
"""
|
|
58
|
+
A sub set of the information contains in a term.
|
|
59
|
+
"""
|
|
60
|
+
MANDATORY_TERM_FIELDS: ClassVar[tuple[str, str]] = ('id', 'type')
|
|
61
|
+
"""The set of mandatory term fields."""
|
|
62
|
+
def accept(self, visitor: DataDescriptorVisitor) -> Any:
|
|
63
|
+
return visitor.visit_sub_set_term(self)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class PlainTermDataDescriptor(DataDescriptor):
|
|
67
|
+
"""
|
|
68
|
+
A data descriptor that describes hand written terms.
|
|
69
|
+
"""
|
|
70
|
+
drs_name: str
|
|
71
|
+
def accept(self, visitor: DataDescriptorVisitor) -> Any:
|
|
72
|
+
return visitor.visit_plain_term(self)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class PatternTermDataDescriptor(DataDescriptor):
|
|
76
|
+
"""
|
|
77
|
+
A data descriptor that describes terms defined by a regular expression.
|
|
78
|
+
"""
|
|
79
|
+
regex: str
|
|
80
|
+
"""The regular expression."""
|
|
81
|
+
def accept(self, visitor: DataDescriptorVisitor) -> Any:
|
|
82
|
+
return visitor.visit_pattern_term(self)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class CompositeTermPart(ConfiguredBaseModel):
|
|
86
|
+
"""
|
|
87
|
+
A reference to a term, part of a composite term.
|
|
88
|
+
"""
|
|
89
|
+
id: str
|
|
90
|
+
"""The id of the referenced term."""
|
|
91
|
+
type: str
|
|
92
|
+
"""The type of the referenced term."""
|
|
93
|
+
is_required : bool
|
|
94
|
+
"""Denote if the term is optional as part of a composite term."""
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class CompositeTermDataDescriptor(DataDescriptor):
|
|
98
|
+
"""
|
|
99
|
+
A data descriptor that describes terms composed of other terms.
|
|
100
|
+
"""
|
|
101
|
+
separator: str
|
|
102
|
+
"""The components separator character."""
|
|
103
|
+
parts: list[CompositeTermPart]
|
|
104
|
+
"""The components."""
|
|
105
|
+
def accept(self, visitor: DataDescriptorVisitor) -> Any:
|
|
106
|
+
return visitor.visit_composite_term(self)
|
|
@@ -1,48 +1,5 @@
|
|
|
1
|
+
from esgvoc.api.data_descriptors.data_descriptor import PatternTermDataDescriptor
|
|
1
2
|
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
from __future__ import annotations
|
|
9
|
-
from pydantic.version import VERSION as PYDANTIC_VERSION
|
|
10
|
-
if int(PYDANTIC_VERSION[0])>=2:
|
|
11
|
-
from pydantic import (
|
|
12
|
-
BaseModel,
|
|
13
|
-
ConfigDict
|
|
14
|
-
)
|
|
15
|
-
else:
|
|
16
|
-
from pydantic import (
|
|
17
|
-
BaseModel
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
metamodel_version = "None"
|
|
21
|
-
version = "None"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
class ConfiguredBaseModel(BaseModel):
|
|
25
|
-
model_config = ConfigDict(
|
|
26
|
-
validate_assignment = True,
|
|
27
|
-
validate_default = True,
|
|
28
|
-
extra = "allow",
|
|
29
|
-
arbitrary_types_allowed = True,
|
|
30
|
-
use_enum_values = True,
|
|
31
|
-
strict = False,
|
|
32
|
-
)
|
|
33
|
-
pass
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
class Date(ConfiguredBaseModel):
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
id: str
|
|
44
|
-
type : str
|
|
45
|
-
regex : str
|
|
46
|
-
# Model rebuild
|
|
47
|
-
# see https://pydantic-docs.helpmanual.io/usage/models/#rebuilding-a-model
|
|
48
|
-
Date.model_rebuild()
|
|
4
|
+
class Date(PatternTermDataDescriptor):
|
|
5
|
+
pass
|
|
@@ -1,48 +1,5 @@
|
|
|
1
|
+
from esgvoc.api.data_descriptors.data_descriptor import PatternTermDataDescriptor
|
|
1
2
|
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
from typing import (
|
|
6
|
-
List
|
|
7
|
-
)
|
|
8
|
-
from pydantic.version import VERSION as PYDANTIC_VERSION
|
|
9
|
-
if int(PYDANTIC_VERSION[0])>=2:
|
|
10
|
-
from pydantic import (
|
|
11
|
-
BaseModel,
|
|
12
|
-
ConfigDict
|
|
13
|
-
)
|
|
14
|
-
else:
|
|
15
|
-
from pydantic import (
|
|
16
|
-
BaseModel
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
metamodel_version = "None"
|
|
20
|
-
version = "None"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class ConfiguredBaseModel(BaseModel):
|
|
24
|
-
model_config = ConfigDict(
|
|
25
|
-
validate_assignment = True,
|
|
26
|
-
validate_default = True,
|
|
27
|
-
extra = "allow",
|
|
28
|
-
arbitrary_types_allowed = True,
|
|
29
|
-
use_enum_values = True,
|
|
30
|
-
strict = False,
|
|
31
|
-
)
|
|
32
|
-
pass
|
|
33
|
-
|
|
34
|
-
class Part(ConfiguredBaseModel):
|
|
35
|
-
id: str
|
|
36
|
-
type : str
|
|
37
|
-
is_required : bool
|
|
38
|
-
|
|
39
|
-
class DirectoryDate(ConfiguredBaseModel):
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
id: str
|
|
43
|
-
type: str
|
|
44
|
-
regex : str
|
|
45
|
-
|
|
46
|
-
# Model rebuild
|
|
47
|
-
# see https://pydantic-docs.helpmanual.io/usage/models/#rebuilding-a-model
|
|
48
|
-
DirectoryDate.model_rebuild()
|
|
4
|
+
class DirectoryDate(PatternTermDataDescriptor):
|
|
5
|
+
pass
|
|
@@ -1,60 +1,25 @@
|
|
|
1
|
+
from pydantic import Field
|
|
2
|
+
from esgvoc.api.data_descriptors.data_descriptor import PlainTermDataDescriptor
|
|
1
3
|
|
|
2
|
-
from __future__ import annotations
|
|
3
|
-
from typing import (
|
|
4
|
-
List,
|
|
5
|
-
Optional
|
|
6
|
-
)
|
|
7
|
-
from pydantic.version import VERSION as PYDANTIC_VERSION
|
|
8
|
-
if int(PYDANTIC_VERSION[0])>=2:
|
|
9
|
-
from pydantic import (
|
|
10
|
-
BaseModel,
|
|
11
|
-
ConfigDict,
|
|
12
|
-
Field
|
|
13
|
-
)
|
|
14
|
-
else:
|
|
15
|
-
from pydantic import (
|
|
16
|
-
BaseModel,
|
|
17
|
-
Field
|
|
18
|
-
)
|
|
19
4
|
|
|
20
|
-
|
|
21
|
-
version = "None"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
class ConfiguredBaseModel(BaseModel):
|
|
25
|
-
model_config = ConfigDict(
|
|
26
|
-
validate_assignment = True,
|
|
27
|
-
validate_default = True,
|
|
28
|
-
extra = "allow",
|
|
29
|
-
arbitrary_types_allowed = True,
|
|
30
|
-
use_enum_values = True,
|
|
31
|
-
strict = False,
|
|
32
|
-
)
|
|
33
|
-
pass
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
class Experiment(ConfiguredBaseModel):
|
|
5
|
+
class Experiment(PlainTermDataDescriptor):
|
|
37
6
|
"""
|
|
38
|
-
|
|
7
|
+
An 'experiment' refers to a specific, controlled simulation conducted using climate models to \
|
|
8
|
+
investigate particular aspects of the Earth's climate system. These experiments are designed \
|
|
9
|
+
with set parameters, such as initial conditions, external forcings (like greenhouse gas \
|
|
10
|
+
concentrations or solar radiation), and duration, to explore and understand climate behavior \
|
|
11
|
+
under various scenarios and conditions.
|
|
39
12
|
"""
|
|
40
|
-
|
|
41
|
-
id: str
|
|
42
|
-
validation_method: str = Field(default ="list")
|
|
43
|
-
activity: List[str] = Field(default_factory=list)
|
|
13
|
+
activity: list[str] = Field(default_factory=list)
|
|
44
14
|
description: str
|
|
45
|
-
tier:
|
|
15
|
+
tier: int|None
|
|
46
16
|
experiment_id: str
|
|
47
|
-
sub_experiment_id:
|
|
48
|
-
experiment: str
|
|
49
|
-
required_model_components:
|
|
50
|
-
|
|
51
|
-
start_year:
|
|
52
|
-
end_year:
|
|
53
|
-
min_number_yrs_per_sim:
|
|
54
|
-
parent_activity_id:
|
|
55
|
-
parent_experiment_id:
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
# Model rebuild
|
|
59
|
-
# see https://pydantic-docs.helpmanual.io/usage/models/#rebuilding-a-model
|
|
60
|
-
Experiment.model_rebuild()
|
|
17
|
+
sub_experiment_id: list[str]|None
|
|
18
|
+
experiment: str
|
|
19
|
+
required_model_components: list[str]|None
|
|
20
|
+
additional_allowed_model_components: list[str] = Field(default_factory=list)
|
|
21
|
+
start_year: int|None
|
|
22
|
+
end_year: int|None
|
|
23
|
+
min_number_yrs_per_sim: int|None
|
|
24
|
+
parent_activity_id: list[str]|None
|
|
25
|
+
parent_experiment_id: list[str]|None
|