{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"2020-11-17 - class #13 - activities.ipynb","provenance":[],"collapsed_sections":["8d6J9xZiFtU2","mgowxnn4Jr0-","N9jItPk18C8h","-a4JdnQVAyYz","NrWbnRpdGGCf"]},"kernelspec":{"name":"python3","display_name":"Python 3"}},"cells":[{"cell_type":"markdown","metadata":{"id":"BRAp37uklN9X"},"source":["# Class \\#13 activities"]},{"cell_type":"markdown","metadata":{"id":"8d6J9xZiFtU2"},"source":["# **Arctic sea ice satellite measurements**\n","### Practice with Matplotlib, Cartopy, and xarray"]},{"cell_type":"markdown","metadata":{"id":"0xyc3kUDwnm0"},"source":[""]},{"cell_type":"markdown","metadata":{"id":"KFObFLvswmTw"},"source":["1. Uncomment the blocks of code with the installation lines (`!pip install`, etc.). Remember the shortcut to uncomment/comment multiple lines is `Command-/` on Macs or `Control-/` on Windows.\n","\n","2. Then run this cell to install the packages, import libraries, and give Colab access to Google Drive.\n","\n","3. When prompted, click the link to give Colab access to Google Drive, copy the code, and paste back into here."]},{"cell_type":"code","metadata":{"id":"XANgNomokhQp","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1605664459361,"user_tz":480,"elapsed":472,"user":{"displayName":"Ethan C Campbell","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GjCBYTiuomqOsCakND1k_5wj0kYvFY53Jt7kunt=s64","userId":"11255944928409084259"}},"outputId":"2c9a2249-b709-4ef4-fd00-9f88bd373f38"},"source":["# # This code installs the netCDF4 module\n","# # Run this code once per session, then comment it out\n","# !pip install netcdf4\n","\n","# # This code allows Cartopy to work with Google Colab\n","# # Run this code once per session, then comment it out\n","# !grep '^deb ' /etc/apt/sources.list | \\\n","# sed 's/^deb /deb-src /g' | \\\n","# tee /etc/apt/sources.list.d/deb-src.list\n","# !apt-get -qq update\n","# !apt-get -qq build-dep python3-cartopy\n","# !pip uninstall -y shapely\n","# !pip install shapely --no-binary shapely\n","# !pip install cartopy\n","\n","# Import NumPy, xarray, Matplotlib, Cartopy (and related imports)\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","import cartopy.crs as ccrs\n","import cartopy.feature as cfeature\n","from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER\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":["Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount(\"/content/drive\", force_remount=True).\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"id":"Zo-_2hnsuoQ0"},"source":["4. Next, update the filepath below. To find the correct filepath, you can click on the left sidebar (folder icon), navigate to the Class #13 data folder, click the \"...\" on the file, and select \"Copy path.\"\n","\n","5. Add back slashes (`\\`) in front of quotation marks in the filepath, as necessary."]},{"cell_type":"code","metadata":{"id":"XR63HVK2Fsu1"},"source":["# Filepath for Arctic sea ice concentration netCDF file\n","filepath = '/content/drive/MyDrive/OCEAN 215 - Autumn \\'20/OCEAN 215 - Autumn \\'20 - Course documents/Zoom class slides and notebooks/2020-11-17 - class #13 - data/nsidc_sea_ice_cdr_north.nc'"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"bO2CuXiov0hy"},"source":["6. Run the code cell to load and display the netCDF file using `xarray`.\n","\n","7. Notice that there are three dimensions: **lat** (50-90°N), **lon** (-180°E to 180°E), and **time** (1978 to 2020). The data are monthly in **time**."]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/","height":432},"id":"G23NWUapv4LM","executionInfo":{"status":"ok","timestamp":1605653439341,"user_tz":480,"elapsed":459,"user":{"displayName":"Ethan C Campbell","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GjCBYTiuomqOsCakND1k_5wj0kYvFY53Jt7kunt=s64","userId":"11255944928409084259"}},"outputId":"3f913bb9-9eaa-4f1b-eef0-3abdc8ce8759"},"source":["# Load netCDF file using xarray\n","data = xr.open_dataset(filepath)\n","\n","# Display netCDF file\n","display(data)"],"execution_count":null,"outputs":[{"output_type":"display_data","data":{"text/html":["
array(['1978-11-01T00:00:00.000000000', '1978-12-01T00:00:00.000000000',\n"," '1979-01-01T00:00:00.000000000', ..., '2020-08-01T00:00:00.000000000',\n"," '2020-09-01T00:00:00.000000000', '2020-10-01T00:00:00.000000000'],\n"," dtype='datetime64[ns]')
array([-180. , -179.5, -179. , ..., 178.5, 179. , 179.5])
array([50. , 50.25, 50.5 , 50.75, 51. , 51.25, 51.5 , 51.75, 52. , 52.25,\n"," 52.5 , 52.75, 53. , 53.25, 53.5 , 53.75, 54. , 54.25, 54.5 , 54.75,\n"," 55. , 55.25, 55.5 , 55.75, 56. , 56.25, 56.5 , 56.75, 57. , 57.25,\n"," 57.5 , 57.75, 58. , 58.25, 58.5 , 58.75, 59. , 59.25, 59.5 , 59.75,\n"," 60. , 60.25, 60.5 , 60.75, 61. , 61.25, 61.5 , 61.75, 62. , 62.25,\n"," 62.5 , 62.75, 63. , 63.25, 63.5 , 63.75, 64. , 64.25, 64.5 , 64.75,\n"," 65. , 65.25, 65.5 , 65.75, 66. , 66.25, 66.5 , 66.75, 67. , 67.25,\n"," 67.5 , 67.75, 68. , 68.25, 68.5 , 68.75, 69. , 69.25, 69.5 , 69.75,\n"," 70. , 70.25, 70.5 , 70.75, 71. , 71.25, 71.5 , 71.75, 72. , 72.25,\n"," 72.5 , 72.75, 73. , 73.25, 73.5 , 73.75, 74. , 74.25, 74.5 , 74.75,\n"," 75. , 75.25, 75.5 , 75.75, 76. , 76.25, 76.5 , 76.75, 77. , 77.25,\n"," 77.5 , 77.75, 78. , 78.25, 78.5 , 78.75, 79. , 79.25, 79.5 , 79.75,\n"," 80. , 80.25, 80.5 , 80.75, 81. , 81.25, 81.5 , 81.75, 82. , 82.25,\n"," 82.5 , 82.75, 83. , 83.25, 83.5 , 83.75, 84. , 84.25, 84.5 , 84.75,\n"," 85. , 85.25, 85.5 , 85.75, 86. , 86.25, 86.5 , 86.75, 87. , 87.25,\n"," 87.5 , 87.75, 88. , 88.25, 88.5 , 88.75, 89. , 89.25, 89.5 , 89.75])
array([11, 12, 1, ..., 8, 9, 10])
[57945600 values with dtype=float64]