Skip to content

Commit

Permalink
demo_pygmt initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
chelle0425 committed Sep 13, 2024
1 parent 000b470 commit b793cc9
Show file tree
Hide file tree
Showing 13 changed files with 10,351 additions and 88 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ IntPyGMT is an open-source Jupyter Notebook library that generates interactive m

Creates an interactive map from a GMT/PyGMT-generated png image. This feature supports all GMT/PyGMT projection systems provided that the correct xshift and yshift parameters are specified.

This works by overlaying an interactive matplotlib widget on top of a GMT/PyGMT-generated png. User's click coordinates are recorded and adjusted for the map's border width (via xshift and yshift) before processed through GMT's mapproject module which returns map coordinates based on the specified region and projection. Please see `demo_conical` for a demonstration.
This works by overlaying an interactive matplotlib widget on top of a GMT/PyGMT-generated png. User's click coordinates are recorded and adjusted for the map's border width (via xshift and yshift) before processed through GMT's mapproject module which returns map coordinates based on the specified region and projection.

The easiest way to control the border width of a GMT map is to first create an empty background canvas that **must be** larger than the main map. Then, you can adjust the xshift and yshift by shifting the main map relative to the background canvas. Please see `demo_conical` and `demo_pygmt` for demonstrations.

#### 2. From a _borderless_ png map (in Mercator projection)

Creates an interactive map from a _borderless_ png image **in Mercator projection**. This is not limited to GMT/PyGMT-generated outputs provided that the coordinates of the lower-left and upper-right corners of the map are known.

This works by aligning a matplotlib map on top of a _borderless_ png image. User's click coordinates on the matplotlib map are then directly registered and returned as map coordinates. Please refer to `demo_borderless_mercator_png` and `demo_borderless_mercator_pygmt` for demonstrations. For an example of this function adapted and applied to an InSAR time-series plot, see `demo_time_series`.
This works by aligning a matplotlib map on top of a _borderless_ png image. User's click coordinates on the matplotlib map are then directly registered and returned as map coordinates. Please see `demo_borderless_mercator_png` and `demo_borderless_mercator_pygmt` for demonstrations. For an example of this function adapted and applied to an InSAR time-series plot, see `demo_time_series`.


<br />
Expand Down
49 changes: 21 additions & 28 deletions demo_borderless_mercator_pygmt/Hindu_Kush.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 1,
"metadata": {},
"outputs": [
{
Expand All @@ -21,10 +21,9 @@
}
],
"source": [
"### making a demo PyGMT basemap ###\n",
"import pygmt\n",
"\n",
"### Making a demo PyGMT basemap ###\n",
"\n",
"###########################################\n",
"## Specify coords\n",
"# llcrnrlat,llcrnrlon, urcrnrlat, urcrnrlon\n",
Expand All @@ -38,7 +37,6 @@
"\n",
"proj_scale_w = 18 # specify projection scale (width)\n",
"proj_scale_unit = \"c\" # choose between c (cm) and i (inches)\n",
"# 17.78c = 7i\n",
"\n",
"meca_scale = \"0.28c\" # meca scale\n",
"meca_trans = 28\n",
Expand All @@ -49,26 +47,26 @@
"region=[llcrnrlon, urcrnrlon, llcrnrlat, urcrnrlat]\n",
"\n",
"\n",
"## plotting a borderless PyGMT basemap\n",
"fig = pygmt.Figure()\n",
"fig.coast(region=region,\\\n",
" projection=\"M%s/%s/%s%s\" % (centerlon, urcrnrlat, proj_scale_w, proj_scale_unit),\\\n",
" water=\"white\", land=\"grey\", shorelines=\"1/0.5p\")\n",
"\n",
" # Mercator\n",
" # a2f0.5 --> major ticks every 2 and minor ticks every 0.5\n",
"\n",
"\n",
"## plot slab2.0 here\n",
"## plotting slab 2.0 (after Hayes et al. (2018))\n",
"fig.plot(data=\"bin/hin_slab2_dep_02.24.18_contours.in\", pen=f\"0.65p,purple\") # Hindu Kush, bounding coords 66 74 40 34\n",
"fig.plot(data=\"bin/pam_slab2_dep_02.26.18_contours.in\", pen=f\"0.65p,purple\") # Pamir, bounding coords 68 78 41 35\n",
"\n",
"\n",
"## plotting faults\n",
"# https://www.pygmt.org/dev/gallery/lines/linefronts.html\n",
"fig.plot(data=\"bin/HimaTibetMap.gmt\", pen=f\"0.7p,black\") # all faults\n",
"## plotting faults (after Styron et al. (2010) and Taylor and An Yin (2009))\n",
"fig.plot(data=\"bin/HimaTibetMap.gmt\", pen=f\"0.7p,black\")\n",
"\n",
"\n",
"## plotting seismicity from the Harvard CMT catalogue\n",
"# Dziewonski et al. (1981), Ekstr ̈om et al. (2012), https://www.globalcmt.org/\n",
"# By fault style, between 20160309 and 20240710\n",
"\n",
"## plotting HarvardCMT earthquakes by fault style 20160309 20240710\n",
"fig.meca(\n",
" spec=\"bin/HarvardCMT_thrust_dropname.xy\",\n",
" convention=\"mt\", scale=meca_scale,\n",
Expand All @@ -94,37 +92,27 @@
" pen=\"thinnest,gray30,solid\", transparency=meca_trans,\n",
")\n",
"\n",
"\n",
"## plotting cities and stuff\n",
"fig.coast(map_scale=\"g76.5/34.3+w200k\", shorelines=\"1/0.5p\", borders=\"1/0.6p, mistyrose4,-\",\\\n",
" lakes=\"royalblue\", rivers=\"a/ royalblue\", water=\"royalblue\")\n",
"\n",
"## plotting cities and stuff\n",
"fig.plot(x=69.1042, y=34.3131, style=\"a0.38c\", pen=\"black\", fill=\"black\") # Kabul\n",
"\n",
"\n",
"fig.show()\n",
"fig.savefig(\"Hindu_Kush.png\")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"#import IntPyGMT_overlay\n",
"from IntPyGMT.IntPyGMT_overlay import mercator_png\n",
"\n",
"%matplotlib inline\n",
"%matplotlib widget"
]
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ec0afe038cbe4bf3a418542382936e8d",
"model_id": "1b8ccdea9eec433b80ecf23326675956",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -148,6 +136,11 @@
}
],
"source": [
"from IntPyGMT.IntPyGMT_overlay import mercator_png\n",
"\n",
"%matplotlib inline\n",
"%matplotlib widget\n",
"\n",
"grid_freq = 2\n",
"mercator_png(\"Hindu_Kush.png\", llcrnrlat, urcrnrlat, llcrnrlon, urcrnrlon, grid_freq)"
]
Expand Down
66 changes: 28 additions & 38 deletions demo_conical/cascadia.ipynb

Large diffs are not rendered by default.

173 changes: 173 additions & 0 deletions demo_pygmt/Herat_InSAR_EWvel.ipynb

Large diffs are not rendered by default.

Binary file added demo_pygmt/bin/EW_mskd_gdalmergefinal2.tif
Binary file not shown.
Loading

0 comments on commit b793cc9

Please sign in to comment.