Merge pull request #474 from PyPSA/rioxarray-to-envs
importing rioxarray instead of xarray to open rasterio file
This commit is contained in:
commit
0c3868b6a1
@ -287,11 +287,14 @@ dependencies:
|
|||||||
- qt-main=5.15.8
|
- qt-main=5.15.8
|
||||||
- rasterio=1.3.4
|
- rasterio=1.3.4
|
||||||
- readline=8.1.2
|
- readline=8.1.2
|
||||||
- requests=2.28.2
|
- requests=2.28.1
|
||||||
- reretry=0.11.8
|
- retry=0.9.2
|
||||||
- rtree=1.0.1
|
- rich=12.5.1
|
||||||
- scikit-learn=1.2.1
|
- rioxarray=0.13.3
|
||||||
- scipy=1.10.0
|
- rtree=1.0.0
|
||||||
|
- s2n=1.0.10
|
||||||
|
- scikit-learn=1.1.1
|
||||||
|
- scipy=1.8.1
|
||||||
- scotch=6.0.9
|
- scotch=6.0.9
|
||||||
- seaborn=0.12.2
|
- seaborn=0.12.2
|
||||||
- seaborn-base=0.12.2
|
- seaborn-base=0.12.2
|
||||||
|
@ -29,6 +29,7 @@ dependencies:
|
|||||||
- pandas>=1.4
|
- pandas>=1.4
|
||||||
- geopandas>=0.11.0
|
- geopandas>=0.11.0
|
||||||
- xarray
|
- xarray
|
||||||
|
- rioxarray
|
||||||
- netcdf4
|
- netcdf4
|
||||||
- networkx
|
- networkx
|
||||||
- scipy
|
- scipy
|
||||||
|
@ -172,7 +172,7 @@ rule build_ship_raster:
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
output:
|
output:
|
||||||
RESOURCES + "shipdensity_raster.nc",
|
RESOURCES + "shipdensity_raster.tif",
|
||||||
log:
|
log:
|
||||||
LOGS + "build_ship_raster.log",
|
LOGS + "build_ship_raster.log",
|
||||||
resources:
|
resources:
|
||||||
@ -202,7 +202,7 @@ rule build_renewable_profiles:
|
|||||||
)
|
)
|
||||||
),
|
),
|
||||||
ship_density=lambda w: (
|
ship_density=lambda w: (
|
||||||
RESOURCES + "shipdensity_raster.nc"
|
RESOURCES + "shipdensity_raster.tif"
|
||||||
if "ship_threshold" in config["renewable"][w.technology].keys()
|
if "ship_threshold" in config["renewable"][w.technology].keys()
|
||||||
else []
|
else []
|
||||||
),
|
),
|
||||||
|
@ -197,7 +197,7 @@ def convert_nuts2_to_regions(bio_nuts2, regions):
|
|||||||
)
|
)
|
||||||
overlay[adjust_cols] = overlay[adjust_cols].multiply(overlay["share"], axis=0)
|
overlay[adjust_cols] = overlay[adjust_cols].multiply(overlay["share"], axis=0)
|
||||||
|
|
||||||
bio_regions = overlay.groupby("name").sum()
|
bio_regions = overlay.dissolve("name", aggfunc="sum")
|
||||||
|
|
||||||
bio_regions.drop(["area_nuts2", "share"], axis=1, inplace=True)
|
bio_regions.drop(["area_nuts2", "share"], axis=1, inplace=True)
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
import xarray as xr
|
import rioxarray
|
||||||
from _helpers import configure_logging
|
from _helpers import configure_logging
|
||||||
from build_natura_raster import determine_cutout_xXyY
|
from build_natura_raster import determine_cutout_xXyY
|
||||||
|
|
||||||
@ -64,10 +64,10 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
with zipfile.ZipFile(snakemake.input.ship_density) as zip_f:
|
with zipfile.ZipFile(snakemake.input.ship_density) as zip_f:
|
||||||
zip_f.extract("shipdensity_global.tif")
|
zip_f.extract("shipdensity_global.tif")
|
||||||
with xr.open_rasterio("shipdensity_global.tif") as ship_density:
|
with rioxarray.open_rasterio("shipdensity_global.tif") as ship_density:
|
||||||
ship_density = ship_density.drop(["band"]).sel(
|
ship_density = ship_density.drop(["band"]).sel(
|
||||||
x=slice(min(xs), max(Xs)), y=slice(max(Ys), min(ys))
|
x=slice(min(xs), max(Xs)), y=slice(max(Ys), min(ys))
|
||||||
)
|
)
|
||||||
ship_density.to_netcdf(snakemake.output[0])
|
ship_density.rio.to_raster(snakemake.output[0])
|
||||||
|
|
||||||
os.remove("shipdensity_global.tif")
|
os.remove("shipdensity_global.tif")
|
||||||
|
Loading…
Reference in New Issue
Block a user