Skip to content

Commit

Permalink
fix: Remove gdal as explicit dependency (#566)
Browse files Browse the repository at this point in the history
* remove GDAL in pyproject.toml

* remove use of GDAL in repo

* remove conda-forge:gdal=3.5.1 from environment.yml

* remove conda-forge:gdal=3.5.1 from tc and docker env YML

* ci: Updated lock file

---------

Co-authored-by: MatthiasHauthDeltares <[email protected]>
  • Loading branch information
Carsopre and MatthiasHauthDeltares authored Aug 30, 2024
1 parent 6bd6ce7 commit d18e7ec
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 50 deletions.
3 changes: 1 addition & 2 deletions .config/docker_environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ channels:
- nodefaults
dependencies:
- conda-forge::python=3.10
- conda-forge::gdal=3.5.1
# from here some dragons
# from here some dragons
- conda-forge::geopandas
- conda-forge::rasterio
- conda-forge::osmnx
Expand Down
1 change: 0 additions & 1 deletion .config/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ channels:
- nodefaults
dependencies:
- conda-forge::python=3.10
- conda-forge::gdal=3.5.1
# Install poetry 1.3.2 (1.4.*) gives issues.
# If this does not work then exclude it from the environment and install it manually
# with: conda install -c conda-forge poetry=1.3.2
Expand Down
1 change: 0 additions & 1 deletion .config/tc_environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ channels:
- nodefaults
dependencies:
- python=3.10
- conda-forge::gdal=3.5.1
- conda-forge::pandoc
- teamcity-messages
16 changes: 1 addition & 15 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ openpyxl = "^3.0.10"
xlrd = "^2.0.1"
xarray = "^2022.6.0"
scipy = "^1.9.1"
GDAL = "3.5.1"
pygeos = "^0.14"
momepy = "0.5.0"
geopandas = "^0.14.0"
Expand Down
18 changes: 11 additions & 7 deletions ra2ce/network/hazard/hazard_common_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import logging
from pathlib import Path

import rasterio
from networkx import Graph
from osgeo import gdal

from ra2ce.network.networks_utils import bounds_intersect_2d, get_extent

Expand All @@ -40,16 +40,20 @@ def validate_extent_graph(extent_graph: list[float], tif_hazard_file: Path) -> N
ValueError: When the hazard raster and the graph geometries do not overlap.
"""
# Check if the hazard and graph extents overlap
extent = get_extent(gdal.Open(str(tif_hazard_file)))
with rasterio.open(tif_hazard_file) as src:
# Get the bounding box
bounds = src.bounds

# Extract the extent
extent_hazard = (
extent["minX"],
extent["maxX"],
extent["minY"],
extent["maxY"],
bounds.left,
bounds.right,
bounds.bottom,
bounds.top,
)

if not bounds_intersect_2d(extent_graph, extent_hazard):
logging.info("Raster extent: {}, Graph extent: {}".format(extent, extent_graph))
logging.info("Raster extent: {}, Graph extent: {}".format(bounds, extent_graph))
raise ValueError(
"The hazard raster and the graph geometries do not overlap, check projection"
)
Expand Down
23 changes: 0 additions & 23 deletions ra2ce/network/networks_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import rtree
from geopy import distance
from numpy.ma import MaskedArray
from osgeo import gdal
from osmnx import graph_to_gdfs
from rasterio.features import shapes
from rasterio.mask import mask
Expand Down Expand Up @@ -1279,28 +1278,6 @@ def read_merge_shp(shp_file_analyse, id_name, shp_file_diversion=[], crs_=4326):
return lines


def check_hazard_extent_resolution(list_hazards):
"""Checks whether the extent of a list of hazard rasters is exactly the same.
Args:
list_hazards (list of pathlib paths or strings): A list of paths to the hazard map rasters of which
the extent needs to be checked
Returns:
(bool): True if the extents are exactly the same, False if they are not.
"""
if len(list_hazards) == 1:
return True
check_hazard_extent = [
gdal.Open(str(haz)).GetGeoTransform() for haz in list_hazards
]
if len(set(check_hazard_extent)) == 1:
# All hazard have the exact same extents and resolution
return True
else:
return False


def get_extent(dataset):
cols = dataset.RasterXSize
rows = dataset.RasterYSize
Expand Down

0 comments on commit d18e7ec

Please sign in to comment.