Skip to content

Commit

Permalink
more docs and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
heikoklein committed Nov 8, 2024
1 parent 246eee3 commit f9f5dc8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion pyaerocom/aeroval/glob_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ class ScaleAndColmap(dict[str, str | list[float]]):
class VarWebScaleAndColormap(dict[str, ScaleAndColmap]):
def __init__(self, config_file: str = "", **kwargs):
"""This class contains scale and colmap informations and is implemented as dict to allow
json serialization. It reads it inital data from data/var_scale_colmap.ini.
json serialization. It reads it inital data from data/var_scale_colmap.ini. kwargs will be send to update.
:param config_file: filename to additional or updated information, defaults to None
"""
super().__init__()
with resources.path("pyaerocom.aeroval.data", "var_scale_colmap.ini") as file:
self.update_from_ini(file)
config_file = kwargs.pop("config_file", config_file)
if config_file != "":
logger.info(f"Reading additional web-scales from '{config_file}'")
if not os.path.exists(config_file):
Expand All @@ -51,6 +52,9 @@ def __init__(self, config_file: str = "", **kwargs):
self.update(**kwargs)

def update(self, **kwargs):
"""update/add scale and colormaps by kwargs, e.g.
update(concso2={"scale"=[0.2,1], "colormap"="bluewhite"})
"""
wvsc = _VarWebScaleAndColormap(scale_colmaps=kwargs)
super().update(**{x: y._asdict() for x, y in wvsc.scale_colmaps.items()})

Expand Down
9 changes: 7 additions & 2 deletions tests/aeroval/test_glob_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@ def test_var_web_scale_and_colormap():
with pytest.raises(ValidationError):
VarWebScaleAndColormap(**{"bla": ["blub"]})

vwsc2 = VarWebScaleAndColormap(**{"new_var": {"scale": [1, 2, 4], "colmap": "my_colormap"}})
assert "concso2" in vwsc2
vwsc2 = VarWebScaleAndColormap(
config_file="", **{"new_var": {"scale": [1, 2, 4], "colmap": "my_colormap"}}
)
assert "new_var" in vwsc2

vwsc3 = VarWebScaleAndColormap(new_var2={"scale": [1, 2, 4], "colmap": "my_colormap"})
assert "new_var2" in vwsc3

0 comments on commit f9f5dc8

Please sign in to comment.