Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
f781946
Add draft of JN for geopandas - geodataframes with lines and polygons
yvonnefroehlich Dec 24, 2024
93afa24
Include output figure
yvonnefroehlich Jan 4, 2025
587da3a
Reduce resolution of output image in JN
yvonnefroehlich Jan 4, 2025
fc103e9
Follow coding style
yvonnefroehlich Jan 5, 2025
57511d0
Adjust filename
yvonnefroehlich Jan 5, 2025
01812e8
Remove comments | Improve code structure
yvonnefroehlich Oct 16, 2025
e288455
Move to normal python script (temporaly)
yvonnefroehlich Nov 5, 2025
fb445fd
Rename files and save output figure
yvonnefroehlich Nov 12, 2025
6c58129
Add codes for choropleth map based on dcw parameter
yvonnefroehlich Nov 13, 2025
0e321e0
Merge remote-tracking branch 'origin/main' into fig/geopandas
yvonnefroehlich Nov 16, 2025
c885c52
Add code for example covering points, lines, and polygons
yvonnefroehlich Nov 19, 2025
ab2ca00
Remove code for chorophleth via dcw
yvonnefroehlich Nov 19, 2025
c6a39c1
Remove unneeded files
yvonnefroehlich Nov 19, 2025
65c458b
Adjust codes for example with natural earth data | temporly focus on …
yvonnefroehlich Nov 20, 2025
012e5fb
Test different regions
yvonnefroehlich Nov 21, 2025
8cb2e58
Remove content for Cicago example
yvonnefroehlich Nov 21, 2025
af55d14
Change scaling to e-6
yvonnefroehlich Nov 21, 2025
7042382
Use 1e-6
yvonnefroehlich Nov 21, 2025
40f4390
Adjust figure number
yvonnefroehlich Nov 21, 2025
dd18459
Adjust color and remove unneeded pen color
yvonnefroehlich Nov 21, 2025
80a0648
Focus on Africa
yvonnefroehlich Nov 21, 2025
8996b68
Use different symobl fill and size for world and smaller cities
yvonnefroehlich Nov 26, 2025
f979b8b
Adjust fill, outline and offset of text labels
yvonnefroehlich Nov 26, 2025
fb6e595
Adjust maximum for CPT to 100
yvonnefroehlich Nov 26, 2025
a3218a5
Follow coding style
yvonnefroehlich Nov 27, 2025
8938542
No need to explecitly select the "geometry" column
yvonnefroehlich Nov 27, 2025
ad7a1bd
Adjust provider | Fix geopandas warning | Use full line length
yvonnefroehlich Nov 27, 2025
61c98f1
Add backslash
yvonnefroehlich Nov 27, 2025
cba722d
Merge remote-tracking branch 'origin/main' into fig/geopandas
yvonnefroehlich Nov 27, 2025
b19ddf0
Adust colormap maximum and colorbar
yvonnefroehlich Nov 27, 2025
561bb43
Adjust color for rivers
yvonnefroehlich Nov 27, 2025
f1eb469
Adjust text labels
yvonnefroehlich Nov 27, 2025
bedf467
Add just colorbar frame
yvonnefroehlich Nov 27, 2025
447c51b
Plot colorbar verticall inside the map
yvonnefroehlich Nov 27, 2025
6e84e65
Update output image
yvonnefroehlich Nov 27, 2025
686b661
Adjust region
yvonnefroehlich Nov 27, 2025
74bcc3a
TEMPORALY add code for focus on Africa
yvonnefroehlich Nov 27, 2025
2d60504
Remove geometry column
yvonnefroehlich Nov 27, 2025
324af82
Use rivers for 110 m
yvonnefroehlich Nov 27, 2025
6eca7da
Update output image
yvonnefroehlich Nov 27, 2025
d0f4920
Merge remote-tracking branch 'origin/main' into fig/geopandas
yvonnefroehlich Nov 27, 2025
645ff9c
Adjust and shorten variable names
yvonnefroehlich Nov 27, 2025
b119528
Use gpd.sjoin instead of pd.concat
yvonnefroehlich Nov 28, 2025
3ed5e1f
Remove unneeded pandas import
yvonnefroehlich Nov 28, 2025
2b4c6b9
Adjust building the city subsets
yvonnefroehlich Nov 28, 2025
7bd7935
Use 110 m also for population
yvonnefroehlich Nov 28, 2025
c45cc6f
Remove geometry column
yvonnefroehlich Nov 28, 2025
ae24b2e
Remove code for old version
yvonnefroehlich Nov 28, 2025
dc38ff0
Update output images
yvonnefroehlich Nov 28, 2025
9effeee
Remove geometry column
yvonnefroehlich Nov 28, 2025
45b56ed
Merge remote-tracking branch 'origin/main' into fig/geopandas
yvonnefroehlich Nov 29, 2025
1653b66
Add codes for Chicago map
yvonnefroehlich Nov 30, 2025
4ba60d6
Improve visualization
yvonnefroehlich Nov 30, 2025
269765d
Add lake
yvonnefroehlich Nov 30, 2025
6c2c772
Merge remote-tracking branch 'origin/main' into fig/geopandas
yvonnefroehlich Nov 30, 2025
07d84c9
Polish code
yvonnefroehlich Nov 30, 2025
1e537a4
Update output figure
yvonnefroehlich Nov 30, 2025
86fbfa7
Use Box class
yvonnefroehlich Nov 30, 2025
1adf58f
Merge remote-tracking branch 'origin/main' into fig/geopandas
yvonnefroehlich Dec 1, 2025
8d07359
Add draft for usa area chorophlet map with rivers and cities
yvonnefroehlich Dec 1, 2025
1de1fd6
Adjust color of rivers
yvonnefroehlich Dec 1, 2025
6ad8285
Start colormap at zero
yvonnefroehlich Dec 1, 2025
97789ee
Update output image
yvonnefroehlich Dec 1, 2025
13c3d3c
Do not subset cities | Use rivers from 110 m dataset | Remove geometr…
yvonnefroehlich Dec 2, 2025
08bbc86
Improve data request
yvonnefroehlich Dec 2, 2025
a811284
Select rivers and cities located in USA
yvonnefroehlich Dec 2, 2025
8a5daaa
Exclude Alaska | Increase thickness of colorbar | Upate output figure
yvonnefroehlich Dec 2, 2025
8eb566a
Remove codes and images of old examples
yvonnefroehlich Dec 2, 2025
477e7b4
Plot Alaska and Hawaii at the lower-left corner
yvonnefroehlich Dec 2, 2025
0826ef4
Do not exclude Alaska
yvonnefroehlich Dec 2, 2025
785502d
Remove codes from old examples
yvonnefroehlich Dec 2, 2025
a7f3262
Adjust position of colorbar
yvonnefroehlich Dec 2, 2025
7d01582
Combine into loop
yvonnefroehlich Dec 2, 2025
42693a2
Adjust colorbar | Improve comment
yvonnefroehlich Dec 2, 2025
55dc3fb
Add missing word
yvonnefroehlich Dec 2, 2025
ae06ce9
Improve preparing the subsets
yvonnefroehlich Dec 2, 2025
e1121f2
Use color map hawaii
yvonnefroehlich Dec 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Fig6_PyGMT_geopandas.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "760146f6-d4c9-4e69-b539-f42e057c7945",
"metadata": {},
"outputs": [],
"source": [
"# Copy finale version of script from normal Python file"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Binary file added Fig6_PyGMT_geopandas.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions Fig6_PyGMT_geopandas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import geopandas as gpd
import pygmt
# import numpy as np

provider = "https://naciscdn.org/naturalearth"
states = gpd.read_file(f"{provider}/50m/cultural/ne_50m_admin_1_states_provinces.zip")
rivers = gpd.read_file(f"{provider}/50m/physical/ne_50m_rivers_lake_centerlines.zip")
cities = gpd.read_file(f"{provider}/110m/cultural/ne_110m_populated_places_simple.zip")

states = states[states["admin"] == "United States of America"]
rivers = rivers[rivers.intersects(states.union_all())]
cities = cities[cities["adm0name"] == "United States of America"]

states["area_sqkm"] = states.to_crs(epsg=6933).area / 10 ** 9
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original dataset has the area_sqkm column with zero values. That's why we compute the areas and store them in this column. But, since the area is in units of 1000 km^2, I feel the column name is more confusing. Maybe we just save it to a new column "area" instead?

# states["area_sqkm_log"] = np.log10(states["area_sqkm"])

fig = pygmt.Figure()
fig.basemap(projection="L-96/35/33/41/12c", region=[-126, -66, 25, 49], frame="+n")

pygmt.makecpt(cmap="hawaii", series=[0, states["area_sqkm"].max()], reverse=True)
fig.plot(data=states, cmap=True, pen="0.2p,gray50", fill="+z", aspatial="Z=area_sqkm")
fig.colorbar(frame="xaf+lArea (1000 km@+2@+)", position="jRB+o1.9c/0.2c+w3c/0.15c+ml")

fig.plot(data=rivers, pen="0.5p,dodgerblue4")

fig.plot(data=cities, style="s0.17c", fill="darkorange", pen="0.5p")
fig.text(
x=cities.geometry.x,
y=cities.geometry.y,
text=cities["name"],
offset="0.35c/0.2c",
justify="BC",
font="4.5p,Helvetica-Bold",
fill="white@30",
pen="0.2p,darkorange",
clearance="0.05c+tO",
)

# Add Alaska and Hawaii separately in the lower left corner
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, we set the region for Alaska and Hawaii manually. Ideally, we should be able to get the region from the data directly. The tricky thing is that Hawaii has many small islands, and the region is [-178., -154., 18., 29.]. The code below removes small islands with area < 1.0e8 m^2, and then the region becomes [-161., -154., 18., 23.]. I'm wondering if the code below is better, although we need to explain more details in the main text.

# Add Alaska and Hawaii separately in the lower left corner
for name, xshift in zip(["Alaska", "Hawaii"], ["0.9c", "2.5c"]):
    substates = states[(states["name"] == name)]
    substates = substates.explode()
    substates = substates[substates.to_crs(epsg=6933).area > 1.0e8].dissolve()
    region = pygmt.info(substates, spacing=1)
    with fig.shift_origin(xshift=xshift):
        fig.plot(
            data=substates,
            region=region,
            projection="M2c",
            cmap=True,
            pen="0.2p,gray50",
            fill="+z",
            aspatial="Z=area_sqkm",
        )

for xshift, region in zip(["0.9c", "2.3c"], [[172, 230, 51, 72], [-168, -154, 18, 29]]):
with fig.shift_origin(xshift=xshift):
fig.plot(
data=states,
region=region,
projection="M2.5c",
cmap=True,
pen="0.2p,gray50",
fill="+z",
aspatial="Z=area_sqkm"
)
Comment on lines +39 to +50
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on how we describe this figure in the manuscript, maybe it makes sense to move the code for insets up to the code part for plotting the polygons of the main map (currently line 18).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would change the region and projection settings and we have to set region and projection again when plotting rivers and cities.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's true. We do not use Figure.inset here.


fig.show()
fig.savefig(fname="Fig6_PyGMT_geopandas.png")