Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose rasterio's opener argument in Rasterlayer.from_file #237

Merged
merged 1 commit into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions mesa_geo/raster_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import itertools
import math
import uuid
from collections.abc import Iterable, Iterator, Sequence
from collections.abc import Callable, Iterable, Iterator, Sequence
from typing import Any, cast, overload

import numpy as np
Expand Down Expand Up @@ -533,7 +533,11 @@ def to_image(self, colormap) -> ImageLayer:

@classmethod
def from_file(
cls, raster_file: str, cell_cls: type[Cell] = Cell, attr_name: str | None = None
cls,
raster_file: str,
cell_cls: type[Cell] = Cell,
attr_name: str | None = None,
rio_opener: Callable | None = None,
) -> RasterLayer:
"""
Creates a RasterLayer from a raster file.
Expand All @@ -542,9 +546,10 @@ def from_file(
:param Type[Cell] cell_cls: The class of the cells in the layer.
:param str | None attr_name: The name of the attribute to use for the cell values.
If None, a random name will be generated. Default is None.
:param Callable | None rio_opener: A callable passed to Rasterio open() function.
"""

with rio.open(raster_file, "r") as dataset:
with rio.open(raster_file, "r", opener=rio_opener) as dataset:
values = dataset.read()
_, height, width = values.shape
total_bounds = [
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dependencies = [
"geopandas",
"libpysal",
"rtree",
"rasterio",
"rasterio>=1.4b1",
"shapely",
"pyproj",
"folium",
Expand Down
Loading