{ "cells": [ { "cell_type": "markdown", "id": "196d6919", "metadata": {}, "source": [ "# Climatological Means\n", "\n", "In this tutorial, we'll look at how to use wxee to calculate long-term climatological means of gridded weather data. Currently, monthly and daily mean climatologies are supported." ] }, { "cell_type": "markdown", "id": "3081bca9", "metadata": {}, "source": [ "## Setup" ] }, { "cell_type": "code", "execution_count": null, "id": "bb2858a2", "metadata": {}, "outputs": [], "source": [ "!pip install wxee" ] }, { "cell_type": "code", "execution_count": 1, "id": "739f74b7", "metadata": { "ExecuteTime": { "end_time": "2021-09-12T04:10:26.651800Z", "start_time": "2021-09-12T04:10:23.250427Z" } }, "outputs": [], "source": [ "import ee\n", "import wxee\n", "\n", "ee.Authenticate()\n", "wxee.Initialize()" ] }, { "cell_type": "markdown", "id": "7c2f16bc", "metadata": {}, "source": [ "## Create a Time Series" ] }, { "cell_type": "markdown", "id": "1b29c81a", "metadata": {}, "source": [ "Time-based methods in wxee, like temporal aggregation and climatology, work with the `TimeSeries` subclass of `ee.ImageCollection`. To use them, we'll need to create a `TimeSeries`. There are two ways to do this." ] }, { "cell_type": "markdown", "id": "fc5b5bed", "metadata": {}, "source": [ "### From an Image Collection\n", "Create an `ee.ImageCollection` and use the `wx` accessor and the `to_time_series` method to convert the Image Collection to a `TimeSeries`. " ] }, { "cell_type": "code", "execution_count": 2, "id": "7a46bdfa", "metadata": { "ExecuteTime": { "end_time": "2021-09-12T04:10:27.684886Z", "start_time": "2021-09-12T04:10:27.677169Z" }, "scrolled": true }, "outputs": [], "source": [ "rtma = ee.ImageCollection(\"IDAHO_EPSCOR/GRIDMET\")\n", "ts = rtma.wx.to_time_series()" ] }, { "cell_type": "markdown", "id": "87386d6a", "metadata": {}, "source": [ "### From Scratch\n", "As a shortcut, you can create a `TimeSeries` just like you would create an `ee.ImageCollection`. Just pass a collection ID or list of Images." ] }, { "cell_type": "code", "execution_count": 3, "id": "4ec3cc84", "metadata": { "ExecuteTime": { "end_time": "2021-09-12T04:10:28.505760Z", "start_time": "2021-09-12T04:10:28.498234Z" } }, "outputs": [], "source": [ "ts = wxee.TimeSeries(\"IDAHO_EPSCOR/GRIDMET\")" ] }, { "cell_type": "markdown", "id": "f5db4613", "metadata": {}, "source": [ "## Monthly Total Rainfall" ] }, { "cell_type": "markdown", "id": "92465eba", "metadata": {}, "source": [ "gridMET contains daily weather data including precipitation. First, we'll load 10 years of data from 2000 - 2010 into a `TimeSeries`, giving us several thousand daily images." ] }, { "cell_type": "code", "execution_count": 4, "id": "7e88f86f", "metadata": { "ExecuteTime": { "end_time": "2021-09-12T04:10:30.663549Z", "start_time": "2021-09-12T04:10:30.325626Z" } }, "outputs": [ { "data": { "text/plain": [ "3653" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ts = ts.select(\"pr\")\n", "ts = ts.filterDate(\"2000\", \"2010\")\n", "\n", "ts.size().getInfo()" ] }, { "cell_type": "markdown", "id": "c47cd687", "metadata": {}, "source": [ "Now, we'll calculate the monthly mean total rainfall over the 10 years, giving us just 12 images (one per month)." ] }, { "cell_type": "code", "execution_count": 5, "id": "344e2dde", "metadata": { "ExecuteTime": { "end_time": "2021-09-12T04:10:36.786299Z", "start_time": "2021-09-12T04:10:31.880623Z" } }, "outputs": [ { "data": { "text/plain": [ "12" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "clim = ts.climatology_mean(frequency=\"month\", reducer=ee.Reducer.sum())\n", "clim.size().getInfo()" ] }, { "cell_type": "markdown", "id": "53f6cbac", "metadata": {}, "source": [ "