HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →
Live examsInternational live exams are comingTell us which exam you want first. Timed practice papers are open now.See what is coming →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Space Science and Astronomy
  • Earth and Environmental Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
Earth Data with Python: Trends, Anomalies and Models
  1. 1Time series, trends and the seasonal cycle
  2. 2Anomalies, baselines and uncertainty
  3. 3Simple models of Earth data
  1. Earth and Environmental Science
  2. /Earth Data with Python: Trends, Anomalies and Models
  3. /Time series, trends and the seasonal cycle

Course 12.3·Lesson 1 of 3

Time series, trends and the seasonal cycle

A record is a trend, a seasonal cycle and noise added together. The least-squares line finds the trend, and its R squared says how much of the scatter the line explains. A mean over twelve months removes a yearly cycle, and the mean of each calendar month gives the cycle itself.

about 30 min1 simulation2 practice questions
Lesson 1 of 3Show all lessonsHide
Earth Data with Python: Trends, Anomalies and Models
  1. 1Time series, trends and the seasonal cycle
  2. 2Anomalies, baselines and uncertainty
  3. 3Simple models of Earth data

Try the code and the simulations beside the lesson.

A staircase hidden in a wave

In March 1958 a young scientist, Charles David Keeling, began to measure the carbon dioxide of the air on a Hawaiian mountain. The line that he drew was not a smooth staircase. It had a wave that came back every year, and the wave stood on a slope. The wave is the breathing of the northern forests: they take up carbon dioxide in summer and release it in winter. The slope is the rise from burning fuels. Both are in one list of numbers. Our task is to pull them apart.

What a time series is

A time series is a list of values taken at known times: a gauge reading each day, a satellite mean each month, a temperature each year. It is useful to think of each value as a sum of three parts:

y=trend+season+noise\displaystyle y = \text{trend} + \text{season} + \text{noise}y=trend+season+noise
  • The trend is the slow change over many years.
  • The seasonal cycle repeats every year.
  • The noise is what is left: weather, instrument error, a volcano.

Not every record has all three. A yearly mean has no seasonal cycle. A river record often has a wet season so large that it hides the trend.

The least-squares line

The straight line y=a+bxy = a + bxy=a+bx that fits best is the one that makes the sum of the squared vertical gaps, the residuals, as small as possible. The result has two closed forms. With xˉ\bar{x}xˉ and yˉ\bar{y}yˉ​ the means,

Sxy=∑(x−xˉ)(y−yˉ)\displaystyle S_{xy} = \sum (x - \bar{x})(y - \bar{y})Sxy​=∑(x−xˉ)(y−yˉ​)
Sxx=∑(x−xˉ)2\displaystyle S_{xx} = \sum (x - \bar{x})^2Sxx​=∑(x−xˉ)2
b=SxySxx,a=yˉ−b xˉ\displaystyle b = \dfrac{S_{xy}}{S_{xx}}, \qquad a = \bar{y} - b\,\bar{x}b=Sxx​Sxy​​,a=yˉ​−bxˉ

The slope bbb has the unit of yyy per unit of xxx, such as ppm per year. The line always passes through the point (xˉ,yˉ)(\bar{x}, \bar{y})(xˉ,yˉ​).

The quantity R2=1−SSE/SSTR^2 = 1 - \text{SSE}/\text{SST}R2=1−SSE/SST says how much of the spread of yyy the line explains. Here SSE is the sum of the squared residuals and SST is the sum of (y−yˉ)2(y - \bar{y})^2(y−yˉ​)2. It lies between 000 and 111. A high R2R^2R2 does not prove that the line is the right shape. A curve can have a high R2R^2R2 for a line and still bend.

Use the time as a number with a clear unit. If the times are the years 2011,2012,…2011, 2012, \dots2011,2012,…, then x−xˉx - \bar{x}x−xˉ is a small number and the arithmetic is easy. The slope is the same whether the origin is 000 or 201120112011.

Taking the cycle out

Two methods remove a yearly cycle.

  • The 12-month mean. The cycle goes up and down, and the sum of its twelve monthly values is zero. So the mean of any twelve consecutive months has no cycle in it. It is the trend, at the middle of those twelve months. A centred version averages the two overlapping windows that straddle a month.
  • The monthly means. Subtract the line first. For each calendar month, average the leftover values over all the years. This table of twelve numbers is the seasonal cycle, or climatology. Its largest and smallest entries give the month of the peak and the size of the cycle.

At Mauna Loa the carbon dioxide cycle is about 666 to 7 ppm7\ \text{ppm}7 ppm from peak to trough, with the peak in May. The trend since 2010 is about 2.5 ppm2.5\ \text{ppm}2.5 ppm per year.

A figure in two parts that share a time axis of three years, from January of year 1. The top part shows the monthly carbon dioxide, in parts per million from 403 to 415, as a blue wavy line that rises from left to right and repeats a yearly cycle: it peaks in the spring and has its lowest values in autumn. A red dashed straight line through the middle of the waves is labelled trend, 2.4 parts per million per year. The bottom part shows what is left when the trend is taken away: a green wave about three parts per million above and below zero, with the same peak and trough each year.

Worked example: a tide gauge

Here are seven yearly means of sea level at a gauge, in millimetres above the gauge's datum. They were made up for this example: 7012, 7019, 7031, 7036, 7048, 7053, 7066. Let x=0,1,…,6x = 0, 1, \dots, 6x=0,1,…,6 count the years.

  1. The means. xˉ=3\bar{x} = 3xˉ=3 and yˉ=7037.9 mm\bar{y} = 7037.9\ \text{mm}yˉ​=7037.9 mm.
  2. The sums. Sxx=9+4+1+0+1+4+9=28S_{xx} = 9 + 4 + 1 + 0 + 1 + 4 + 9 = 28Sxx​=9+4+1+0+1+4+9=28. Sxy=247 mm yearS_{xy} = 247\ \text{mm year}Sxy​=247 mm year.
  3. The slope. b=247/28=8.82 mm/yearb = 247/28 = 8.82\ \text{mm/year}b=247/28=8.82 mm/year.
  4. The intercept. a=7037.9−8.82×3=7011.4 mma = 7037.9 - 8.82 \times 3 = 7011.4\ \text{mm}a=7037.9−8.82×3=7011.4 mm.
  5. The fit. R2=0.991R^2 = 0.991R2=0.991, so the line explains 99 %99\ \%99 % of the spread.
  6. A prediction. At x=10x = 10x=10, the line gives 7099.6 mm7099.6\ \text{mm}7099.6 mm. Four years beyond the record, this is an extrapolation, and it assumes that nothing changes.

Take the amplitude to 000. What does the monthly record become? Now set the trend to 000. What is left of the 12-month mean?

Practise with new numbers

Try it in Python

The program fits a line to nine yearly values of a lake's level, finds how well the line fits, and then predicts three years. One of them is far outside the record.

Predict first. Is the prediction for 2040 as reliable as the one for 2019? Then run it. Check with Show the answer.

1. Change the last value from 6.1 to 4.0. What happens to the slope and to R2R^2R2?

2. Add 2020 to the years and 6.4 to the levels. How does the slope change?

Common mistakes

  • Reading a high R2R^2R2 as proof of the model. It says only how much of the scatter the line takes.
  • Predicting far outside the record. The line says nothing about what happens beyond the data.
  • Averaging fewer than twelve months to remove a yearly cycle. Only a whole number of cycles cancels.
  • Mixing the unit of the slope. A slope per month is not a slope per year.

Remember these

  • Record === trend +++ season +++ noise.
  • b=Sxy/Sxxb = S_{xy}/S_{xx}b=Sxy​/Sxx​ and a=yˉ−bxˉa = \bar{y} - b\bar{x}a=yˉ​−bxˉ. The line goes through (xˉ,yˉ)(\bar{x}, \bar{y})(xˉ,yˉ​).
  • R2=1−SSE/SSTR^2 = 1 - \text{SSE}/\text{SST}R2=1−SSE/SST.
  • A 12-month mean removes a yearly cycle. The mean of each calendar month gives the cycle.

Check yourself

Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.

  1. A record rises by 9.6 ppm9.6\ \text{ppm}9.6 ppm in 444 years along its trend line. What is the trend, in ppm per year?
  1. Why does the least-squares line pass through (xˉ,yˉ)(\bar{x}, \bar{y})(xˉ,yˉ​)?
  1. The twelve monthly values of a cycle add to zero. What is the mean of the cycle?
  1. Can the slope of a record of monthly values and of the same record in years be compared directly?

References

  • D. S. Wilks, Statistical Methods in the Atmospheric Sciences (4th edition, Elsevier, 2019), the chapters on Time Series and on Linear Regression.
  • OpenStax, Introductory Statistics (2nd edition), the chapter Linear Regression and Correlation.
  • NOAA Global Monitoring Laboratory, Trends in atmospheric carbon dioxide, the Mauna Loa record, for the size of the trend and of the cycle.

Enroll free in Earth Data with Python: Trends, Anomalies and Models

Every lesson is open to read. Enrolling also lets you:

  • Mark lessons done and carry on where you stopped.
  • Take the tests of this lesson and its course.
  • Count the course towards the certificate for its chapter.
No payment. You can leave at any time.

Problems (3)

The annual mean carbon dioxide of a remote station, rounded to 0.1 ppm, was as follows…Hard · High School (11–12) · by StemPy Lab
A station's monthly carbon dioxide is modelled by c(t) = 405 + 0.21 t + 3.1 cos(2π(t - 4.5)/12) in…Advanced · High School (11–12) · by StemPy Lab
At a gauging station on a river the stage h, the height of the water in metres, was measured…Advanced · High School (11–12) · by StemPy Lab
Next: lesson 2Anomalies, baselines and uncertainty
← Earth Data with Python: Trends, Anomalies and Models
← PreviousAnomalies, baselines and uncertainty →

Discussion (0)

Log in to join the discussion.

Loading…

1 Python program
5 questions to check yourself

This lesson is free to read. Enroll free to keep your place and take the tests.

Python Labs (1)

A carbon dioxide record: trend and cyclePython Lab · by StemPy Lab