Skip to content
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2c35c25
First version for openalea configuration
pradal Jun 4, 2026
37d3282
First try
pradal Jun 4, 2026
7b5315c
Fix syntax error
pradal Jun 4, 2026
73d4c67
i add 2 news classes Parameter and MyModelUnit and many functions in …
LeticiaNapolitano-34 Jun 4, 2026
542175d
adding pyyaml
LeticiaNapolitano-34 Jun 5, 2026
2c3e8e1
Update meta.yaml
LeticiaNapolitano-34 Jun 5, 2026
f60d764
i add pyyaml in dependencies
LeticiaNapolitano-34 Jun 5, 2026
2b5091d
i made some test to create a params.json file with one example of Hyd…
LeticiaNapolitano-34 Jun 5, 2026
9d61cae
[no ci] modification of the classes and some test from a params.json …
LeticiaNapolitano-34 Jun 8, 2026
6bbde94
Merge branch 'config' of github.com:openalea/core into config
LeticiaNapolitano-34 Jun 8, 2026
f355e7d
modification of the indexation
LeticiaNapolitano-34 Jun 8, 2026
d14b987
I do some test with yml
LeticiaNapolitano-34 Jun 8, 2026
486ac6b
Update the tests
pradal Jun 10, 2026
eaae10c
Update the tests
pradal Jun 10, 2026
b551247
i add new functions and made some test
LeticiaNapolitano-34 Jun 10, 2026
59273ee
i add 3 new functions and dict
LeticiaNapolitano-34 Jun 10, 2026
8a5899e
ajout de nouveaux parametres
LeticiaNapolitano-34 Jun 16, 2026
bb66dc6
modification of the load function
LeticiaNapolitano-34 Jun 16, 2026
dc55b88
modification of the dump function
LeticiaNapolitano-34 Jun 17, 2026
ba618be
i just add some test
LeticiaNapolitano-34 Jun 19, 2026
c343804
i made config a dict and dataclass of parameter
LeticiaNapolitano-34 Jun 19, 2026
44a3063
after several attempts, I found a function to generate a function but…
LeticiaNapolitano-34 Jun 23, 2026
1b81681
test with comment
LeticiaNapolitano-34 Jun 24, 2026
454023a
new function for adding comment
LeticiaNapolitano-34 Jun 24, 2026
b7a7562
add ruamel.yaml
LeticiaNapolitano-34 Jun 24, 2026
6db511e
Tutorial of the configuration
LeticiaNapolitano-34 Jun 25, 2026
032b4bc
I made some test and add new comments, in some parameters and section…
LeticiaNapolitano-34 Jun 26, 2026
5eefc99
I add 2 functons for adding comments before each section and paramete…
LeticiaNapolitano-34 Jun 26, 2026
8f0460b
New documentation
LeticiaNapolitano-34 Jun 29, 2026
ea24456
Tutorial and documentation about configuration on Jupyternotebook
LeticiaNapolitano-34 Jun 30, 2026
5d4c27f
Modification of comment section and ModelUnit class
LeticiaNapolitano-34 Jul 2, 2026
1522c19
Delete Documentation.ipynb
LeticiaNapolitano-34 Jul 3, 2026
8dd9c4a
Add description to the sections
LeticiaNapolitano-34 Jul 3, 2026
4d53bbd
Merge branch 'config' of github.com:openalea/core into config
LeticiaNapolitano-34 Jul 3, 2026
14d3e88
Json and yml file
LeticiaNapolitano-34 Jul 3, 2026
6e94dba
last version of config, new parameters in modelUnit
LeticiaNapolitano-34 Jul 3, 2026
2d92d10
The tutorial in Jupyter notebook
LeticiaNapolitano-34 Jul 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ build:
requirements:
host:
- python
- pyyaml
{% for dep in build_deps %}
- {{ dep }}
{% endfor %}

run:
- python
- pyyaml
{% for dep in deps + conda_deps %}
- {{ dep }}
{% endfor %}
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ dependencies = [
"configobj",
"six",
"setuptools",
"pyyaml",
]

[tool.setuptools.dynamic]
Expand Down
184 changes: 184 additions & 0 deletions src/openalea/core/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
# -*- python -*-
#
# OpenAlea.Core
#
# Copyright 2006-2026 CIRAD - INRAE - inria
#
# File author(s): Leticia Napolitano
# Christophe Pradal <christophe.prada@cirad.fr>
# Fabrice Bauget <fabrice.bauget@cirad.fr>
#
# Distributed under the Cecill-C License.
# See accompanying file LICENSE.txt or copy at
# http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html
#
# OpenAlea WebSite : http://openalea.gforge.inria.fr
#
##############################################################################
"""Configuration of OpenAlea models"""

__license__ = "Cecill-C"

import yaml
import json
from openalea.core.singleton import Singleton
from openalea.core.observer import Observed
from pathlib import Path

def _load_json(filename: str):
"""Load configuration from a JSON file."""

file = Path(filename)
with file.open() as f:
data = json.load(f)
return data

def _load_yml(filename: str):
"""Load configuration from a YAML file."""

file = Path(filename)
with file.open() as f:
data = yaml.load(f, Loader=yaml.SafeLoader)
return data

def _dump_yml(data, filename: str, sort_keys=False):
"""Dump configuration to a YAML file."""

file = Path(filename)
with file.open("w") as f:
yaml.dump(data, f, sort_keys=sort_keys)

def _dump_json(data, filename: str):
"""Dump configuration to a JSON file."""

file = Path(filename)
with file.open("w") as f:
json.dump(data, f, indent=4)


class Parameter:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Parameter, I would use a Data Class.
Look at it

def __init__(self, name, value=None, unit=None, param_type=None, description="", uid=None, uri=None):
self.name = name
self.value = value
self.unit = unit
self.param_type = param_type
self.description = description
self.uid = uid
self.uri = uri

def to_dict(self):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is also directly managed by dataclass
https://docs.python.org/3/library/dataclasses.html

return {
self.name: {
"value": self.value,
"unit": self.unit,
"description": self.description,
"type": self.param_type,
"uid": self.uid,
"uri": self.uri
}
}

def __str__(self):
return f"name={self.name}, value={self.value}, unit={self.unit}, param_type={self.param_type}, description={self.description}, uid={self.uid}, uri={self.uri}"

class MyModelUnit:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The My in MyModel is just for tutos.
Rename it!

Like ModelUnitConfig

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also inherit from dict, no?

def __init__(self, name, parameters: list):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name: str

self.name = name
self.parameters=parameters

def to_dict(self):
params = {k : v for param in self.parameters for k, v in param.to_dict().items()}
return {
self.name : params
}

def __str__(self):
return f"name={self.name}, parameters={self.to_dict()}"


class Config:
"""Configuration of OpenAlea models

TODO : Documentation to write
"""
def __init__(self, model_unit_configs: list):
"""Initialize the configuration with a list of unit configurations."""
self.model_unit_configs = model_unit_configs

def to_dict(self):
dict = {}
for unit in self.model_unit_configs:
dict.update(unit.to_dict())
return dict

def __len__(self):
return len(self.model_unit_configs)

def __getitem__(self, key):
return self.to_dict()[key]

def __str__(self):
return f"{self.model_unit_configs}"


def add_section(self, unit):
self.model_unit_configs.append(unit)

#@staticmethod
def load(self, filename: str):
"""Load configuration from a file.

Dispatch method based on file extension (YAML, JSON, etc.).
"""

extension = filename.split(".")[-1]

if extension in ("yml", "yaml"):
data = _load_yml(filename)

elif extension == "json":
data = _load_json(filename)

units = []

'''
for unit_name, params in data.items():
parameters = [Parameter(name=k, value=v) for k, v in params.items()]
unit = MyModelUnit(unit_name, parameters)
units.append(unit)
'''
for unit_name, params in data.items():
parameters = [
Parameter(
name=name,
value=params[name]["value"],
unit=params[name].get("unit"),
description=params[name].get("description"),
param_type=params[name].get("type"),
uid=params[name].get("uid"),
uri=params[name].get("uri")
)
for name in params
]

unit = MyModelUnit(unit_name, parameters)
units.append(unit)


#print(data)

return Config(units)

def dump(self, filename: str):
"""Dump configuration to a file."""

extension = filename.split(".")[-1]
data = self.to_dict()

if extension in ("yml", "yaml"):
_dump_yml(data, filename)

elif extension == "json":
_dump_json(data, filename)


Loading
Loading