Skip to content

Commit 36b85ea

Browse files
cleaned up some lint.
1 parent 8cee14a commit 36b85ea

10 files changed

Lines changed: 26 additions & 32 deletions

File tree

docs/source/api_reference.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,17 @@ The user can now plot the time series for a given location and times, without ha
6565
Duck Typing
6666
-----------
6767

68-
The Grid objects (Grid, Time, Depth) are for the most part "duck typed", rather than strict subclassing. Though there are base classes that provide shared functionality.
68+
The Grid objects (Grid, Time, Depth) are for the most part "duck typed", rather than strict subclassing, though there are base classes that provide shared functionality.
6969

70-
We are trying to be clear about the "public" vs "private" API by using leading underscores for methods and attributes not intended for external use.
70+
We are trying to be clear about the "public" vs "private" API by using leading underscores for methods and attributes not intended for external use, but it's not as consitent as it should be.
7171

7272

7373
Lazy loading / data arrays
7474
--------------------------
7575

7676
Many of the datasets users need to work with can be quite large. As a result it is impractical to load entire datasets into memory at once. ``gridded`` for the most part shifts the burden of handling lazy loading to external libraries, and does this by keeping data stored in a "numpy array-like" objects. Users can use pure numpy arrays, or any object that "acts" like a numpy array. This should allow ``gridded`` to work with netcdf variables, hdf5 arrays, dask arrays, etc.
7777

78-
In practice, there is no clear definition of "array-like", so ``gridded`` has defined its own definition, based on features we know we need. But it is assumed that nd indexing behaves that same as numpy arrays -- as there is no way to easily confirm that. This is a goal, but in fact, only numpy arrays and ``netCDF4 Variables`` have been implimented and tested. In the future, we may use ``xarray`` as a single abstration layer, rather than rolling our own.
78+
In practice, there is no clear definition of "array-like", so ``gridded`` has defined its own definition, based on features we know we need. But it is assumed that nd indexing behaves that same as numpy arrays -- as there is no way to easily confirm that. This is a goal, but in fact, only numpy arrays and ``netCDF4 Variables`` have been implemented and tested. In the future, we may use ``xarray`` as a single abstraction layer, rather than rolling our own.
7979

8080
To support that, we support converting and testing for array-like with:
8181

@@ -85,7 +85,7 @@ and
8585

8686
``gridded.utils.isarraylike()``
8787

88-
Those utilities will be updated as new needs arrise.
88+
Those utilities will be updated as new needs arise.
8989

9090
Reference
9191
=========

gridded/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22

33
from ._version import __version__
4+
45
# __version__ = "0.7.5"
56

67
VALID_SGRID_LOCATIONS = (None, "center", "edge1", "edge2", "node")

gridded/depth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ def from_netCDF(
517517
grid=grid,
518518
name="bathymetry",
519519
)
520-
else:
520+
else:
521521
h = (bathy_var[0:-1,:] + bathy_var[1:,:]) / 2
522522
psi_h = (h[:,0:-1] + h[:,1:]) /2
523523
bathymetry = Bathymetry(
@@ -774,7 +774,7 @@ def _apply_boundary_conditions(
774774
if bottom_boundary_condition == "mask":
775775
indices.mask[below_bottom_mask] = True
776776
alphas.mask[below_bottom_mask] = True
777-
777+
778778
indices.mask = np.logical_or(indices.mask, exclusion_mask)
779779
alphas.mask = np.logical_or(alphas.mask, exclusion_mask)
780780
return indices, alphas, oob_mask

gridded/gridded.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ def __init__(self, ncfile=None, grid=None, variables=None, grid_topology=None, a
7777
else: # Create from grid and variables -- this is what should usually happen.
7878
self.filename = None
7979
self.grid = grid
80+
self.time = None
81+
self.depth = None
8082
self.variables = {} if variables is None else variables
8183
self.attributes = {} if attributes is None else attributes
8284

@@ -93,7 +95,9 @@ def _init_from_netCDF(self, filename=None, grid_file=None, variable_files=None,
9395

9496
self.nc_dataset = get_dataset(filename)
9597
self.filename = self.nc_dataset.filepath()
96-
self.grid = Grid.from_netCDF(filename=self.filename, dataset=self.nc_dataset, grid_topology=grid_topology)
98+
self.grid = Grid.from_netCDF(filename=self.filename,
99+
dataset=self.nc_dataset,
100+
grid_topology=grid_topology)
97101
# fixme: this should load the depth and time, and then the variables.
98102
self.variables = self._variables_from_netCDF(self.nc_dataset)
99103
self.attributes = get_dataset_attrs(self.nc_dataset)
@@ -102,7 +106,7 @@ def _init_from_netCDF(self, filename=None, grid_file=None, variable_files=None,
102106
def from_netCDF(cls, filename=None, grid_file=None, variable_files=None, grid_topology=None):
103107
"""
104108
NOTE: only loading from a single file is currently implemented.
105-
you can create a DATaset by hand, by loading the grid and
109+
you can create a Dataset by hand, by loading the grid and
106110
variables separately, and then adding them
107111
108112
load a gridded.Dataset from a netCDF file

gridded/tests/test_depth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def test_interpolation_alphas(self, get_roms_depth):
307307
)
308308
assert np.all(idx == expected_idx)
309309
assert np.all(np.isclose(alphas, expected_alpha))
310-
310+
311311
points = np.array(
312312
[[20, 20, 9.9], [20, 20, 10.0], [20, 20, 10.1], [-1, -1, 5], [20, 20, -0.1], [20, 20, 0], [20, 20, 0.1]]
313313
)

gridded/tests/test_variable.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
but good to have a few explicitly for the Variable object
66
"""
77

8-
import os
9-
108
import netCDF4
119
import numpy as np
1210

@@ -67,7 +65,7 @@ def test_Variable_api_at_function_edge_cases():
6765
p1 = (1.5, 35.5)
6866
p2 = (1.5, 35.5, 1) # expected: r2 == r1
6967
p3 = [(1.5, 35.5), (35.5, 1.5)] # expected: [[1],[masked]]
70-
p4 = [(1.5, 35.5, 1), (35.5, 1.5, 1)] # expected: [[1],[masked]]
68+
# p4 = [(1.5, 35.5, 1), (35.5, 1.5, 1)] # expected: [[1],[masked]]
7169

7270
t = var.time.min_time
7371

@@ -145,7 +143,7 @@ def test_VectorVariable_api_at_function_edge_cases():
145143
p1 = (1.5, 35.5)
146144
p2 = (1.5, 35.5, 1) # expected: r2 == r1
147145
p3 = [(1.5, 35.5), (35.5, 1.5)] # expected: [[1],[masked]]
148-
p4 = [(1.5, 35.5, 1), (35.5, 1.5, 1)] # expected: [[1],[masked]]
146+
# p4 = [(1.5, 35.5, 1), (35.5, 1.5, 1)] # expected: [[1],[masked]]
149147

150148
t = var.time.min_time
151149

gridded/tests/utilities.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"""
77

88
import contextlib
9-
import glob
109
import os
1110
from pathlib import Path
1211

gridded/utilities.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@
44
assorted utility functions needed by gridded
55
"""
66

7-
try:
8-
from collections.abc import Collection, Iterable, Mapping
9-
except ImportError: # py2
10-
from collections.abc import Iterable
11-
127
import os
8+
from collections.abc import Iterable, Mapping
139

1410
import netCDF4 as nc4
1511
import numpy as np
@@ -74,7 +70,7 @@ def gen_celltree_mask_from_center_mask(center_mask, sl):
7470
#
7571
def regrid_variable(grid, o_var, location="node"):
7672
from gridded.depth import DepthBase, L_Depth, S_Depth
77-
from gridded.grids import Grid_S, Grid_U
73+
from gridded.grids import Grid_U
7874
from gridded.variable import Variable
7975

8076
"""
@@ -139,7 +135,8 @@ def regrid_variable(grid, o_var, location="node"):
139135
if o_var.time is not None:
140136
for t_idx, t in enumerate(o_var.time.data):
141137
if n_depth is not None and issubclass(n_depth.__class__, S_Depth):
142-
transect = o_var.depth.get_depth_profile(o_var.grid.nodes.reshape(-1, 2), t, data_shape=(len(n_depth),)).T
138+
transect = o_var.depth.get_depth_profile(o_var.grid.nodes.reshape(-1, 2),
139+
t, data_shape=(len(n_depth),)).T
143140
for lev_idx, lev_data in enumerate(transect):
144141
lev = Variable(
145142
name=f"level{lev_idx}", data=lev_data.reshape(o_var.grid.node_lon.shape), grid=o_var.grid

gridded/variable.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
import collections
22
import hashlib
33
import logging
4-
import os
54
from functools import wraps
65
from textwrap import dedent
76

87
import netCDF4 as nc4
98
import numpy as np
109

1110
from gridded import VALID_LOCATIONS
12-
from gridded.depth import Depth, DepthBase
11+
from gridded.depth import Depth
1312
from gridded.grids import Grid, Grid_R, Grid_S, Grid_U
1413
from gridded.time import Time
1514
from gridded.utilities import (
16-
_align_results_to_spatial_data,
1715
_reorganize_spatial_data,
1816
asarraylike,
1917
get_dataset,
2018
parse_filename_dataset_args,
21-
search_dataset_for_variables_by_varname,
2219
)
2320

2421
log = logging.getLogger(__name__)
@@ -392,14 +389,13 @@ def data(self, d):
392389
if self.time is not None and len(d) != len(self.time):
393390
raise ValueError("Data/time interval mismatch")
394391
## fixme: we should check Depth, too.
395-
# if self.grid is not None and self.grid.infer_location(d) is None:
396-
# raise ValueError("Data/grid shape mismatch. Data shape is {0}, Grid shape is {1}".format(d.shape, self.grid.node_lon.shape))
397392
if self.grid is not None: # if there is not a grid, we can't check this
398393
if self.location is None: # not set, let's try to figure it out
399394
self.location = self.grid.infer_location(d)
400395
if self.location is None:
401396
raise ValueError(
402-
f"Data/grid shape mismatch: Data shape is {d.shape}, Grid shape is {self.grid.node_lon.shape}"
397+
f"Data/grid shape mismatch: Data shape is {d.shape}, "
398+
f"Grid shape is {self.grid.node_lon.shape}"
403399
)
404400
self._data = d
405401

@@ -655,7 +651,6 @@ def _xy_interp(self, points, time, extrapolate, slices=(), **kwargs):
655651
:type slices: tuple of integers or slice objects
656652
"""
657653
_hash = kwargs["_hash"] if "_hash" in kwargs else None
658-
units = kwargs["units"] if "units" in kwargs else None
659654

660655
value = self.grid.interpolate_var_to_points(
661656
points[:, 0:2],
@@ -1342,8 +1337,8 @@ def _mod(n):
13421337
if _mod("grid"):
13431338
gt = kws.get("grid_topology", None)
13441339
kws["grid"] = Grid.from_netCDF(kws["filename"], dataset=dg, grid_topology=gt)
1345-
if kws.get("varnames", None) is None:
1346-
varnames = cls._gen_varnames(kws["data_file"], dataset=ds)
1340+
# if kws.get("varnames", None) is None:
1341+
# varnames = cls._gen_varnames(kws["data_file"], dataset=ds)
13471342
# if _mod('time'):
13481343
# time = Time.from_netCDF(filename=kws['data_file'],
13491344
# dataset=ds,

pixi.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ build_docs = {cmd = "cd docs && make html", default-environment = "docs", depend
6969

7070
test = { cmd = "pytest --pyargs gridded", depends-on = ["install"] }
7171

72-
lint = { cmd = "ruff check src/libgoods", default-environment = "dev"}
72+
lint = { cmd = "ruff check gridded", default-environment = "dev"}
7373

7474

0 commit comments

Comments
 (0)