-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADD: plotting options to analysis, regional fixes (#12)
* embed the post in try/except blocks * add titles to figures * analysis plots populate dynamically * fix updates to images * regional analysis works * removing unwanted capability * fix failing tests
- Loading branch information
Showing
11 changed files
with
748 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -287,7 +287,7 @@ def __call__( | |
analysis_name, | ||
f"Score {var_dep} vs {var_ind}", | ||
"score", | ||
"", | ||
"1", | ||
score, | ||
] | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
"""Configuration for ilamb3""" | ||
|
||
import contextlib | ||
import copy | ||
from pathlib import Path | ||
|
||
import yaml | ||
|
||
import ilamb3.regions as reg | ||
|
||
defaults = { | ||
"build_dir": "./_build", | ||
"regions": [None], | ||
} | ||
|
||
|
||
class Config(dict): | ||
"""A global configuration object used in the package.""" | ||
|
||
def __init__(self, filename: Path | None = None, **kwargs): | ||
self.filename = ( | ||
Path(filename) | ||
if filename is not None | ||
else Path.home() / ".config/ilamb3/conf.yaml" | ||
) | ||
self.filename.parent.mkdir(parents=True, exist_ok=True) | ||
self.reload_all() | ||
self.temp = None | ||
super().__init__(**kwargs) | ||
|
||
def __repr__(self): | ||
return yaml.dump(dict(self)) | ||
|
||
def reset(self): | ||
"""Return to defaults.""" | ||
self.clear() | ||
self.update(copy.deepcopy(defaults)) | ||
|
||
def save(self, filename: Path | None = None): | ||
"""Save current configuration to file as YAML.""" | ||
filename = filename or self.filename | ||
filename.parent.mkdir(parents=True, exist_ok=True) | ||
with open(filename, "w") as f: | ||
yaml.dump(dict(self), f) | ||
|
||
@contextlib.contextmanager | ||
def _unset(self, temp): | ||
yield | ||
self.clear() | ||
self.update(temp) | ||
|
||
def set( | ||
self, | ||
*, | ||
build_dir: str | None = None, | ||
regions: list[str] | None = None, | ||
): | ||
"""Change ilamb3 configuration options.""" | ||
temp = copy.deepcopy(self) | ||
if build_dir is not None: | ||
self["build_dir"] = str(build_dir) | ||
if regions is not None: | ||
ilamb_regions = reg.Regions() | ||
does_not_exist = set(regions) - set(ilamb_regions._regions) - set([None]) | ||
if does_not_exist: | ||
raise ValueError( | ||
f"Cannot run ILAMB over these regions [{list(does_not_exist)}] which are not registered in our system [{list(ilamb_regions._regions)}]" | ||
) | ||
self["regions"] = regions | ||
return self._unset(temp) | ||
|
||
def __getitem__(self, item): | ||
if item in self: | ||
return super().__getitem__(item) | ||
elif item in defaults: | ||
return defaults[item] | ||
else: | ||
raise KeyError(item) | ||
|
||
def get(self, key, default=None): | ||
if key in self: | ||
return super().__getitem__(key) | ||
return default | ||
|
||
def reload_all(self): | ||
self.reset() | ||
self.load() | ||
|
||
def load(self, filename: Path | None = None): | ||
"""Update global config from YAML file or default file if None.""" | ||
filename = filename or self.filename | ||
if filename.is_file(): | ||
with open(filename) as f: | ||
try: | ||
self.update(yaml.safe_load(f)) | ||
except Exception: | ||
pass | ||
|
||
|
||
conf = Config() | ||
conf.reload_all() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.