Skip to content

Commit

Permalink
BUG: Allow resolution in list format (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 authored Oct 4, 2022
1 parent 9561b70 commit d6d4ad9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion docs/history.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
History
=======

Latest
0.3.3
------
- BUG: Allow resolution in list format (Pull #122)

0.3.2
------
Expand Down
6 changes: 3 additions & 3 deletions geocube/api/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
GeoCube client core functionality
"""
import os
from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Union
from typing import Any, Callable, Dict, Iterable, List, Literal, Optional, Tuple, Union

import geopandas
import numpy
Expand All @@ -20,7 +20,7 @@ def make_geocube(
measurements: Optional[List[str]] = None,
datetime_measurements: Optional[List[str]] = None,
output_crs: Any = None,
resolution: Optional[Union[float, Tuple[float, float]]] = None,
resolution: Optional[Union[float, Iterable[float]]] = None,
align: Optional[Tuple[float, float]] = None,
geom: Optional[
Union[str, Dict, shapely.geometry.base.BaseGeometry, Geometry]
Expand Down Expand Up @@ -51,7 +51,7 @@ def make_geocube(
output_crs: Any, optional
The CRS of the returned data. Can be anything accepted by :obj:`pyproj.CRS`.
If no CRS is supplied, the CRS of the stored data is used.
resolution: Union[float, Tuple[float, float]], optional
resolution: Union[float, Iterable[float]], optional
A tuple of the spatial resolution of the returned data (Y, X).
This includes the direction (as indicated by a positive or negative number).
Typically when using most CRSs, the first number would be negative.
Expand Down
8 changes: 4 additions & 4 deletions geocube/geo_utils/geobox.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""
import json
import os
from typing import Any, Dict, Optional, Tuple, Union
from typing import Any, Dict, Iterable, Optional, Tuple, Union

import geopandas
import rioxarray # noqa: F401 pylint: disable=unused-import
Expand Down Expand Up @@ -94,7 +94,7 @@ class GeoBoxMaker:
def __init__(
self,
output_crs: Any,
resolution: Optional[Union[float, Tuple[float, float]]],
resolution: Optional[Union[float, Iterable[float]]],
align: Optional[Tuple[float, float]],
geom: Optional[Union[str, Dict, shapely.geometry.base.BaseGeometry, Geometry]],
like: Optional[Union[xarray.Dataset, xarray.DataArray]],
Expand All @@ -106,7 +106,7 @@ def __init__(
output_crs: Any, optional
The CRS of the returned data. If no CRS is supplied, the CRS of
the stored data is used.
resolution: Union[float, Tuple[float, float]], optional
resolution: Union[float, Iterable[float]], optional
A tuple of the spatial resolution of the returned data.
This includes the direction (as indicated by a positive or negative number).
Typically when using most CRSs, the first number would be negative.
Expand All @@ -123,7 +123,7 @@ def __init__(
"""
self.output_crs = output_crs
self.resolution = (
resolution if not isinstance(resolution, tuple) else resyx_(*resolution)
resolution if not isinstance(resolution, Iterable) else resyx_(*resolution)
)
self.align = None if align is None else resyx_(*align)

Expand Down
2 changes: 1 addition & 1 deletion test/integration/api/test_core_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_make_geocube(input_geodata, tmpdir):
measurements=soil_attribute_list,
output_crs=TEST_GARS_PROJ,
geom=json.dumps(mapping(TEST_GARS_POLY)),
resolution=(-10, 10),
resolution=[-10, 10],
fill=-9999.0,
)
# test writing to netCDF
Expand Down

0 comments on commit d6d4ad9

Please sign in to comment.