|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "ea863e05", |
| 6 | + "metadata": { |
| 7 | + "pycharm": { |
| 8 | + "name": "#%% md\n" |
| 9 | + } |
| 10 | + }, |
| 11 | + "source": [ |
| 12 | + "# HW#2: Visualizing Historical Temperature Changes in Singapore\n", |
| 13 | + "\n", |
| 14 | + "```{admonition} Objectives\n", |
| 15 | + ":class: tip\n", |
| 16 | + "\n", |
| 17 | + "This homework will provide you a real-world example in terms of:\n", |
| 18 | + "* how to visualize the GEV distribution\n", |
| 19 | + "* how to visualize time series of temperature anomalies and the trend\n", |
| 20 | + "* how to make beautiful, accessible, and understandable data visualizations\n", |
| 21 | + "\n", |
| 22 | + "Happy coding!\n", |
| 23 | + "```" |
| 24 | + ] |
| 25 | + }, |
| 26 | + { |
| 27 | + "cell_type": "markdown", |
| 28 | + "id": "af48d568", |
| 29 | + "metadata": { |
| 30 | + "pycharm": { |
| 31 | + "name": "#%% md\n" |
| 32 | + } |
| 33 | + }, |
| 34 | + "source": [ |
| 35 | + "```{admonition} Submission Guide\n", |
| 36 | + "\n", |
| 37 | + "Deadline: **Sunday 11:59 pm, 16th November 2025** \n", |
| 38 | + "(Note: Late submissions will not be accepted). \n", |
| 39 | + "\n", |
| 40 | + "Please upload your solutions to [Canvas](https://canvas.nus.edu.sg/courses/77993/assignments) 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. \n", |
| 41 | + "\n", |
| 42 | + "For any questions, feel free to contact Prof. Xiaogang HE ([hexg@nus.edu.sg](mailto:hexg@nus.edu.sg)), Kewei ZHANG ([kewei_zhang@u.nus.edu](mailto:kewei_zhang@u.nus.edu)) or Yifan LU ([yifan_lu@u.nus.edu](mailto:yifan_lu@u.nus.edu)).\n", |
| 43 | + "\n", |
| 44 | + "```" |
| 45 | + ] |
| 46 | + }, |
| 47 | + { |
| 48 | + "cell_type": "code", |
| 49 | + "execution_count": 1, |
| 50 | + "id": "c8ae81f2", |
| 51 | + "metadata": { |
| 52 | + "pycharm": { |
| 53 | + "name": "#%%\n" |
| 54 | + } |
| 55 | + }, |
| 56 | + "outputs": [], |
| 57 | + "source": [ |
| 58 | + "## Fill your student ID and full name below.\n", |
| 59 | + "\n", |
| 60 | + "# Student ID:\n", |
| 61 | + "# Full name:" |
| 62 | + ] |
| 63 | + }, |
| 64 | + { |
| 65 | + "cell_type": "markdown", |
| 66 | + "id": "5abc96cb", |
| 67 | + "metadata": { |
| 68 | + "pycharm": { |
| 69 | + "name": "#%% md\n" |
| 70 | + } |
| 71 | + }, |
| 72 | + "source": [ |
| 73 | + "**Data**:\n", |
| 74 | + "You will need to use the historical (1982-2020) daily mean air temperature data measured at Singapore's Changi station for this homework.\n", |
| 75 | + "You can create a DataFrame using Pandas by reading the file \"../../assets/data/Changi_daily_temperature.csv\"." |
| 76 | + ] |
| 77 | + }, |
| 78 | + { |
| 79 | + "cell_type": "markdown", |
| 80 | + "id": "1b60eb96", |
| 81 | + "metadata": {}, |
| 82 | + "source": [ |
| 83 | + "## Task 1: Visualize the GEV distribution (30 marks)\n", |
| 84 | + "To visualize the GEV distribution, you can:\n", |
| 85 | + "1. Fit the Generalized Extreme Value (GEV) distribution to annual maximum daily temperature data and estimate the GEV parameters using the **L-Moments method**.\n", |
| 86 | + "2. Plot the probability density function (PDF) curve to represent the distribution directly.\n", |
| 87 | + "3. Calculate the return level for a 10-year event and mark it on the plot.\n", |
| 88 | + "4. Shade the plot with different colors to distinguish areas above and below the calculated return level.\n", |
| 89 | + "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](https://xiaoganghe.github.io/python-climate-visuals/chapters/data-visuals/matplotlib-basic.html) for details)." |
| 90 | + ] |
| 91 | + }, |
| 92 | + { |
| 93 | + "cell_type": "markdown", |
| 94 | + "id": "8f7a646f", |
| 95 | + "metadata": {}, |
| 96 | + "source": [ |
| 97 | + "```{admonition} Bonus: 10 marks\n", |
| 98 | + ":class: tip\n", |
| 99 | + "\n", |
| 100 | + "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](https://plotly.com/python/sliders/) and [this tutorial video](https://www.youtube.com/watch?v=gs4d0_AKQi8) may be helpful for this task.\n", |
| 101 | + "\n", |
| 102 | + "```" |
| 103 | + ] |
| 104 | + }, |
| 105 | + { |
| 106 | + "cell_type": "code", |
| 107 | + "execution_count": 2, |
| 108 | + "id": "77f174cb", |
| 109 | + "metadata": {}, |
| 110 | + "outputs": [], |
| 111 | + "source": [ |
| 112 | + "# Your solutions go here.\n", |
| 113 | + "# Use the + icon in the toolbar to add a cell." |
| 114 | + ] |
| 115 | + }, |
| 116 | + { |
| 117 | + "cell_type": "markdown", |
| 118 | + "id": "67c41c3b", |
| 119 | + "metadata": {}, |
| 120 | + "source": [ |
| 121 | + "## Task 2: Visualize the trend of temperature anomaly (70 marks)\n", |
| 122 | + "### Q1: Visualize the time series and local trend (slope) of historical temperature anomalies for Singapore (35 marks)\n", |
| 123 | + "- Calculate the annual mean temperature from the daily data. This will result in a dataset of 39 values — one per year. (5 marks)\n", |
| 124 | + "- 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)\n", |
| 125 | + "- Visualize the change in these annual temperature anomalies over time, ensuring that you include essential non-data elements. (10 marks)\n", |
| 126 | + "- Compute a rolling linear regression (10-year moving window) of annual mean temperature anomalies to estimate how the local warming rate evolves through time. (10 marks)\n", |
| 127 | + "- Plot the resulting slope (°C per decade) against the central year. (5 marks)" |
| 128 | + ] |
| 129 | + }, |
| 130 | + { |
| 131 | + "cell_type": "code", |
| 132 | + "execution_count": 3, |
| 133 | + "id": "a6aa6f17", |
| 134 | + "metadata": { |
| 135 | + "pycharm": { |
| 136 | + "name": "#%%\n" |
| 137 | + } |
| 138 | + }, |
| 139 | + "outputs": [], |
| 140 | + "source": [ |
| 141 | + "# Your solutions go here.\n", |
| 142 | + "# Use the + icon in the toolbar to add a cell." |
| 143 | + ] |
| 144 | + }, |
| 145 | + { |
| 146 | + "cell_type": "markdown", |
| 147 | + "id": "43a25e7c", |
| 148 | + "metadata": { |
| 149 | + "pycharm": { |
| 150 | + "name": "#%% md\n" |
| 151 | + } |
| 152 | + }, |
| 153 | + "source": [ |
| 154 | + "### Q2: Add climate stripes for Singapore (35 marks)\n", |
| 155 | + "\n", |
| 156 | + "- Reproduce the [climate stripes](https://showyourstripes.info/s/asia/singapore) for Singapore using `Matplotlib`. (20 marks)\n", |
| 157 | + "- Overlay the annual temperature anomaly time series and its local trend (from Q1) on top of your generated climate stripes. (15 marks)\n", |
| 158 | + "\n", |
| 159 | + "Tips: \n", |
| 160 | + "- Refer to [this GitHub repository](https://github.com/josephshea/ClimateStripes/blob/master/ClimateStripes-Canada.ipynb) for guidance on creating climate stripes.\n", |
| 161 | + "- 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)." |
| 162 | + ] |
| 163 | + }, |
| 164 | + { |
| 165 | + "cell_type": "code", |
| 166 | + "execution_count": 4, |
| 167 | + "id": "39b394e4", |
| 168 | + "metadata": { |
| 169 | + "pycharm": { |
| 170 | + "name": "#%%\n" |
| 171 | + } |
| 172 | + }, |
| 173 | + "outputs": [], |
| 174 | + "source": [ |
| 175 | + "# Your solutions go here.\n", |
| 176 | + "# Use the + icon in the toolbar to add a cell." |
| 177 | + ] |
| 178 | + }, |
| 179 | + { |
| 180 | + "cell_type": "markdown", |
| 181 | + "id": "14d1fb06", |
| 182 | + "metadata": {}, |
| 183 | + "source": [ |
| 184 | + "```{admonition} Bonus: 10 marks\n", |
| 185 | + ":class: tip\n", |
| 186 | + "\n", |
| 187 | + "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](https://ourworldindata.org/un-population-2024-revision).\n", |
| 188 | + "\n", |
| 189 | + "```" |
| 190 | + ] |
| 191 | + } |
| 192 | + ], |
| 193 | + "metadata": { |
| 194 | + "kernelspec": { |
| 195 | + "display_name": "Python 3 (ipykernel)", |
| 196 | + "language": "python", |
| 197 | + "name": "python3" |
| 198 | + }, |
| 199 | + "language_info": { |
| 200 | + "codemirror_mode": { |
| 201 | + "name": "ipython", |
| 202 | + "version": 3 |
| 203 | + }, |
| 204 | + "file_extension": ".py", |
| 205 | + "mimetype": "text/x-python", |
| 206 | + "name": "python", |
| 207 | + "nbconvert_exporter": "python", |
| 208 | + "pygments_lexer": "ipython3", |
| 209 | + "version": "3.10.13" |
| 210 | + }, |
| 211 | + "toc": { |
| 212 | + "base_numbering": 1, |
| 213 | + "nav_menu": {}, |
| 214 | + "number_sections": true, |
| 215 | + "sideBar": true, |
| 216 | + "skip_h1_title": false, |
| 217 | + "title_cell": "Table of Contents", |
| 218 | + "title_sidebar": "Contents", |
| 219 | + "toc_cell": false, |
| 220 | + "toc_position": {}, |
| 221 | + "toc_section_display": true, |
| 222 | + "toc_window_display": false |
| 223 | + }, |
| 224 | + "varInspector": { |
| 225 | + "cols": { |
| 226 | + "lenName": 16, |
| 227 | + "lenType": 16, |
| 228 | + "lenVar": 40 |
| 229 | + }, |
| 230 | + "kernels_config": { |
| 231 | + "python": { |
| 232 | + "delete_cmd_postfix": "", |
| 233 | + "delete_cmd_prefix": "del ", |
| 234 | + "library": "var_list.py", |
| 235 | + "varRefreshCmd": "print(var_dic_list())" |
| 236 | + }, |
| 237 | + "r": { |
| 238 | + "delete_cmd_postfix": ") ", |
| 239 | + "delete_cmd_prefix": "rm(", |
| 240 | + "library": "var_list.r", |
| 241 | + "varRefreshCmd": "cat(var_dic_list()) " |
| 242 | + } |
| 243 | + }, |
| 244 | + "types_to_exclude": [ |
| 245 | + "module", |
| 246 | + "function", |
| 247 | + "builtin_function_or_method", |
| 248 | + "instance", |
| 249 | + "_Feature" |
| 250 | + ], |
| 251 | + "window_display": false |
| 252 | + } |
| 253 | + }, |
| 254 | + "nbformat": 4, |
| 255 | + "nbformat_minor": 5 |
| 256 | +} |
0 commit comments