Skip to content

Commit

Permalink
Feature/use covjsonkit (#524)
Browse files Browse the repository at this point in the history
* Use covjsonkit instead of eccovjson
  • Loading branch information
sandorkertesz authored Nov 15, 2024
1 parent 2f3a9b9 commit 8f45591
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Alternatively, you can install the following components:
- odb: provides full support for the :ref:`odb` data type
- geopandas: adds geojson/geopandas support
- projection: adds projection support
- eccovjson: provides access to coverage json data served by the :ref:`data-sources-polytope` source
- covjsonkit: provides access to coverage json data served by the :ref:`data-sources-polytope` source

E.g. to add :ref:`data-sources-mars` support you can use:

Expand Down
9 changes: 9 additions & 0 deletions docs/release_notes/version_0.10_updates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ Version 0.10 Updates
/////////////////////////


Version 0.10.10
===============

Changes
+++++++

- Use ``covjsonkit`` instead of ``ecccovjson`` to read coverage json data retrieved from the :ref:`data-sources-polytope` source (:pr:`445`).


Version 0.10.9
===============

Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies:
- ecmwf-opendata>=0.1.2
- polytope-client>=0.7.4
- earthkit-meteo>=0.0.1
- eccovjson>=0.0.5
- covjsonkit>=0.0.25
- earthkit-geo>=0.2.0
- tqdm>=4.63.0
- lru-dict
Expand Down
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ dependencies = [
optional-dependencies.all = [
"cartopy",
"cdsapi>=0.7.2",
"eccovjson>=0.0.5",
"covjsonkit>=0.0.25",
"ecmwf-api-client>=1.6.1",
"ecmwf-opendata>=0.3.3",
"geopandas",
Expand All @@ -69,11 +69,14 @@ optional-dependencies.ci = [
"array-api-compat",
"torch",
]
optional-dependencies.covjsonkit = [
"covjsonkit>=0.0.25",
]
optional-dependencies.dev = [
"cartopy",
"cdsapi>=0.7.2",
"covjsonkit>=0.0.25",
"earthkit-data-demo-source",
"eccovjson>=0.0.5",
"ecmwf-api-client>=1.6.1",
"ecmwf-opendata>=0.3.3",
"geopandas",
Expand All @@ -88,9 +91,6 @@ optional-dependencies.dev = [
"pytest-forked",
"pytest-timeout",
]
optional-dependencies.eccovjson = [
"eccovjson>=0.0.5",
]
optional-dependencies.ecmwf-opendata = [
"ecmwf-opendata>=0.3.3",
]
Expand Down
6 changes: 3 additions & 3 deletions src/earthkit/data/readers/covjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
class XarrayMixIn:
def to_xarray(self, **kwargs):
try:
from eccovjson.api import Eccovjson
from covjsonkit.api import Covjsonkit
except ImportError:
raise ImportError("covjason handling requires 'eccovjson' to be installed")
raise ImportError("covjason handling requires 'covjsonkit' to be installed")

decoder = Eccovjson().decode(self._json())
decoder = Covjsonkit().decode(self._json())
return decoder.to_xarray()


Expand Down
2 changes: 1 addition & 1 deletion src/earthkit/data/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def modules_installed(*modules):
NO_FDB = True

NO_POLYTOPE = not os.path.exists(os.path.expanduser("~/.polytopeapirc"))
NO_ECCOVJSON = not modules_installed("eccovjson")
NO_COVJSONKIT = not modules_installed("covjsonkit")
NO_PYTORCH = not modules_installed("torch")
NO_CUPY = not modules_installed("cupy")
if not NO_CUPY:
Expand Down
2 changes: 1 addition & 1 deletion tests/data/time_series.covjson
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"type": "CoverageCollection", "domainType": "PointSeries", "coverages": [{"mars:metadata": {"class": "od", "date": "20240103T00", "domain": "g", "expver": "0001", "levtype": "sfc", "stream": "oper", "type": "fc", "number": 1}, "type": "Coverage", "domain": {"type": "Domain", "axes": {"x": {"values": [0.035149384216]}, "y": {"values": [0.0]}, "z": {"values": ["sfc"]}, "t": {"values": ["2024-01-03T00:00:00", "2024-01-03T01:00:00", "2024-01-03T02:00:00", "2024-01-03T03:00:00", "2024-01-03T04:00:00", "2024-01-03T05:00:00", "2024-01-03T06:00:00", "2024-01-03T07:00:00", "2024-01-03T08:00:00"]}}}, "ranges": {"t": {"type": "NdArray", "dataType": "float", "shape": [9], "axisNames": ["t"], "values": [298.9648132324219, 298.6933288574219, 298.9999694824219, 298.5683288574219, 298.9960632324219, 298.4452819824219, 299.05596923828125, 299.21807861328125, 298.95050048828125]}}}], "parameters": {"t": {"type": "Parameter", "description": "Temperature", "unit": {"symbol": "K"}, "observedProperty": {"id": "t", "label": {"en": "Temperature"}}}}, "referencing": [{"coordinates": ["x", "y", "z"], "system": {"type": "GeographicCRS", "id": "http://www.opengis.net/def/crs/OGC/1.3/CRS84"}}]}
{"type": "CoverageCollection", "domainType": "PointSeries", "coverages": [{"mars:metadata": {"class": "od", "Forecast date": "20240103T00", "domain": "g", "expver": "0001", "levtype": "sfc", "stream": "oper", "type": "fc", "number": 1}, "type": "Coverage", "domain": {"type": "Domain", "axes": {"x": {"values": [0.035149384216]}, "y": {"values": [0.0]}, "z": {"values": ["sfc"]}, "t": {"values": ["2024-01-03T00:00:00", "2024-01-03T01:00:00", "2024-01-03T02:00:00", "2024-01-03T03:00:00", "2024-01-03T04:00:00", "2024-01-03T05:00:00", "2024-01-03T06:00:00", "2024-01-03T07:00:00", "2024-01-03T08:00:00"]}}}, "ranges": {"2t": {"type": "NdArray", "dataType": "float", "shape": [9], "axisNames": ["t"], "values": [298.9648132324219, 298.6933288574219, 298.9999694824219, 298.5683288574219, 298.9960632324219, 298.4452819824219, 299.05596923828125, 299.21807861328125, 298.95050048828125]}}}], "parameters": {"2t": {"type": "Parameter", "description": "Temperature", "unit": {"symbol": "K"}, "observedProperty": {"id": "2t", "label": {"en": "Temperature"}}}}, "referencing": [{"coordinates": ["x", "y", "z"], "system": {"type": "GeographicCRS", "id": "http://www.opengis.net/def/crs/OGC/1.3/CRS84"}}]}
2 changes: 1 addition & 1 deletion tests/environment-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies:
- polytope-client>=0.7.4
- earthkit-meteo>=0.0.1
- git+https://github.com/ecmwf/earthkit-data-demo-source
- eccovjson>=0.0.5
- covjsonkit>=0.0.25
- earthkit-geo>=0.2.0
- tqdm>=4.63.0
- lru-dict
Expand Down
10 changes: 5 additions & 5 deletions tests/readers/test_covjson_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import pytest

from earthkit.data import from_source
from earthkit.data.testing import NO_ECCOVJSON
from earthkit.data.testing import NO_COVJSONKIT
from earthkit.data.testing import earthkit_test_data_file


Expand All @@ -20,15 +20,15 @@ def test_covjson():
assert ds


@pytest.mark.skipif(NO_ECCOVJSON, reason="no eccovjson available")
@pytest.mark.skipif(NO_COVJSONKIT, reason="no covjsonkit available")
def test_covjson_to_xarray():
ds = from_source("file", earthkit_test_data_file("time_series.covjson"))
assert ds
a = ds.to_xarray()
assert len(a.data_vars) == 1


@pytest.mark.skipif(NO_ECCOVJSON, reason="no eccovjson available")
@pytest.mark.skipif(NO_COVJSONKIT, reason="no covjsonkit available")
def test_covjson_memory():
with open(earthkit_test_data_file("time_series.covjson"), "r") as f:
d = f.read().encode()
Expand All @@ -39,7 +39,7 @@ def test_covjson_memory():
assert len(a.data_vars) == 1


@pytest.mark.skipif(NO_ECCOVJSON, reason="no eccovjson available")
@pytest.mark.skipif(NO_COVJSONKIT, reason="no covjsonkit available")
def test_covjson_stream():
stream = open(earthkit_test_data_file("time_series.covjson"), "rb")

Expand All @@ -54,7 +54,7 @@ def test_covjson_stream():
next(it)


@pytest.mark.skipif(NO_ECCOVJSON, reason="no eccovjson available")
@pytest.mark.skipif(NO_COVJSONKIT, reason="no covjsonkit available")
def test_covjson_stream_memory():
stream = open(earthkit_test_data_file("time_series.covjson"), "rb")

Expand Down

0 comments on commit 8f45591

Please sign in to comment.