Skip to content
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

Zonal face weights at constant lat #555

Merged

Conversation

hongyuchen1030
Copy link
Collaborator

@hongyuchen1030 hongyuchen1030 commented Oct 25, 2023

Closes #544

Overview

  • The _get_zonal_face_weights_at_constlat method has been added to calculate the weight of each face at a constant latitude.
  • The user can specify if the given edge is a great circle arc or a constant latitude one
  • This method computes the perimeter of a circle at constant latitude, identifies overlapping intervals, and calculates the weight of each face based on the longitude bounds.
  • Sweepline algorithm is used to calculate the overlapped intervals' weights
  • Errors and edge cases are handled gracefully, with informative error messages and comments for future maintenance.

Expected Usage

# Assuming uxarray is imported as ux
grid_path = "/path/to/grid.nc"
data_path = "/path/to/data.nc"

uxds = ux.open_dataset(grid_path, data_path)

# Replace `latitude_rad` with the desired latitude in radians
latitude_rad = 0.0  # Example value

        weight_df = _get_zonal_faces_weight_at_constLat(np.array([
            face_0_edge_nodes, face_1_edge_nodes, face_2_edge_nodes,
            face_3_edge_nodes
        ]),
                                                        0.01,
                                                        latlon_bounds,
                                                        is_directed=False)

PR Checklist

General

  • An issue is linked created and linked
  • Add appropriate labels
  • Filled out Overview and Expected Usage (if applicable) sections

Testing

  • Adequate tests are created if there is new functionality
  • Tests cover all possible logical paths in your function
  • Tests are not too basic (such as simply calling a function and nothing else)

Documentation

  • Docstrings have been added to all new functions
  • Docstrings have updated with any function changes
  • Internal functions have a preceding underscore (_) and have been added to docs/internal_api/index.rst
  • User functions have been added to docs/user_api/index.rst

@hongyuchen1030 hongyuchen1030 added the new feature New feature or request label Oct 25, 2023
@hongyuchen1030 hongyuchen1030 self-assigned this Oct 25, 2023
@hongyuchen1030 hongyuchen1030 marked this pull request as draft October 25, 2023 23:59
@hongyuchen1030 hongyuchen1030 added the help wanted Extra attention is needed label Oct 25, 2023
@philipc2 philipc2 changed the title Zonal face weights at constantlat DRAFT: Zonal face weights at constant lat Oct 30, 2023
@erogluorhan erogluorhan self-requested a review March 26, 2024 21:21
Copy link
Member

@erogluorhan erogluorhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re current CI failures:

With the commit entitled "WIP" on the Feb 4th this year, several lines of codes seem to have been added. The following code block:

unique_intersection_lonlat = np.array(
                    [node_xyz_to_lonlat_rad(pt.tolist()) for pt in unique_intersection]
                )
>               unique_intersection_lonlat = unique_intersection_lonlat.append(
                    [2 * np.pi, latitude_rad]
                )

apparently creates a numpy.ndarray then attempts to .append() into that, which results in

AttributeError: 'numpy.ndarray' object has no attribute 'append'

FYI: The last successful CI actions before the above commit seems to be Merge branch 'main' into zonal_face_weights_at_constantlat, which was on Jan 16.

@hongyuchen1030
Copy link
Collaborator Author

Re current CI failures:

With the commit entitled "WIP" on the Feb 4th this year, several lines of codes seem to have been added. The following code block:

unique_intersection_lonlat = np.array(
                    [node_xyz_to_lonlat_rad(pt.tolist()) for pt in unique_intersection]
                )
>               unique_intersection_lonlat = unique_intersection_lonlat.append(
                    [2 * np.pi, latitude_rad]
                )

apparently creates a numpy.ndarray then attempts to .append() into that, which results in

AttributeError: 'numpy.ndarray' object has no attribute 'append'

FYI: The last successful CI actions before the above commit seems to be Merge branch 'main' into zonal_face_weights_at_constantlat, which was on Jan 16.

Thanks for your information. Yeah I also noticed that this was the cause. So this syntax is actually valid before. I assume it was the version upgrade that makes it corrupts. I am still working on fixing it since I have been working on other research project recently.

@erogluorhan
Copy link
Member

Thanks for your information. Yeah I also noticed that this was the cause. So this syntax is actually valid before. I assume it was the version upgrade that makes it corrupts. I am still working on fixing it since I have been working on other research project recently.

I think you intended to use numpy.append(array-like1, array-like2,...) rather than the one here (i.e. non-existent numpy.ndarray.append()?

@hongyuchen1030
Copy link
Collaborator Author

Thanks for your information. Yeah I also noticed that this was the cause. So this syntax is actually valid before. I assume it was the version upgrade that makes it corrupts. I am still working on fixing it since I have been working on other research project recently.

I think you intended to use numpy.append(array-like1, array-like2,...) rather than the one here (i.e. non-existent numpy.ndarray.append()?

I guessed the same thing before. But when I tried to fix it by using this numpy.append(array-like1, array-like2,...) , all my following codes and functions call corrupts due to incorrect array shape, which is not logical since my previous implementation passed all the test cases. I am still trying to figure out what I intended to do for that WIP commit. I had been actively working on this branch to test many current research ideas since it's been hanging there for a while.

@hongyuchen1030
Copy link
Collaborator Author

Hi @philipc2 @erogluorhan,

I have cleaned up and fixed the CI for this branch and it is mostly ready to go now. However, the read-doc failed is currently failing because the module uxarray.Grid.grid_spec., which I didn't modify in this PR. I wonder if you can take a look into this? Thanks. Other than that, this PR is ready to be merged

Running Sphinx v7.3.6
making output directory... done
[autosummary] generating autosummary for: api.rst, citation.rst, contributing.rst, examples.rst, examples/000-template.ipynb, examples/001-working-with-unstructured-grids.ipynb, examples/002-grid-topology.ipynb, examples/003-area-calc.ipynb, examples/004-working-with-mpas-grids.ipynb, examples/005-to-geodataframe-for-holoviz.ipynb, ..., examples/009-subsetting.ipynb, getting-started/freq-asked-questions.rst, getting-started/overview.rst, getting-started/quick-install.rst, index.rst, installation.rst, internal_api/index.rst, quickstart.rst, tutorials.rst, user_api/index.rst
WARNING: [autosummary] failed to import uxarray.Grid.grid_spec.
Possible hints:

  • PycodeError: no source found for module 'builtins'
  • AttributeError: type object 'Grid' has no attribute 'grid_spec'
  • ModuleNotFoundError: No module named 'uxarray.Grid'
    WARNING: [autosummary] failed to import uxarray.Grid.n_max_node_nodes.
    Possible hints:
  • AttributeError: type object 'Grid' has no attribute 'n_max_node_nodes'
  • PycodeError: no source found for module 'builtins'
  • ModuleNotFoundError: No module named 'uxarray.Grid'
    WARNING: [autosummary] failed to import uxarray.grid._slice_edge_indices.
    Possible hints:
  • ModuleNotFoundError: No module named 'uxarray.grid._slice_edge_indices'
  • ImportError:
  • AttributeError: module 'uxarray.grid' has no attribute '_slice_edge_indices'
    WARNING: [autosummary] failed to import uxarray.grid._slice_face_indices.
    Possible hints:
  • ImportError:
  • AttributeError: module 'uxarray.grid' has no attribute '_slice_face_indices'
  • ModuleNotFoundError: No module named 'uxarray.grid._slice_face_indices'
    WARNING: [autosummary] failed to import uxarray.grid.connectivity._build_face_edges_connectivity.
    Possible hints:
  • ModuleNotFoundError: No module named 'uxarray.grid.connectivity._build_face_edges_connectivity'; 'uxarray.grid.connectivity' is not a package
  • AttributeError: module 'uxarray.grid.connectivity' has no attribute '_build_face_edges_connectivity'
  • ImportError:
    WARNING: [autosummary] failed to import uxarray.grid.connectivity._build_nNodes_per_face.
    Possible hints:
  • AttributeError: module 'uxarray.grid.connectivity' has no attribute '_build_nNodes_per_face'
  • ImportError:
  • ModuleNotFoundError: No module named 'uxarray.grid.connectivity._build_nNodes_per_face'; 'uxarray.grid.connectivity' is not a package
    WARNING: [autosummary] failed to import uxarray.grid.connectivity._populate_face_edges_connectivity.
    Possible hints:
  • AttributeError: module 'uxarray.grid.connectivity' has no attribute '_populate_face_edges_connectivity'
  • ImportError:
  • ModuleNotFoundError: No module named 'uxarray.grid.connectivity._populate_face_edges_connectivity'; 'uxarray.grid.connectivity' is not a package
    WARNING: [autosummary] failed to import uxarray.grid.connectivity._populate_node_faces_connectivity.
    Possible hints:
  • AttributeError: module 'uxarray.grid.connectivity' has no attribute '_populate_node_faces_connectivity'
  • ModuleNotFoundError: No module named 'uxarray.grid.connectivity._populate_node_faces_connectivity'; 'uxarray.grid.connectivity' is not a package
  • ImportError:

@philipc2
Copy link
Member

Details

Hi @hongyuchen1030

Thanks for the revisions! Giving this a look through now and I'll look into what's causing the RTD failures.

@hongyuchen1030
Copy link
Collaborator Author

Details

Hi @hongyuchen1030

Thanks for the revisions! Giving this a look through now and I'll look into what's causing the RTD failures.

Thank you very much! I just fixed a typo in the .rst file, I think the read-docs works now

Copy link
Member

@philipc2 philipc2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fantastic! Thanks for addressing all the comments! Documentation looks good after your fix too!

Copy link
Member

@erogluorhan erogluorhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Thanks for addressing all the issues!

@erogluorhan erogluorhan merged commit dff3971 into UXARRAY:main Apr 24, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Calculate the weight for each face on the constant latitude
4 participants