{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"2020-11-10 - class #11 - activities.ipynb","provenance":[],"collapsed_sections":[],"toc_visible":true},"kernelspec":{"name":"python3","display_name":"Python 3"}},"cells":[{"cell_type":"markdown","metadata":{"id":"BRAp37uklN9X"},"source":["# Class \\#11 activities"]},{"cell_type":"markdown","metadata":{"id":"8d6J9xZiFtU2"},"source":["# Practice with `xarray`: World Ocean Atlas global ocean temperatures"]},{"cell_type":"code","metadata":{"id":"XR63HVK2Fsu1","executionInfo":{"status":"ok","timestamp":1605052102457,"user_tz":480,"elapsed":4965,"user":{"displayName":"Katy Christensen","photoUrl":"","userId":"13309436073132227481"}},"outputId":"9456c807-81dc-4502-dba7-bef44e1b9004","colab":{"base_uri":"https://localhost:8080/"}},"source":["# Import NumPy, Pandas, xarray, Matplotlib, and datetime at the top of your code\n","import numpy as np\n","import pandas as pd\n","import xarray as xr\n","import matplotlib.pyplot as plt\n","from datetime import datetime, timedelta\n","\n","# Download netCDF4 library\n","!pip install netcdf4 # You can comment this out once it has run\n","\n","# Give Colab access to Google Drive\n","from google.colab import drive\n","drive.mount('/content/drive')"],"execution_count":null,"outputs":[{"output_type":"stream","text":["Collecting netcdf4\n","\u001b[?25l Downloading https://files.pythonhosted.org/packages/09/39/3687b2ba762a709cd97e48dfaf3ae36a78ae603ec3d1487f767ad58a7b2e/netCDF4-1.5.4-cp36-cp36m-manylinux1_x86_64.whl (4.3MB)\n","\u001b[K |████████████████████████████████| 4.3MB 2.7MB/s \n","\u001b[?25hRequirement already satisfied: numpy>=1.9 in /usr/local/lib/python3.6/dist-packages (from netcdf4) (1.18.5)\n","Collecting cftime\n","\u001b[?25l Downloading https://files.pythonhosted.org/packages/81/f4/31cb9b65f462ea960bd334c5466313cb7b8af792f272546b68b7868fccd4/cftime-1.2.1-cp36-cp36m-manylinux1_x86_64.whl (287kB)\n","\u001b[K |████████████████████████████████| 296kB 36.2MB/s \n","\u001b[?25hInstalling collected packages: cftime, netcdf4\n","Successfully installed cftime-1.2.1 netcdf4-1.5.4\n","Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount(\"/content/drive\", force_remount=True).\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"id":"eNufKrAzPJjt"},"source":["# Filepath for World Ocean Atlas 2018 (WOA18) temperature netCDF file\n","\n","# Note: you may need to change this to match your own filepath,\n","# which you can get by opening the left sidebar (folder icon),\n","# navigating to the file, clicking the \"...\" on the file, and\n","# selecting \"Copy path\"\n","filepath = '/content/drive/My Drive/OCEAN 215 - Autumn \\'20/OCEAN 215 - Autumn \\'20 - Course documents/Zoom class slides and notebooks/2020-11-10 - class #11 - data/woa18_temp.nc'"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"2RgrRzzmS2lF"},"source":["## **Breakout rooms, round 1**"]},{"cell_type":"markdown","metadata":{"id":"mgowxnn4Jr0-"},"source":["0. Assign roles:\n","> * **Choose one person to write code and share their screen.**\n","> * **Choose a different person to take notes on the answers to report back to the class.**\n","1. Load the WOA18 netCDF file into xarray using `xr.open_dataset()`.\n","2. Display the data.\n","3. Using just the interactive display, answer the following questions with your group:\n","\n","* How many data variables are there?\n","* The variable abbreviations aren't very informative. Using the attributes button (page icon), can you tell what the variables represent?\n","* What is the time range of the data?\n","* What is the latitude and longitude resolution (spacing) of the data? Note that we call this the \"grid spacing\" or \"resolution\" of the data.\n","* What is the deepest depth level in the data?\n","* Take a peek at the 46 attributes. What is one thing you can learn from them?"]},{"cell_type":"code","metadata":{"id":"7r4RNUVAJr0_","executionInfo":{"status":"ok","timestamp":1605052103990,"user_tz":480,"elapsed":486,"user":{"displayName":"Katy Christensen","photoUrl":"","userId":"13309436073132227481"}},"outputId":"0711efde-fe39-46aa-dae2-104986074610","colab":{"base_uri":"https://localhost:8080/","height":285}},"source":["# Load the data file from Google Drive as an xarray Dataset\n","temp = xr.open_dataset(filepath)\n","\n","# View data and stats\n","display(temp)\n","\n","# Answers\n","# a. 2 variables\n","# b. Average temperature and number of observations per grid cell\n","# c. 1960-2011\n","# d. 1°\n","# e. 5500 m"],"execution_count":null,"outputs":[{"output_type":"display_data","data":{"text/html":["
array([-89.5, -88.5, -87.5, -86.5, -85.5, -84.5, -83.5, -82.5, -81.5, -80.5,\n"," -79.5, -78.5, -77.5, -76.5, -75.5, -74.5, -73.5, -72.5, -71.5, -70.5,\n"," -69.5, -68.5, -67.5, -66.5, -65.5, -64.5, -63.5, -62.5, -61.5, -60.5,\n"," -59.5, -58.5, -57.5, -56.5, -55.5, -54.5, -53.5, -52.5, -51.5, -50.5,\n"," -49.5, -48.5, -47.5, -46.5, -45.5, -44.5, -43.5, -42.5, -41.5, -40.5,\n"," -39.5, -38.5, -37.5, -36.5, -35.5, -34.5, -33.5, -32.5, -31.5, -30.5,\n"," -29.5, -28.5, -27.5, -26.5, -25.5, -24.5, -23.5, -22.5, -21.5, -20.5,\n"," -19.5, -18.5, -17.5, -16.5, -15.5, -14.5, -13.5, -12.5, -11.5, -10.5,\n"," -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,\n"," 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5,\n"," 10.5, 11.5, 12.5, 13.5, 14.5, 15.5, 16.5, 17.5, 18.5, 19.5,\n"," 20.5, 21.5, 22.5, 23.5, 24.5, 25.5, 26.5, 27.5, 28.5, 29.5,\n"," 30.5, 31.5, 32.5, 33.5, 34.5, 35.5, 36.5, 37.5, 38.5, 39.5,\n"," 40.5, 41.5, 42.5, 43.5, 44.5, 45.5, 46.5, 47.5, 48.5, 49.5,\n"," 50.5, 51.5, 52.5, 53.5, 54.5, 55.5, 56.5, 57.5, 58.5, 59.5,\n"," 60.5, 61.5, 62.5, 63.5, 64.5, 65.5, 66.5, 67.5, 68.5, 69.5,\n"," 70.5, 71.5, 72.5, 73.5, 74.5, 75.5, 76.5, 77.5, 78.5, 79.5,\n"," 80.5, 81.5, 82.5, 83.5, 84.5, 85.5, 86.5, 87.5, 88.5, 89.5],\n"," dtype=float32)
array([-179.5, -178.5, -177.5, ..., 177.5, 178.5, 179.5], dtype=float32)
array([0.00e+00, 5.00e+00, 1.00e+01, 1.50e+01, 2.00e+01, 2.50e+01, 3.00e+01,\n"," 3.50e+01, 4.00e+01, 4.50e+01, 5.00e+01, 5.50e+01, 6.00e+01, 6.50e+01,\n"," 7.00e+01, 7.50e+01, 8.00e+01, 8.50e+01, 9.00e+01, 9.50e+01, 1.00e+02,\n"," 1.25e+02, 1.50e+02, 1.75e+02, 2.00e+02, 2.25e+02, 2.50e+02, 2.75e+02,\n"," 3.00e+02, 3.25e+02, 3.50e+02, 3.75e+02, 4.00e+02, 4.25e+02, 4.50e+02,\n"," 4.75e+02, 5.00e+02, 5.50e+02, 6.00e+02, 6.50e+02, 7.00e+02, 7.50e+02,\n"," 8.00e+02, 8.50e+02, 9.00e+02, 9.50e+02, 1.00e+03, 1.05e+03, 1.10e+03,\n"," 1.15e+03, 1.20e+03, 1.25e+03, 1.30e+03, 1.35e+03, 1.40e+03, 1.45e+03,\n"," 1.50e+03, 1.55e+03, 1.60e+03, 1.65e+03, 1.70e+03, 1.75e+03, 1.80e+03,\n"," 1.85e+03, 1.90e+03, 1.95e+03, 2.00e+03, 2.10e+03, 2.20e+03, 2.30e+03,\n"," 2.40e+03, 2.50e+03, 2.60e+03, 2.70e+03, 2.80e+03, 2.90e+03, 3.00e+03,\n"," 3.10e+03, 3.20e+03, 3.30e+03, 3.40e+03, 3.50e+03, 3.60e+03, 3.70e+03,\n"," 3.80e+03, 3.90e+03, 4.00e+03, 4.10e+03, 4.20e+03, 4.30e+03, 4.40e+03,\n"," 4.50e+03, 4.60e+03, 4.70e+03, 4.80e+03, 4.90e+03, 5.00e+03, 5.10e+03,\n"," 5.20e+03, 5.30e+03, 5.40e+03, 5.50e+03], dtype=float32)
array(['1960-01-01T00:00:00.000000000', '1970-01-01T00:00:00.000000000',\n"," '1980-01-01T00:00:00.000000000', '1990-01-01T00:00:00.000000000',\n"," '2000-01-01T00:00:00.000000000', '2011-01-01T00:00:00.000000000'],\n"," dtype='datetime64[ns]')
[39657600 values with dtype=float32]
[39657600 values with dtype=float64]
array([12.13939 , 11.557309, 12.053809, 12.469 , 12.54699 , 12.28359 ],\n"," dtype=float32)
array(46.5, dtype=float32)
array(-127.5, dtype=float32)
array(0., dtype=float32)
array(['1960-01-01T00:00:00.000000000', '1970-01-01T00:00:00.000000000',\n"," '1980-01-01T00:00:00.000000000', '1990-01-01T00:00:00.000000000',\n"," '2000-01-01T00:00:00.000000000', '2011-01-01T00:00:00.000000000'],\n"," dtype='datetime64[ns]')
array([12.28359 , 12.236891, 12.12149 , 11.995391, 11.823 , 11.56039 ,\n"," 11.2394 , 10.86769 , 10.48499 , 10.13469 , 9.80599 , 9.45741 ,\n"," 9.22761 , 9.02841 , 8.845091, 8.67829 , 8.51851 , 8.385091,\n"," 8.262091, 8.151409, 8.057509, 7.78181 , 7.60519 , 7.3891 ,\n"," 7.13661 , 6.87709 , 6.62841 , 6.39269 , 6.17411 , 5.97299 ,\n"," 5.79171 , 5.62489 , 5.4736 , 5.3348 , 5.20839 , 5.09211 ,\n"," 4.98801 , 4.78741 , 4.60779 , 4.44011 , 4.28301 , 4.1431 ,\n"," 3.99991 , 3.86751 , 3.74121 , 3.61401 , 3.49789 , 3.3786 ,\n"," 3.26571 , 3.15461 , 3.05081 , 2.9508 , 2.8504 , 2.75689 ,\n"," 2.6666 , 2.58041 , 2.49761 , 2.41569 , 2.34019 , 2.26849 ,\n"," 2.20359 , 2.1448 , 2.09019 , 2.03921 , 1.99301 , 1.95381 ,\n"," 1.91519 , 1.86401 , 1.8251 , 1.79659 , 1.7768 , 1.76599 ,\n"," 1.76079 , 1.76041 , 1.765 , nan, nan, nan,\n"," nan, nan, nan, nan, nan, nan,\n"," nan, nan, nan, nan, nan, nan,\n"," nan, nan, nan, nan, nan, nan,\n"," nan, nan, nan, nan, nan, nan],\n"," dtype=float32)
array(46.5, dtype=float32)
array(-127.5, dtype=float32)
array([0.00e+00, 5.00e+00, 1.00e+01, 1.50e+01, 2.00e+01, 2.50e+01, 3.00e+01,\n"," 3.50e+01, 4.00e+01, 4.50e+01, 5.00e+01, 5.50e+01, 6.00e+01, 6.50e+01,\n"," 7.00e+01, 7.50e+01, 8.00e+01, 8.50e+01, 9.00e+01, 9.50e+01, 1.00e+02,\n"," 1.25e+02, 1.50e+02, 1.75e+02, 2.00e+02, 2.25e+02, 2.50e+02, 2.75e+02,\n"," 3.00e+02, 3.25e+02, 3.50e+02, 3.75e+02, 4.00e+02, 4.25e+02, 4.50e+02,\n"," 4.75e+02, 5.00e+02, 5.50e+02, 6.00e+02, 6.50e+02, 7.00e+02, 7.50e+02,\n"," 8.00e+02, 8.50e+02, 9.00e+02, 9.50e+02, 1.00e+03, 1.05e+03, 1.10e+03,\n"," 1.15e+03, 1.20e+03, 1.25e+03, 1.30e+03, 1.35e+03, 1.40e+03, 1.45e+03,\n"," 1.50e+03, 1.55e+03, 1.60e+03, 1.65e+03, 1.70e+03, 1.75e+03, 1.80e+03,\n"," 1.85e+03, 1.90e+03, 1.95e+03, 2.00e+03, 2.10e+03, 2.20e+03, 2.30e+03,\n"," 2.40e+03, 2.50e+03, 2.60e+03, 2.70e+03, 2.80e+03, 2.90e+03, 3.00e+03,\n"," 3.10e+03, 3.20e+03, 3.30e+03, 3.40e+03, 3.50e+03, 3.60e+03, 3.70e+03,\n"," 3.80e+03, 3.90e+03, 4.00e+03, 4.10e+03, 4.20e+03, 4.30e+03, 4.40e+03,\n"," 4.50e+03, 4.60e+03, 4.70e+03, 4.80e+03, 4.90e+03, 5.00e+03, 5.10e+03,\n"," 5.20e+03, 5.30e+03, 5.40e+03, 5.50e+03], dtype=float32)
array('2011-01-01T00:00:00.000000000', dtype='datetime64[ns]')