-
Notifications
You must be signed in to change notification settings - Fork 173
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
Natura tiff check #464
Natura tiff check #464
Conversation
@davide-f, many thanks for checking!
Totally agree! Such a visualisation tool could be very helpful to check cutout-natura.tiff correspondance. The notebook is there
The point is cutout and natura.tiff raster are being kept as rectangulars but were generated using different projections. Which means that we need to make a coordinates transform (on at least one of them) to be able overlay them on the same map. The grid is really helpful to highlight this effect: compare please the maps in the notebook. Of course, I may be biased but for me it looks like now the problem is fixed as compared with an initial natura.tiff generation approach: for Africa or Central Asia |
Thanks @ekatef ! Regarding the projections that's unfortunate and it shall be fixed in future releases. For natura, there may have been an old refuse that may have led to using 3035 by mistake and that shall be fixed, if that's the case. |
@davide-f, thanks for the comments :)
Yes, CRS of the pre-built If I understand properly pypsa-earth/scripts/build_natura_raster.py Line 150 in e35545c
...and generating the raster itself pypsa-earth/scripts/build_natura_raster.py Lines 187 to 188 in e35545c
Probably we could re-project the resulted raster and cut it to match exactly with to the cutout extend? However, I wouldn't say that raster approach to re-projection is the most elegant one (which seems to be connected with the raster format itself): https://github.com/rasterio/rasterio/blob/main/examples/reproject.py Have I understood your idea correctly? |
for more information, see https://pre-commit.ci
@davide-f, would be very grateful for your review. I have left |
Perfect! I completely agree. @ekatef do you think this PR is ready? |
@davide-f Thank you :) |
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
@ekatef I created the new world natura.tiff, may you check it with your scripts and compare to a cutout? |
@davide-f, fantastic news :) Thank you so much! |
@davide-f, unfortunately it looks like there are some troubles with applying the global That's a bit strange as the original raster boundary is Just to be sure about coordinates definition: Should be here the limiting range be +/-180 deg the same both for # ----------------------------------------------------
# error listing
# ----------------------------------------------------
INFO:snakemake.logging:rule build_renewable_profiles:
input: networks/base.nc, resources/natura.tiff, data/copernicus/PROBAV_LC100_global_v3.0.1_2019-nrt_Discrete-Classification-map_EPSG-4326.tif, data/gebco/GEBCO_2021_TID.nc, resources/shapes/country_shapes.geojson, resources/shapes/offshore_shapes.geojson, data/hydro_capacities.csv, data/eia_hydro_annual_generation.csv, resources/powerplants.csv, resources/bus_regions/regions_onshore.geojson, cutouts/casr-2018-era5.nc
output: resources/renewable_profiles/profile_onwind.nc
log: logs/build_renewable_profile_onwind.log
jobid: 8
benchmark: benchmarks/build_renewable_profiles_onwind
reason: Missing output files: resources/renewable_profiles/profile_onwind.nc; Input files updated by another job: networks/base.nc, resources/bus_regions/regions_onshore.geojson, resources/shapes/offshore_shapes.geojson, resources/shapes/country_shapes.geojson, resources/powerplants.csv
wildcards: technology=onwind
resources: tmpdir=/var/folders/qn/vpndfm21795ckkq89np1ckp40000gn/T, mem_mb=20000
INFO:snakemake.logging:
Traceback (most recent call last):
File "~Documents/_github_/pypsa-earth/.snakemake/scripts/tmpsjdn5q29.build_renewable_profiles.py", line 425, in <module>
natura_gejson = rio.warp.transform_geom(
File "~opt/miniconda3/envs/pypsa-africa/lib/python3.9/site-packages/rasterio/env.py", line 387, in wrapper
return f(*args, **kwds)
File "~opt/miniconda3/envs/pypsa-africa/lib/python3.9/site-packages/rasterio/env.py", line 612, in wrapper
return f(*args, **kwds)
File "~opt/miniconda3/envs/pypsa-africa/lib/python3.9/site-packages/rasterio/warp.py", line 109, in transform_geom
return _transform_geom(
File "rasterio/_warp.pyx", line 125, in rasterio._warp._transform_geom
File "rasterio/_warp.pyx", line 76, in rasterio._warp._transform_single_geom
File "rasterio/_err.pyx", line 215, in rasterio._err.exc_wrap_pointer
rasterio._err.CPLE_AppDefinedError: Point outside of projection domain
[Thu Oct 13 22:23:50 2022]
INFO:snakemake.logging:[Thu Oct 13 22:23:50 2022]
Error in rule build_renewable_profiles:
jobid: 8
output: resources/renewable_profiles/profile_onwind.nc
log: logs/build_renewable_profile_onwind.log (check log file(s) for error message)
ERROR:snakemake.logging:Error in rule build_renewable_profiles:
jobid: 8
output: resources/renewable_profiles/profile_onwind.nc
log: logs/build_renewable_profile_onwind.log (check log file(s) for error message)
RuleException:
CalledProcessErrorin line 341 of ~Documents/_github_/pypsa-earth/Snakefile:
Command 'set -euo pipefail; ~opt/miniconda3/envs/pypsa-africa/bin/python3.9 ~Documents/_github_/pypsa-earth/.snakemake/scripts/tmpsjdn5q29.build_renewable_profiles.py' returned non-zero exit status 1.
File "~Documents/_github_/pypsa-earth/Snakefile", line 341, in __rule_build_renewable_profiles
File "~opt/miniconda3/envs/pypsa-africa/lib/python3.9/concurrent/futures/thread.py", line 58, in run
ERROR:snakemake.logging:RuleException:
CalledProcessErrorin line 341 of ~Documents/_github_/pypsa-earth/Snakefile:
Command 'set -euo pipefail; ~opt/miniconda3/envs/pypsa-africa/bin/python3.9 ~Documents/_github_/pypsa-earth/.snakemake/scripts/tmpsjdn5q29.build_renewable_profiles.py' returned non-zero exit status 1.
File "~Documents/_github_/pypsa-earth/Snakefile", line 341, in __rule_build_renewable_profiles
File "~opt/miniconda3/envs/pypsa-africa/lib/python3.9/concurrent/futures/thread.py", line 58, in run
Shutting down, this might take some time.
WARNING:snakemake.logging:Shutting down, this might take some time.
Exiting because a job execution failed. Look above for error message
ERROR:snakemake.logging:Exiting because a job execution failed. Look above for error message
Complete log: .snakemake/log/2022-10-13T220051.621624.snakemake.log
WARNING:snakemake.logging:Complete log: .snakemake/log/2022-10-13T220051.621624.snakemake.log |
Thanks katia! I'll investigate the issue; I reposted the comment in the other PR. |
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering: rather than testing the cutout to be contained into natura, shouldn't we check:
- the "world_shape" to be contained into natura
- the "world_shape" to be contained into cutout
Having cutout contained into natura is not necessarily what we need.
What do you think?
Actually, this PR was intended to fix a mismatch between natura.tiff and cutout areas. Such a mismatch may be difficult to detect but if being present it leads to issues like reported here #411 (comment). Agree that it may be worth to re-think checking of the GIS inputs. My feeling is that the country-cutout correspondence check is definitely needed. As for natura.tiff, the idea was to ensure that the raster file was generated correctly. Since From the perspective of the model interfaces the logic your suggest may be more natural. E.g. we supply the intersecting cutout and natura.tiff while both are fine for a selected country, and the workflow should be happy with that. But the proposed check will not have any objections in that case just issuing a warning which indicates that the situation is a bit unusual. |
By the way, the problem with renewable_profiles_generation for China was linked to data loss in the raw ERA5 data. Many thanks @davide-f for sharing experiences in this regard :-) My feeling is that probably it may be worth to tackle both cutout issues (location and data validity) in a separate PR:
@davide-f, what do you think? |
@pz-max, could you please check if merging of this PR went properly? |
This is super weird... the main doesn't show it. Once, I click on "show difference to the previous version, it will show up in the original & the previous version... |
@pz-max, thank you for checking! I have done a local copy of the PR branch. In case it'll not show-up in some days, I'll just quickly create a new version. Software is generally unpredictable... (c) :D |
Closes #442 .
Continues #454 on the updated repo.
Changes proposed in this Pull Request
Discrepancy between the cutout and natura.tiff extents can lead to errors when generating renewable profiles. This PR is intended to prevent this by
Checklist
envs/environment.yaml
andenvs/environment.docs.yaml
.config.default.yaml
,config.tutorial.yaml
, andtest/config.test1.yaml
.doc/configtables/*.csv
and line references are adjusted indoc/configuration.rst
anddoc/tutorial.rst
.doc/release_notes.rst
is amended in the format of previous release notes, including reference to the requested PR.