# Add Cyclic Points to Python Cartopy Map

During visualisation of climate data using Python and Cartopy, I encountered term called cyclic point. You may have not heard about it yet but it is important to know it before you jump into geospatial raster data visualisation.

# What Is the Cyclic Point and Why Do We Need It?

## Projection Discontinuity

Sometimes, when we are trying to plot geospatial data, we may encounter discontinuity (a jump) at the edge of projection (you can spot this in one of my articles). This is usually due to the way we store the longitude data in geospatial datasets.

Let’s say we have an array of data that has longitude and latitude dimensions. Our longitude spans from 0° to 359.9° (incl.) with 0.1° resolution (3600 values) and latitude from -90° to 90° (incl.) also with 0.1° resolution (1801 values). Our final array has shape of (1801, 3600).

Why does our dataset not containt value for 360th degree of longitude? The answer is simple — because 360° of longitude is the same as 0° of longitude (which we already have in our data).

Now, let’s try to plot the data over our cartopy map. I have used dataset that you can download from Climate Data Store. Specifically, it is an ERA5-Land monthly averaged data from 1950 to present dataset. We will load this dataset in the grib format using xarray with cfgrib backend and then use matplotlib to visualise data. To learn more about plotting climate data using cartopy, read this article of mine.

Note the white line which spans from the top to the bottom exactly at 0° longitude. This is the issue we are talking about.

## Adding a Cyclic Point to the data

Fortunately, there is a feature from Cartopy that allows us to fix this issue. The function is called add_cyclic_point and can be imported from cartopy.util module.

This function takes data array and optional coordinates and returns cyclic data and cyclic coordinates. What does it mean that they are cyclic?

It means that we will add one more longitude coordinate equal to 360 with data equal to 359.9° longitude. Let’s prove this on the data itself.

First we add cyclic point to our data and then we compare values at 359.9° longitude and 360° longitude.

Let’s reuse our plot_data() function and call it plot_data(new_ds). When we plot the data that was extented using cyclic point, we can see that the white line is gone and our plot is now correct.

This article describes uncommon function of cartopy called add_cyclic_point. You may encounter a white line like this while ploting geospatial data and I hope that this article have helped you in resolving your issue.

# Stay Connected

• Follow me on Medium for more stories like this
• Find more datasets about Climate Change on CDS

If you are interested where to get climate data or how to plot them, have a look at my other articles:

--

--

## More from Lubomir Franko

Experienced Data Engineer with passion in geospatial data analysis

## Get the Medium app

Experienced Data Engineer with passion in geospatial data analysis