Skip to content

Commit

Permalink
Fix dependencies v0.10 (#1112)
Browse files Browse the repository at this point in the history
Co-authored-by: DirkEilander <[email protected]>
Co-authored-by: DirkEilander <[email protected]>
  • Loading branch information
3 people authored Feb 18, 2025
1 parent e5c93ae commit b4ebfd7
Show file tree
Hide file tree
Showing 15 changed files with 8,316 additions and 27,437 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check-data-catalogs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ jobs:

steps:
- uses: actions/checkout@v3
- uses: prefix-dev/setup-pixi@v0.6.0
- uses: prefix-dev/setup-pixi@v0.8.2
with:
pixi-version: "v0.21.1"
pixi-version: v0.41.1
environments: min-py311
- name: Prepare pixi
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ jobs:
steps:
- name: checkout code
uses: actions/checkout@v3
- uses: prefix-dev/setup-pixi@v0.6.0
- uses: prefix-dev/setup-pixi@v0.8.2
with:
pixi-version: "v0.21.1"
pixi-version: v0.41.1
environments: full-py311
- name: Prepare pixi
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pixi_auto_update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
- uses: actions/checkout@v4
with:
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
- uses: prefix-dev/setup-pixi@v0.6.0
- uses: prefix-dev/setup-pixi@v0.8.2
with:
pixi-version: "v0.21.1"
pixi-version: v0.41.1
cache: false
- name: Update pixi lock file
run: |
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
push:
branches:
- main
- v1
- v0.10.1
paths:
- tests/*
- hydromt/*
Expand All @@ -15,9 +15,9 @@ on:
- pixi.toml
- .github/workflows/tests.yml
pull_request:
branches:
- main
- v1
# branches:
# - main
# - v1
paths:
- tests/*
- hydromt/*
Expand Down Expand Up @@ -48,9 +48,9 @@ jobs:
steps:

- uses: actions/checkout@v4
- uses: prefix-dev/setup-pixi@v0.6.0
- uses: prefix-dev/setup-pixi@v0.8.2
with:
pixi-version: "v0.21.1"
pixi-version: v0.41.1
environments: full-py${{ matrix.python-version }}
- name: Prepare pixi
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tests_pip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ name: Tests with pip install

on:
push:
branches: [main]
branches: [main, v0.10.1]
paths:
- tests/*
- hydromt/*
- data/*
- pyproject.toml
pull_request:
branches:
- main
# branches:
# - main
paths:
- tests/*
- hydromt/*
Expand Down
2 changes: 2 additions & 0 deletions hydromt/io.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Implementations for all of pythe necessary IO for HydroMT."""

import glob
import io as pyio
import logging
Expand Down Expand Up @@ -633,6 +634,7 @@ def open_vector(
)
gdf = read_dataframe(str(fn), bbox=bbox_reader, mode=mode, **kwargs)
else:
bbox = tuple(bbox) if bbox is not None else None
gdf = gpd.read_file(str(fn), bbox=bbox, mask=geom, mode=mode, **kwargs)

# check geometry type
Expand Down
9 changes: 4 additions & 5 deletions hydromt/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# license file: https://github.com/corteva/rioxarray/blob/0.9.0/LICENSE

"""Extension for xarray to provide rasterio capabilities to xarray datasets/arrays."""

from __future__ import annotations

import itertools
Expand Down Expand Up @@ -222,7 +223,6 @@ def tile_window_xyz(shape, px):


class XGeoBase(object):

"""Base class for the GIS extensions for xarray."""

def __init__(self, xarray_obj: xr.DataArray | xr.Dataset) -> None:
Expand Down Expand Up @@ -333,7 +333,6 @@ def set_crs(self, input_crs=None, write_crs=True) -> CRS:


class XRasterBase(XGeoBase):

"""Base class for a Raster GIS extensions for xarray."""

def __init__(self, xarray_obj):
Expand Down Expand Up @@ -528,7 +527,7 @@ def bounds(self) -> tuple[float, float, float, float]:
c3x, c3y = transform * (self.width, 0)
xs = (c0x, c1x, c2x, c3x)
ys = (c0y, c1y, c2y, c3y)
return min(xs), min(ys), max(xs), max(ys)
return float(min(xs)), float(min(ys)), float(max(xs)), float(max(ys))

@property
def box(self) -> gpd.GeoDataFrame:
Expand Down Expand Up @@ -1801,7 +1800,6 @@ def nearest_index(

@xr.register_dataarray_accessor("raster")
class RasterDataArray(XRasterBase):

"""GIS extension for xarray.DataArray."""

def __init__(self, xarray_obj):
Expand Down Expand Up @@ -2244,6 +2242,8 @@ def _interpolate_na(
xs, ys = self.xcoords.values, self.ycoords.values
if xs.ndim == 1:
xs, ys = np.meshgrid(xs, ys)
xs = xs.reshape(*mask.shape)
ys = ys.reshape(*mask.shape)
if method == "rio_idw":
# NOTE: modifies src_data inplace
interp_data = rasterio.fill.fillnodata(src_data.copy(), mask, **kwargs)
Expand Down Expand Up @@ -2873,7 +2873,6 @@ def vectorize(self, connectivity=8):

@xr.register_dataset_accessor("raster")
class RasterDataset(XRasterBase):

"""GIS extension for :class:`xarray.Dataset`."""

@property
Expand Down
4 changes: 2 additions & 2 deletions hydromt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ def elevation2rgba(val, nodata=np.nan):

def rgba2elevation(rgba: np.ndarray, nodata=np.nan, dtype=np.float32):
"""Convert rgb tuple to elevation."""
r, g, b, a = np.split(rgba, 4, axis=2)
r, g, b, a = np.split(rgba.astype(dtype), 4, axis=2)
val = (r * 256 + g + b / 256) - 32768
return np.where(a == 0, nodata, val).squeeze().astype(dtype)
return np.where(a == 0, nodata, val).squeeze()


def _dict_pprint(d):
Expand Down
20 changes: 11 additions & 9 deletions hydromt/vector.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Implementation of the vector workloads."""

from __future__ import annotations

import logging
Expand All @@ -20,7 +21,6 @@


class GeoBase(raster.XGeoBase):

"""Base accessor class for geo data."""

def __init__(self, xarray_obj) -> None:
Expand All @@ -45,7 +45,7 @@ def _get_geom_names_types(self, geom_name: str = None) -> tuple[list, list]:
ndim = self._obj[name].ndim
if ndim != 1: # only single dim geometries
continue
item = self._obj[name][0].values.item()
item = self._obj[name].values[0]
if isinstance(item, BaseGeometry):
names.append(name)
types.append("geom")
Expand Down Expand Up @@ -352,7 +352,7 @@ def update_geometry(
x_name: (index_dim, geometry.x.values),
y_name: (index_dim, geometry.y.values),
}
obj = self._obj.copy()
obj = self._obj.copy(deep=False)
if replace:
obj = obj.drop_vars(drop_vars, errors="ignore")
obj = obj.assign_coords(coords)
Expand Down Expand Up @@ -663,7 +663,6 @@ def to_netcdf(

@xr.register_dataarray_accessor("vector")
class GeoDataArray(GeoBase):

"""Accessor class for vector based geo data arrays."""

def __init__(self, xarray_obj):
Expand Down Expand Up @@ -785,7 +784,9 @@ def from_gdf(
da = da.reindex({index_dim: _index}).transpose(index_dim, ...)
# set gdf geometry and optional other columns
hdrs = gdf.columns if keep_cols else [geom_name]
da = da.assign_coords({hdr: (index_dim, gdf.loc[_index, hdr]) for hdr in hdrs})
da = da.assign_coords(
{hdr: (index_dim, gdf.loc[_index, hdr].to_numpy()) for hdr in hdrs}
)
# set geospatial attributes
da.vector.set_spatial_dims(geom_name=geom_name, geom_format="geom")
da.vector.set_crs(gdf.crs)
Expand Down Expand Up @@ -836,8 +837,7 @@ def from_netcdf(

@xr.register_dataset_accessor("vector")
class GeoDataset(GeoBase):

"""Implementation for a vectorased geo dataset."""
"""Implementation for a vectorized geo dataset."""

def __init__(self, xarray_obj):
"""Initialise the object."""
Expand Down Expand Up @@ -953,10 +953,12 @@ def from_gdf(
if hdr != geom_name:
ds[hdr] = (index_dim, gdf.loc[_index, hdr])
else:
ds = ds.assign_coords({hdr: (index_dim, gdf.loc[_index, hdr])})
ds = ds.assign_coords(
{hdr: (index_dim, gdf.loc[_index, hdr].to_numpy())}
)
else:
ds = ds.assign_coords(
{hdr: (index_dim, gdf.loc[_index, hdr]) for hdr in hdrs}
{hdr: (index_dim, gdf.loc[_index, hdr].to_numpy()) for hdr in hdrs}
)
# set geospatial attributes
ds.vector.set_spatial_dims(geom_name=geom_name, geom_format="geom")
Expand Down
Loading

0 comments on commit b4ebfd7

Please sign in to comment.