Analysis of data from a weather station

Analysis of data from a weather station#

Context and Objectives#

The objective of this tutorial is to introduce the core steps of data processing and basic data analysis through the manipulation of a real-world temperature dataset of significant size. The tutorial follows a pragmatic and progressive approach, focusing on essential tools and methods commonly used in engineering data analysis.

The work is structured around a typical data analysis workflow, starting from raw data and leading to quantitative indicators and graphical representations.

By completing this tutorial, students will be able to:

  • Load and explore a dataset: Import temperature data from external files using Python, inspect the structure of the dataset, and identify variables, data types, and basic formatting issues.

  • Perform basic data cleaning operations: Handle missing values, filter time periods, select relevant variables, and apply simple transformations required for analysis.

  • Manipulate and aggregate data: Group data over time, compute annual averages, and extract relevant subsets needed for further analysis.

  • Compute descriptive statistics: Calculate elementary statistical quantities such as mean values, extrema, and variability in order to characterize long-term temperature evolution.

  • Visualize data for analysis and communication: Generate clear and informative plots, with particular emphasis on the construction of a Warming Stripe graphic, a compact visualization designed to communicate long-term temperature trends.

Practical objective of the tutorial#

Beyond the methodological aspects, the concrete objective of this tutorial is to produce a Warming Stripe visualization from raw temperature data. Students will start from daily temperature measurements, process and aggregate the data, and finally generate a visual representation highlighting temperature anomalies over time.

Warming stripes
Évolution des températures (“warming stripes”), source : [Wiki - Warming stripes](https://en.wikipedia.org/wiki/Warming_stripes) / WMO.

This final output illustrates how simple data processing and visualization choices can effectively convey complex information, and emphasizes the role of data analysis in scientific communication and dissemination.

The Data set#

The data can be downloaded here for the french departemnt of Haute-Savoie (74). If you wish to use a different area, you can find more data here.

The data set is organized as follows:

  • the description file : Q_descriptif_champs_RR-T-Vent.csv

  • the data from 1950 to 2024 : Q_74_previous-1950-2024_RR-T-Vent.csv

  • the data from 1876 to 1950 : Q_74_1876-1949_RR-T-Vent.csv

The description file gives folowig information about the data columns: `

  • NUM_POSTE : numéro Météo-France du poste sur 8 chiffres

  • NOM_USUEL : nom usuel du poste

  • LAT : latitude, négative au sud (en degrés et millionièmes de degré)

  • LON : longitude, négative à l’ouest de GREENWICH (en degrés et millionièmes de degré)

  • ALTI : altitude du pied de l’abri ou du pluviomètre si pas d’abri (en m)

  • AAAAMMJJ : date de la mesure (année mois jour)

  • RR : quantité de précipitation tombée en 24 heures (de 06h FU le jour J à 06h FU le jour J+1). La valeur relevée à J+1 est affectée au jour J (en mm et 1/10)

  • TN : température minimale sous abri (en °C et 1/10)

  • HTN : heure de TN (hhmm)

  • TX : température maximale sous abri (en °C et 1/10)

  • HTX : heure de TX (hhmm)

  • TM : moyenne quotidienne des températures horaires sous abri (en °C et 1/10)

  • TNTXM : moyenne quotidienne (TN+TX)/2 (en °C et 1/10)

  • TAMPLI : amplitude thermique quotidienne : écart entre TX et TN quotidiens (TX-TN) (en °C et 1/10)

  • TNSOL : température quotidienne minimale à 10 cm au-dessus du sol (en °C et 1/10)

  • TN50 : température quotidienne minimale à 50 cm au-dessus du sol (en °C et 1/10)

  • DG : durée de gel sous abri (T ≤ 0°C) (en mn)

  • FFM : moyenne quotidienne de la force du vent moyenné sur 10 mn, à 10 m (en m/s et 1/10)

  • FF2M : moyenne quotidienne de la force du vent moyenné sur 10 mn, à 2 m (en m/s et 1/10)

  • FXY : maximum quotidien de la force maximale horaire du vent moyenné sur 10 mn, à 10 m (en m/s et 1/10)

  • DXY : direction de FXY (en rose de 360)

  • HXY : heure de FXY (hhmm)

  • FXI : maximum quotidien de la force maximale horaire du vent instantané, à 10 m (en m/s et 1/10)

  • DXI : direction de FXI (en rose de 360)

  • HXI : heure de FXI (hhmm)

  • FXI2 : maximum quotidien de la force maximale horaire du vent instantané, à 2 m (en m/s et 1/10)

  • DXI2 : direction de FXI2 (en rose de 360)

  • HXI2 : heure de FXI2 (hhmm)

  • FXI3S : maximum quotidien de la force maximale horaire du vent moyenné sur 3 s, à 10 m (en m/s et 1/10)

  • DXI3S : direction de FXI3S (en rose de 360)

  • HXI3S : heure de FXI3S (hhmm)

  • DRR : durée des précipitations (en mn) `

# Setup
%matplotlib widget
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib as mpl
from matplotlib import animation, rc, cm

rc("animation", html="html5")

Questions#

Question:

  • What is the file format of the data provided?

  • Which program can you open it with?

  • What is the size of the data file?

  • how many records (rows) does it contain?

  • identify a station that we would like to analyse.

You can use one of the following satation :

  • 74001001 ABONDANCE

  • 74056001 CHAMONIX

  • 74024001 AYZE

  • 74203001 NOVEL

  • 74280001 THONES

  • 74281001 THONON-INRAE

  • 74256001 SALLANCHES

  • 74134002 GETS (LES)

  • 74173001 MEGEVE

  • 74087001 CONTAMINE-SUR- ARVE

  • 74085001 CONTAMINES MJ

Question: Load the data base with pandasand observe the different fields.

Question: Select de data for the station you identified before.

Question: Remove unnecessary columns, keep only the date and the temperature fields (TX, TM, TN).

Question: How the date is formatted? Use the pandas function to_datetime() to convert it to date type data.

Question: Plot the temperature vs time for the selected station.

Question: Compute the annual average of each temperature (TN, TX)? And plot it.

The date object allows to acces date informations. If D is a DATE object :

  • D.dt.year gives the year of the date

  • D.dt.month gives the month of the date

Question: Compute the average temperature on the preindustrial period 1950-1980 and plot it as a horizontal line on the previous plot.

Question: Calculates the gap between this reference temperature and the following years (1980 to 2024).

Question: Make a plot looking like the warming stripes plot shown above.

# a look like warmping stripes plot that you can use
T_dummy = np.random.rand(100)
fig, ax = plt.subplots()
plt.imshow([T_dummy], aspect="auto", cmap=cm.bwr)
# set axis off
ax.axis("off")
plt.show()

Question: using the extra data set Q_74_1876-1949_RR-T-Vent.csv extend the analysis back to 1876.