Skip to content

Commit

Permalink
Update docs to crs change
Browse files Browse the repository at this point in the history
  • Loading branch information
joeloskarsson committed Nov 26, 2024
1 parent c95f023 commit bcaf1e1
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions docs/lat_lons.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"source": [
"# Working with lat-lon coordinates\n",
"\n",
"In the previous sections we have considered grid point positions `coords` given as Cartesian coordinates. However, it is common that we have coordinates given as latitudes and longitudes. This notebook describes how we can constuct graphs directly using lat-lon coordinates. This is achieved by also providing a specific projection, used to project the lat-lons to a euclidean space where the graph can be construced."
"In the previous sections we have considered grid point positions `coords` given as Cartesian coordinates. However, it is common that we have coordinates given as latitudes and longitudes. This notebook describes how we can constuct graphs directly using lat-lon coordinates. This is achieved by specifying the Coordinate Reference System (CRS) of `coords` and the CRS that the graph construction should be carried out in. `coords` will then be projected to this new CRS before any calculations are carried out."
]
},
{
Expand Down Expand Up @@ -96,9 +96,9 @@
"metadata": {},
"source": [
"## Constructing a graph within a projection\n",
"For our example above, let's instead try to construct the graph based on first projecting our lat-lon coordinates to within a specific projection. This can be done by giving a `projection` argument to the graph creation functions. The projection should be an instance of `cartopy.crs.CRS`. See [the cartopy documentation](https://scitools.org.uk/cartopy/docs/latest/reference/projections.html) for a list of available projections. \n",
"For our example above, let's instead try to construct the graph based on first projecting our lat-lon coordinates to another CRS with 2-dimensional cartesian coordinates. This can be done by giving the `coords_crs` and `graph_crs` arguments to the graph creation functions. Theses arguments should both be instances of `pyproj.crs.CRS` ([pyproj docs.](https://pyproj4.github.io/pyproj/stable/api/crs/crs.html#pyproj.crs.CRS)). Nicely, they can be `cartopy.crs.CRS`, which provides easy ways to specify such CRS:s. For more advanced use cases a `pyproj.crs.CRS` can be specified directly. See [the cartopy documentation](https://scitools.org.uk/cartopy/docs/latest/reference/projections.html) for a list of readily available CRS:s to use for projecting the coordinates. \n",
"\n",
"We will here try the same thing as above, but using a Azimuthal equidistant projection centered at the pole:"
"We will here try the same thing as above, but using a Azimuthal equidistant projection centered at the pole. The CRS of our lat-lon coordinates will be `cartopy.crs.PlateCarree` and we want to project this to `cartopy.crs.AzimuthalEquidistant`:"
]
},
{
Expand All @@ -109,9 +109,10 @@
"outputs": [],
"source": [
"# Define our projection\n",
"ae_projection = ccrs.AzimuthalEquidistant(central_latitude=90)\n",
"coords_crs = ccrs.PlateCarree()\n",
"graph_crs = ccrs.AzimuthalEquidistant(central_latitude=90)\n",
"\n",
"fig, ax = plt.subplots(figsize=(15, 9), subplot_kw={\"projection\": ae_projection})\n",
"fig, ax = plt.subplots(figsize=(15, 9), subplot_kw={\"projection\": graph_crs})\n",
"ax.scatter(coords[:, 0], coords[:, 1], marker=\".\", transform=ccrs.PlateCarree())\n",
"_ = ax.coastlines()"
]
Expand All @@ -135,9 +136,9 @@
" 10**6\n",
") # Large euclidean distance in projection coordinates between mesh nodes\n",
"graph = wmg.create.archetype.create_keisler_graph(\n",
" coords, mesh_node_distance=mesh_distance, projection=ae_projection\n",
" coords, mesh_node_distance=mesh_distance, coords_crs=coords_crs, graph_crs=graph_crs\n",
") # Note that we here specify the projection argument\n",
"fig, ax = plt.subplots(figsize=(15, 9), subplot_kw={\"projection\": ae_projection})\n",
"fig, ax = plt.subplots(figsize=(15, 9), subplot_kw={\"projection\": graph_crs})\n",
"wmg.visualise.nx_draw_with_pos_and_attr(\n",
" graph, ax=ax, node_size=30, edge_color_attr=\"component\", node_color_attr=\"type\"\n",
")\n",
Expand All @@ -149,7 +150,9 @@
"id": "f5acf83a-df33-4925-bb32-c106e27e51a4",
"metadata": {},
"source": [
"Now this looks like a more reasonable graph layout, that better respects the spatial relations between the grid points. There are still things that could be tweaked further (e.g. the large number of grid nodes connected to the center mesh node), but this ends our example of defining graphs using lat-lon coordinates."
"Now this looks like a more reasonable graph layout, that better respects the spatial relations between the grid points. There are still things that could be tweaked further (e.g. the large number of grid nodes connected to the center mesh node), but this ends our example of defining graphs using lat-lon coordinates.\n",
"\n",
"It can be noted that this projection between different CRS:s provides more general functionality than just handling lat-lon coordinates. It is entirely possible to transform from any `coords_crs` to any `graph_crs` using these arguments."
]
}
],
Expand All @@ -169,7 +172,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
"version": "3.10.15"
}
},
"nbformat": 4,
Expand Down

0 comments on commit bcaf1e1

Please sign in to comment.