|
280 | 280 | "cell_type": "markdown",
|
281 | 281 | "metadata": {},
|
282 | 282 | "source": [
|
283 |
| - "### Calculations within a date range\n", |
| 283 | + "## Calculations within a date range\n", |
284 | 284 | "\n",
|
285 | 285 | "One common thing we'd like to do is calculate something about our data over a fixed time range, for example, one year.\n",
|
286 | 286 | "We've seen this idea previously, but just to remind you we can do this by masking our data.\n",
|
| 287 | + "\n", |
| 288 | + "### Removing missing data\n", |
| 289 | + "\n", |
287 | 290 | "First, let's check for any missing data in the `tmax` array."
|
288 | 291 | ]
|
289 | 292 | },
|
|
423 | 426 | "cell_type": "markdown",
|
424 | 427 | "metadata": {},
|
425 | 428 | "source": [
|
426 |
| - "### Splitting dates into separate year, month, day\n", |
| 429 | + "## Splitting dates into separate year, month, and day\n", |
427 | 430 | "\n",
|
428 | 431 | "Now we can go about splitting our dates into separate arrays for the year, month, and day.\n",
|
| 432 | + "\n", |
| 433 | + "### Splitting a single date string\n", |
| 434 | + "\n", |
429 | 435 | "As a reminder, it is first useful to recall that character strings can be sliced using index values just like arrays."
|
430 | 436 | ]
|
431 | 437 | },
|
|
462 | 468 | "cell_type": "markdown",
|
463 | 469 | "metadata": {},
|
464 | 470 | "source": [
|
| 471 | + "### Splitting dates in a NumPy array\n", |
| 472 | + "\n", |
465 | 473 | "With this in mind, we can now attempt the same in our NumPy array `date_clean_str`."
|
466 | 474 | ]
|
467 | 475 | },
|
|
534 | 542 | "cell_type": "markdown",
|
535 | 543 | "metadata": {},
|
536 | 544 | "source": [
|
537 |
| - "### Finding the average monthly max temperature\n", |
| 545 | + "## Finding averages in a date range\n", |
538 | 546 | "\n",
|
539 | 547 | "Now that we have separate arrays for the year, month, and day we can do some fun stuff like calculate the monthly average temperature for a given year.\n",
|
| 548 | + "\n", |
| 549 | + "### Finding the average monthly max temperature\n", |
| 550 | + "\n", |
540 | 551 | "Let's take 2010 again as our example and find the average temperatures for each month in 2010.\n",
|
541 | 552 | "For this, we can use a `for` loop."
|
542 | 553 | ]
|
|
571 | 582 | "1. We created an array of zeros with 12 locations to store the monthly average temperatures.\n",
|
572 | 583 | "2. We used an index variable called `index` to define where to store those monthly average temperatures. We could have done this differently, but there is a good reason to use `index` here because it is more flexible if we wanted to consider more than one year of data as you'll see in this week's exercise.\n",
|
573 | 584 | "3. We then used a `for` loop to go through each unique month (found using `np.unique()`).\n",
|
574 |
| - "4. For each month we found the max temperature using the condition `month == month_now`, and taking the `tmax_clean.mean()` for that month.\n", |
| 585 | + "4. For each month we found the max temperature using the condition `month == month_now`, and taking the `tmax_clean.mean()` for that month. We also limit the months to those in 2010 by using the `year == '2010'` condition.\n", |
575 | 586 | "5. We added `1` to the `index` value to ensure the next mean value goes into the correct location in the `means_2010` array.\n",
|
576 | 587 | "\n",
|
577 | 588 | "This might seem a bit complicated, but it is rather powerful as well.\n",
|
|
709 | 720 | "cell_type": "markdown",
|
710 | 721 | "metadata": {},
|
711 | 722 | "source": [
|
712 |
| - "### Comparing monthly temperatures\n", |
| 723 | + "### Calculating temperature anomalies\n", |
713 | 724 | "\n",
|
714 | 725 | "One thing we can do now that we have a mean temperature for February in 2010-2015 is to compare one of those years to the average max temperature in the time period.\n",
|
715 | 726 | "This would give us a temperature anomaly, the difference between the mean value and a given year.\n",
|
|
734 | 745 | "cell_type": "markdown",
|
735 | 746 | "metadata": {},
|
736 | 747 | "source": [
|
737 |
| - "As we can see, February of 2010 was 1.7° Fahrenheit warmer than the average February between 2010 and 2015.\n", |
| 748 | + "As we can see, February of 2010 was only 0.08° Fahrenheit warmer than the average February between 2010 and 2015.\n", |
| 749 | + "Pretty typical February, it would seem.\n", |
738 | 750 | "We'll explore exactly this kind of thing in more detail in this week's exercise."
|
739 | 751 | ]
|
740 | 752 | }
|
|
0 commit comments