Skip to content

Commit

Permalink
refine coastline example
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelchin committed Nov 10, 2023
1 parent e65ddf5 commit ed73b39
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 5 deletions.
82 changes: 78 additions & 4 deletions examples/plot_paleo_coastlines.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,88 @@
#!/usr/bin/env python3
import io
import sys

import cartopy.crs as ccrs
import matplotlib.pyplot as plt
from common import OUTPUT_DIR, get_basemap_with_coastlines, save_fig
from common import OUTPUT_DIR, save_fig

from gplates_ws_proxy import PlateModel


def main(show=True):
time = 100
get_basemap_with_coastlines(time=100)
plt.title(f"{time} Ma")
fig = plt.figure(figsize=(12, 6), dpi=120)

ax1 = fig.add_subplot(221, projection=ccrs.Robinson())
ax1.set_global()
ax1.gridlines()

model = PlateModel("Muller2022")
coastlines_shapely = model.get_coastlines(
time=100, extent=[-90, 90, -40, 40], min_area=10, format="shapely"
)

ax1.add_geometries(
coastlines_shapely,
crs=ccrs.PlateCarree(),
facecolor="blue",
edgecolor="none",
alpha=0.5,
)

ax1.set_title(f"{100} Ma")

ax2 = fig.add_subplot(222, projection=ccrs.PlateCarree())
ax2.set_extent([-100, 100, -50, 50], crs=ccrs.Geodetic())
ax2.gridlines()

model = PlateModel("Muller2022")
coastlines_shapely = model.get_coastlines(time=10, min_area=10, format="shapely")

ax2.add_geometries(
coastlines_shapely,
crs=ccrs.PlateCarree(),
facecolor="green",
edgecolor="none",
alpha=0.5,
)

ax2.set_title(f"{10} Ma")

ax3 = fig.add_subplot(223, projection=ccrs.Mollweide())
ax3.set_global()
ax3.gridlines()

model = PlateModel("Muller2022")
coastlines_shapely = model.get_coastlines(
time=10, min_area=70 * 1000, format="shapely"
)

ax3.add_geometries(
coastlines_shapely,
crs=ccrs.PlateCarree(),
facecolor="green",
edgecolor="none",
alpha=0.5,
)

ax3.set_title(f"min area 70000")

ax4 = fig.add_subplot(224)

model = PlateModel("Muller2022")
coastlines_png = model.get_coastlines(
time=200, format="png", facecolor="lime", edgecolor="red"
)
# print(type(coastlines_png))
data = plt.imread(io.BytesIO(coastlines_png), format="png")
ax4.imshow(data)

ax3.set_title(f"200 Ma")

fig.subplots_adjust(
bottom=0.05, top=0.95, left=0.1, right=0.9, wspace=0.02, hspace=0.02
)

if show:
plt.show()
else:
Expand Down
4 changes: 3 additions & 1 deletion src/gplates_ws_proxy/coastlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ def get_paleo_coastlines(
if min_area is not None:
params["min_area"] = min_area

if extent is not None:
params["extent"] = f"{extent[0]},{extent[1]},{extent[2]},{extent[3]}"

if format == "png":
params["fmt"] = "png"
params["facecolor"] = facecolor
params["edgecolor"] = edgecolor
params["alpha"] = alpha
params["extent"] = f"{extent[0]},{extent[1]},{extent[2]},{extent[3]}"
headers = {
"Accept": "image/png",
}
Expand Down

0 comments on commit ed73b39

Please sign in to comment.