Skip to content

Detecting & Splitting Faces that cross the Antemeridian  #171

Closed

Description

@philipc2

Overview

The connectivity used to described unstructured grids typically assumes that the grid resides on a sphere. When you connect two nodes together to form an edge across the antimeridian, attempting to project them onto a 2D projection (as is the case with many visualizations) leads to an incorrect representation, where the edge spans across the projection when it should instead directly "wrap" to the other node.

Activity

  1. added
    new feature
    on Nov 3, 2022
  2. self-assigned this
    on Nov 3, 2022
  3. moved this from 📝 To Do to 🏗 In progress in UXarray Developmenton Nov 15, 2022
  4. changed the title [-]Function to detect cyclic faces[/-] [+]Function for detecting faces that cross the Antimeridian [/+] on Dec 5, 2022
  5. moved this from 🏗 In progress to 👀 In review in UXarray Developmenton Dec 6, 2022
  6. hongyuchen1030 commented on Jun 8, 2023

    @hongyuchen1030
    Contributor

    Hi, @philipc2 @ifranda as mentioned in the meeting, here's the sudo codes that you can refer to so as to find the anti-meridian face

    Please keep in mind that we made a rule here: the span of the edge cannot be larger than 180 degree: We will always pick the direction of the edge that's less than 180 degree

    • Helper Function sudo codes to detect if an edge is across the anti-meridian (longitude 0 in this case)
      This function summarizes each anti-meridian scenario that you can refer to (If you want to do a more detailed operation on the antimeridian case)
    def edge_antimeridian_case(gcr_cart)
    
            # Special case: when the gcr and the point are all on the same longitude line:
            if gcr_lonlat_rad[0][0] == gcr_lonlat_rad[1][0] == 0:
                pass
    
    
            GCR0_lonlat = node_xyz_to_lonlat_rad(gcr_cart[0])
            GCR1_lonlat = node_xyz_to_lonlat_rad(gcr_cart[1])
    
            # The anti-meridian case Sufficient condition: absolute difference between the longitudes of the two
            # vertices is greater than 180 degrees (π radians): abs(GCRv1_lon - GCRv0_lon) > π
            if abs(GCRv1_lonlat[0] - GCRv0_lonlat[0]) > np.pi:
    
                # The necessary condition: the pt longitude is on the opposite side of the anti-meridian
                # Case 1: where 0 --> x0--> 180 -->x1 -->0 case is lager than the 180degrees (pi radians)
                # Need to redirect such that 180 --> x0 --> 0 --> x1 --> 180
                if GCRv0_lonlat[0] <= np.pi <= GCRv1_lonlat[0]:
                    pass
                
                # The necessary condition: the pt longitude is on the opposite side of the anti-meridian
                # Case 2: The anti-meridian case where 180 -->x0 --> 0 lon --> x1 --> 180 that doesn't require redirection.
                elif 2*np.pi > GCRv0_lonlat[0] > np.pi > GCRv1_lonlat[0] > 0:
                    pass

    If all you want to do is to find out if this edge is anti-meridian or not, use the following branching:

    if abs(GCRv1_lonlat[0] - GCRv0_lonlat[0]) > np.pi or gcr_lonlat_rad[0][0] == gcr_lonlat_rad[1][0] == 0:
    • The final function sudo codes that can help you detect if the face goes across the antimeridian

    for each face, loop over each edge and use the above function to test if this edge is anti-meridian, if any of the edges is True(across the meridian), then the entire face is antimeridian.

    Please let me know if you have any question about this

  7. philipc2 commented on Jun 8, 2023

    @philipc2
    MemberAuthor

    e, lo

    Thank you so much for this! This is extremely helpful!

  8. linked a pull request that will close this issueData Structures & Helpers for Visualization #354on Jun 22, 2023
  9. changed the title [-]Function for detecting faces that cross the Antimeridian [/-] [+]Detecting & Splitting Faces that cross the Antemeridian [/+] on Jun 25, 2023
  10. moved this from 👀 In review to 🏗 In progress in UXarray Developmenton Jul 11, 2023
  11. hongyuchen1030 commented on Jul 21, 2023

    @hongyuchen1030
    Contributor

    Hi @philipc2
    some update related to the issue I just posted #392 , we need to add the exception for edge larger or equal to 180 degree here.

    def edge_antimeridian_case(gcr_cart)
    
           # Special case: when the gcr and the point are all on the same longitude line:
           if gcr_lonlat_rad[0][0] == gcr_lonlat_rad[1][0] == 0:
               pass
    
    
           GCR0_lonlat = node_xyz_to_lonlat_rad(gcr_cart[0])
           GCR1_lonlat = node_xyz_to_lonlat_rad(gcr_cart[1])
    
           # The anti-meridian case Sufficient condition: absolute difference between the longitudes of the two
           # vertices is greater than 180 degrees (π radians): abs(GCRv1_lon - GCRv0_lon) > π
           if abs(GCRv1_lonlat[0] - GCRv0_lonlat[0]) >= np.pi:
    
               # The necessary condition: the pt longitude is on the opposite side of the anti-meridian
               # Case 1: where 0 --> x0--> 180 -->x1 -->0 case is not less than the 180degrees (pi radians)
               # 
               if GCRv0_lonlat[0] <= np.pi <= GCRv1_lonlat[0]:
                   raise ValueError("All edge span should be less than 180 degree")
               
               # The necessary condition: the pt longitude is on the opposite side of the anti-meridian
               # Case 2: The anti-meridian case where 180 -->x0 --> 0 lon --> x1 --> 180 
               elif 2*np.pi > GCRv0_lonlat[0] > np.pi > GCRv1_lonlat[0] > 0:
                   pass

    If all you want to do is to find out if this edge is anti-meridian or not, use the following branching:

    if abs(GCRv1_lonlat[0] - GCRv0_lonlat[0]) >= np.pi or gcr_lonlat_rad[0][0] == gcr_lonlat_rad[1][0] == 0:
  12. philipc2 commented on Jul 21, 2023

    @philipc2
    MemberAuthor

    @hongyuchen1030

    Thank you for this! I've been using the antimeridian package for my visualization work, and possibly for future analysis work if it's applicable.

    Here's a great example from their documentation outlining the algorithm, which appears to be similar to what was outlined here.

  13. hongyuchen1030 commented on Jul 21, 2023

    @hongyuchen1030
    Contributor

    @hongyuchen1030

    Thank you for this! I've been using the antimeridian package for my visualization work, and possibly for future analysis work if it's applicable.

    Here's a great example from their documentation outlining the algorithm, which appears to be similar to what was outlined here.

    I took a look at their algorithm. Yes, they basically employ the same steps we're doing here. I think it should be compatible with our future implementation

  14. moved this from 🏗 In progress to ✅ Done in UXarray Developmenton Aug 11, 2023
  15. added this to the Visualization milestone on Sep 12, 2023
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