diff --git a/tutorials/Earthdata_Subset_and_Plot.ipynb b/tutorials/Earthdata_Subset_and_Plot.ipynb index 399ab64..c2cf56f 100644 --- a/tutorials/Earthdata_Subset_and_Plot.ipynb +++ b/tutorials/Earthdata_Subset_and_Plot.ipynb @@ -25,7 +25,7 @@ "\n", "1. Example 1 - `earthaccess` and `xarray` for precipitation estimates from [IMERG, Daily Level 3 data](https://doi.org/10.5067/GPM/IMERGDF/DAY/07)\n", "2. Example 2 - `harmony-py` for direct cloud subsetting of precipitable water data from the [DSCOVR EPIC Composite](https://doi.org/10.5067/EPIC/DSCOVR/L2_COMPOSITE_01).\n", - "3. Appendix 1 - Snow cover data from [MODIS/Terra, Daily Level 3 data](https://doi.org/10.5067/MODIS/MOD10C1.061)\n", + "3. Appendix 1 - Snow cover data from [MODIS/Terra, Daily Level 3 data](https://doi.org/10.5067/MODIS/MOD10C1.061) with `rioxarray`\n", "4. Appendix 2 - Snow mass data from [SMAP, 3-hourly Level 4 data](https://doi.org/10.5067/EVKPQZ4AFC4D)\n", " \n", "In the first example, we will be accessing data directly from Amazon Web Services (AWS), specifically in the us-west-2 region, which is where all cloud-hosted NASA Earthdata reside. This shared compute environment (JupyterHub) is also running in the same location. We will then load the data into Python as an `xarray` dataset.\n", @@ -625,28 +625,27 @@ "warnings.filterwarnings('ignore')\n", "from pprint import pprint\n", "\n", - "# Direct access\n", + "# Example 1 imports\n", "import earthaccess\n", - "from pathlib import Path\n", "import xarray as xr\n", "xr.set_options(display_expand_attrs=False)\n", + "import matplotlib.pyplot as plt\n", + "import cartopy.crs as ccrs\n", + "import cartopy.feature as cfeature\n", "\n", - "# Harmony\n", - "from harmony import BBox, Client, Collection, Request, LinkType, CapabilitiesRequest\n", + "# Example 2 imports (Example 1 imports plus these...)\n", "import datetime as dt\n", "import json\n", - "import numpy as np\n", - "\n", - "# Plotting\n", + "from cartopy.mpl.ticker import LatitudeFormatter, LongitudeFormatter\n", "import geopandas as gpd\n", "import geoviews as gv\n", - "from geoviews import opts\n", "gv.extension('bokeh', 'matplotlib', logo=False)\n", - "import cartopy.crs as ccrs\n", - "import cartopy.feature as cfeature\n", - "from cartopy.mpl.ticker import LatitudeFormatter, LongitudeFormatter\n", - "import matplotlib.pyplot as plt\n", + "from harmony import Client, Collection, Request, CapabilitiesRequest\n", + "\n", + "# Appendix 1 imports\n", + "from pathlib import Path\n", "import rioxarray as rxr\n", + "\n", "%matplotlib inline" ] }, @@ -674,7 +673,7 @@ "text": [ "EARTHDATA_USERNAME and EARTHDATA_PASSWORD are not set in the current environment, try setting them or use a different strategy (netrc, interactive)\n", "You're now authenticated with NASA Earthdata Login\n", - "Using token with expiration date: 11/25/2023\n", + "Using token with expiration date: 01/26/2024\n", "Using .netrc file for EDL\n" ] } @@ -730,7 +729,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "9b62a39554ab46098a59f16473f4fa9c", + "model_id": "fd179bfbc37043628d1382e7274a4e3b", "version_major": 2, "version_minor": 0 }, @@ -744,7 +743,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "57fc89da9cb948f0adb223a2f8a0162a", + "model_id": "0364418fcc1345d5b23f8f2eee4e716e", "version_major": 2, "version_minor": 0 }, @@ -758,7 +757,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "3b8abd169b3c4dcd8a92158d53c2a61d", + "model_id": "4c7161e8136d4a5ca98e622563769647", "version_major": 2, "version_minor": 0 }, @@ -777,7 +776,7 @@ "date_start = \"2023-02-24\"\n", "date_end = \"2023-02-26\"\n", "date_range = (date_start, date_end)\n", - "bbox = (-127.0761, 31.6444, -113.9039, 42.6310)\n", + "bbox = (-127.0761, 31.6444, -113.9039, 42.6310) # min lon, min lat, max lon, max lat\n", "\n", "# For reference (e.g., to visualize in https://geojson.io/), here is a GeoJSON representing the above bounding box:\n", "# {\"type\": \"FeatureCollection\", \"features\": [{\"type\": \"Feature\", \"properties\": {}, \"geometry\": {\"type\": \"LineString\", \"bbox\": [-127.0761, 31.6444, -113.9039, 42.631], \"coordinates\": [[-113.9039, 42.631], [-127.0761,42.631], [-127.0761, 31.6444], [-113.9039, 31.6444], [-113.9039, 42.631]]}}]}\n", @@ -792,6 +791,14 @@ "ds = xr.open_mfdataset(earthaccess.open(results))" ] }, + { + "cell_type": "markdown", + "id": "7de0326f-8c8e-4ae1-b8b2-ae0a73f594cb", + "metadata": {}, + "source": [ + "Note that `xarray` works with \"lazy\" computation whenever possible. In this case, the metadata are loaded into JupyterHub memory, but the data arrays and their values are not — until there is a need for them." + ] + }, { "cell_type": "markdown", "id": "f72eb32d-8421-4f54-a2bd-7b8bc3dc531a", @@ -964,7 +971,7 @@ "id": "23fc1e31-656b-4a02-a80f-b6ea11712068", "metadata": {}, "source": [ - "We start with a subset that represents the U.S. state of California. Notice the dimensions of the Dataset and each variable." + "We start with a subset that represents the U.S. state of California. Notice the dimensions of the Dataset and each variable — time, lon, lat, and 'nv' (number of vertices) for the bounds variable." ] }, { @@ -1359,9 +1366,9 @@ " randomError_cnt (time, lon, lat) int8 dask.array<chunksize=(1, 3600, 1800), meta=np.ndarray>\n", " probabilityLiquidPrecipitation (time, lon, lat) int8 dask.array<chunksize=(1, 3600, 1800), meta=np.ndarray>\n", " time_bnds (time, nv) datetime64[ns] dask.array<chunksize=(1, 2), meta=np.ndarray>\n", - "Attributes: (9)