Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the starter tutorial introduction #1607

Merged
merged 55 commits into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
62d3f3f
add starter-tutorial.rst as intro for tutorial
willschlitzer Nov 5, 2021
ef4d987
update doc/conf.py to fix merge conflicts
willschlitzer Nov 15, 2021
8f5c49c
merge main branch changes
willschlitzer Nov 15, 2021
41814f3
update conf.py for starer tutorials folder
willschlitzer Nov 15, 2021
3661ada
Apply suggestions from code review
willschlitzer Nov 16, 2021
5605b9d
moving tutorial files
willschlitzer Nov 16, 2021
793b555
update conf.py
willschlitzer Nov 16, 2021
77799f0
add starter tutorial files to gitignore
willschlitzer Nov 16, 2021
1ab117c
add starter tutorials to Makefile
willschlitzer Nov 16, 2021
962d05d
run make fomrat
willschlitzer Nov 16, 2021
a9441a2
add into to README.txt
willschlitzer Nov 17, 2021
d6e7c1e
remove sub-sections in intro
willschlitzer Nov 17, 2021
943c51f
update docstrings
willschlitzer Nov 17, 2021
016b7f7
update the first figure plotted
willschlitzer Nov 17, 2021
33fb360
update coordinates in first figure example
willschlitzer Nov 17, 2021
473a63b
add external display parameter explanation
willschlitzer Nov 17, 2021
bd99bcf
style fix
willschlitzer Nov 17, 2021
cf98638
format fix
willschlitzer Nov 17, 2021
9131163
add projection settings
willschlitzer Nov 17, 2021
b9aa8d6
removing figure saving from tutorial
willschlitzer Nov 17, 2021
03bc80a
wording update
willschlitzer Nov 18, 2021
3c53e55
add frame section
willschlitzer Nov 18, 2021
c880bd7
add additional exercises
willschlitzer Nov 18, 2021
b89e708
format fix
willschlitzer Nov 18, 2021
ae030ba
specify sphinx gallery image
willschlitzer Nov 18, 2021
0e8efcb
Apply suggestions from code review
willschlitzer Nov 19, 2021
af13124
remove "About PyGMT" section from starter tutorial
willschlitzer Dec 4, 2021
416175b
rename starter tutorial
willschlitzer Dec 6, 2021
3be0dca
rename starter tutorial folder
willschlitzer Dec 6, 2021
3479d32
update Makefile with new tutorial folder name
willschlitzer Dec 6, 2021
94b9976
update gitignore with new tutorial folder name
willschlitzer Dec 6, 2021
cd7f278
update index with new tutorial folder name
willschlitzer Dec 6, 2021
748c12b
update folder name
willschlitzer Dec 6, 2021
c02cdaf
fix link
willschlitzer Dec 6, 2021
b792c6c
Apply suggestions from code review
willschlitzer Dec 8, 2021
9604d7f
Apply suggestions from code review
willschlitzer Dec 11, 2021
b1e3b5e
update additional exercises
willschlitzer Dec 11, 2021
7fe3ee1
style fix
willschlitzer Dec 11, 2021
1f3a071
Merge branch 'main' into tutorial/starter-tutorial
willschlitzer Dec 11, 2021
380d4af
Merge branch 'main' into tutorial/starter-tutorial
willschlitzer Dec 14, 2021
e90bc27
Apply suggestions from code review
willschlitzer Dec 14, 2021
64dfe0a
change frame argument
willschlitzer Dec 14, 2021
3ae1a1e
run make format
willschlitzer Dec 14, 2021
75fb36c
format lines
willschlitzer Dec 14, 2021
a4a417c
Merge branch 'main' into tutorial/starter-tutorial
michaelgrund Dec 15, 2021
7c1ffec
Apply suggestions from code review
willschlitzer Dec 16, 2021
2024b6c
remove mention of using external method for show
willschlitzer Dec 16, 2021
f912e75
changing frame settings
willschlitzer Dec 16, 2021
dfc996d
change ISO code description
willschlitzer Dec 16, 2021
892a14c
format fix
willschlitzer Dec 16, 2021
3ce6a71
Apply suggestions from code review
willschlitzer Dec 17, 2021
237e141
update README
willschlitzer Dec 17, 2021
9f5568f
add link to Jupyter notebook
willschlitzer Dec 17, 2021
5910c38
update install link
willschlitzer Dec 19, 2021
894a1cd
Merge branch 'main' into tutorial/starter-tutorial
willschlitzer Dec 19, 2021
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ doc/_build/
doc/gallery/
doc/projections/
doc/tutorials/
doc/get-started/

# Jupyter Notebook
.ipynb_checkpoints/
Expand Down
1 change: 1 addition & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ clean:
rm -rf api/generated
rm -rf gallery
rm -rf tutorials
rm -rf get-started
rm -rf projections
4 changes: 3 additions & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@
"examples_dirs": [
"../examples/gallery",
"../examples/tutorials",
"../examples/get-started",
"../examples/projections",
],
# path where to save gallery generated examples
"gallery_dirs": ["gallery", "tutorials", "projections"],
"gallery_dirs": ["gallery", "tutorials", "get-started", "projections"],
"subsection_order": ExplicitOrder(
[
"../examples/gallery/maps",
Expand All @@ -89,6 +90,7 @@
"../examples/projections/table",
"../examples/tutorials/basics",
"../examples/tutorials/advanced",
"../examples/get-started",
]
),
# Patter to search for example files
Expand Down
2 changes: 1 addition & 1 deletion doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

overview.rst
install.rst
tutorials/basics/first_figure.rst
get-started/index.rst

.. toctree::
:maxdepth: 2
Expand Down
16 changes: 16 additions & 0 deletions examples/get-started/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Intro to PyGMT
==============

Welcome to PyGMT! This tutorial is designed to teach the basic concepts to
make a map in PyGMT.

**About this tutorial**

This tutorial assumes that PyGMT has been successfully installed. A quick
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a link to the install instructions here. (Is there a way to do relative links?)

Suggested change
This tutorial assumes that PyGMT has been successfully installed. A quick
This tutorial assumes that PyGMT has been successfully [installed](https://www.pygmt.org/latest/install.html). A quick

Copy link
Member

Choose a reason for hiding this comment

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

The following directive should work:

:doc:`install`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How do I add the text that I want to be linked ("installed")?

Copy link
Member

Choose a reason for hiding this comment

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

:doc:`installed <install>`

or

:doc:`installed </install>`

should work.

way to test this is to type ``import pygmt`` in a Python IDE or Jupyter
seisman marked this conversation as resolved.
Show resolved Hide resolved
Notebook.

This tutorial will progressively cover PyGMT plotting concepts, and later
examples will use concepts explained in previous examples. It will not
cover all PyGMT modules.

159 changes: 159 additions & 0 deletions examples/get-started/first_figure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
"""
1. Making your first figure
Copy link
Member

Choose a reason for hiding this comment

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

Just as a thought, should we add a binder link so that people can 'follow along' with the tutorial interactively?

Copy link
Contributor Author

@willschlitzer willschlitzer Dec 17, 2021

Choose a reason for hiding this comment

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

@weiji14 I'm not familiar with using binder; could you make a code suggestion to add it?

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps it's better to add the binder link in a separate PR. Ideally, we should modify the template to automatically add the binder links for each example.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, sounds good to me.

===========================

This tutorial page covers the basics of creating a figure. It will only use
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
the ``coast`` module for plotting. Later examples will address other PyGMT
modules.
"""

maxrjones marked this conversation as resolved.
Show resolved Hide resolved
###############################################################################
# Setting up the development environment
# --------------------------------------
#
# PyGMT can be used in both a Python script and a notebook environment, such
# as Jupyter. The tutorial's recommended method is to use a notebook, and the
# code will be for a notebook environment. If you use a Python script instead,
# there will be a difference in how the figure is shown that is explained in
# the first example.
seisman marked this conversation as resolved.
Show resolved Hide resolved


###############################################################################
# Loading the library
# -------------------
#
# The first step is to import ``pygmt``. All modules and figure generation is
# accessible from the :mod:`pygmt` top level package.

willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
# sphinx_gallery_thumbnail_number = 4
import pygmt

###############################################################################
# Creating a figure
# -----------------
#
# All figure generation in PyGMT is handled by the :class:`pygmt.Figure` class.
# Start a new figure by creating an instance of this class:

fig = pygmt.Figure()

###############################################################################
# To add to a plot object (``fig`` in this example), the PyGMT module is used
# as a method on the class. This example will use the module ``coast``, which
# can be used to create a map without any other modules or external data. The
# ``coast`` module plots the coastlines, borders, and bodies of water using a
# database that is included in GMT.
#
# First, a region for the figure must be selected. This example will plot some
# of the coast of Maine in the northeastern US. A Python list can be passed to
# the ``region`` argument with the minimum and maximum X-values (longitude)
# and the minimum and maximum Y-values (latitude). For this example, the
# minimum (bottom left) coordinates are N43.75 W69 and the maximum (top right)
# coordinates are N44.75 W68. Negative values can be passed for latitudes in
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
# the southern hemisphere or longitudes in the western hemisphere.
#
# In addition to the region, an argument needs to be passed to ``coast`` to
# tell it what to plot. In this example, ``coast`` will be told to plot the
# shorelines by passing the Boolean value ``True`` to the ``shorelines``
# parameter. The ``shorelines`` parameter has other options for finer control,
# but setting it to ``True`` uses its default values.
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved

fig.coast(region=[-69, -68, 43.75, 44.75], shorelines=True)

###############################################################################
# To see the figure, call :meth:`pygmt.Figure.show`. If you are using a Python
# script instead of a notebook, use ``fig.show(method="external)`` to display
# the figure.
seisman marked this conversation as resolved.
Show resolved Hide resolved

fig.show()

###############################################################################
# Color the land and water
# ------------------------
#
# This figure plots all of the coastlines in the given region, but it does not
# indicate where the land and water are. Color values can be passed to ``land``
# and ``water`` to set the colors on the figure.
#
# When plotting colors in PyGMT, there are multiple
# :gmt-docs:`color codes <gmtcolors.html>`, that can be used. This includes
weiji14 marked this conversation as resolved.
Show resolved Hide resolved
# standard GMT color names (like ``skyblue``), R/G/B levels (like ``0/0/255``),
# a hex value (like ``#333333``), and a graylevel (like ``50``). For this
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
# example, GMT color names are used.

fig = pygmt.Figure()
fig.coast(
region=[-69, -68, 43.75, 44.75],
shorelines=True,
land="lightgreen",
water="lightblue",
)
fig.show()

###############################################################################
# Set the projection
# ------------------
#
# This figure now has its colors set, but there is not projection or size
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
# set for the map. Both of these values are set using the ``projection``
# parameter.
#
# The appropriate projection varies for the type of map. The available
# projections are explained in the :doc:`projection </projections/index>`
# gallery. For this example, the Mercator projection is set using ``"M"``.
# The width of the figure will be 10 centimeters, as set by ``"10c"``. The map
# size can also be set in inches using "i" (e.g. a 5 inch wide Mercator
# projection would use ``"M5i"``).

fig = pygmt.Figure()
fig.coast(
region=[-69, -68, 43.75, 44.75],
shorelines=True,
land="lightgreen",
water="lightblue",
projection="M10c",
)
fig.show()

###############################################################################
# Add a frame
# -----------
#
# While that the map's colors, projection, and size have been set, the region
# that is being displayed is not apparent. A frame can be added to
# annotate the latitude and longitude of the region.
#
# The ``frame`` parameter is used to add a frame to the figure. For now, it
# will be set to ``a`` to use default settings, but later tutorials will
seisman marked this conversation as resolved.
Show resolved Hide resolved
# show how ``frame`` can be used to customize the axes, gridlines, and titles.

fig = pygmt.Figure()
fig.coast(
region=[-69, -68, 43.75, 44.75],
shorelines=True,
land="lightgreen",
water="lightblue",
projection="M10c",
frame="a",
)
fig.show()

###############################################################################
# Additional exercises
# --------------------
#
# This is the end of the first tutorial. Here are some additional exercises
# for the concepts that were discussed:
#
# 1. Make a map of Germany using its DCW ISO code ("DE"). Pass the ISO code
seisman marked this conversation as resolved.
Show resolved Hide resolved
# as a Python string to the ``"region"`` parameter.
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
#
# 2. Change the color of the land to "khaki" and the water to "azure".
#
# 3. Change the color of the lakes (using the ``"lakes"`` parameter) to "red."
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
#
# 4. Create a global map. Set the region to "d" to center the map at the Prime
# Meridian or "g" to center the map at the International Date Line. When the
# region is set without using a list full of integers or floating numbers,
Copy link
Member

Choose a reason for hiding this comment

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

When the region is set without using a list full of integers or floating numbers, the argument needs to be passed as a Python string.

If I understand you correctly, you mean passing a string like -20/20/-30/30 to region, right? I don't think it's clearly explained by this sentence because it doesn't say that the string should contain slash-separated numbers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm actually referring to passing d or g when it comes to region. While I know that the literal GMT string can be passed for region, I don't want to make a mention of it in the first section of the tutorial. I think bringing up too many options early on is confusing, and using a list for something like this is probably more familiar to Python users instead of a string with numbers.

Copy link
Member

Choose a reason for hiding this comment

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

I see what you meant. I also agree that a string like -20/20/-30/30 is not Pythonic and should not be covered in this starter tutoria.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, you could pass in a list of strings like ["10W", "20E", "30S", "40N"] right? Not necessarily all numbers.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, you could pass in a list of strings like ["10W", "20E", "30S", "40N"] right? Not necessarily all numbers.

Yes, but it's not commonly used, and better not to introduce too many options.

# the argument needs to be passed as a Python string. Create a 15 centimeter
# map using the Mollwide ("W") projection.
98 changes: 0 additions & 98 deletions examples/tutorials/basics/first_figure.py

This file was deleted.