diff --git a/scripts/build_ship_raster.py b/scripts/build_ship_raster.py index 7d59c4b12..af9b87020 100644 --- a/scripts/build_ship_raster.py +++ b/scripts/build_ship_raster.py @@ -54,8 +54,8 @@ with zipfile.ZipFile(snakemake.input.ship_density) as zip_f: zip_f.extract("shipdensity_global.tif") - ship_density = xr.open_rasterio("shipdensity_global.tif") - - da = ship_density.drop(["band"]).sel(x=slice(min(xs),max(Xs)), y=slice(max(Ys),min(ys))) - - da.to_netcdf(snakemake.output[0]) + with xr.open_rasterio("shipdensity_global.tif") as ship_density: + ship_density = ship_density.drop(["band"]).sel(x=slice(min(xs),max(Xs)), y=slice(max(Ys),min(ys))) + ship_density.to_netcdf(snakemake.output[0]) + + os.remove("shipdensity_global.tif") \ No newline at end of file