How to Create 2D and 3D Interactive Weather Maps in Python and R
Tags: Climate Change, Data Science, Weather, Data Visualization

How to Create 2D and 3D Interactive Weather Maps in Python and R plotly Follow Mar 5, 2018 · 7 min read

Robert FitzRoy. Source: nzhistory.govt.nz.

It was the year 1860. Robert FitzRoy, of England and New Zealand, was using the new telegraph system to gather daily weather observations and produce the first synoptic weather map. He coined the term “weather forecast” and his were the first ever to be published daily.

Fitzroy probably would have never imagined in his wildest dreams what the weather map scene would be like 160 years into the future…

⏩ ⏩ ⏩

In 2018, weather maps are commonly produced in the Grid Analysis and Display System (GrADS), R, and Python.

Kazakhstan, parts of Russia and China, and Japan had a colder than normal start to winter in 2017–18.

Weather and climate maps in Plotly add a new layer to the interrogation of our atmosphere. When it comes to these maps, Plotly’s point of difference comes in its ability to hover-over and interact with specific data points on the fly, instead of looking at a legend and ‘ballparking’ a value.

Below, you’ll find several new examples of weather and climate maps created from freely available data on the web. If you’d like to create similar maps, you’ll have to get familiar with the NCEP Reanalysis plotter, an amazingly useful tool that is used to investigative the climate system and day-to-day weather.

Here’s a short tutorial:

Go ahead, immerse yourself in this new and amazing interactive weather world that we are so fortunate to have in 2018.

Temperature Anomaly

Do you live in the eastern North America? If so, you’ve were subject to some of the coldest temperatures (with respect to normal) on the globe during December and January 2018. Siberia, a place that is already brutally cold during winter, was also colder than average.

On the flip side, the Arctic (winter), Europe (winter), eastern Australia (summer), and New Zealand (summer) have had above average temperatures during December-January. In fact, January was New Zealand’s warmest month of any month on record (nationwide records began in 1909).

See the blue patch to the west of South America? That’s associated with a climate signature known as La Niña, defined by cooler that normal sea temperatures in that part of the world that has wide-reaching impacts on a global scale.

Temperature Difference from Normal 🌡️

Data source: NCEP Reanalysis Plotter.

Data used to create this plot: GitHub.

Python code: Jupyter notebook.

R code: Make this in R.

Rainfall Anomaly 🌧️

We can apply the same techniques that we used to create the temperature anomaly map above to precipitation (rain and snow).

The map below looks at precipitation as a difference from normal for the period December to January 2018.

The Western Pacific had wetter than normal conditions chiefly because of La Niña. La Niña is associated with warmer than average sea surface temperatures near the Philippines, Papua New Guinea, and across Southeast Asia. These warm seas result in more rising motion than average in the atmosphere, which culminates in rainy conditions.

In direct contrast, there is quite a bit of brown shading about southern Africa as Cape Town approaches Day Zero. In addition, California sticks out along the West Coast of North America for being a much drier than normal location.

Precipitation Difference from Normal

Data source: NCEP Reanalysis Plotter.

Data used to create this plot: GitHub.

Python code: Jupyter notebook.

R code: Make this in R.

Zoom

While you can always zoom in on a global projection, maybe you’re looking for something more localized. In this case, you can set your latitude and longitude as such:

layout = Layout(

title=title,

showlegend=False,

hovermode="closest", # highlight closest point on hover

xaxis=XAxis(

axis_style,

range=[lon[-185], lon[-105]], # set your custom longitude

autorange=False



),

yaxis=YAxis(

axis_style,

range=[lat[50], lat[85]], # set your custom latitude

autorange=False

This the resulting graph will be a zoom to North America. For further detail, you can add state borders like this:

# Function generating state lon/lat traces def get_state_traces():

poly_paths = m.drawstates().get_paths() # country polygon paths

N_poly = len(poly_paths) # use all states

return polygons_to_traces(poly_paths, N_poly) # Get list of of coastline, country, and state lon/lat traces traces_cc = get_coastline_traces()+get_country_traces()+get_state_traces()

Python code: Jupyter notebook.

Here’s a closer look at southern Africa where Cape Town where the water taps are expected to run dry on June 4th. After three years of low rainfall and drought or near-drought conditions, locals and visitors are limited to 50 liters (about 13 gallons) of water per day. For some perspective, the average American uses about 380 liters per day or almost 8 times the Cape Town restricted amount.

Python code: Jupyter notebook.

Mercator projections, like the graphs above, are popular because they preserve direction and are ideal for navigation. They also have further educational value — such as being a good way of learning the shapes of nations.

However, Mercator maps misrepresent the size of countries and are poorly defined at the poles.

For a different perspective, Plotly user empet mapped the flat Earth onto a sphere for a 3-D experience.

Precipitation Difference from Normal in 3-D

Learn to map mercator projections onto a sphere.

Sunshine Anomaly 🌞

Outgoing longwave radiation (OLR) is a measure of the amount of energy emitted to space by earth’s surface, oceans and atmosphere. OLR is a good proxy for clear skies — the larger (on the positive side) the OLR anomaly, the more unusually clear it might have been at a given location. Conversely, a large negative anomaly might imply more cloud cover than normal and frequent thunderstorms or rain.

Below, we investigate OLR as a difference from normal for the period December 2017-January 2018.

Above normal sunshine: New Zealand, Queensland, Zimbabwe, Zambia, Portugal, western USA, Alaska.

Below normal sunshine: Central America, northern Africa, eastern Canada, western India, Philippines and South Asia, western Australia.

OLR Difference from Normal

Data source: NCEP Reanalysis Plotter.

Data used to create this plot: GitHub.

Python code: Jupyter notebook.

R code: Make this in R.

OLR Difference from Normal in 3-D

Python code: Learn how to make this spherical plot.

R code: Make this in R.

Sea Surface Temperature Anomaly

Sea surface temperatures are the main driver of climate variability in the global tropics (10ºN-10ºS latitude) and play a major role in the global sub-tropics and midlatitudes as well.

Here, we can identify that a La Niña is present by the ‘cool pool’ of water found along the coast of western South America and into the eastern and central equatorial Pacific. La Niña, which is part of the natural El Niño-Southern Oscillation (ENSO) cycle, is considered to be a climate driver.

What is not totally natural is the ‘red blob’ between Australia and New Zealand — known as the Tasman Sea marine heatwave. Although this climate feature’s development was fueled by the ENSO cycle, the extent of the anomaly was the largest ever observed, almost certainly influenced upward by the tailwind that is anthropogenic global warming.

Data source: NCEP Reanalysis Plotter.

Data used to create this plot: GitHub.

Python code: Jupyter notebook.

R code: Make this in R.

Forecast Wind Speed and Direction

The weather goes as the wind blows. Using weather data in Plotly, not only can you diagnose cyclones, but zoom to low levels to see how much of a breeze is forecast in your town.

The plot below was originally created by Plotly user ToniBois and the 3-D version below was created by empet. If you look carefully, you’ll notice Hurricane Hermine (September 2016) swirling perilously off of the East Coast of the United States.

The data used to create this plot comes from the NCEP Products Inventory.

Colorscales

Looking for the right colorscale to complement your weather map? Look no further: https://react-colorscales.getforge.io/.

The “CMOCEAN” and “DIVERGENT” colorscales are recommended for weather and climate charts. For the temperature chart, we used “balance”

For the precipitation chart, we used “BrBG”

For the outgoing longwave radiation chart, we used “RdYlBu”

For the sea surface temperature chart, we used “curl”

Weather and climate maps in Plotly add a new layer to the interrogation of our atmosphere. When it comes to weather maps, Plotly’s point of difference comes in its ability to hover-over and interact with specific data points on the fly, instead of looking at a legend and ‘ballparking’ a value.