-
Notifications
You must be signed in to change notification settings - Fork 42
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
Rework DEM.vcrs
to support any 3D transformation (and fix with PROJ update)
#350
Conversation
DEM.vref
into DEM.vcrs
and fix with pyproj update DEM.vcrs
to support any 3D transformation (and fix with PROJ update)
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.
Wow, what a big change with so few things for me to say! This looks like a great modification of the current behaviour and I only have nitpicks.
…nd add tests for it
…h TransformationGroup during transform
Thanks a lot for the review @erikmannerfelt! 😄 I realized there was still a bit more to do to have everything practical and consistent!
And, most importantly, wrote the documentation page! Here is it: https://xdem-rhugonnet.readthedocs.io/en/fix_vref/vertical_ref.html |
Finally fixed the last little bit! All yours to review @erikmannerfelt! One big question remains for me: Should we integrate the |
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 only have documentation comments now!
Regarding your suggestion to override crs with vcrs, do you mean to override crs with ccrs, or am I missing something? I'm still a bit new to vcrs so it might be a dumb question!
- **Any PROJ grid name available at [https://cdn.proj.org/](https://cdn.proj.org/)**, | ||
|
||
```{tip} | ||
**No need to download the grid!** This is done automatically during the setting operation, if the grid does not already exist locally. |
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.
"[...] in most installations of proj [...]". On some installations like in nix, the proj folders are readonly.
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 not sure where you would place the addition?
Thanks for the comments!
Yes, exactly, overriding it with @adehecq: Curious about your feedback on this PR as well! |
Merging as @erikmannerfelt is on fieldwork so I assume the review is finished! 😄 |
This PR reworks the vertical CRS attribute of
DEM
from.vref
into.vcrs
and uses more rigorouslypyproj
to define.vcrs
as a vertical CRS (1D vertical axis) andccrs
as a 3D CRS (compound 2D + 1D, or promoted 2D to 3D CRS) required for vertical transformation.The previous implementation stopped working because, since PROJ6, having 3D CRS as both input and output of a transformation is necessary to transform
z
(otherwise runs but without transforming). See: https://pyproj4.github.io/pyproj/stable/advanced_examples.html#promote-crs-to-3d.Now, two methods are implemented in
DEM
:to_vcrs()
andset_vcrs
(very much liketo_crs()
andset_crs()
in GeoPandas). The functionalities resides in a separate modulevcrs.py
.I ran into some difficulties implementing the functionality because the function
pyproj.CRS.to_2d()
did not exist whilepyproj.CRS.to_3d()
does. This is now solved as it existed in PROJ and just needed to be wrapped, see related discussion: pyproj4/pyproj#1265 and related PR: pyproj4/pyproj#1267.Also removes one time test that still failed randomly (forgotten in #355).
Details
This PR:
vcrs.py
module with his own teststest_vcrs.py
,_vcrs_from_user_input()
function to parse any vertical CRS from either common names ("EGM96", "EGM08", "Ellipsoid"), or a PROJ grid path, or an EPSG code or a CRS object,_build_vcrs_from_grid()
function to consistently build a vertical CRS from a grid. If the grid does not exist locally, it attempts to download it from the PROJ fixed repo: https://cdn.proj.org/._build_ccrs_from_crs_and_vcrs()
function to consistently build a 3D CRS from a 2D/3D CRS stored in.crs
byRaster
(dropping the 3D if needed), and a vertical CRS in.vcrs
. Additionally, if the target is the ellipsoid, the function casts to 3D._transform_zz
function that creates aTransformerGroup
to list all possible transformers and, if thebest_available
is not there, downloads the grids automatically,DEM.set_vcrs
andDEM.to_vcrs
using the previous functions ofvcrs.py
,DEM.from_array()
to setvcrs
during DEM creation from array,DEM.__init__
to set avcrs
if the.crs
is 3D,proj-data
as a dependency,pyproj>=3.4
to ensure thatTransformer.transform()
returns anp.ma.MaskedArray
,Issues
Resolves #344
Resolves #345
Resolves #331
Resolves #262
Resolves #311
Resolves #223