Skip to content

Commit dee6363

Browse files
authored
gis: Use gzip.open opener in RasterLayer.from_file (#184)
Use pass the new rio_opener argument with gzip.open in RasterLayer.from_file(). This prevents having to do the weird /vsigzip/ stuff. Note that urban_growth uses the rasterio opener directly, while the other two examples pass it via the mesa_geo.raster_layers.RasterLayer.open_file() method.
1 parent 3d29e4c commit dee6363

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

gis/population/population/space.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import gzip
34
import uuid
45

56
import geopandas as gpd
@@ -36,9 +37,10 @@ def __init__(self, crs):
3637
def load_data(self, population_gzip_file, lake_zip_file, world_zip_file, model):
3738
world_size = gpd.GeoDataFrame.from_file(world_zip_file)
3839
raster_layer = RasterLayer.from_file(
39-
f"/vsigzip/{population_gzip_file}",
40+
population_gzip_file,
4041
cell_cls=UgandaCell,
4142
attr_name="population",
43+
rio_opener=gzip.open,
4244
)
4345
raster_layer.crs = world_size.crs
4446
raster_layer.total_bounds = world_size.total_bounds

gis/rainfall/rainfall/space.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
import gzip
4+
35
import mesa
46
import mesa_geo as mg
57
import numpy as np
@@ -34,9 +36,10 @@ def __init__(self, crs, water_height, model):
3436

3537
def set_elevation_layer(self, elevation_gzip_file, crs):
3638
raster_layer = mg.RasterLayer.from_file(
37-
f"/vsigzip/{elevation_gzip_file}",
39+
elevation_gzip_file,
3840
cell_cls=LakeCell,
3941
attr_name="elevation",
42+
rio_opener=gzip.open,
4043
)
4144
raster_layer.crs = crs
4245
raster_layer.apply_raster(

gis/urban_growth/urban_growth/space.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import gzip
34
import random
45

56
import mesa
@@ -96,7 +97,7 @@ def load_datasets(
9697
"land_use": land_use_data,
9798
}
9899
for attribute_name, data_file in data.items():
99-
with rio.open(f"/vsigzip/{data_file}", "r") as dataset:
100+
with rio.open(data_file, "r", opener=gzip.open) as dataset:
100101
values = dataset.read()
101102
self.raster_layer.apply_raster(values, attr_name=attribute_name)
102103

0 commit comments

Comments
 (0)