{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"id": "bd37e360-d885-4ea8-9623-c72813a68d27",
"metadata": {},
"source": [
"# GDPS 🅱\n",
"\n",
"\n",
"\n",
"BETA\n",
"Requires MetPy >=1.6\n",
"\n",
"This demonstrates using data from Canada's GEM Global or Global Deterministic Prediction System (GDPS).\n",
"\n",
"[GDPS Model Description](https://eccc-msc.github.io/open-data/msc-data/nwp_gdps/readme_gdps-datamart_en/#data-location)\n",
"\n",
"\n",
"**Data Sources**\n",
"\n",
"|`prioriy=`|Data source| Archive Duration|\n",
"|--|--|--|\n",
"|`\"mcs\"` | [Meteorological Service of Canada](https://dd.weather.gc.ca/model_gem_global/) | Last 24 hours\n",
"\n",
"**Model Initialization**\n",
"\n",
"Model cyles every twelve hours.\n",
"\n",
"**Forecast Hour**\n",
"\n",
"For the most recent version of GDPS...\n",
"\n",
"|`fxx=`|Forecast lead time|\n",
"|--|--|\n",
"|`0` through `240`, step=3| 3-hourly forecasts available\n",
"\n",
"\n",
"**Products**\n",
"\n",
"|`product=`| Product Description | \n",
"|--|--|\n",
"|`\"15km/grib2/lat_lon\"`| Global domain\n",
"\n",
"**Variable and Level**\n",
"\n",
"You will need to specify the variable and level for each request. \n",
"\n",
"
\n",
"\n",
"\n",
"> **NOTE:** The organization of these files is different than other NWP products.\n",
">\n",
"> 1. There are no index files provided.\n",
"> 1. Each GRIB2 file only contains one message. The variable name and level is in the file's name.\n",
">\n",
"> Herbie requires you provide a keyword argument for both `variable` and `level`. Pay special attention to model description (linked above) to understand how the model data is organized. If you don't provide input for `variable` or `level`, Herbie will give you some ideas. For example, `variable=TMP` and `level=TGL_2` will give you the filename that contains\n",
">\n",
"> ```\n",
"> TMP_TGL_2\n",
"> ```\n",
"\n",
"> **Note:** This requires MetPy version 1.6 or greater which has the capability to parse the _rotated latitude longitude_ map projection type (see [MetPy/#3123](https://github.com/Unidata/MetPy/pull/3123)).\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "c04a6a84-7862-4d19-8460-ba50b5577ac8",
"metadata": {},
"outputs": [],
"source": [
"from herbie import Herbie\n",
"import xarray as xr\n",
"import numpy as np\n",
"\n",
"import matplotlib.pyplot as plt\n",
"from toolbox import EasyMap, pc\n",
"import cartopy.crs as ccrs\n",
"import cartopy.feature as feature\n",
"import pandas as pd\n",
"\n",
"recent = pd.Timestamp(\"now\").floor(\"12h\") - pd.Timedelta(\"12h\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "bced665f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Timestamp('2024-04-11 00:00:00')"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"recent"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "2a6c7cc7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"✅ Found ┊ model=gdps ┊ \u001b[3mproduct=15km/grib2/lat_lon\u001b[0m ┊ \u001b[38;2;41;130;13m2024-Apr-11 00:00 UTC\u001b[92m F30\u001b[0m ┊ \u001b[38;2;255;153;0m\u001b[3mGRIB2 @ msc\u001b[0m ┊ \u001b[38;2;255;153;0m\u001b[3mIDX @ None\u001b[0m\n"
]
},
{
"data": {
"text/plain": [
"'https://dd.weather.gc.ca/model_gem_global/15km/grib2/lat_lon/00/030/CMC_glb_TMP_TGL_2_latlon.15x.15_2024041100_P030.grib2'"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Some examples\n",
"\n",
"H = Herbie(\n",
" recent, # Datetime\n",
" model=\"gdps\",\n",
" fxx=30,\n",
" variable=\"TMP\",\n",
" level=\"TGL_2\",\n",
")\n",
"H.grib"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "e03b7b67",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"✅ Found ┊ model=gdps ┊ \u001b[3mproduct=15km/grib2/lat_lon\u001b[0m ┊ \u001b[38;2;41;130;13m2024-Apr-11 00:00 UTC\u001b[92m F12\u001b[0m ┊ \u001b[38;2;255;153;0m\u001b[3mGRIB2 @ msc\u001b[0m ┊ \u001b[38;2;255;153;0m\u001b[3mIDX @ None\u001b[0m\n"
]
},
{
"data": {
"text/plain": [
"'https://dd.weather.gc.ca/model_gem_global/15km/grib2/lat_lon/00/012/CMC_glb_HGT_ISBL_500_latlon.15x.15_2024041100_P012.grib2'"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"H = Herbie(\n",
" recent, # Datetime\n",
" model=\"gdps\",\n",
" fxx=12,\n",
" variable=\"HGT\",\n",
" level=\"ISBL_500\",\n",
")\n",
"H.grib"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "4fab3cd3",
"metadata": {},
"source": [
"## Get the 2-metre temperature\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "ac4fc277-c878-42a0-843f-ffb60b21661f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"✅ Found ┊ model=gdps ┊ \u001b[3mproduct=15km/grib2/lat_lon\u001b[0m ┊ \u001b[38;2;41;130;13m2024-Apr-11 00:00 UTC\u001b[92m F00\u001b[0m ┊ \u001b[38;2;255;153;0m\u001b[3mGRIB2 @ local\u001b[0m ┊ \u001b[38;2;255;153;0m\u001b[3mIDX @ None\u001b[0m\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/p/home/blaylock/BB_python/Herbie/herbie/core.py:1100: UserWarning: Will not remove GRIB file because it previously existed.\n",
" warnings.warn(\"Will not remove GRIB file because it previously existed.\")\n"
]
},
{
"data": {
"text/html": [
"
<xarray.Dataset> Size: 12MB\n", "Dimensions: (latitude: 1201, longitude: 2400)\n", "Coordinates:\n", " time datetime64[ns] 8B 2024-04-11\n", " step timedelta64[ns] 8B 00:00:00\n", " heightAboveGround float64 8B 2.0\n", " * latitude (latitude) float64 10kB -90.0 -89.85 ... 89.85 90.0\n", " * longitude (longitude) float64 19kB -180.0 -179.8 ... 179.7 179.8\n", " valid_time datetime64[ns] 8B ...\n", "Data variables:\n", " t2m (latitude, longitude) float32 12MB ...\n", " gribfile_projection object 8B None\n", "Attributes:\n", " GRIB_edition: 2\n", " GRIB_centre: cwao\n", " GRIB_centreDescription: Canadian Meteorological Service - Montreal\n", " GRIB_subCentre: 0\n", " Conventions: CF-1.7\n", " institution: Canadian Meteorological Service - Montreal\n", " model: gdps\n", " product: 15km/grib2/lat_lon\n", " description: Canada's Global Deterministic Prediction System ...\n", " remote_grib: /p/cwfs/blaylock/data/gdps/20240411/CMC_glb_TMP_...\n", " local_grib: /p/cwfs/blaylock/data/gdps/20240411/CMC_glb_TMP_...\n", " search: None
<xarray.Dataset> Size: 23MB\n", "Dimensions: (latitude: 1201, longitude: 2400)\n", "Coordinates:\n", " time datetime64[ns] 8B 2024-04-11\n", " step timedelta64[ns] 8B 00:00:00\n", " heightAboveGround float64 8B 10.0\n", " * latitude (latitude) float64 10kB -90.0 -89.85 ... 89.85 90.0\n", " * longitude (longitude) float64 19kB -180.0 -179.8 ... 179.7 179.8\n", " valid_time datetime64[ns] 8B 2024-04-11\n", "Data variables:\n", " u10 (latitude, longitude) float32 12MB ...\n", " gribfile_projection object 8B None\n", " v10 (latitude, longitude) float32 12MB ...\n", "Attributes:\n", " GRIB_edition: 2\n", " GRIB_centre: cwao\n", " GRIB_centreDescription: Canadian Meteorological Service - Montreal\n", " GRIB_subCentre: 0\n", " Conventions: CF-1.7\n", " institution: Canadian Meteorological Service - Montreal\n", " model: gdps\n", " product: 15km/grib2/lat_lon\n", " description: Canada's Global Deterministic Prediction System ...\n", " remote_grib: /p/cwfs/blaylock/data/gdps/20240411/CMC_glb_UGRD...\n", " local_grib: /p/cwfs/blaylock/data/gdps/20240411/CMC_glb_UGRD...\n", " search: None
<cartopy.crs.PlateCarree object at 0x2b334b583d50>" ], "text/plain": [ "
<xarray.Dataset> Size: 23MB\n", "Dimensions: (latitude: 1201, longitude: 2400)\n", "Coordinates:\n", " time datetime64[ns] 8B 2024-04-11\n", " step timedelta64[ns] 8B 00:00:00\n", " isobaricInhPa float64 8B 500.0\n", " * latitude (latitude) float64 10kB -90.0 -89.85 ... 89.85 90.0\n", " * longitude (longitude) float64 19kB -180.0 -179.8 ... 179.7 179.8\n", " valid_time datetime64[ns] 8B 2024-04-11\n", "Data variables:\n", " gh (latitude, longitude) float32 12MB ...\n", " gribfile_projection object 8B None\n", " r (latitude, longitude) float32 12MB ...\n", "Attributes:\n", " GRIB_edition: 2\n", " GRIB_centre: cwao\n", " GRIB_centreDescription: Canadian Meteorological Service - Montreal\n", " GRIB_subCentre: 0\n", " Conventions: CF-1.7\n", " institution: Canadian Meteorological Service - Montreal\n", " model: gdps\n", " product: 15km/grib2/lat_lon\n", " description: Canada's Global Deterministic Prediction System ...\n", " remote_grib: /p/cwfs/blaylock/data/gdps/20240411/CMC_glb_HGT_...\n", " local_grib: /p/cwfs/blaylock/data/gdps/20240411/CMC_glb_HGT_...\n", " search: None