-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of github.com:ecmwf/climetlab into develop
- Loading branch information
Showing
44 changed files
with
569 additions
and
285 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 |
---|---|---|
|
@@ -157,3 +157,5 @@ logs/ | |
*.index | ||
*.data-* | ||
*.out | ||
test.* | ||
test |
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,17 @@ | ||
--- | ||
# This file contains convertion for units that are not cf-compliants | ||
|
||
- from: kelvin | ||
to: degC | ||
scaling: 1 | ||
offset: -273.15 | ||
|
||
- from: kelvin | ||
to: K | ||
scaling: 1 | ||
offset: 0 | ||
|
||
- from: Celcius | ||
to: degC | ||
scaling: 1 | ||
offset: 0 |
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 |
---|---|---|
|
@@ -604,6 +604,11 @@ def cache_file( | |
|
||
check_cache_size() | ||
|
||
try: | ||
os.unlink(lock) | ||
except OSError: | ||
pass | ||
|
||
return path | ||
|
||
|
||
|
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,96 @@ | ||
# (C) Copyright 2020 ECMWF. | ||
# | ||
# This software is licensed under the terms of the Apache Licence Version 2.0 | ||
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. | ||
# In applying this licence, ECMWF does not waive the privileges and immunities | ||
# granted to it by virtue of its status as an intergovernmental organisation | ||
# nor does it submit to any jurisdiction. | ||
# | ||
|
||
from climetlab.sources import Source | ||
|
||
|
||
class TestingMockup: | ||
def __init__(self, *args, **kwargs): | ||
self.args = args | ||
self.kwargs = kwargs | ||
|
||
|
||
class TestingXarrayAttrs(dict): | ||
pass | ||
|
||
|
||
class TestingXarrayDims(list): | ||
pass | ||
|
||
|
||
class TestingDatasetAsXarray(TestingMockup): | ||
def __init__(self, *args, **kwargs): | ||
super(TestingDatasetAsXarray, self).__init__(*args, **kwargs) | ||
self.attrs = TestingXarrayAttrs() | ||
self.dims = TestingXarrayDims() | ||
|
||
# TODO: make this generic | ||
def min(self, *args, **kwargs): | ||
print(f"xr.min({args}, {kwargs})") | ||
return 42.0 | ||
|
||
def max(self, *args, **kwargs): | ||
print(f"xr.min({args}, {kwargs})") | ||
return 42.0 | ||
|
||
def map(self, *args, **kwargs): | ||
print("xr.map(...)") | ||
# print(f'xr.map({args}, {kwargs})') | ||
return self | ||
|
||
def sortby(self, *args, **kwargs): | ||
print(f"xr.sortby({args}, {kwargs})") | ||
return self | ||
|
||
def __getitem__(self, key): | ||
print(f"xr.__getitem__({key})") | ||
return self | ||
|
||
def __setitem__(self, key, value): | ||
print(f"xr.__setitem__({key})=...") | ||
# print(f'xr.__setitem__({key})={value}') | ||
return self | ||
|
||
def chunk(self, *args, **kwargs): | ||
print(f"xr.chunk({args}, {kwargs})") | ||
return self | ||
|
||
def astype(self, *args, **kwargs): | ||
print(f"xr.astype({args}, {kwargs})") | ||
return self | ||
|
||
def to_zarr(self, *args, **kwargs): | ||
print(f"xr.to_zarr({args}, {kwargs})") | ||
return self | ||
|
||
def __getattr__(self, name): | ||
print(f"xr.{name} (unkwown)") | ||
return self | ||
|
||
|
||
class DatasetMockup(TestingMockup): | ||
def __init__(self, *args, **kwargs): | ||
self.args = args | ||
self.kwargs = kwargs | ||
print(f"Climetlab SourceMockup : args={args}, kwargs={kwargs}") | ||
super(SourceMockup, self).__init__(**kwargs) | ||
|
||
def to_xarray(self, *args, **kwargs): | ||
return TestingDatasetAsXarray(*self.args, **self.kwargs) | ||
|
||
|
||
class SourceMockup(Source): | ||
def __init__(self, *args, **kwargs): | ||
self.args = args | ||
self.kwargs = kwargs | ||
print(f"Climetlab SourceMockup : args={args}, kwargs={kwargs}") | ||
super(SourceMockup, self).__init__(**kwargs) | ||
|
||
def to_xarray(self, *args, **kwargs): | ||
return TestingDatasetAsXarray(*self.args, **self.kwargs) |
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,83 @@ | ||
# (C) Copyright 2020 ECMWF. | ||
# | ||
# This software is licensed under the terms of the Apache Licence Version 2.0 | ||
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. | ||
# In applying this licence, ECMWF does not waive the privileges and immunities | ||
# granted to it by virtue of its status as an intergovernmental organisation | ||
# nor does it submit to any jurisdiction. | ||
# | ||
import os | ||
import sys | ||
from importlib import import_module | ||
|
||
import climetlab | ||
|
||
|
||
def check(): | ||
print( | ||
( | ||
"This script is experimental to help debugging." | ||
"Seeing everything to 'ok' does NOT means that you have the right versions installed." | ||
) | ||
) | ||
print("--------------------") | ||
|
||
print("Checking climetlab installation.") | ||
print(f"Climetlab installed in {os.path.dirname(climetlab.__file__)}") | ||
print("Checking required compiled dependencies...") | ||
|
||
import ecmwflibs | ||
|
||
versions = ecmwflibs.versions() | ||
|
||
for name in ["eccodes", "magics"]: | ||
try: | ||
print( | ||
f" {name} from ecwmlibs: ok {versions[name]} ({ecmwflibs.find(name)})" | ||
) | ||
except Exception as e: # noqa: F841 | ||
print(f" {name} from ecmwflib: Warning: ecmwflibs cannot find {name}") | ||
|
||
for name in ["eccodes", "MagPlus", "netcdf"]: | ||
try: | ||
import findlibs | ||
except Exception as e: # noqa: F841 | ||
print(f" {name} from findlibs: Warning: cannot import findlibs") | ||
continue | ||
try: | ||
print(f" {name} from findlibs: ({findlibs.find(name)})") | ||
except Exception as e: # noqa: F841 | ||
print(f" {name} from findlibs: Warning: findlibs cannot find {name}") | ||
|
||
print("Checking required python dependencies...") | ||
for name in ["xarray", "Magics", "eccodes", "ecmwflibs"]: | ||
more = "" | ||
try: | ||
lib = import_module(name) | ||
except ImportError: | ||
print(f" Error: cannot import {name}.") | ||
continue | ||
if name == "eccodes": | ||
more = f" (using .lib={lib.lib})" | ||
print(f" {name}: ok {lib.__version__} ({os.path.dirname(lib.__file__)}){more}") | ||
|
||
print("Checking optional dependencies...") | ||
for name in ["folium", "pdbufr", "pyodc"]: | ||
try: | ||
lib = import_module(name) | ||
print(f" {name}: ok {lib.__version__} ({os.path.dirname(lib.__file__)})") | ||
except Exception as e: | ||
print(e) | ||
print(f" Warning: cannot import {name}. Limited capabilities.") | ||
|
||
# TODO: add more | ||
# TODO: automate this from requirements.txt. Create a pip install climetlab[extra] or climetlab-light. | ||
|
||
|
||
def main_climetlab(): | ||
if sys.argv and sys.argv[1] == "check": | ||
check() | ||
|
||
|
||
if __name__ == "__main__": | ||
main_climetlab() |
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.