Skip to content

Robust implementation of _point_within_gca_cartesian using only Cartesian coordinates - #1112

Merged
philipc2 merged 24 commits into
mainfrom
robust_point_within_gca
Dec 17, 2024
Merged

philipc2 merged 24 commits into
mainfrom
robust_point_within_gca

Conversation

@philipc2

@philipc2 philipc2 commented Dec 16, 2024 •

Copy link
Copy Markdown
Member

Add _point_within_gca Function for Cartesian-Only Implementation

Closes #1102

Overview

  • Reimplemented the _point_within_gca function to exclusively use Cartesian coordinates.
  • Removed reliance on back-and-forth conversions between Cartesian and longitude/latitude coordinates, improving robustness and efficiency.
  • Added comprehensive tests to ensure correctness and handle edge cases.
  • Updated relevant internal documentation to reflect the new implementation.

Expected Usage

import uxarray as ux

# Example grid and data files
grid_path = "/path/to/grid.nc"
data_path = "/path/to/data.nc"

uxds = ux.open_dataset(grid_path, data_path)

# Use the _point_within_gca function to check if a Cartesian point is within the grid cell
is_within = uxds._point_within_gca(cartesian_coordinates=[x, y, z])

# Test edge cases or specific points
is_within_edge = uxds._point_within_gca(cartesian_coordinates=[x_edge, y_edge, z_edge])

@philipc2 philipc2 mentioned this pull request Dec 16, 2024
10 tasks done
@philipc2 philipc2 added the run-benchmark Run ASV benchmark workflow label Dec 17, 2024
@github-actions

Copy link
Copy Markdown

ASV Benchmarking

Benchmark Comparison Results

Benchmarks that have improved:

Change Before [e1d4893] After [210db81] Ratio Benchmark (Parameter)
- 584M 404M 0.69 face_bounds.FaceBounds.peakmem_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/geoflow-small/grid.nc'))
failed 395M n/a face_bounds.FaceBounds.peakmem_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/quad-hexagon/grid.nc'))
- 22.5±0.08ms 18.5±0.07ms 0.82 face_bounds.FaceBounds.time_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/mpas/QU/oQU480.231010.nc'))
- 49.6±0.3ms 42.7±0.1ms 0.86 face_bounds.FaceBounds.time_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/geoflow-small/grid.nc'))
- 482M 386M 0.80 mpas_ocean.Integrate.peakmem_integrate('480km')

Benchmarks that have stayed the same:

Change Before [e1d4893] After [210db81] Ratio Benchmark (Parameter)
403M 401M 0.99 face_bounds.FaceBounds.peakmem_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/mpas/QU/oQU480.231010.nc'))
436M 435M 1.00 face_bounds.FaceBounds.peakmem_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/scrip/outCSne8/outCSne8.nc'))
8.04±0.1ms 7.37±0.09ms 0.92 face_bounds.FaceBounds.time_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/scrip/outCSne8/outCSne8.nc'))
3.90±0.07ms 3.81±0.07ms 0.98 face_bounds.FaceBounds.time_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/quad-hexagon/grid.nc'))
2.89±0.02s 2.88±0.01s 1.00 import.Imports.timeraw_import_uxarray
672±10μs 662±6μs 0.99 mpas_ocean.CheckNorm.time_check_norm('120km')
442±2μs 439±2μs 0.99 mpas_ocean.CheckNorm.time_check_norm('480km')
652±10ms 636±9ms 0.98 mpas_ocean.ConnectivityConstruction.time_face_face_connectivity('120km')
40.9±0.3ms 40.8±0.5ms 1.00 mpas_ocean.ConnectivityConstruction.time_face_face_connectivity('480km')
1.72±0.03ms 1.71±0.04ms 1.00 mpas_ocean.ConnectivityConstruction.time_n_nodes_per_face('120km')
581±20μs 557±7μs 0.96 mpas_ocean.ConnectivityConstruction.time_n_nodes_per_face('480km')
5.95±0.06ms 5.79±0.03ms 0.97 mpas_ocean.ConstructFaceLatLon.time_cartesian_averaging('120km')
3.54±0.06ms 3.45±0.03ms 0.97 mpas_ocean.ConstructFaceLatLon.time_cartesian_averaging('480km')
3.55±0.01s 3.56±0.01s 1.00 mpas_ocean.ConstructFaceLatLon.time_welzl('120km')
226±0.6ms 227±0.8ms 1.01 mpas_ocean.ConstructFaceLatLon.time_welzl('480km')
1.22±0.02μs 1.32±0μs 1.08 mpas_ocean.ConstructTreeStructures.time_ball_tree('120km')
304±4ns 307±3ns 1.01 mpas_ocean.ConstructTreeStructures.time_ball_tree('480km')
878±80ns 803±2ns 0.91 mpas_ocean.ConstructTreeStructures.time_kd_tree('120km')
298±3ns 288±2ns 0.97 mpas_ocean.ConstructTreeStructures.time_kd_tree('480km')
failed failed n/a mpas_ocean.CrossSections.time_constant_lat_fast('120km', 1)
failed failed n/a mpas_ocean.CrossSections.time_constant_lat_fast('120km', 2)
failed failed n/a mpas_ocean.CrossSections.time_constant_lat_fast('120km', 4)
failed failed n/a mpas_ocean.CrossSections.time_constant_lat_fast('120km', 8)
failed failed n/a mpas_ocean.CrossSections.time_constant_lat_fast('480km', 1)
failed failed n/a mpas_ocean.CrossSections.time_constant_lat_fast('480km', 2)
failed failed n/a mpas_ocean.CrossSections.time_constant_lat_fast('480km', 4)
failed failed n/a mpas_ocean.CrossSections.time_constant_lat_fast('480km', 8)
125±0.7ms 122±0.5ms 0.98 mpas_ocean.DualMesh.time_dual_mesh_construction('120km')
8.92±0.4ms 8.54±0.2ms 0.96 mpas_ocean.DualMesh.time_dual_mesh_construction('480km')
1.03±0.01s 1.04±0.01s 1.00 mpas_ocean.GeoDataFrame.time_to_geodataframe('120km', False)
53.6±0.7ms 52.5±0.3ms 0.98 mpas_ocean.GeoDataFrame.time_to_geodataframe('120km', True)
78.4±0.3ms 76.7±0.1ms 0.98 mpas_ocean.GeoDataFrame.time_to_geodataframe('480km', False)
5.27±0.2ms 5.00±0.2ms 0.95 mpas_ocean.GeoDataFrame.time_to_geodataframe('480km', True)
342M 339M 0.99 mpas_ocean.Gradient.peakmem_gradient('120km')
317M 317M 1.00 mpas_ocean.Gradient.peakmem_gradient('480km')
2.77±0.05ms 2.70±0.01ms 0.98 mpas_ocean.Gradient.time_gradient('120km')
324±2μs 308±0.6μs 0.95 mpas_ocean.Gradient.time_gradient('480km')
failed failed n/a mpas_ocean.HoleEdgeIndices.time_construct_hole_edge_indices('120km')
failed failed n/a mpas_ocean.HoleEdgeIndices.time_construct_hole_edge_indices('480km')
403M 403M 1.00 mpas_ocean.Integrate.peakmem_integrate('120km')
176±3ms 173±0.6ms 0.98 mpas_ocean.Integrate.time_integrate('120km')
12.2±0.03ms 12.2±0.2ms 1.00 mpas_ocean.Integrate.time_integrate('480km')
346±2ms 343±2ms 0.99 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('120km', 'exclude')
347±1ms 340±3ms 0.98 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('120km', 'include')
349±0.9ms 344±2ms 0.99 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('120km', 'split')
23.2±0.4ms 22.3±0.3ms 0.96 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('480km', 'exclude')
22.7±0.2ms 22.3±0.3ms 0.98 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('480km', 'include')
23.1±0.2ms 22.0±0.1ms 0.95 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('480km', 'split')
56.2±0.7ms 55.2±0.06ms 0.98 mpas_ocean.RemapDownsample.time_inverse_distance_weighted_remapping
45.8±0.6ms 45.0±0.04ms 0.98 mpas_ocean.RemapDownsample.time_nearest_neighbor_remapping
361±1ms 360±1ms 1.00 mpas_ocean.RemapUpsample.time_inverse_distance_weighted_remapping
264±0.6ms 266±0.8ms 1.00 mpas_ocean.RemapUpsample.time_nearest_neighbor_remapping
315M 313M 0.99 quad_hexagon.QuadHexagon.peakmem_open_dataset
312M 312M 1.00 quad_hexagon.QuadHexagon.peakmem_open_grid
6.31±0.03ms 6.18±0.09ms 0.98 quad_hexagon.QuadHexagon.time_open_dataset
5.37±0.07ms 5.30±0.06ms 0.99 quad_hexagon.QuadHexagon.time_open_grid

@philipc2
philipc2 merged commit 79275c5 into main Dec 17, 2024
@erogluorhan
erogluorhan deleted the robust_point_within_gca branch February 5, 2025 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-benchmark Run ASV benchmark workflow

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Robust implementation of point_within_gca using only Cartesian coordinates

2 participants