Skip to content

Commit 4307244

Browse files
authored
REF: Make kwargs required (#180)
1 parent 0e21a69 commit 4307244

File tree

5 files changed

+31
-13
lines changed

5 files changed

+31
-13
lines changed

geocube/api/core.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
def make_geocube(
1919
vector_data: Union[str, os.PathLike, geopandas.GeoDataFrame],
20+
*,
2021
measurements: Optional[list[str]] = None,
2122
datetime_measurements: Optional[list[str]] = None,
2223
output_crs: Any = None,
@@ -94,7 +95,9 @@ def make_geocube(
9495
Requested data in a :obj:`xarray.Dataset`.
9596
9697
"""
97-
geobox_maker = GeoBoxMaker(output_crs, resolution, align, geom, like)
98+
geobox_maker = GeoBoxMaker(
99+
output_crs=output_crs, resolution=resolution, align=align, geom=geom, like=like
100+
)
98101

99102
return VectorToCube(
100103
vector_data=vector_data,

geocube/cli/commands/make_geocube.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
@click.argument("vector_data", type=click.Path(exists=True), required=True)
8484
@click.argument("output_file", required=True)
8585
def make_geocube(
86+
*,
8687
output_file,
8788
vector_data,
8889
measurements,

geocube/geo_utils/geobox.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def geobox_from_rio(xds: Union[xarray.Dataset, xarray.DataArray]) -> GeoBox:
4747

4848
def load_vector_data(
4949
vector_data: Union[str, os.PathLike, geopandas.GeoDataFrame],
50+
*,
5051
measurements: Optional[list[str]] = None,
5152
) -> geopandas.GeoDataFrame:
5253
"""
@@ -105,6 +106,7 @@ class GeoBoxMaker:
105106

106107
def __init__(
107108
self,
109+
*,
108110
output_crs: Any,
109111
resolution: Optional[Union[float, Iterable[float]]],
110112
align: Optional[tuple[float, float]],

geocube/rasterize.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def _remove_missing_data(
4242
return data_values, geometry_array
4343

4444

45-
def _minimize_dtype(dtype: numpy.dtype, fill: float) -> numpy.dtype:
45+
def _minimize_dtype(*, dtype: numpy.dtype, fill: float) -> numpy.dtype:
4646
"""
4747
If int64, convert to float64:
4848
https://github.com/OSGeo/gdal/issues/3325
@@ -64,6 +64,7 @@ def _minimize_dtype(dtype: numpy.dtype, fill: float) -> numpy.dtype:
6464

6565

6666
def rasterize_image(
67+
*,
6768
geometry_array: geopandas.GeoSeries,
6869
data_values: Union[NDArray, pandas.arrays.IntegerArray],
6970
geobox: odc.geo.geobox.GeoBox,
@@ -112,7 +113,7 @@ def rasterize_image(
112113

113114
if isinstance(data_values, pandas.arrays.IntegerArray):
114115
data_values = data_values.to_numpy(
115-
dtype=_minimize_dtype(data_values.dtype.numpy_dtype, fill),
116+
dtype=_minimize_dtype(dtype=data_values.dtype.numpy_dtype, fill=fill),
116117
na_value=fill,
117118
)
118119

@@ -126,12 +127,13 @@ def rasterize_image(
126127
fill=fill,
127128
all_touched=all_touched,
128129
merge_alg=merge_alg,
129-
dtype=_minimize_dtype(data_values.dtype, fill),
130+
dtype=_minimize_dtype(dtype=data_values.dtype, fill=fill),
130131
)
131132
return image
132133

133134

134135
def rasterize_points_griddata(
136+
*,
135137
geometry_array: geopandas.GeoSeries,
136138
data_values: NDArray,
137139
grid_coords: dict[str, NDArray],
@@ -189,6 +191,7 @@ def rasterize_points_griddata(
189191

190192

191193
def rasterize_points_radial(
194+
*,
192195
geometry_array: geopandas.GeoSeries,
193196
data_values: NDArray,
194197
grid_coords: dict[str, NDArray],

geocube/vector_to_cube.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class VectorToCube:
5252

5353
def __init__(
5454
self,
55+
*,
5556
vector_data: Union[str, os.PathLike, geopandas.GeoDataFrame],
5657
geobox_maker: GeoBoxMaker,
5758
fill: float,
@@ -103,7 +104,9 @@ def __init__(
103104
)
104105
self._geobox = geobox_maker.from_vector(self._vector_data)
105106
self._grid_coords = affine_to_coords(
106-
self._geobox.affine, self._geobox.width, self._geobox.height
107+
affine=self._geobox.affine,
108+
width=self._geobox.width,
109+
height=self._geobox.height,
107110
)
108111
if self._geobox.crs is not None:
109112
self._vector_data = self._vector_data.to_crs(self._geobox.crs)
@@ -159,6 +162,7 @@ def __init__(
159162

160163
def make_geocube(
161164
self,
165+
*,
162166
interpolate_na_method: Optional[Literal["linear", "nearest", "cubic"]] = None,
163167
rasterize_function: Optional[Callable[..., Optional[NDArray]]] = None,
164168
) -> xarray.Dataset:
@@ -193,7 +197,7 @@ def make_geocube(
193197

194198
@staticmethod
195199
def _get_attrs(
196-
measurement_name: str, fill_value: float
200+
*, measurement_name: str, fill_value: float
197201
) -> dict[str, Union[str, float]]:
198202
"""
199203
Get attributes for data array.
@@ -215,7 +219,7 @@ def _get_attrs(
215219
"_FillValue": fill_value,
216220
}
217221

218-
def _update_time_attrs(self, attrs: dict[str, Any], image_data: NDArray) -> None:
222+
def _update_time_attrs(self, *, attrs: dict[str, Any], image_data: NDArray) -> None:
219223
"""
220224
Update attributes and nodata values for time grid.
221225
@@ -262,7 +266,7 @@ def _get_dataset(
262266
)
263267
else:
264268
grid_array = self._get_grid(
265-
self._vector_data[[measurement, "geometry"]],
269+
dataframe=self._vector_data[[measurement, "geometry"]],
266270
measurement_name=measurement,
267271
)
268272
if grid_array is not None:
@@ -291,6 +295,7 @@ def _get_dataset(
291295
def _get_grouped_grid(
292296
self,
293297
grouped_dataframe: geopandas.GeoDataFrame,
298+
*,
294299
measurement_name: str,
295300
) -> Optional[tuple]:
296301
"""Retrieve the variable data to append to the ssurgo :obj:`xarray.Dataset`.
@@ -337,11 +342,13 @@ def _get_grouped_grid(
337342

338343
image_data.append(image)
339344

340-
attrs = self._get_attrs(measurement_name, fill_value)
345+
attrs = self._get_attrs(
346+
measurement_name=measurement_name, fill_value=fill_value
347+
)
341348
image_data = numpy.array(image_data)
342349
# it was converted to numeric date value
343350
if df_group is not None and "datetime" in str(df_group[measurement_name].dtype):
344-
self._update_time_attrs(attrs, image_data)
351+
self._update_time_attrs(attrs=attrs, image_data=image_data)
345352

346353
return (
347354
(self._group_by, "y", "x"),
@@ -351,7 +358,7 @@ def _get_grouped_grid(
351358
)
352359

353360
def _get_grid(
354-
self, dataframe: geopandas.GeoDataFrame, measurement_name: str
361+
self, dataframe: geopandas.GeoDataFrame, *, measurement_name: str
355362
) -> Optional[tuple]:
356363
"""Retrieve the variable data to append to the ssurgo :obj:`xarray.Dataset`
357364
from a regular :obj:`geopandas.GeoDataFrame`.
@@ -387,11 +394,13 @@ def _get_grid(
387394
)
388395
return None
389396

390-
attrs = self._get_attrs(measurement_name, fill_value)
397+
attrs = self._get_attrs(
398+
measurement_name=measurement_name, fill_value=fill_value
399+
)
391400

392401
# it was converted to numeric date value
393402
if "datetime" in str(dataframe[measurement_name].dtype):
394-
self._update_time_attrs(attrs, image_data)
403+
self._update_time_attrs(attrs=attrs, image_data=image_data)
395404

396405
return (
397406
("y", "x"),

0 commit comments

Comments
 (0)