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

Latitude & Longitude Interval Cross Section, Updated Bounding Box Subset #1115

Merged
merged 12 commits into from
Jan 17, 2025
8 changes: 7 additions & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ Grid

Grid.cross_section
Grid.cross_section.constant_latitude
Grid.cross_section.constant_longitude
Grid.cross_section.constant_latitude_interval
Grid.cross_section.constant_longitude_interval


UxDataArray
~~~~~~~~~~~
Expand All @@ -333,7 +337,9 @@ UxDataArray

UxDataArray.cross_section
UxDataArray.cross_section.constant_latitude

UxDataArray.cross_section.constant_longitude
UxDataArray.cross_section.constant_latitude_interval
UxDataArray.cross_section.constant_longitude_interval
Remapping
---------

Expand Down
180 changes: 115 additions & 65 deletions docs/user-guide/cross-sections.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,13 @@
"source": [
"# Cross-Sections\n",
"\n",
"This section demonstrates how to extract cross-sections from an unstructured grid using UXarray, which allows the analysis and visualization across slices of grids.\n"
"This section demonstrates how to extract cross-sections from an unstructured grid using UXarray, which allows the analysis and visualization across slices of grids. Cross-sections can be performed directly on a `ux.Grid` object or on a `ux.UxDataArray`\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b35ba4a2c30750e4",
"metadata": {
"ExecuteTime": {
"start_time": "2024-10-14T16:39:35.957687Z"
},
"jupyter": {
"is_executing": true
}
},
"outputs": [],
"metadata": {},
"source": [
"import uxarray as ux\n",
"import geoviews.feature as gf\n",
Expand All @@ -31,27 +22,14 @@
"import geoviews as gv\n",
"\n",
"projection = ccrs.Robinson()"
]
},
{
"cell_type": "markdown",
"id": "395a3db7-495c-4cff-b733-06bbe522a604",
"metadata": {},
"source": [
"## Data"
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "code",
"execution_count": null,
"id": "b4160275c09fe6b0",
"metadata": {
"ExecuteTime": {
"end_time": "2024-10-09T17:50:51.217211Z",
"start_time": "2024-10-09T17:50:50.540946Z"
}
},
"outputs": [],
"metadata": {},
"source": [
"base_path = \"../../test/meshfiles/ugrid/outCSne30/\"\n",
"grid_path = base_path + \"outCSne30.ug\"\n",
Expand All @@ -64,17 +42,9 @@
" projection=projection,\n",
" title=\"Global Plot\",\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c844a3b5-ef71-41c8-a0ae-02ea937801d6",
"metadata": {},
],
"outputs": [],
"source": [
"uxds.uxgrid.normalize_cartesian_coordinates()"
]
"execution_count": null
},
{
"cell_type": "markdown",
Expand All @@ -83,33 +53,26 @@
"source": [
"## Constant Latitude\n",
"\n",
"Cross-sections along constant latitude lines can be obtained using the ``.cross_section.constant_latitude`` method, available for both ``ux.Grid`` and ``ux.DataArray`` objects. This functionality allows users to extract and analyze slices of data at specified latitudes, providing insights into variations along horizontal sections of the grid.\n"
"Cross-sections along constant latitude lines can be obtained by using the ``.cross_section.constant_latitude(lat)`` method. The sliced grid will be made up of the faces that contain at least one edge that intersects with a line of constant latitude.\n"
]
},
{
"cell_type": "markdown",
"id": "2fbe9f6e5bb59a17",
"metadata": {},
"source": [
"For example, we can obtain a cross-section at 30 degrees latitude by doing the following:"
]
"source": "For example, we can obtain a cross-section at 0 degrees latitude by doing the following:"
},
{
"cell_type": "code",
"execution_count": null,
"id": "3775daa1-2f1d-4738-bab5-2b69ebd689d9",
"metadata": {
"ExecuteTime": {
"end_time": "2024-10-09T17:50:53.093314Z",
"start_time": "2024-10-09T17:50:53.077719Z"
}
},
"outputs": [],
"metadata": {},
"source": [
"lat = 0\n",
"\n",
"uxda_constant_lat = uxds[\"psi\"].cross_section.constant_latitude(lat)"
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
Expand All @@ -121,10 +84,8 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "484b77a6-86da-4395-9e63-f5ac56e37deb",
"metadata": {},
"outputs": [],
"source": [
"(\n",
" uxda_constant_lat.plot(\n",
Expand All @@ -138,7 +99,9 @@
" )\n",
" * gf.grid(projection=projection)\n",
")"
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
Expand All @@ -150,14 +113,14 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "1cbee722-34a4-4e67-8e22-f393d7d36c99",
"metadata": {},
"outputs": [],
"source": [
"print(f\"Global Mean: {uxds['psi'].data.mean()}\")\n",
"print(f\"Mean at {lat} degrees lat: {uxda_constant_lat.data.mean()}\")"
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
Expand All @@ -167,28 +130,25 @@
"## Constant Longitude\n",
"\n",
"\n",
"\n",
"Cross-sections along constant longitude lines can be obtained using the ``.cross_section.constant_longitude`` method, available for both ``ux.Grid`` and ``ux.DataArray`` objects. \n"
"Cross-sections along constant longitude lines can be obtained using the ``.cross_section.constant_longitude(lon)`` method. The sliced grid will be made up of the faces that contain at least one edge that intersects with a line of constant longitude.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f10917ce-568c-4e98-9b9c-d7c3c82e9ba3",
"metadata": {},
"outputs": [],
"source": [
"lon = 90\n",
"\n",
"uxda_constant_lon = uxds[\"psi\"].cross_section.constant_longitude(lon)"
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "code",
"execution_count": null,
"id": "4add3a54-263e-41af-ac97-1e43c9141cb4",
"metadata": {},
"outputs": [],
"source": [
"(\n",
" uxda_constant_lon.plot(\n",
Expand All @@ -203,7 +163,97 @@
" )\n",
" * gf.grid(projection=projection)\n",
")"
]
],
"outputs": [],
"execution_count": null
},
{
"metadata": {},
"cell_type": "markdown",
"source": [
"## Constant Latitude Interval\n",
"\n",
"Cross-sections between two lines of latitudes can be obtained using the ``.cross_section.constant_lats_interval(lats)`` method. The sliced grid will contain faces that are strictly between the latitude interval."
],
"id": "5044b8680d514fdc"
},
{
"metadata": {},
"cell_type": "code",
"source": [
"lats = [-20, 20]\n",
"\n",
"uxda_constant_lat_interval = uxds[\"psi\"].cross_section.constant_latitude_interval(lats)"
],
"id": "fc84e47efe2edf96",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
"cell_type": "code",
"source": [
"(\n",
" uxda_constant_lat_interval.plot(\n",
" rasterize=False,\n",
" backend=\"bokeh\",\n",
" cmap=\"inferno\",\n",
" projection=projection,\n",
" global_extent=True,\n",
" coastline=True,\n",
" title=f\"Cross Section between {lats[0]} and {lats[1]} degrees latitude\",\n",
" periodic_elements=\"split\",\n",
" )\n",
" * gf.grid(projection=projection)\n",
")"
],
"id": "60232626ba6c74ad",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
"cell_type": "markdown",
"source": [
"## Constant Longitude Interval\n",
"\n",
"Cross-sections between two lines of longitude can be obtained using the ``.cross_section.constant_lons_interval(lons)`` method. The sliced grid will contain faces that are strictly between the longitude interval.\n"
],
"id": "4afa3d891a80c597"
},
{
"metadata": {},
"cell_type": "code",
"source": [
"lons = [-25, 25]\n",
"\n",
"uxda_constant_lon_interval = uxds[\"psi\"].cross_section.constant_longitude_interval(lats)"
],
"id": "b183d15838aaf6bb",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
"cell_type": "code",
"source": [
"(\n",
" uxda_constant_lon_interval.plot(\n",
" rasterize=False,\n",
" backend=\"bokeh\",\n",
" cmap=\"inferno\",\n",
" projection=projection,\n",
" global_extent=True,\n",
" coastline=True,\n",
" title=f\"Cross Section between {lons[0]} and {lons[1]} degrees longitude\",\n",
" periodic_elements=\"split\",\n",
" )\n",
" * gf.grid(projection=projection)\n",
")"
],
"id": "22793d56701504ce",
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
Expand Down
Loading
Loading