{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Exercise: NetCDF and xarray" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## External formats" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# import the xarray library\n", "import xarray as xr" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# Open the NetCdf file ../data/gfs_example.nc using the Xarray open_dataset method\n", "ds = xr.open_dataset(\"../data/gfs_example.nc\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Inspect the rich set of information about this dataset\n", "# ds" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Which coordinates are in this dataset?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Which convention is used for the latitude dimension, are the values sorted North-South or South-North?\n", "# Why is this relevant when converting a file to Dfs2?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Which data variables are in this dataset?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# What time period does it cover?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# What is the long name of the first data variable?\n", "# Hint: ds.name_of_item.attrs" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# To get the relative humidity at 40N, 10E @ '2021-08-24 02:00' we can use the .sel method like this:\n", "# ds.rh2m.sel(lon=10, lat=40, time='2021-08-24 03:00')\n", "\n", "# What is the surface temperature at 45N, 12E at 2021-08-24 00:00?\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.10.5 ('base')", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.5" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "7aec4f91c09090e98e6ae8203c38529831bb4a3ce54cd1b69639b53cb01a6aa9" } } }, "nbformat": 4, "nbformat_minor": 2 }