ecmwflibs-0.7.0/ 0000775 0001750 0001750 00000000000 15201521775 013662 5 ustar alastair alastair ecmwflibs-0.7.0/ecmwflibs/ 0000775 0001750 0001750 00000000000 15201521641 015625 5 ustar alastair alastair ecmwflibs-0.7.0/ecmwflibs/__init__.py 0000664 0001750 0001750 00000013461 15201521641 017743 0 ustar alastair alastair #!/usr/bin/env python3
# (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 atexit
import json
import os
import sys
import tempfile
import warnings
from findlibs import find as _find_library
__version__ = "0.7.0"
_here = os.path.join(os.path.dirname(__file__))
_universal = os.path.exists(os.path.join(_here, "_universal"))
if _universal:
_versions = dict
else:
_fonts = f"""
{_here}/share/magics/ttf
"""
_fontcfg = tempfile.mktemp("ecmwflibs.xml")
with open(_fontcfg, "w") as _f:
print(_fonts, file=_f)
if "ECMWFLIBS_MAGPLUS" not in os.environ:
os.environ["FONTCONFIG_FILE"] = os.environ.get(
"ECMWFLIBS_FONTCONFIG_FILE", _fontcfg
)
os.environ["PROJ_LIB"] = os.environ.get(
"ECMWFLIBS_PROJ_LIB", os.path.join(_here, "share", "proj")
)
os.environ["MAGPLUS_HOME"] = os.environ.get("ECMWFLIBS_MAGPLUS_HOME", _here)
if "ECMWFLIBS_ECCODES" not in os.environ:
for env in (
"ECCODES_DEFINITION_PATH",
"ECCODES_EXTRA_DEFINITION_PATH",
"ECCODES_EXTRA_SAMPLES_PATH",
"ECCODES_SAMPLES_PATH",
"GRIB_DEFINITION_PATH",
"GRIB_SAMPLES_PATH",
):
if env in os.environ:
if "ECMWFLIBS_" + env in os.environ:
os.environ[env] = os.environ["ECMWFLIBS_" + env]
warnings.warn(
"ecmwflibs: using provided '{}' set to '{}".format(
env, os.environ[env]
)
)
else:
warnings.warn(
(
"ecmwflibs: ignoring provided '{}' set to '{}'. "
"If you want ecmwflibs to use this environment variable, use ECMWFLIBS_{} instead. "
"If you want to use your own ECCODES library, use ECMWFLIBS_ECCODES."
).format(env, os.environ[env], env)
)
del os.environ[env]
# This comes *after* the variables are set, so c++ has access to them
try:
from ._ecmwflibs import versions as _versions
except ImportError as e:
# ImportError: DLL load failed while importing _ecmwflibs: The specified module could not be found.
warnings.warn(str(e))
raise
def universal():
return _universal
def _cleanup():
try:
os.unlink(_fontcfg)
except Exception:
pass
if not _universal:
atexit.register(_cleanup)
_MAP = {
"magics": "MagPlus",
"magplus": "MagPlus",
"grib_api": "eccodes",
"gribapi": "eccodes",
}
EXTENSIONS = {
"darwin": ".dylib",
"win32": ".dll",
}
def _lookup(name):
return _MAP.get(name, name)
def find(name):
"""Returns the path to the selected library, or None if not found."""
name = _lookup(name)
if int(os.environ.get("ECMWFLIBS_DISABLED", "0")):
warnings.warn(f"ECMWFLIBS_DISABLED is set looking for {name}")
return None
if int(os.environ.get("ECMWFLIBS_USED_INSTALLED", "0")):
path = _find_library(name)
if path is None:
warnings.warn(f"ECMWFLIBS_USED_INSTALLED did not find {name}")
else:
warnings.warn(f"ECMWFLIBS_USED_INSTALLED found {name} at {path}")
return path
if _universal: # Universal version
path = _find_library(name)
if path:
warnings.warn(f"ecmwflibs universal: found {name} at {path}")
else:
warnings.warn(f"ecmwflibs universal: cannot find a library called {name}")
return path
env = "ECMWFLIBS_" + name.upper()
if env in os.environ:
warnings.warn(
"ecmwflibs: using provided '{}' set to '{}".format(env, os.environ[env])
)
return os.environ[env]
here = os.path.dirname(__file__)
extension = EXTENSIONS.get(sys.platform, ".so")
for libdir in [here + ".libs", os.path.join(here, ".dylibs"), here]:
if not name.startswith("lib"):
names = ["lib" + name, name]
else:
names = [name, name[3:]]
if os.path.exists(libdir):
for file in os.listdir(libdir):
if file.endswith(extension):
for name in names:
if name == file.split("-")[0].split(".")[0]:
return os.path.join(libdir, file)
return None
def versions():
"""Returns the list of libraries and their version."""
v = {"ecmwflibs": __version__}
v.update(_versions())
return v
def files():
here = os.path.dirname(__file__)
for root, dirs, files in os.walk(here):
for file in files:
yield os.path.join(root, file).replace(here, "")
def credits():
"""Displays the list of embedded libraries and their copyright
notices and/or licenses."""
here = os.path.dirname(__file__)
with open(os.path.join(here, "copying/list.json")) as f:
x = json.loads(f.read())
for k, v in sorted(x.items()):
print("*" * 80)
print("name", k)
print("home", v["home"])
print("*" * 80)
print()
with open(os.path.join(here, v["path"])) as f:
print(f.read())
print("*" * 80)
def builds():
here = os.path.dirname(__file__)
with open(os.path.join(here, "versions.txt")) as f:
for d in f.readlines():
print(d)
ecmwflibs-0.7.0/ecmwflibs/copying/ 0000775 0001750 0001750 00000000000 15201521641 017275 5 ustar alastair alastair ecmwflibs-0.7.0/ecmwflibs/copying/.gitignore 0000664 0001750 0001750 00000000015 15201521641 021261 0 ustar alastair alastair *.txt
*.json
ecmwflibs-0.7.0/ecmwflibs/_ecmwflibs.cc 0000664 0001750 0001750 00000001441 15201521641 020246 0 ustar alastair alastair #include
#include
#include
#include
extern "C" const char* knowndrivers_();
static PyObject* versions(PyObject *self, PyObject *args) {
long s = grib_get_api_version(); // Force linking
auto p = knowndrivers_();
return Py_BuildValue("{s:s,s:s}",
"eccodes", ECCODES_VERSION_STR,
"magics", MAGICS_VERSION_STR);
}
static PyMethodDef ecmwflibs_methods[] = {
{
"versions", versions, METH_NOARGS,
"Versions",
},
{0,}
};
static struct PyModuleDef ecmwflibs_definition = {
PyModuleDef_HEAD_INIT,
"ecmwflibs",
"Load ECMWF libraries.",
-1,
ecmwflibs_methods
};
PyMODINIT_FUNC PyInit__ecmwflibs(void) {
Py_Initialize();
return PyModule_Create(&ecmwflibs_definition);
}
ecmwflibs-0.7.0/ecmwflibs/__main__.py 0000664 0001750 0001750 00000000327 15201521641 017721 0 ustar alastair alastair import sys
from ecmwflibs import credits
if sys.argv[-1] != "credits":
print("Type 'python -m ecmwflibs credits' to see the")
print("Open Source software installed with ecmwflibs.")
exit(0)
credits()
ecmwflibs-0.7.0/ecmwflibs/.gitignore 0000664 0001750 0001750 00000000007 15201521641 017612 0 ustar alastair alastair share/
ecmwflibs-0.7.0/ecmwflibs/etc/ 0000775 0001750 0001750 00000000000 15201521641 016400 5 ustar alastair alastair ecmwflibs-0.7.0/ecmwflibs/etc/README 0000664 0001750 0001750 00000000105 15201521641 017254 0 ustar alastair alastair Add files to this drirectory that will be installed with the package
ecmwflibs-0.7.0/tests/ 0000775 0001750 0001750 00000000000 15201521641 015014 5 ustar alastair alastair ecmwflibs-0.7.0/tests/requirements.txt 0000664 0001750 0001750 00000000026 15201521641 020276 0 ustar alastair alastair magics
eccodes
pytest
ecmwflibs-0.7.0/tests/test_versions.py 0000664 0001750 0001750 00000000740 15201521641 020276 0 ustar alastair alastair import json
import ecmwflibs
def test_versions():
versions = ecmwflibs.versions()
print(json.dumps(versions, sort_keys=True, indent=4))
assert "eccodes" in versions, versions
assert "magics" in versions, versions
assert "ecmwflibs" in versions, versions
for lib in ("eccodes", "magics"):
print(lib, ecmwflibs.find(lib))
assert ecmwflibs.find(lib) is not None
# def test_files():
# for f in ecmwflibs.files():
# print(f)
ecmwflibs-0.7.0/tests/test_climetlab.py 0000664 0001750 0001750 00000012473 15201521641 020370 0 ustar alastair alastair #!/usr/bin/env python3
import pytest
from Magics import macro
def test_climetlab_grib():
actions = [
macro.output(
output_formats=["png"],
output_name="climetlab_grib_1",
output_name_first_page_number=False,
output_width=680,
page_frame=False,
page_id_line=False,
page_x_length=10.0,
page_y_length=5.555555555555555,
subpage_x_length=10.0,
subpage_x_position=0.0,
subpage_y_length=5.555555555555555,
subpage_y_position=0.0,
super_page_x_length=10.0,
super_page_y_length=5.555555555555555,
),
macro.mmap(
subpage_lower_left_latitude=33.0,
subpage_lower_left_longitude=-27.0,
subpage_map_projection="cylindrical",
subpage_upper_right_latitude=73.0,
subpage_upper_right_longitude=45.0,
),
macro.mcoast(
map_boundaries=True,
map_coastline_colour="tan",
map_coastline_land_shade=True,
map_coastline_land_shade_colour="cream",
map_grid=False,
map_grid_colour="tan",
map_grid_frame=True,
map_grid_frame_thickness=5,
map_label=False,
),
macro.mgrib(
grib_field_position=0,
grib_file_address_mode="byte_offset",
grib_input_file_name="climetlab.grib",
),
macro.mcont(
contour_automatic_setting="climetlab",
legend=False,
),
macro.mcoast(
map_grid=False,
map_grid_frame=True,
map_grid_frame_thickness=5,
map_label=False,
),
]
print(actions)
macro.plot(*actions)
actions = [
macro.output(
output_formats=["png"],
output_name="climetlab_grib_2",
output_name_first_page_number=False,
output_width=680,
page_frame=False,
page_id_line=False,
page_x_length=10.0,
page_y_length=5.555555555555555,
subpage_x_length=10.0,
subpage_x_position=0.0,
subpage_y_length=5.555555555555555,
subpage_y_position=0.0,
super_page_x_length=10.0,
super_page_y_length=5.555555555555555,
),
macro.mmap(
subpage_lower_left_latitude=33.0,
subpage_lower_left_longitude=-27.0,
subpage_map_projection="cylindrical",
subpage_upper_right_latitude=73.0,
subpage_upper_right_longitude=45.0,
),
macro.mcoast(
map_boundaries=True,
map_coastline_colour="tan",
map_coastline_land_shade=True,
map_coastline_land_shade_colour="cream",
map_grid=False,
map_grid_colour="tan",
map_grid_frame=True,
map_grid_frame_thickness=5,
map_label=False,
),
macro.mgrib(
grib_field_position=526,
grib_file_address_mode="byte_offset",
grib_input_file_name="climetlab.grib",
),
macro.mcont(
contour_automatic_setting="climetlab",
legend=False,
),
macro.mcoast(
map_grid=False,
map_grid_frame=True,
map_grid_frame_thickness=5,
map_label=False,
),
]
print(actions)
macro.plot(*actions)
@pytest.mark.parametrize("filename", ["climetlab.nc", "test.nc4"])
def test_climetlab_netcdf(filename):
from Magics import macro
output = filename.replace(".", "-") + ".png"
actions = [
macro.output(
output_file=output,
output_width=680,
page_frame=False,
page_id_line=False,
page_x_length=10,
page_y_length=5.555555555555555,
subpage_frame=False,
subpage_x_length=10,
subpage_x_position=0.0,
subpage_y_length=5.555555555555555,
subpage_y_position=0.0,
super_page_frame=False,
super_page_x_length=10,
super_page_y_length=5.555555555555555,
),
macro.mmap(
subpage_lower_left_latitude=33.0,
subpage_lower_left_longitude=-27.0,
subpage_map_projection="cylindrical",
subpage_upper_right_latitude=73.0,
subpage_upper_right_longitude=45.0,
),
macro.mcoast(
map_boundaries=True,
map_coastline_colour="tan",
map_coastline_land_shade=True,
map_coastline_land_shade_colour="cream",
map_grid=False,
map_grid_colour="tan",
map_grid_frame=True,
map_grid_frame_thickness=5,
map_label=False,
),
macro.mnetcdf(
netcdf_filename=filename,
netcdf_value_variable="t2m",
),
macro.mcont(
contour_automatic_setting="climetlab",
legend=False,
),
macro.mcoast(
map_grid=False,
map_grid_frame=True,
map_grid_frame_thickness=5,
map_label=False,
),
]
print(actions)
macro.plot(*actions)
if __name__ == "__main__":
test_climetlab_netcdf()
# test_climetlab_grib()
ecmwflibs-0.7.0/tests/test_eccodes.py 0000664 0001750 0001750 00000000534 15201521641 020034 0 ustar alastair alastair from eccodes import codes_get, codes_grib_new_from_file, codes_release
def test_versions():
with open("data.grib", "rb") as f:
grib = codes_grib_new_from_file(f)
date = codes_get(grib, "date")
assert date == 20130325, date
print(date)
print(codes_get(grib, "shortName"))
codes_release(grib)
ecmwflibs-0.7.0/tests/open_netcdf.c 0000664 0001750 0001750 00000000657 15201521641 017454 0 ustar alastair alastair
#include
#include
#include
int main(int argc, const char* argv[]) {
int ncid, e;
if (argc != 2) {
fprintf(stderr, "Usage: %s file.nc\n", argv[0]);
exit(1);
}
if ((e = nc_open(argv[1], NC_NOWRITE, &ncid))) {
fprintf(stderr,"%s: %s\n", argv[1], nc_strerror(e));
exit(1);
}
printf("%s: file opened successfully\n", argv[1]);
exit(0);
}
ecmwflibs-0.7.0/tests/.gitignore 0000664 0001750 0001750 00000000104 15201521641 016777 0 ustar alastair alastair CMakeFiles/
Makefile
open_netcdf
CMakeCache.txt
cmake_install.cmake
ecmwflibs-0.7.0/tests/test_magics.py 0000664 0001750 0001750 00000001337 15201521641 017674 0 ustar alastair alastair #!/usr/bin/env python3
from Magics import macro as magics
def test_magics_plot():
# Setting of the output file name
output = magics.output(
output_formats=["png"],
output_name_first_page_number="off",
output_name="magics1",
)
# Import the data
data = magics.mgrib(
grib_input_file_name="data.grib",
)
# proj = magics.mmap(subpage_map_projection="mollweide")
# proj = magics.mmap(subpage_map_projection="cylindrical")
proj = magics.mmap(subpage_map_projection="robinson")
# Apply an automatic styling
contour = magics.mcont(
contour_automatic_setting="ecmwf",
)
coast = magics.mcoast()
magics.plot(output, proj, data, contour, coast)
ecmwflibs-0.7.0/tests/test.nc4 0000664 0001750 0001750 00000062667 15201521641 016422 0 ustar alastair alastair HDF
e 0 kYsOHDR
"
%_ O O
L :
GRIB_edition % GRIB_centre ecmf^ GRIB_centreDescription 2 European Centre for Medium-Range Weather Forecasts<