PyPSA / atlite

Atlite: A Lightweight Python Package for Calculating Renewable Power Potentials and Time Series
https://atlite.readthedocs.io
268 stars 90 forks source link

let `add_geometry` and `add_raster` read from URL #309

Closed fneum closed 1 year ago

fneum commented 1 year ago

Closes #307

Popular feature request in the Data Science for Energy System Modelling course.

Follows PyPSA implementation.

Test with:

import geopandas as gpd
from atlite.gis import ExclusionContainer

URL = 'https://tubcloud.tu-berlin.de/s/mxgaA7wH8NsmdDi/download/Natura2000_end2021-PT.gpkg'
CRS = 3035

world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
shape = world.query("iso_a3 == 'PRT'").to_crs(CRS).geometry

excluder = ExclusionContainer(crs=CRS)
excluder.add_geometry(URL)

excluder.plot_shape_availability(shape)
fneum commented 1 year ago

I don't think the test failures are related to this PR.

euronion commented 1 year ago

a.) Your code for testing does not affect the code lines you have changes, The test is for a geometry, and the changes you proposed affect raster exclusions ;-)

b.) With rasterio>1.3.2 reading from URL is now enabled, so we don't need to change anything (free new features - yeah! 🥳 )

For testing:

from atlite.gis import ExclusionContainer
import geopandas as gpd

world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
shape = world.query("iso_a3 == 'PRT'").to_crs(CRS).geometry

CRS = 3035

excluder = ExclusionContainer(crs=CRS)
excluder.add_raster(
    "https://fex.hrz.uni-giessen.de/fop/sJ3xfVzn/g250_06.tif",
    codes=[12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 32]
    )
excluder.plot_shape_availability(shape)