-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/mllam/neural-lam into maint…
…/simplify-precommit-setup
- Loading branch information
Showing
15 changed files
with
272 additions
and
210 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ graphs | |
*.sif | ||
sweeps | ||
test_*.sh | ||
.vscode | ||
|
||
### Python ### | ||
# Byte-compiled / optimized / DLL files | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Standard library | ||
import functools | ||
from pathlib import Path | ||
|
||
# Third-party | ||
import cartopy.crs as ccrs | ||
import yaml | ||
|
||
|
||
class Config: | ||
""" | ||
Class for loading configuration files. | ||
This class loads a configuration file and provides a way to access its | ||
values as attributes. | ||
""" | ||
|
||
def __init__(self, values): | ||
self.values = values | ||
|
||
@classmethod | ||
def from_file(cls, filepath): | ||
"""Load a configuration file.""" | ||
if filepath.endswith(".yaml"): | ||
with open(filepath, encoding="utf-8", mode="r") as file: | ||
return cls(values=yaml.safe_load(file)) | ||
else: | ||
raise NotImplementedError(Path(filepath).suffix) | ||
|
||
def __getattr__(self, name): | ||
keys = name.split(".") | ||
value = self.values | ||
for key in keys: | ||
if key in value: | ||
value = value[key] | ||
else: | ||
return None | ||
if isinstance(value, dict): | ||
return Config(values=value) | ||
return value | ||
|
||
def __getitem__(self, key): | ||
value = self.values[key] | ||
if isinstance(value, dict): | ||
return Config(values=value) | ||
return value | ||
|
||
def __contains__(self, key): | ||
return key in self.values | ||
|
||
def num_data_vars(self): | ||
"""Return the number of data variables for a given key.""" | ||
return len(self.dataset.var_names) | ||
|
||
@functools.cached_property | ||
def coords_projection(self): | ||
"""Return the projection.""" | ||
proj_config = self.values["projection"] | ||
proj_class_name = proj_config["class"] | ||
proj_class = getattr(ccrs, proj_class_name) | ||
proj_params = proj_config.get("kwargs", {}) | ||
return proj_class(**proj_params) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.