|
193 | 193 | "# Show\n",
|
194 | 194 | "plt.tight_layout()"
|
195 | 195 | ]
|
196 |
| - }, |
197 |
| - { |
198 |
| - "cell_type": "markdown", |
199 |
| - "metadata": { |
200 |
| - "jp-MarkdownHeadingCollapsed": true, |
201 |
| - "tags": [] |
202 |
| - }, |
203 |
| - "source": [ |
204 |
| - "## `imshow()` and rasterio map projections\n", |
205 |
| - "\n", |
206 |
| - "\n", |
207 |
| - "Using rasterio's projection information for more accurate plots.\n", |
208 |
| - "\n", |
209 |
| - "This example extends `recipes.rasterio` and plots the image in the\n", |
210 |
| - "original map projection instead of relying on pcolormesh and a map\n", |
211 |
| - "transformation." |
212 |
| - ] |
213 |
| - }, |
214 |
| - { |
215 |
| - "cell_type": "code", |
216 |
| - "execution_count": null, |
217 |
| - "metadata": {}, |
218 |
| - "outputs": [], |
219 |
| - "source": [ |
220 |
| - "da = xr.tutorial.open_rasterio(\"RGB.byte\")\n", |
221 |
| - "\n", |
222 |
| - "# The data is in UTM projection. We have to set it manually until\n", |
223 |
| - "# https://github.com/SciTools/cartopy/issues/813 is implemented\n", |
224 |
| - "crs = ccrs.UTM(\"18\")\n", |
225 |
| - "\n", |
226 |
| - "# Plot on a map\n", |
227 |
| - "ax = plt.subplot(projection=crs)\n", |
228 |
| - "da.plot.imshow(ax=ax, rgb=\"band\", transform=crs)\n", |
229 |
| - "ax.coastlines(\"10m\", color=\"r\")" |
230 |
| - ] |
231 |
| - }, |
232 |
| - { |
233 |
| - "cell_type": "markdown", |
234 |
| - "metadata": {}, |
235 |
| - "source": [ |
236 |
| - "## Parsing rasterio geocoordinates\n", |
237 |
| - "\n", |
238 |
| - "Converting a projection's cartesian coordinates into 2D longitudes and\n", |
239 |
| - "latitudes.\n", |
240 |
| - "\n", |
241 |
| - "These new coordinates might be handy for plotting and indexing, but it should\n", |
242 |
| - "be kept in mind that a grid which is regular in projection coordinates will\n", |
243 |
| - "likely be irregular in lon/lat. It is often recommended to work in the data's\n", |
244 |
| - "original map projection (see `recipes.rasterio_rgb`)." |
245 |
| - ] |
246 |
| - }, |
247 |
| - { |
248 |
| - "cell_type": "code", |
249 |
| - "execution_count": null, |
250 |
| - "metadata": {}, |
251 |
| - "outputs": [], |
252 |
| - "source": [ |
253 |
| - "from pyproj import Transformer\n", |
254 |
| - "import numpy as np\n", |
255 |
| - "\n", |
256 |
| - "da = xr.tutorial.open_rasterio(\"RGB.byte\")\n", |
257 |
| - "\n", |
258 |
| - "x, y = np.meshgrid(da[\"x\"], da[\"y\"])\n", |
259 |
| - "transformer = Transformer.from_crs(da.crs, \"EPSG:4326\", always_xy=True)\n", |
260 |
| - "lon, lat = transformer.transform(x, y)\n", |
261 |
| - "da.coords[\"lon\"] = ((\"y\", \"x\"), lon)\n", |
262 |
| - "da.coords[\"lat\"] = ((\"y\", \"x\"), lat)\n", |
263 |
| - "\n", |
264 |
| - "# Compute a greyscale out of the rgb image\n", |
265 |
| - "greyscale = da.mean(dim=\"band\")\n", |
266 |
| - "\n", |
267 |
| - "# Plot on a map\n", |
268 |
| - "ax = plt.subplot(projection=ccrs.PlateCarree())\n", |
269 |
| - "greyscale.plot(\n", |
270 |
| - " ax=ax,\n", |
271 |
| - " x=\"lon\",\n", |
272 |
| - " y=\"lat\",\n", |
273 |
| - " transform=ccrs.PlateCarree(),\n", |
274 |
| - " cmap=\"Greys_r\",\n", |
275 |
| - " shading=\"auto\",\n", |
276 |
| - " add_colorbar=False,\n", |
277 |
| - ")\n", |
278 |
| - "ax.coastlines(\"10m\", color=\"r\")" |
279 |
| - ] |
280 | 196 | }
|
281 | 197 | ],
|
282 | 198 | "metadata": {
|
|
296 | 212 | "nbconvert_exporter": "python",
|
297 | 213 | "pygments_lexer": "ipython3",
|
298 | 214 | "version": "3.9.7"
|
| 215 | + }, |
| 216 | + "widgets": { |
| 217 | + "application/vnd.jupyter.widget-state+json": { |
| 218 | + "state": {}, |
| 219 | + "version_major": 2, |
| 220 | + "version_minor": 0 |
| 221 | + } |
299 | 222 | }
|
300 | 223 | },
|
301 | 224 | "nbformat": 4,
|
|
0 commit comments