diff --git a/benchmarks/mpas_ocean.py b/benchmarks/mpas_ocean.py index 659c19014..2d47627c1 100644 --- a/benchmarks/mpas_ocean.py +++ b/benchmarks/mpas_ocean.py @@ -56,6 +56,14 @@ def teardown(self, resolution, *args, **kwargs): del self.uxgrid +class FaceAreas(GridBenchmark): + def time_compute_face_areas(self, resolution): + self.uxgrid.compute_face_areas() + + def peakmem_compute_face_areas(self, resolution): + self.uxgrid.compute_face_areas() + + class Gradient(DatasetBenchmark): def time_gradient(self, resolution): self.uxds[data_var].gradient() diff --git a/docs/user-guide/area_calc.ipynb b/docs/user-guide/area_calc.ipynb index 08cf5e441..349b720a4 100644 --- a/docs/user-guide/area_calc.ipynb +++ b/docs/user-guide/area_calc.ipynb @@ -29,9 +29,15 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "collapsed": false, + "execution": { + "iopub.execute_input": "2026-07-17T18:49:15.166870Z", + "iopub.status.busy": "2026-07-17T18:49:15.166704Z", + "iopub.status.idle": "2026-07-17T18:49:16.484474Z", + "shell.execute_reply": "2026-07-17T18:49:16.483964Z" + }, "jupyter": { "outputs_hidden": false } @@ -55,9 +61,15 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "collapsed": false, + "execution": { + "iopub.execute_input": "2026-07-17T18:49:16.486070Z", + "iopub.status.busy": "2026-07-17T18:49:16.485935Z", + "iopub.status.idle": "2026-07-17T18:49:16.708579Z", + "shell.execute_reply": "2026-07-17T18:49:16.708080Z" + }, "jupyter": { "outputs_hidden": false } @@ -77,14 +89,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "collapsed": false, + "execution": { + "iopub.execute_input": "2026-07-17T18:49:16.710491Z", + "iopub.status.busy": "2026-07-17T18:49:16.710286Z", + "iopub.status.idle": "2026-07-17T18:49:16.936544Z", + "shell.execute_reply": "2026-07-17T18:49:16.936125Z" + }, "jupyter": { "outputs_hidden": false } }, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "OMP: Info #276: omp_set_nested routine deprecated, please use omp_set_max_active_levels instead.\n" + ] + }, + { + "data": { + "text/plain": [ + "np.float64(12.566370614678554)" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "t4_area = ugrid.calculate_total_face_area()\n", "t4_area" @@ -108,9 +144,35 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 4, + "metadata": { + "execution": { + "iopub.execute_input": "2026-07-17T18:49:16.974275Z", + "iopub.status.busy": "2026-07-17T18:49:16.974126Z", + "iopub.status.idle": "2026-07-17T18:49:16.978220Z", + "shell.execute_reply": "2026-07-17T18:49:16.977844Z" + } + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/mbook/uxarray/uxarray/grid/grid.py:2042: UserWarning: Total face area 12.571403993719983 exceeds the unit-sphere area 12.566370614359172. This usually indicates a malformed grid or incorrect connectivity.\n", + " face_areas, face_jacobian = self._compute_face_areas_and_jacobian(\n" + ] + }, + { + "data": { + "text/plain": [ + "np.float64(12.571403993719983)" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "t1_area = ugrid.calculate_total_face_area(quadrature_rule=\"triangular\", order=1)\n", "t1_area" @@ -140,35 +202,1923 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "collapsed": false, + "execution": { + "iopub.execute_input": "2026-07-17T18:49:16.979426Z", + "iopub.status.busy": "2026-07-17T18:49:16.979339Z", + "iopub.status.idle": "2026-07-17T18:49:16.985486Z", + "shell.execute_reply": "2026-07-17T18:49:16.984829Z" + }, "jupyter": { "outputs_hidden": false } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
<xarray.DataArray 'face_areas' (n_face: 5400)> Size: 43kB\n", + "array([0.00211174, 0.00211221, 0.00210723, ..., 0.00210723, 0.00211221,\n", + " 0.00211174], shape=(5400,))\n", + "Dimensions without coordinates: n_face\n", + "Attributes:\n", + " cf_role: face_areas\n", + " long_name: Area of each face.
<xarray.UxDataset> Size: 16B\n", + "Dimensions: ()\n", + "Data variables:\n", + " face_lat float32 4B 1.512e+08\n", + " face_lon float32 4B 1.218e+11\n", + " gaussian float32 4B 6.714e+10\n", + " inverse_gaussian float32 4B 8.804e+10
<xarray.UxDataArray 'gaussian' ()> Size: 4B\n", + "array(6.7136676e+10, dtype=float32)
<uxarray.Grid>\n", + "Original Grid Type: HEALPix\n", + "Grid Dimensions:\n", + " * n_face: 768\n", + "Grid Coordinates (Spherical):\n", + " * face_lon: (768,)\n", + " * face_lat: (768,)\n", + "Grid Coordinates (Cartesian):\n", + "Grid Connectivity Variables:\n", + "Grid Descriptor Variables:\n", + "
<uxarray.Grid>\n", + "Original Grid Type: HEALPix\n", + "Grid Dimensions:\n", + " * n_node: 770\n", + " * n_face: 768\n", + " * n_max_face_nodes: 4\n", + "Grid Coordinates (Spherical):\n", + " * node_lon: (770,)\n", + " * node_lat: (770,)\n", + " * face_lon: (768,)\n", + " * face_lat: (768,)\n", + "Grid Coordinates (Cartesian):\n", + "Grid Connectivity Variables:\n", + " * face_node_connectivity: (768, 4)\n", + "Grid Descriptor Variables:\n", + "
<xarray.DataArray 'face_node_connectivity' (n_face: 768, n_max_face_nodes: 4)> Size: 25kB\n", + "array([[103, 537, 207, 146],\n", + " [362, 578, 537, 103],\n", + " [537, 97, 147, 207],\n", + " ...,\n", + " [560, 550, 709, 536],\n", + " [709, 556, 395, 59],\n", + " [550, 673, 556, 709]], shape=(768, 4))\n", + "Dimensions without coordinates: n_face, n_max_face_nodes\n", + "Attributes:\n", + " cf_role: face_node_connectivity\n", + " long name: Maps every face to its corner nodes.\n", + " start_index: 0\n", + " _FillValue: -9223372036854775808
<xarray.UxDataArray 'psi' (n_face: 12288)> Size: 98kB\n", + "array([0.631794, 0.634404, 0.666049, ..., 1.424628, 1.437251, 1.437746],\n", + " shape=(12288,))\n", + "Dimensions without coordinates: n_face
<xarray.UxDataset> Size: 98kB\n", + "Dimensions: (n_face: 12288)\n", + "Dimensions without coordinates: n_face\n", + "Data variables:\n", + " psi (n_face) float64 98kB ...
<xarray.Dataset> Size: 98kB\n", + "Dimensions: (cell: 12288)\n", + "Dimensions without coordinates: cell\n", + "Data variables:\n", + " psi (cell) float64 98kB ...
<uxarray.Grid>\n", + "Original Grid Type: HEALPix\n", + "Grid Dimensions:\n", + " * n_face: 12288\n", + "Grid Coordinates (Spherical):\n", + " * face_lon: (12288,)\n", + " * face_lat: (12288,)\n", + "Grid Coordinates (Cartesian):\n", + "Grid Connectivity Variables:\n", + "Grid Descriptor Variables:\n", + "