HW#2: Visualizing Historical Temperature Changes in Singapore#

Objectives

This homework will provide you a real-world example in terms of:

  • how to visualize the GEV distribution

  • how to visualize time series of temperature anomalies and the trend

  • how to make beautiful, accessible, and understandable data visualizations

Happy coding!

Submission Guide

Deadline: Sunday 11:59 pm, 17th November 2024 (Note: Late submissions will not be accepted).

Please upload your solutions to Canvas in a Jupyter Notebook format with the name “Homework2_StudentID.ipynb”. Make sure to write down your student ID and full name in the cell below.

For any questions, feel free to contact Prof. Xiaogang HE (hexg@nus.edu.sg), Haoling CHEN (h.chen@u.nus.edu) or Meilian LI (limeilian@u.nus.edu).

## Fill your student ID and full name below.

# Student ID:
# Full name:

Data: You will need to use the historical (1982-2020) daily mean air temperature data measured at Singapore’s Changi station for this homework. You can create a DataFrame using Pandas by reading the file “../../assets/data/Changi_daily_temperature.csv”.

Task 1: Visualize the GEV distribution (30 marks)#

To visualize the GEV distribution, you can:

  1. Fit the Generalized Extreme Value (GEV) distribution to annual maximum daily temperature data and estimate the GEV parameters using the L-Moments method.

  2. Plot the probability density function (PDF) curve to represent the distribution directly.

  3. Calculate the return level for a 10-year event and mark it on the plot.

  4. Shade the plot with different colors to distinguish areas above and below the calculated return level.

  5. Ensure that the necessary non-data elements are included, such as title, x/y axis labels, legend, etc. (you can check the Matplotlib tutorial for details).

Bonus: 10 marks

Illustrate how return levels vary across different return periods (e.g., 2, 5, 10, 20, 50, 100 years) using interactive sliders or dashboards. Resources such as the Plotly documentation and this tutorial video may be helpful for this task.

# Your solutions go here.
# Use the + icon in the toolbar to add a cell.

Task 2: Visualize the trend of temperature anomaly (70 marks)#

Q1: Visualize the time series and trend of historical temperature anomalies of Singapore (35 marks)#

  • Calculate the annual mean temperature from the daily data. This will result in a dataset of 39 values — one per year. (5 marks)

  • Calculate the annual temperature anomalies using the first 10-year period as the baseline. (Hint: subtract the mean temperature over 1982 to 1991 from the annual mean temperature for each year.) (5 marks)

  • Visualize the change in these annual temperature anomalies over time, ensuring that you include essential non-data elements. (10 marks)

  • Visualize the trend of the annual temperature anomalies using a 5-year moving window. (15 marks)

# Your solutions go here.
# Use the + icon in the toolbar to add a cell.

Q2: Add climate stripes for Singapore (35 marks)#

  • Reproduce the climate stripes for Singapore using Matplotlib. (20 marks)

  • Use your generated climate stripes as the background and then overlay the time series and the trend of annual anomalies (from Q1) on top of the climate stripes. (15 marks)

Tips:

  • Refer to this GitHub repository for guidance on creating climate stripes.

  • Fine-tune the aesthetics of your chart (e.g., color palette of the diverging colorbar) to ensure it is visually appealing and accessible (colorblind safe).

# Your solutions go here.
# Use the + icon in the toolbar to add a cell.

Bonus: 10 marks

Create an interactive plot where users can hover over climate stripes and trend lines to view detailed information. For inspiration, you can refer to this example.