Tips

Shapefiles

When you make a global map using Cartopy, you can draw coastal lines or state borders. These lines originate from shapefiles. When you run your python script with Cartopy, it automatically downloads the required shapefiles for the first time. Such files come from the open-source server in the Natural Earth. However, the server sometimes downs, and your script may have an error message like this:

/...../site-packages/cartopy/io/__init__.py:260:
DownloadWarning:   Downloading: https://naciscdn.org/naturalearth/50m/cultural/ne_50m_admin_1_states_provinces_lakes.zip
warnings.warn('Downloading: {}'.format(url), DownloadWarning)

To migrate this error, you may find the required shapefiles in zion:

zion:/work1/software/cartopy/shapefiles/natural_earth

In this directory, you may find several additional directories. The most commonly used shapefile would be found under the directory physical. You may try like this:

cd ~/.local/share/cartopy/shapefiles/natural_earth/physical
cp /work1/software/cartopy/shapefiles/natural_earth/physical/*.* ./

Once you get the required shapefiles under your local directory, you are ready to go.

F-string Manipulation

During the coding, you may want to refer to the integer variable within the string text. There are several ways to do that. But the easiest way would be the Python f-strings. Let’s see the following example to express ‘1980-01-01’ using the variable ystr:

ystr = 1980
print(f'{ystr}-01-01')