Skip to content

Support projection coordinates in _read_ugrid #901

Open

Description

@kjnam

Proposed new feature or change:

The current _read_ugrid assumes the coordinate values are in longitude and latitude. and this not always true.

def _read_ugrid(ds):
"""Parses an unstructured grid dataset and encodes it in the UGRID
conventions."""
# Grid Topology
grid_topology_name = list(ds.filter_by_attrs(cf_role="mesh_topology").keys())[0]
ds = ds.rename({grid_topology_name: "grid_topology"})
# Coordinates
# get the names of node_lon and node_lat
node_lon_name, node_lat_name = ds["grid_topology"].node_coordinates.split()
coord_dict = {
node_lon_name: ugrid.NODE_COORDINATES[0],
node_lat_name: ugrid.NODE_COORDINATES[1],
}

The coordinates can be projected ones. So, I think it is better to rename coordinate variables only when the standard names of those are "longitude" and "latitude" following the CF convention.
This behavior can be added easily without disturbing the current approach.

Activity

  1. added
    new feature
    on Aug 22, 2024
  2. philipc2 commented on Aug 23, 2024

    @philipc2
    Member

    I don't have a formal geoscience background, so I was wondering what the coordinates should be referred to once they are projected.

    In addition to node_lon and node_lat, we have the means to store node_x node_y and node_z coordinates, which we've been using to store the Cartesian coordinate system. Should projected coordinates be stored here instead?

  3. kjnam commented on Aug 23, 2024

    @kjnam
    ContributorAuthor

    @philipc2 I am aware of node_?, and I am using those already for my codes. An alternative way to deal with this is modifying ani input dataset to provide lat and long coordinates via the UGRID coordinate variables while copying the original data to node_?. I have not tried it, but it is doable.
    Assuming the coordinate values from the UGRID dataset as lat and long, however, is still not quite safe, I think. So, the feature is suggested.
    In fact, a bigger and a fundamental issue to me is that the whole uxarray and routines assume the lat and long geographical coordinate system. I wish uxarray eventually provides functions for projected coordinates as well.

  4. philipc2 commented on Aug 23, 2024

    @philipc2
    Member

    In fact, a bigger and a fundamental issue to me is that the whole uxarray and routines assume the lat and long geographical coordinate system. I wish uxarray eventually provides functions for projected coordinates as well.

    Agreed, I'd like to prioritize this, as supporting projected coordinates also goes along with the themes of #493 and #849

  5. kjnam commented on Aug 23, 2024

    @kjnam
    ContributorAuthor

    @philipc2 Awesome! I can use and contribute to features related to projected coordinates happily. You've got a sure user for those here. 👍

  6. kafitzgerald commented on Aug 23, 2024

    @kafitzgerald
    Collaborator

    @philipc2, I think you're on the right track with "x" and "y", but I don't know enough about the internals of UXarray to know if overloading node_x and node_y might be problematic. These would likely be Cartesian (x, y) coordinates, but not in the way you seem to be defining / using them elsewhere in UXarray.

    Happy to chat geospatial whenever if it'd be helpful.

  7. rljacob commented on Aug 23, 2024

    @rljacob
    Member

    I'm also not sure what is meant by a "projected coordinate". When you project the lats and longs of sphere on to a flat surface, they're still called latitudes and longitudes.

  8. kjnam commented on Aug 23, 2024

    @kjnam
    ContributorAuthor

    @rljacob Projected coordinates are typically in length such as meter on a plain coordinate system, if I am not mistaken.

  9. philipc2 commented on Aug 23, 2024

    @philipc2
    Member

    @kjnam

    In addition to projections, supporting different coordinate systems (like how GeoPandas does) could also be of value.

    https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoSeries.crs.html

  10. philipc2 commented on Aug 23, 2024

    @philipc2
    Member

    @kafitzgerald

    @philipc2, I think you're on the right track with "x" and "y", but I don't know enough about the internals of UXarray to know if overloading node_x and node_y might be problematic. These would likely be Cartesian (x, y) coordinates, but not in the way you seem to be defining / using them elsewhere in UXarray.

    Our node_x ,node_y and node_z coordinates are used for storing Cartesian coordinates. node_lon and node_lat are reserved for spherical lat-lon coordinates.

  11. philipc2 commented on Aug 23, 2024

    @philipc2
    Member

    I'd like to mention that many of our algorithms are written assuming that we are working with spherical geometry, which typically involves us using normalized Cartesian (x, y, z) coordinates for the algorithms. So even if we do support projected coordinates, we'd still need to be able to convert them to the coordinates we use internally for computations.

    Looping @hongyuchen1030 into this discussion if she has any thoughts or experience with this.

  12. hongyuchen1030 commented on Aug 23, 2024

    @hongyuchen1030
    Contributor

    I'd like to mention that many of our algorithms are written assuming that we are working with spherical geometry, which typically involves us using normalized Cartesian (x, y, z) coordinates for the algorithms. So even if we do support projected coordinates, we'd still need to be able to convert them to the coordinates we use internally for computations.

    Looping @hongyuchen1030 into this discussion if she has any thoughts or experience with this.

    Thanks, @philipc2! Indeed, all internal algorithms utilize Cartesian coordinates for geometric calculations. The use of longitude and latitude in this context is primarily for providing users with a more intuitive geologic representation.

    Spherical and Cartesian coordinates can be easily converted between one another mathematically.

    @kjnam, could you clarify what you mean by "projected coordinates"? Are you referring to supporting the _read_ugrid function to read Cartesian coordinates as input? I believe this functionality might already be implemented, @philipc2. I recall implementing something similar in the __from_vertice__ function.

  13. kjnam commented on Aug 23, 2024

    @kjnam
    ContributorAuthor

    @hongyuchen1030 Yes, our dataset uses a UTM coordinate system, which is a projected coordinate system. And, yes, _read_ugrid just remap (or rename) x and y coordinates to *_lat and *_lon assuming they are already in those. This is not the case for me.
    I understand that many of computational functions in uxarray already convert lat and long to x and y coordinates, though they are mostly normalized. I guess we can use those for natively projected coordinates, but it may need some work.

  14. hongyuchen1030 commented on Aug 23, 2024

    @hongyuchen1030
    Contributor

    @hongyuchen1030 Yes, our dataset uses a UTM coordinate system, which is a projected coordinate system. And, yes, _read_ugrid just remap (or rename) x and y coordinates to *_lat and *_lon assuming they are already in those. This is not the case for me.

    We are aware of that problems as well, that's why internally we store both node_lon ,node_lat, and node_x, node_y, node_z in the internal data structure. But for the API design for the _read_ugrid, probably @philipc2 have a better thoughts about this.

    I understand that many of computational functions in uxarray already convert lat and long to x and y coordinates, though they are mostly normalized. I guess we can use those for natively projected coordinates, but it may need some work.

    Are the natively projected coordinates meant to represent coordinates that are not on a perfect sphere or are they the actual coordinates on Earth?

    Uxarray uses normalized coordinates ONLY for two reasons:

    1. Most geometric algorithms work exclusively on a perfect sphere. While other parameterized surfaces are mathematically possible, constructing them would require significant effort.
    2. You can easily transform unit sphere coordinates to other spherical coordinates by multiplying by the radius of the target sphere.
  15. kjnam commented on Aug 23, 2024

    @kjnam
    ContributorAuthor

    @hongyuchen1030 For example, UTM, Wikipedia - UTM, is projected or converted from a (non-perfect) sphere, WGS84. For us, those local length coordinates work fine and conveniently because our domain is local (or small), not global.
    Thanks for explaining about the normalized coordinates.

  16. hongyuchen1030 commented on Aug 23, 2024

    @hongyuchen1030
    Contributor

    @hongyuchen1030 For example, UTM, Wikipedia - UTM, is projected or converted from a (non-perfect) sphere, WGS84. For us, those local length coordinates work fine and conveniently because our domain is local (or small), not global. Thanks for explaining about the normalized coordinates.

    Thanks for your explanation. So it seems like UTM is using perfect ellipsoid, which is not supported for many Uxarray geometry algorithms right now.

    However, I think UTM can still be supported for the I/O and some visualization functions (without any geometry operations) in Uxarray. Again, for this part, @philipc2 probably has a better idea than me.

  17. kjnam commented on Aug 23, 2024

    @kjnam
    ContributorAuthor

    @hongyuchen1030 Exactly that is what I was looking for, beginning from _read_ugrid. Glad we discussed about this.

  18. added this to the General I/O milestone on Mar 24, 2026
  19. moved this from 📚 Backlog to 🏗 In progress in UXarray Developmenton Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

new feature

Type

No type

Fields

Priority

None yet

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions