{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# MetPy Intro: NYS Mesonet Map\n", "---" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "## Overview\n", "In this notebook, we'll use Cartopy, Matplotlib, and Pandas (with a bunch of help from [MetPy](https://unidata.github.io/MetPy)) to read in, manipulate, and visualize current data from the [New York State Mesonet](https://www2.nysmesonet.org)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Prerequisites\n", "\n", "| Concepts | Importance | Notes |\n", "| --- | --- | --- |\n", "| Matplotlib | Necessary | |\n", "| Cartopy | Necessary | |\n", "| Pandas | Necessary | |\n", "| MetPy | Necessary | Intro |\n", "\n", "* **Time to learn**: 30 minutes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "___\n", "## Imports" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import pandas as pd\n", "from datetime import datetime\n", "from cartopy import crs as ccrs\n", "from cartopy import feature as cfeature\n", "from metpy.calc import wind_components, dewpoint_from_relative_humidity\n", "from metpy.units import units\n", "from metpy.plots import StationPlot, USCOUNTIES" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a Pandas `DataFrame` object pointing to the most recent set of NYSM obs." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "nysm_data = pd.read_csv('https://www.atmos.albany.edu/products/nysm/nysm_latest.csv')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "nysm_data.columns" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create several `Series` objects for some of the columns." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "stid = nysm_data['station']\n", "lats = nysm_data['lat']\n", "lons = nysm_data['lon']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Our goal is to make a map of NYSM observations, which includes the wind velocity. The convention is to plot wind velocity using wind barbs. The **MetPy** library allows us to not only make such a map, but perform a variety of meteorologically-relevant calculations and diagnostics. Here, we will use such a calculation, which will determine the two scalar components of wind velocity (*u* and *v*), from wind speed and direction. We will use MetPy's [wind_components](https://unidata.github.io/MetPy/latest/api/generated/metpy.calc.wind_components.html) method. \n", "\n", "This method requires us to do the following:\n", "1. Create Pandas `Series` objects for the variables of interest\n", "1. Extract the underlying Numpy array via the `Series`' `values` attribute\n", "1. Attach units to these arrays using MetPy's `units` class" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Perform these three steps" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "wspd = nysm_data['max_wind_speed_prop [m/s]'].values * units['m/s']\n", "drct = nysm_data['wind_direction_prop [degrees]'].values * units['degree']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "