Skip to content

Commit 006632f

Browse files
Use earthkit-utils (#672)
* Use earthkit-utils
1 parent 6a41bd8 commit 006632f

19 files changed

+88
-610
lines changed

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ dependencies:
2929
- earthkit-meteo>=0.0.1
3030
- covjsonkit>=0.1.1
3131
- earthkit-geo>=0.2.0
32+
- earthkit-utils>=0.0.1
3233
- tqdm>=4.63.0
3334
- lru-dict
3435
- markdown
@@ -56,5 +57,4 @@ dependencies:
5657
- nbsphinx
5758
- ipykernel
5859
- geopandas
59-
- array-api-compat
6060
- deprecation

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ classifiers = [
2626
]
2727
dynamic = [ "version" ]
2828
dependencies = [
29-
"array-api-compat",
3029
"cfgrib>=0.9.10.1",
3130
"dask",
3231
"deprecation",
3332
"earthkit-meteo>=0.0.1",
33+
"earthkit-utils>=0.0.1",
3434
"eccodes>=1.7",
3535
"entrypoints",
3636
"filelock",

src/earthkit/data/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# Local copy or not installed with setuptools
1616
__version__ = "999"
1717

18+
from earthkit.utils import array as array_api
19+
1820
from earthkit.data.translators import transform
1921
from earthkit.data.wrappers import get_wrapper as from_object
2022

@@ -32,7 +34,6 @@
3234
from .sources.array_list import ArrayField
3335
from .targets import create_target
3436
from .targets import to_target
35-
from .utils import array as array_api
3637
from .utils.examples import download_example_file
3738
from .utils.examples import remote_example_file
3839

src/earthkit/data/core/fieldlist.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313
from functools import cached_property
1414

1515
import deprecation
16+
from earthkit.utils.array import array_namespace
17+
from earthkit.utils.array import array_to_numpy
18+
from earthkit.utils.array import convert_array
19+
from earthkit.utils.array import get_backend
1620

1721
from earthkit.data.core import Base
1822
from earthkit.data.core.index import Index
1923
from earthkit.data.core.index import MaskIndex
2024
from earthkit.data.core.index import MultiIndex
2125
from earthkit.data.decorators import cached_method
2226
from earthkit.data.decorators import detect_out_filename
23-
from earthkit.data.utils.array import array_namespace
24-
from earthkit.data.utils.array import array_to_numpy
25-
from earthkit.data.utils.array import convert_array
26-
from earthkit.data.utils.array import get_backend
2727
from earthkit.data.utils.metadata.args import metadata_argument
2828

2929

src/earthkit/data/sources/array_list.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
import logging
1111
import math
1212

13+
from earthkit.utils.array import array_namespace
14+
1315
from earthkit.data.core.fieldlist import Field
1416
from earthkit.data.indexing.fieldlist import ClonedFieldCore
15-
from earthkit.data.utils.array import array_namespace
1617

1718
LOG = logging.getLogger(__name__)
1819

src/earthkit/data/testing.py

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from importlib import import_module
1616
from unittest.mock import patch
1717

18+
from earthkit.utils.testing import get_array_backend
19+
1820
from earthkit.data import from_object
1921
from earthkit.data import from_source
2022
from earthkit.data.readers.text import TextReader
@@ -121,17 +123,7 @@ def modules_installed(*modules):
121123

122124
NO_POLYTOPE = not os.path.exists(os.path.expanduser("~/.polytopeapirc"))
123125
NO_COVJSONKIT = not modules_installed("covjsonkit")
124-
NO_PYTORCH = not modules_installed("torch")
125126
NO_RIOXARRAY = not modules_installed("rioxarray")
126-
NO_CUPY = not modules_installed("cupy")
127-
NO_JAX = not modules_installed("jax")
128-
if not NO_CUPY:
129-
try:
130-
import cupy as cp
131-
132-
a = cp.ones(2)
133-
except Exception:
134-
NO_CUPY = True
135127

136128
NO_S3_AUTH = not modules_installed("aws_requests_auth")
137129
NO_GEO = not modules_installed("earthkit-data")
@@ -187,34 +179,8 @@ def load_nc_or_xr_source(path, mode):
187179
return from_object(xarray.open_dataset(path))
188180

189181

190-
def check_array_type(array, expected_backend, dtype=None):
191-
from earthkit.data.utils.array import get_backend
192-
193-
b1 = get_backend(array)
194-
b2 = get_backend(expected_backend)
195-
196-
assert b1 == b2, f"{b1=}, {b2=}"
197-
198-
expected_dtype = dtype
199-
if expected_dtype is not None:
200-
assert b2.match_dtype(array, expected_dtype), f"{array.dtype}, {expected_dtype=}"
201-
202-
203-
def get_array_namespace(backend):
204-
if backend is None:
205-
backend = "numpy"
206-
207-
from earthkit.data.utils.array import get_backend
208-
209-
return get_backend(backend).namespace
210-
211-
212-
ARRAY_BACKENDS = ["numpy"]
213-
if not NO_PYTORCH:
214-
ARRAY_BACKENDS.append("pytorch")
215-
216-
if not NO_CUPY:
217-
ARRAY_BACKENDS.append("cupy")
182+
# Array backends
183+
ARRAY_BACKENDS = get_array_backend(["numpy", "torch", "cupy", "jax"], raise_on_missing=False)
218184

219185

220186
def make_tgz(target_dir, target_name, paths):

0 commit comments

Comments
 (0)