Skip to content

Commit c657a3f

Browse files
committed
lint + format
1 parent 997e328 commit c657a3f

File tree

6 files changed

+23
-39
lines changed

6 files changed

+23
-39
lines changed

pyproject.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ select = [
6565
"F",
6666
# Pycodestyle
6767
"E",
68-
"W",
6968
# isort
7069
"I",
7170
# Pyupgrade
7271
"UP",
7372
]
73+
line-length = 100
7474

7575
[tool.ruff.isort]
7676
known-first-party = ["xdggs"]
@@ -79,6 +79,3 @@ known-third-party=[
7979
"healpy",
8080
"h3",
8181
]
82-
83-
[tool.ruff.format]
84-
line-length = 100

xdggs/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from importlib.metadata import PackageNotFoundError, version
22

3-
from .accessor import DGGSAccessor # noqa
4-
from .index import DGGSIndex
5-
from .healpix import HealpixIndex
6-
3+
from xdggs.accessor import DGGSAccessor # noqa
4+
from xdggs.healpix import HealpixIndex
5+
from xdggs.index import DGGSIndex
76

87
try:
98
__version__ = version("xdggs")

xdggs/accessor.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
import xarray as xr
22

3-
from .index import DGGSIndex
3+
from xdggs.index import DGGSIndex
44

55

66
@xr.register_dataset_accessor("dggs")
77
class DGGSAccessor:
8-
98
def __init__(self, obj):
109
self._obj = obj
11-
12-
indexes = {
13-
k: idx for k, idx in obj.xindexes.items() if isinstance(idx, DGGSIndex)
14-
}
10+
11+
indexes = {k: idx for k, idx in obj.xindexes.items() if isinstance(idx, DGGSIndex)}
1512
if len(indexes) > 1:
1613
raise ValueError("Only one DGGSIndex per object is supported")
17-
14+
1815
self._name, self._index = next(iter(indexes.items()))
1916

2017
def sel_latlon(self, lat, lon):
@@ -31,4 +28,4 @@ def assign_latlon_coords(self):
3128
return self._obj.assign_coords(
3229
latitude=(self._index._dim, lat_data),
3330
longitude=(self._index._dim, lon_data),
34-
)
31+
)

xdggs/healpix.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import healpy
22

3-
from .index import DGGSIndex
4-
from .utils import register_dggs, _extract_cell_id_variable
3+
from xdggs.index import DGGSIndex
4+
from xdggs.utils import _extract_cell_id_variable, register_dggs
55

66

77
@register_dggs("healpix")
88
class HealpixIndex(DGGSIndex):
9-
109
def __init__(self, cell_ids, dim, nside, nest, rot_latlon):
1110
super().__init__(cell_ids, dim)
1211

@@ -20,13 +19,13 @@ def from_variables(cls, variables, *, options):
2019

2120
nside = var.attrs.get("nside", options.get("nside"))
2221
nest = var.attrs.get("nest", options.get("nest", False))
23-
rot_latlon = var.attrs.get("rot_latlon", options.get("rot_latlon", (0., 0.)))
24-
22+
rot_latlon = var.attrs.get("rot_latlon", options.get("rot_latlon", (0.0, 0.0)))
23+
2524
return cls(var.data, dim, nside, nest, rot_latlon)
2625

2726
def _replace(self, new_pd_index):
2827
return type(self)(new_pd_index, self._dim, self._nside, self._nest, self._rot_latlon)
29-
28+
3029
def _latlon2cellid(self, lat, lon):
3130
return healpy.ang2pix(self._nside, -lon, lat, lonlat=True, nest=self._nest)
3231

@@ -35,4 +34,6 @@ def _cellid2latlon(self, cell_ids):
3534
return lat, -lon
3635

3736
def _repr_inline_(self, max_width):
38-
return f"HealpixIndex(nside={self._nside}, nest={self._nest}, rot_latlon={self._rot_latlon!r})"
37+
return (
38+
f"HealpixIndex(nside={self._nside}, nest={self._nest}, rot_latlon={self._rot_latlon!r})"
39+
)

xdggs/index.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,7 @@
33
from .utils import GRID_REGISTRY, _extract_cell_id_variable
44

55

6-
def _extract_cell_id_variable(variables):
7-
# TODO: only one variable supported (raise otherwise)
8-
name, var = next(iter(variables.items()))
9-
10-
# TODO: only 1-d variable supported (raise otherwise)
11-
dim = next(iter(var.dims))
12-
13-
return name, var, dim
14-
15-
166
class DGGSIndex(Index):
17-
187
def __init__(self, cell_ids, dim):
198
self._dim = dim
209

@@ -31,7 +20,7 @@ def from_variables(cls, variables, *, options):
3120
cls = GRID_REGISTRY[grid_name]
3221

3322
return cls.from_variables(variables, options=options)
34-
23+
3524
def create_variables(self, variables=None):
3625
return self._pd_index.create_variables(variables)
3726

@@ -41,15 +30,15 @@ def isel(self, indexers):
4130
return self._replace(new_pd_index)
4231
else:
4332
return None
44-
33+
4534
def sel(self, labels, method=None, tolerance=None):
4635
if method == "nearest":
4736
raise ValueError("finding nearest grid cell has no meaning")
4837
return self._pd_index.sel(labels, method=method, tolerance=tolerance)
4938

5039
def _replace(self, new_pd_index):
5140
raise NotImplementedError()
52-
41+
5342
def _latlon2cellid(self, lat, lon):
5443
"""convert latitude / longitude points to cell ids."""
5544
raise NotImplementedError()
@@ -60,4 +49,4 @@ def _cellid2latlon(self, cell_ids):
6049

6150
@property
6251
def cell_centers(self):
63-
return self._cellid2latlon(self._pd_index.index.values)
52+
return self._cellid2latlon(self._pd_index.index.values)

xdggs/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ def register_dggs(name):
55
def inner(cls):
66
GRID_REGISTRY[name] = cls
77
return cls
8+
89
return inner
910

1011

@@ -15,4 +16,4 @@ def _extract_cell_id_variable(variables):
1516
# TODO: only 1-d variable supported (raise otherwise)
1617
dim = next(iter(var.dims))
1718

18-
return name, var, dim
19+
return name, var, dim

0 commit comments

Comments
 (0)