|
7 | 7 | "source": [ |
8 | 8 | "# Cross-Sections\n", |
9 | 9 | "\n", |
| 10 | + "UXarray allows for cross‑sections to be performed along arbitrary great‑circle arcs (GCAs) and lines of constant latitude or longitude. This enables workflows such as vertical or temporal cross-section visualizations.\n", |
10 | 11 | "\n", |
11 | | - "UXarray allows for cross-sections to be performed along arbitrary great-circle arcs (GCAs) and lines of constant latitude or longitude. This enables workflows such as vertical or temporal cross-section visualizations\n" |
| 12 | + "The data variable is sampled along the cross‑section, and the result is an `xarray.DataArray` (no longer a `uxarray.UxDataArray`) since the output is detached from the original unstructured grid.\n" |
12 | 13 | ] |
13 | 14 | }, |
14 | 15 | { |
15 | 16 | "cell_type": "code", |
16 | | - "execution_count": null, |
17 | 17 | "id": "16db9f880115ac2b", |
18 | 18 | "metadata": {}, |
19 | | - "outputs": [], |
20 | 19 | "source": [ |
21 | 20 | "import matplotlib.pyplot as plt\n", |
22 | 21 | "import numpy as np\n", |
23 | 22 | "\n", |
24 | 23 | "import uxarray as ux" |
25 | | - ] |
| 24 | + ], |
| 25 | + "outputs": [], |
| 26 | + "execution_count": null |
26 | 27 | }, |
27 | 28 | { |
28 | 29 | "cell_type": "code", |
29 | | - "execution_count": null, |
30 | 30 | "id": "720c4a345d659fd3", |
31 | 31 | "metadata": {}, |
32 | | - "outputs": [], |
33 | 32 | "source": [ |
34 | 33 | "def set_lon_lat_xticks(ax, cross_section, n_ticks=6):\n", |
35 | 34 | " \"\"\"Utility function to draw stacked lat/lon points along the sampled cross-section\"\"\"\n", |
|
53 | 52 | " plt.tight_layout()\n", |
54 | 53 | "\n", |
55 | 54 | " return fig, ax" |
56 | | - ] |
| 55 | + ], |
| 56 | + "outputs": [], |
| 57 | + "execution_count": null |
57 | 58 | }, |
58 | 59 | { |
59 | 60 | "cell_type": "code", |
60 | | - "execution_count": null, |
61 | 61 | "id": "2a42a1aa9249a94f", |
62 | 62 | "metadata": {}, |
63 | | - "outputs": [], |
64 | 63 | "source": [ |
65 | 64 | "grid_path = \"../../test/meshfiles/scrip/ne30pg2/grid.nc\"\n", |
66 | 65 | "data_path = \"../../test/meshfiles/scrip/ne30pg2/data.nc\"\n", |
67 | 66 | "\n", |
68 | 67 | "uxds = ux.open_dataset(grid_path, data_path)\n", |
69 | 68 | "uxds[\"RELHUM\"]" |
70 | | - ] |
| 69 | + ], |
| 70 | + "outputs": [], |
| 71 | + "execution_count": null |
71 | 72 | }, |
72 | 73 | { |
73 | 74 | "cell_type": "markdown", |
74 | 75 | "id": "637eaeb7670eea9b", |
75 | 76 | "metadata": {}, |
76 | | - "source": "## Arbitrary Great Circle Arc (GCA)" |
| 77 | + "source": [ |
| 78 | + "## Arbitrary Great Circle Arc (GCA)\n", |
| 79 | + "\n", |
| 80 | + "A cross‑section can be performed between two **arbitrary** (lon,lat) points, which will form a geodesic arc." |
| 81 | + ] |
77 | 82 | }, |
78 | 83 | { |
79 | 84 | "cell_type": "code", |
80 | | - "execution_count": null, |
81 | 85 | "id": "11d2b717ba274d79", |
82 | 86 | "metadata": {}, |
83 | | - "outputs": [], |
84 | 87 | "source": [ |
85 | 88 | "start_point = (-45, -45)\n", |
86 | 89 | "end_point = (45, 45)\n", |
87 | 90 | "\n", |
88 | 91 | "cross_section_gca = uxds[\"RELHUM\"].cross_section(\n", |
89 | 92 | " start=start_point, end=end_point, steps=100\n", |
90 | 93 | ")" |
91 | | - ] |
| 94 | + ], |
| 95 | + "outputs": [], |
| 96 | + "execution_count": null |
92 | 97 | }, |
93 | 98 | { |
94 | 99 | "cell_type": "code", |
95 | | - "execution_count": null, |
96 | 100 | "id": "cf73e86a3ddd57d9", |
97 | 101 | "metadata": {}, |
98 | | - "outputs": [], |
99 | 102 | "source": [ |
100 | 103 | "fig, ax = plt.subplots()\n", |
101 | 104 | "cross_section_gca.plot(ax=ax)\n", |
102 | 105 | "\n", |
103 | 106 | "set_lon_lat_xticks(ax, cross_section_gca)\n", |
104 | 107 | "ax.set_title(f\"Cross Section between {start_point} and {end_point}\")\n", |
105 | 108 | "ax.invert_yaxis()" |
106 | | - ] |
| 109 | + ], |
| 110 | + "outputs": [], |
| 111 | + "execution_count": null |
107 | 112 | }, |
108 | 113 | { |
109 | 114 | "cell_type": "markdown", |
110 | 115 | "id": "c2f3ff22dc82d6ce", |
111 | 116 | "metadata": {}, |
112 | | - "source": "## Constant Latitude" |
| 117 | + "source": [ |
| 118 | + "## Constant Latitude\n", |
| 119 | + "\n", |
| 120 | + "A constant‐latitude cross‐section samples data along a horizontal line at a fixed latitude.\n" |
| 121 | + ] |
113 | 122 | }, |
114 | 123 | { |
115 | 124 | "cell_type": "code", |
116 | | - "execution_count": null, |
117 | 125 | "id": "5a7415fa56f86071", |
118 | 126 | "metadata": {}, |
119 | | - "outputs": [], |
120 | 127 | "source": [ |
121 | 128 | "lat = 45\n", |
122 | 129 | "cross_section_const_lat = uxds[\"RELHUM\"].cross_section(lat=lat, steps=100)" |
123 | | - ] |
| 130 | + ], |
| 131 | + "outputs": [], |
| 132 | + "execution_count": null |
124 | 133 | }, |
125 | 134 | { |
126 | 135 | "cell_type": "code", |
127 | | - "execution_count": null, |
128 | 136 | "id": "b8cfda1b537a059e", |
129 | 137 | "metadata": {}, |
130 | | - "outputs": [], |
131 | 138 | "source": [ |
132 | 139 | "fig, ax = plt.subplots()\n", |
133 | 140 | "cross_section_const_lat.plot(ax=ax)\n", |
134 | 141 | "\n", |
135 | 142 | "set_lon_lat_xticks(ax, cross_section_const_lat)\n", |
136 | 143 | "ax.set_title(f\"Cross Section at {lat}° latitude.\")\n", |
137 | 144 | "ax.invert_yaxis()" |
138 | | - ] |
| 145 | + ], |
| 146 | + "outputs": [], |
| 147 | + "execution_count": null |
139 | 148 | }, |
140 | 149 | { |
141 | 150 | "cell_type": "markdown", |
142 | 151 | "id": "b6ab076677f11637", |
143 | 152 | "metadata": {}, |
144 | | - "source": "## Constant Longitude" |
| 153 | + "source": [ |
| 154 | + "## Constant Longitude\n", |
| 155 | + "\n", |
| 156 | + "A constant‐longitude cross‐section samples data along a vertical line at a fixed longitude" |
| 157 | + ] |
145 | 158 | }, |
146 | 159 | { |
147 | 160 | "cell_type": "code", |
148 | | - "execution_count": null, |
149 | 161 | "id": "add5646acb68496e", |
150 | 162 | "metadata": {}, |
151 | | - "outputs": [], |
152 | 163 | "source": [ |
153 | 164 | "lon = 0\n", |
154 | 165 | "cross_section_const_lon = uxds[\"RELHUM\"].cross_section(lon=lon, steps=100)" |
155 | | - ] |
| 166 | + ], |
| 167 | + "outputs": [], |
| 168 | + "execution_count": null |
156 | 169 | }, |
157 | 170 | { |
158 | 171 | "cell_type": "code", |
159 | | - "execution_count": null, |
160 | 172 | "id": "1999ff933ce37f4e", |
161 | 173 | "metadata": {}, |
162 | | - "outputs": [], |
163 | 174 | "source": [ |
164 | 175 | "fig, ax = plt.subplots()\n", |
165 | 176 | "cross_section_const_lon.plot(ax=ax)\n", |
166 | 177 | "\n", |
167 | 178 | "set_lon_lat_xticks(ax, cross_section_const_lon)\n", |
168 | 179 | "ax.set_title(f\"Cross Section at {lon}° longitude.\")\n", |
169 | 180 | "ax.invert_yaxis()" |
170 | | - ] |
| 181 | + ], |
| 182 | + "outputs": [], |
| 183 | + "execution_count": null |
171 | 184 | } |
172 | 185 | ], |
173 | 186 | "metadata": { |
|
0 commit comments