{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "be2c57c1-798a-4eaf-b2b8-41c261b657d1",
   "metadata": {},
   "source": [
    "# How to read data from STAC\n",
    "\n",
    "This notebook shows how to read the data in from a STAC asset using [xarray](https://docs.xarray.dev/en/stable/) and a little hidden helper library called [xpystac](https://pypi.org/project/xpystac/).\n",
    "\n",
    "## tl;dr\n",
    "\n",
    "For any PySTAC object that can be represented as an ndimensional dataset you can read the data using the following command:\n",
    "\n",
    "```python\n",
    "xr.open_dataset(object)\n",
    "```\n",
    "\n",
    "## Dependencies\n",
    "\n",
    "There are lots of optional dependencies depending on where and how the data you are interested in are stored. Here are some of the libraries that you will probably need:\n",
    "\n",
    "- dask - to delay data loading until access\n",
    "- fsspec - to access data from remote storage\n",
    "- pystac - STAC object structures\n",
    "- xarray, rioxarray - data structures\n",
    "- xpystac, stackstac - helper for loading pystac into xarray objects"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "11dddb09-6313-4822-90ba-26eb6e5c143b",
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install adlfs dask 'fsspec[http]' planetary_computer --quiet\n",
    "!pip install stackstac xarray xpystac zarr --quiet"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ad3fb6dc-3529-47bd-a5b3-f5260f23db88",
   "metadata": {},
   "source": [
    "Despite all these install instructions, the import block is very straightforward"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "2a8afebd-b397-4e7a-b448-0f59cc030e66",
   "metadata": {},
   "outputs": [],
   "source": [
    "import xarray as xr\n",
    "\n",
    "import pystac"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6b24745c-b2d5-43d6-9c7e-66458b3a88e3",
   "metadata": {},
   "source": [
    "## Examples\n",
    "\n",
    "Here are a few examples of the different types of objects that you can open in xarray."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "30da7cfd-2861-4095-b15b-9952a7d824d9",
   "metadata": {},
   "source": [
    "### COGs\n",
    "\n",
    "Read all the data from the COGs referenced by the assets on an item."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c77432e6-8b0d-44d2-a947-ec74a529b8cb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "
\n",
       "/* CSS stylesheet for displaying xarray objects in jupyterlab.\n",
       " *\n",
       " */\n",
       "\n",
       ":root {\n",
       "  --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));\n",
       "  --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));\n",
       "  --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));\n",
       "  --xr-border-color: var(--jp-border-color2, #e0e0e0);\n",
       "  --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);\n",
       "  --xr-background-color: var(--jp-layout-color0, white);\n",
       "  --xr-background-color-row-even: var(--jp-layout-color1, white);\n",
       "  --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);\n",
       "}\n",
       "\n",
       "html[theme=dark],\n",
       "body[data-theme=dark],\n",
       "body.vscode-dark {\n",
       "  --xr-font-color0: rgba(255, 255, 255, 1);\n",
       "  --xr-font-color2: rgba(255, 255, 255, 0.54);\n",
       "  --xr-font-color3: rgba(255, 255, 255, 0.38);\n",
       "  --xr-border-color: #1F1F1F;\n",
       "  --xr-disabled-color: #515151;\n",
       "  --xr-background-color: #111111;\n",
       "  --xr-background-color-row-even: #111111;\n",
       "  --xr-background-color-row-odd: #313131;\n",
       "}\n",
       "\n",
       ".xr-wrap {\n",
       "  display: block !important;\n",
       "  min-width: 300px;\n",
       "  max-width: 700px;\n",
       "}\n",
       "\n",
       ".xr-text-repr-fallback {\n",
       "  /* fallback to plain text repr when CSS is not injected (untrusted notebook) */\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-header {\n",
       "  padding-top: 6px;\n",
       "  padding-bottom: 6px;\n",
       "  margin-bottom: 4px;\n",
       "  border-bottom: solid 1px var(--xr-border-color);\n",
       "}\n",
       "\n",
       ".xr-header > div,\n",
       ".xr-header > ul {\n",
       "  display: inline;\n",
       "  margin-top: 0;\n",
       "  margin-bottom: 0;\n",
       "}\n",
       "\n",
       ".xr-obj-type,\n",
       ".xr-array-name {\n",
       "  margin-left: 2px;\n",
       "  margin-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-obj-type {\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-sections {\n",
       "  padding-left: 0 !important;\n",
       "  display: grid;\n",
       "  grid-template-columns: 150px auto auto 1fr 20px 20px;\n",
       "}\n",
       "\n",
       ".xr-section-item {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-section-item input {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-section-item input + label {\n",
       "  color: var(--xr-disabled-color);\n",
       "}\n",
       "\n",
       ".xr-section-item input:enabled + label {\n",
       "  cursor: pointer;\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-section-item input:enabled + label:hover {\n",
       "  color: var(--xr-font-color0);\n",
       "}\n",
       "\n",
       ".xr-section-summary {\n",
       "  grid-column: 1;\n",
       "  color: var(--xr-font-color2);\n",
       "  font-weight: 500;\n",
       "}\n",
       "\n",
       ".xr-section-summary > span {\n",
       "  display: inline-block;\n",
       "  padding-left: 0.5em;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:disabled + label {\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-section-summary-in + label:before {\n",
       "  display: inline-block;\n",
       "  content: '►';\n",
       "  font-size: 11px;\n",
       "  width: 15px;\n",
       "  text-align: center;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:disabled + label:before {\n",
       "  color: var(--xr-disabled-color);\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked + label:before {\n",
       "  content: '▼';\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked + label > span {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-section-summary,\n",
       ".xr-section-inline-details {\n",
       "  padding-top: 4px;\n",
       "  padding-bottom: 4px;\n",
       "}\n",
       "\n",
       ".xr-section-inline-details {\n",
       "  grid-column: 2 / -1;\n",
       "}\n",
       "\n",
       ".xr-section-details {\n",
       "  display: none;\n",
       "  grid-column: 1 / -1;\n",
       "  margin-bottom: 5px;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked ~ .xr-section-details {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-array-wrap {\n",
       "  grid-column: 1 / -1;\n",
       "  display: grid;\n",
       "  grid-template-columns: 20px auto;\n",
       "}\n",
       "\n",
       ".xr-array-wrap > label {\n",
       "  grid-column: 1;\n",
       "  vertical-align: top;\n",
       "}\n",
       "\n",
       ".xr-preview {\n",
       "  color: var(--xr-font-color3);\n",
       "}\n",
       "\n",
       ".xr-array-preview,\n",
       ".xr-array-data {\n",
       "  padding: 0 5px !important;\n",
       "  grid-column: 2;\n",
       "}\n",
       "\n",
       ".xr-array-data,\n",
       ".xr-array-in:checked ~ .xr-array-preview {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-array-in:checked ~ .xr-array-data,\n",
       ".xr-array-preview {\n",
       "  display: inline-block;\n",
       "}\n",
       "\n",
       ".xr-dim-list {\n",
       "  display: inline-block !important;\n",
       "  list-style: none;\n",
       "  padding: 0 !important;\n",
       "  margin: 0;\n",
       "}\n",
       "\n",
       ".xr-dim-list li {\n",
       "  display: inline-block;\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "}\n",
       "\n",
       ".xr-dim-list:before {\n",
       "  content: '(';\n",
       "}\n",
       "\n",
       ".xr-dim-list:after {\n",
       "  content: ')';\n",
       "}\n",
       "\n",
       ".xr-dim-list li:not(:last-child):after {\n",
       "  content: ',';\n",
       "  padding-right: 5px;\n",
       "}\n",
       "\n",
       ".xr-has-index {\n",
       "  font-weight: bold;\n",
       "}\n",
       "\n",
       ".xr-var-list,\n",
       ".xr-var-item {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-var-item > div,\n",
       ".xr-var-item label,\n",
       ".xr-var-item > .xr-var-name span {\n",
       "  background-color: var(--xr-background-color-row-even);\n",
       "  margin-bottom: 0;\n",
       "}\n",
       "\n",
       ".xr-var-item > .xr-var-name:hover span {\n",
       "  padding-right: 5px;\n",
       "}\n",
       "\n",
       ".xr-var-list > li:nth-child(odd) > div,\n",
       ".xr-var-list > li:nth-child(odd) > label,\n",
       ".xr-var-list > li:nth-child(odd) > .xr-var-name span {\n",
       "  background-color: var(--xr-background-color-row-odd);\n",
       "}\n",
       "\n",
       ".xr-var-name {\n",
       "  grid-column: 1;\n",
       "}\n",
       "\n",
       ".xr-var-dims {\n",
       "  grid-column: 2;\n",
       "}\n",
       "\n",
       ".xr-var-dtype {\n",
       "  grid-column: 3;\n",
       "  text-align: right;\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-var-preview {\n",
       "  grid-column: 4;\n",
       "}\n",
       "\n",
       ".xr-index-preview {\n",
       "  grid-column: 2 / 5;\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-var-name,\n",
       ".xr-var-dims,\n",
       ".xr-var-dtype,\n",
       ".xr-preview,\n",
       ".xr-attrs dt {\n",
       "  white-space: nowrap;\n",
       "  overflow: hidden;\n",
       "  text-overflow: ellipsis;\n",
       "  padding-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-var-name:hover,\n",
       ".xr-var-dims:hover,\n",
       ".xr-var-dtype:hover,\n",
       ".xr-attrs dt:hover {\n",
       "  overflow: visible;\n",
       "  width: auto;\n",
       "  z-index: 1;\n",
       "}\n",
       "\n",
       ".xr-var-attrs,\n",
       ".xr-var-data,\n",
       ".xr-index-data {\n",
       "  display: none;\n",
       "  background-color: var(--xr-background-color) !important;\n",
       "  padding-bottom: 5px !important;\n",
       "}\n",
       "\n",
       ".xr-var-attrs-in:checked ~ .xr-var-attrs,\n",
       ".xr-var-data-in:checked ~ .xr-var-data,\n",
       ".xr-index-data-in:checked ~ .xr-index-data {\n",
       "  display: block;\n",
       "}\n",
       "\n",
       ".xr-var-data > table {\n",
       "  float: right;\n",
       "}\n",
       "\n",
       ".xr-var-name span,\n",
       ".xr-var-data,\n",
       ".xr-index-name div,\n",
       ".xr-index-data,\n",
       ".xr-attrs {\n",
       "  padding-left: 25px !important;\n",
       "}\n",
       "\n",
       ".xr-attrs,\n",
       ".xr-var-attrs,\n",
       ".xr-var-data,\n",
       ".xr-index-data {\n",
       "  grid-column: 1 / -1;\n",
       "}\n",
       "\n",
       "dl.xr-attrs {\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "  display: grid;\n",
       "  grid-template-columns: 125px auto;\n",
       "}\n",
       "\n",
       ".xr-attrs dt,\n",
       ".xr-attrs dd {\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "  float: left;\n",
       "  padding-right: 10px;\n",
       "  width: auto;\n",
       "}\n",
       "\n",
       ".xr-attrs dt {\n",
       "  font-weight: normal;\n",
       "  grid-column: 1;\n",
       "}\n",
       "\n",
       ".xr-attrs dt:hover span {\n",
       "  display: inline-block;\n",
       "  background: var(--xr-background-color);\n",
       "  padding-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-attrs dd {\n",
       "  grid-column: 2;\n",
       "  white-space: pre-wrap;\n",
       "  word-break: break-all;\n",
       "}\n",
       "\n",
       ".xr-icon-database,\n",
       ".xr-icon-file-text2,\n",
       ".xr-no-icon {\n",
       "  display: inline-block;\n",
       "  vertical-align: middle;\n",
       "  width: 1em;\n",
       "  height: 1.5em !important;\n",
       "  stroke-width: 0;\n",
       "  stroke: currentColor;\n",
       "  fill: currentColor;\n",
       "}\n",
       "
<xarray.Dataset>\n",
       "Dimensions:                      (time: 1, y: 7802, x: 7762, band: 19)\n",
       "Coordinates: (12/32)\n",
       "  * time                         (time) datetime64[ns] 2023-04-08T23:37:51.63...\n",
       "    id                           (time) <U31 ...\n",
       "  * x                            (x) float64 3.774e+05 3.774e+05 ... 6.102e+05\n",
       "  * y                            (y) float64 -3.713e+06 ... -3.947e+06\n",
       "    proj:shape                   object ...\n",
       "    sci:doi                      <U16 ...\n",
       "    ...                           ...\n",
       "    raster:bands                 (band) object ...\n",
       "    classification:bitfields     (band) object ...\n",
       "    common_name                  (band) object ...\n",
       "    center_wavelength            (band) object ...\n",
       "    full_width_half_max          (band) object ...\n",
       "    epsg                         int64 ...\n",
       "Dimensions without coordinates: band\n",
       "Data variables: (12/19)\n",
       "    qa                           (time, y, x) float64 ...\n",
       "    red                          (time, y, x) float64 ...\n",
       "    blue                         (time, y, x) float64 ...\n",
       "    drad                         (time, y, x) float64 ...\n",
       "    emis                         (time, y, x) float64 ...\n",
       "    emsd                         (time, y, x) float64 ...\n",
       "    ...                           ...\n",
       "    swir16                       (time, y, x) float64 ...\n",
       "    swir22                       (time, y, x) float64 ...\n",
       "    coastal                      (time, y, x) float64 ...\n",
       "    qa_pixel                     (time, y, x) float64 ...\n",
       "    qa_radsat                    (time, y, x) float64 ...\n",
       "    qa_aerosol                   (time, y, x) float64 ...\n",
       "Attributes:\n",
       "    spec:        RasterSpec(epsg=32656, bounds=(377370.0, -3947130.0, 610230....\n",
       "    crs:         epsg:32656\n",
       "    transform:   | 30.00, 0.00, 377370.00|\\n| 0.00,-30.00,-3713070.00|\\n| 0.0...\n",
       "    resolution:  30.0

xarray.Dataset

- Dimensions:

- time: 1
- y: 7802
- x: 7762
- band: 19

- Coordinates: (32)

- 
time

(time)

datetime64[ns]

2023-04-08T23:37:51.630731

array(['2023-04-08T23:37:51.630731000'], dtype='datetime64[ns]')

- 
id

(time)

<U31

...

[1 values with dtype=<U31]

- 
x

(x)

float64

3.774e+05 3.774e+05 ... 6.102e+05

array([377370., 377400., 377430., ..., 610140., 610170., 610200.])

- 
y

(y)

float64

-3.713e+06 ... -3.947e+06

array([-3713070., -3713100., -3713130., ..., -3947040., -3947070., -3947100.])

- 
proj:shape

()

object

...

[1 values with dtype=object]

- 
sci:doi

()

<U16

...

[1 values with dtype=<U16]

- 
landsat:collection_number

()

<U2

...

[1 values with dtype=<U2]

- 
landsat:wrs_path

()

<U3

...

[1 values with dtype=<U3]

- 
landsat:wrs_type

()

<U1

...

[1 values with dtype=<U1]

- 
landsat:wrs_row

()

<U3

...

[1 values with dtype=<U3]

- 
landsat:cloud_cover_land

()

float64

...

[1 values with dtype=float64]

- 
landsat:scene_id

()

<U21

...

[1 values with dtype=<U21]

- 
proj:epsg

()

int64

...

[1 values with dtype=int64]

- 
view:sun_azimuth

()

float64

...

[1 values with dtype=float64]

- 
created

()

<U27

...

[1 values with dtype=<U27]

- 
gsd

(band)

object

...

[19 values with dtype=object]

- 
description

(band)

<U101

...

[19 values with dtype=<U101]

- 
landsat:correction

()

<U4

...

[1 values with dtype=<U4]

- 
instruments

()

object

...

[1 values with dtype=object]

- 
eo:cloud_cover

()

float64

...

[1 values with dtype=float64]

- 
view:off_nadir

()

int64

...

[1 values with dtype=int64]

- 
landsat:collection_category

()

<U2

...

[1 values with dtype=<U2]

- 
platform

()

<U9

...

[1 values with dtype=<U9]

- 
view:sun_elevation

()

float64

...

[1 values with dtype=float64]

- 
proj:transform

()

object

...

[1 values with dtype=object]

- 
title

(band)

<U68

...

[19 values with dtype=<U68]

- 
raster:bands

(band)

object

...

[19 values with dtype=object]

- 
classification:bitfields

(band)

object

...

[19 values with dtype=object]

- 
common_name

(band)

object

...

[19 values with dtype=object]

- 
center_wavelength

(band)

object

...

[19 values with dtype=object]

- 
full_width_half_max

(band)

object

...

[19 values with dtype=object]

- 
epsg

()

int64

...

[1 values with dtype=int64]

- Data variables: (19)

- 
qa

(time, y, x)

float64

...

[60559124 values with dtype=float64]

- 
red

(time, y, x)

float64

...

[60559124 values with dtype=float64]

- 
blue

(time, y, x)

float64

...

[60559124 values with dtype=float64]

- 
drad

(time, y, x)

float64

...

[60559124 values with dtype=float64]

- 
emis

(time, y, x)

float64

...

[60559124 values with dtype=float64]

- 
emsd

(time, y, x)

float64

...

[60559124 values with dtype=float64]

- 
trad

(time, y, x)

float64

...

[60559124 values with dtype=float64]

- 
urad

(time, y, x)

float64

...

[60559124 values with dtype=float64]

- 
atran

(time, y, x)

float64

...

[60559124 values with dtype=float64]

- 
cdist

(time, y, x)

float64

...

[60559124 values with dtype=float64]

- 
green

(time, y, x)

float64

...

[60559124 values with dtype=float64]

- 
nir08

(time, y, x)

float64

...

[60559124 values with dtype=float64]

- 
lwir11

(time, y, x)

float64

...

[60559124 values with dtype=float64]

- 
swir16

(time, y, x)

float64

...

[60559124 values with dtype=float64]

- 
swir22

(time, y, x)

float64

...

[60559124 values with dtype=float64]

- 
coastal

(time, y, x)

float64

...

[60559124 values with dtype=float64]

- 
qa_pixel

(time, y, x)

float64

...

[60559124 values with dtype=float64]

- 
qa_radsat

(time, y, x)

float64

...

[60559124 values with dtype=float64]

- 
qa_aerosol

(time, y, x)

float64

...

[60559124 values with dtype=float64]

- Indexes: (3)

- 

time

PandasIndex

PandasIndex(DatetimeIndex(['2023-04-08 23:37:51.630731'], dtype='datetime64[ns]', name='time', freq=None))

- 

x

PandasIndex

PandasIndex(Float64Index([377370.0, 377400.0, 377430.0, 377460.0, 377490.0, 377520.0,\n",
       "              377550.0, 377580.0, 377610.0, 377640.0,\n",
       "              ...\n",
       "              609930.0, 609960.0, 609990.0, 610020.0, 610050.0, 610080.0,\n",
       "              610110.0, 610140.0, 610170.0, 610200.0],\n",
       "             dtype='float64', name='x', length=7762))

- 

y

PandasIndex

PandasIndex(Float64Index([-3713070.0, -3713100.0, -3713130.0, -3713160.0, -3713190.0,\n",
       "              -3713220.0, -3713250.0, -3713280.0, -3713310.0, -3713340.0,\n",
       "              ...\n",
       "              -3946830.0, -3946860.0, -3946890.0, -3946920.0, -3946950.0,\n",
       "              -3946980.0, -3947010.0, -3947040.0, -3947070.0, -3947100.0],\n",
       "             dtype='float64', name='y', length=7802))

- Attributes: (4)

spec :

RasterSpec(epsg=32656, bounds=(377370.0, -3947130.0, 610230.0, -3713070.0), resolutions_xy=(30.0, 30.0))

crs :

epsg:32656

transform :

| 30.00, 0.00, 377370.00|\n",
       "| 0.00,-30.00,-3713070.00|\n",
       "| 0.00, 0.00, 1.00|

resolution :

30.0

"
      ],
      "text/plain": [
       "<xarray.Dataset>\n",
       "Dimensions:                      (time: 1, y: 7802, x: 7762, band: 19)\n",
       "Coordinates: (12/32)\n",
       "  * time                         (time) datetime64[ns] 2023-04-08T23:37:51.63...\n",
       "    id                           (time) <U31 ...\n",
       "  * x                            (x) float64 3.774e+05 3.774e+05 ... 6.102e+05\n",
       "  * y                            (y) float64 -3.713e+06 ... -3.947e+06\n",
       "    proj:shape                   object ...\n",
       "    sci:doi                      <U16 ...\n",
       "    ...                           ...\n",
       "    raster:bands                 (band) object ...\n",
       "    classification:bitfields     (band) object ...\n",
       "    common_name                  (band) object ...\n",
       "    center_wavelength            (band) object ...\n",
       "    full_width_half_max          (band) object ...\n",
       "    epsg                         int64 ...\n",
       "Dimensions without coordinates: band\n",
       "Data variables: (12/19)\n",
       "    qa                           (time, y, x) float64 ...\n",
       "    red                          (time, y, x) float64 ...\n",
       "    blue                         (time, y, x) float64 ...\n",
       "    drad                         (time, y, x) float64 ...\n",
       "    emis                         (time, y, x) float64 ...\n",
       "    emsd                         (time, y, x) float64 ...\n",
       "    ...                           ...\n",
       "    swir16                       (time, y, x) float64 ...\n",
       "    swir22                       (time, y, x) float64 ...\n",
       "    coastal                      (time, y, x) float64 ...\n",
       "    qa_pixel                     (time, y, x) float64 ...\n",
       "    qa_radsat                    (time, y, x) float64 ...\n",
       "    qa_aerosol                   (time, y, x) float64 ...\n",
       "Attributes:\n",
       "    spec:        RasterSpec(epsg=32656, bounds=(377370.0, -3947130.0, 610230....\n",
       "    crs:         epsg:32656\n",
       "    transform:   | 30.00, 0.00, 377370.00|\\n| 0.00,-30.00,-3713070.00|\\n| 0.0...\n",
       "    resolution:  30.0"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "landsat_item = pystac.Item.from_file(\n",
    "    \"https://planetarycomputer.microsoft.com/api/stac/v1/collections/landsat-c2-l2/items/LC09_L2SP_088084_20230408_02_T2\"\n",
    ")\n",
    "xr.open_dataset(landsat_item)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b2eceda5-7dc7-482c-a95a-7f24f7698933",
   "metadata": {},
   "source": [
    "### Zarr\n",
    "\n",
    "Read from an asset that references data stored in zarr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "5176680b-3d58-4c72-bf58-d80051f6de75",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "
\n",
       "/* CSS stylesheet for displaying xarray objects in jupyterlab.\n",
       " *\n",
       " */\n",
       "\n",
       ":root {\n",
       "  --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));\n",
       "  --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));\n",
       "  --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));\n",
       "  --xr-border-color: var(--jp-border-color2, #e0e0e0);\n",
       "  --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);\n",
       "  --xr-background-color: var(--jp-layout-color0, white);\n",
       "  --xr-background-color-row-even: var(--jp-layout-color1, white);\n",
       "  --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);\n",
       "}\n",
       "\n",
       "html[theme=dark],\n",
       "body[data-theme=dark],\n",
       "body.vscode-dark {\n",
       "  --xr-font-color0: rgba(255, 255, 255, 1);\n",
       "  --xr-font-color2: rgba(255, 255, 255, 0.54);\n",
       "  --xr-font-color3: rgba(255, 255, 255, 0.38);\n",
       "  --xr-border-color: #1F1F1F;\n",
       "  --xr-disabled-color: #515151;\n",
       "  --xr-background-color: #111111;\n",
       "  --xr-background-color-row-even: #111111;\n",
       "  --xr-background-color-row-odd: #313131;\n",
       "}\n",
       "\n",
       ".xr-wrap {\n",
       "  display: block !important;\n",
       "  min-width: 300px;\n",
       "  max-width: 700px;\n",
       "}\n",
       "\n",
       ".xr-text-repr-fallback {\n",
       "  /* fallback to plain text repr when CSS is not injected (untrusted notebook) */\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-header {\n",
       "  padding-top: 6px;\n",
       "  padding-bottom: 6px;\n",
       "  margin-bottom: 4px;\n",
       "  border-bottom: solid 1px var(--xr-border-color);\n",
       "}\n",
       "\n",
       ".xr-header > div,\n",
       ".xr-header > ul {\n",
       "  display: inline;\n",
       "  margin-top: 0;\n",
       "  margin-bottom: 0;\n",
       "}\n",
       "\n",
       ".xr-obj-type,\n",
       ".xr-array-name {\n",
       "  margin-left: 2px;\n",
       "  margin-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-obj-type {\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-sections {\n",
       "  padding-left: 0 !important;\n",
       "  display: grid;\n",
       "  grid-template-columns: 150px auto auto 1fr 20px 20px;\n",
       "}\n",
       "\n",
       ".xr-section-item {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-section-item input {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-section-item input + label {\n",
       "  color: var(--xr-disabled-color);\n",
       "}\n",
       "\n",
       ".xr-section-item input:enabled + label {\n",
       "  cursor: pointer;\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-section-item input:enabled + label:hover {\n",
       "  color: var(--xr-font-color0);\n",
       "}\n",
       "\n",
       ".xr-section-summary {\n",
       "  grid-column: 1;\n",
       "  color: var(--xr-font-color2);\n",
       "  font-weight: 500;\n",
       "}\n",
       "\n",
       ".xr-section-summary > span {\n",
       "  display: inline-block;\n",
       "  padding-left: 0.5em;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:disabled + label {\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-section-summary-in + label:before {\n",
       "  display: inline-block;\n",
       "  content: '►';\n",
       "  font-size: 11px;\n",
       "  width: 15px;\n",
       "  text-align: center;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:disabled + label:before {\n",
       "  color: var(--xr-disabled-color);\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked + label:before {\n",
       "  content: '▼';\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked + label > span {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-section-summary,\n",
       ".xr-section-inline-details {\n",
       "  padding-top: 4px;\n",
       "  padding-bottom: 4px;\n",
       "}\n",
       "\n",
       ".xr-section-inline-details {\n",
       "  grid-column: 2 / -1;\n",
       "}\n",
       "\n",
       ".xr-section-details {\n",
       "  display: none;\n",
       "  grid-column: 1 / -1;\n",
       "  margin-bottom: 5px;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked ~ .xr-section-details {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-array-wrap {\n",
       "  grid-column: 1 / -1;\n",
       "  display: grid;\n",
       "  grid-template-columns: 20px auto;\n",
       "}\n",
       "\n",
       ".xr-array-wrap > label {\n",
       "  grid-column: 1;\n",
       "  vertical-align: top;\n",
       "}\n",
       "\n",
       ".xr-preview {\n",
       "  color: var(--xr-font-color3);\n",
       "}\n",
       "\n",
       ".xr-array-preview,\n",
       ".xr-array-data {\n",
       "  padding: 0 5px !important;\n",
       "  grid-column: 2;\n",
       "}\n",
       "\n",
       ".xr-array-data,\n",
       ".xr-array-in:checked ~ .xr-array-preview {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-array-in:checked ~ .xr-array-data,\n",
       ".xr-array-preview {\n",
       "  display: inline-block;\n",
       "}\n",
       "\n",
       ".xr-dim-list {\n",
       "  display: inline-block !important;\n",
       "  list-style: none;\n",
       "  padding: 0 !important;\n",
       "  margin: 0;\n",
       "}\n",
       "\n",
       ".xr-dim-list li {\n",
       "  display: inline-block;\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "}\n",
       "\n",
       ".xr-dim-list:before {\n",
       "  content: '(';\n",
       "}\n",
       "\n",
       ".xr-dim-list:after {\n",
       "  content: ')';\n",
       "}\n",
       "\n",
       ".xr-dim-list li:not(:last-child):after {\n",
       "  content: ',';\n",
       "  padding-right: 5px;\n",
       "}\n",
       "\n",
       ".xr-has-index {\n",
       "  font-weight: bold;\n",
       "}\n",
       "\n",
       ".xr-var-list,\n",
       ".xr-var-item {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-var-item > div,\n",
       ".xr-var-item label,\n",
       ".xr-var-item > .xr-var-name span {\n",
       "  background-color: var(--xr-background-color-row-even);\n",
       "  margin-bottom: 0;\n",
       "}\n",
       "\n",
       ".xr-var-item > .xr-var-name:hover span {\n",
       "  padding-right: 5px;\n",
       "}\n",
       "\n",
       ".xr-var-list > li:nth-child(odd) > div,\n",
       ".xr-var-list > li:nth-child(odd) > label,\n",
       ".xr-var-list > li:nth-child(odd) > .xr-var-name span {\n",
       "  background-color: var(--xr-background-color-row-odd);\n",
       "}\n",
       "\n",
       ".xr-var-name {\n",
       "  grid-column: 1;\n",
       "}\n",
       "\n",
       ".xr-var-dims {\n",
       "  grid-column: 2;\n",
       "}\n",
       "\n",
       ".xr-var-dtype {\n",
       "  grid-column: 3;\n",
       "  text-align: right;\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-var-preview {\n",
       "  grid-column: 4;\n",
       "}\n",
       "\n",
       ".xr-index-preview {\n",
       "  grid-column: 2 / 5;\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-var-name,\n",
       ".xr-var-dims,\n",
       ".xr-var-dtype,\n",
       ".xr-preview,\n",
       ".xr-attrs dt {\n",
       "  white-space: nowrap;\n",
       "  overflow: hidden;\n",
       "  text-overflow: ellipsis;\n",
       "  padding-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-var-name:hover,\n",
       ".xr-var-dims:hover,\n",
       ".xr-var-dtype:hover,\n",
       ".xr-attrs dt:hover {\n",
       "  overflow: visible;\n",
       "  width: auto;\n",
       "  z-index: 1;\n",
       "}\n",
       "\n",
       ".xr-var-attrs,\n",
       ".xr-var-data,\n",
       ".xr-index-data {\n",
       "  display: none;\n",
       "  background-color: var(--xr-background-color) !important;\n",
       "  padding-bottom: 5px !important;\n",
       "}\n",
       "\n",
       ".xr-var-attrs-in:checked ~ .xr-var-attrs,\n",
       ".xr-var-data-in:checked ~ .xr-var-data,\n",
       ".xr-index-data-in:checked ~ .xr-index-data {\n",
       "  display: block;\n",
       "}\n",
       "\n",
       ".xr-var-data > table {\n",
       "  float: right;\n",
       "}\n",
       "\n",
       ".xr-var-name span,\n",
       ".xr-var-data,\n",
       ".xr-index-name div,\n",
       ".xr-index-data,\n",
       ".xr-attrs {\n",
       "  padding-left: 25px !important;\n",
       "}\n",
       "\n",
       ".xr-attrs,\n",
       ".xr-var-attrs,\n",
       ".xr-var-data,\n",
       ".xr-index-data {\n",
       "  grid-column: 1 / -1;\n",
       "}\n",
       "\n",
       "dl.xr-attrs {\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "  display: grid;\n",
       "  grid-template-columns: 125px auto;\n",
       "}\n",
       "\n",
       ".xr-attrs dt,\n",
       ".xr-attrs dd {\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "  float: left;\n",
       "  padding-right: 10px;\n",
       "  width: auto;\n",
       "}\n",
       "\n",
       ".xr-attrs dt {\n",
       "  font-weight: normal;\n",
       "  grid-column: 1;\n",
       "}\n",
       "\n",
       ".xr-attrs dt:hover span {\n",
       "  display: inline-block;\n",
       "  background: var(--xr-background-color);\n",
       "  padding-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-attrs dd {\n",
       "  grid-column: 2;\n",
       "  white-space: pre-wrap;\n",
       "  word-break: break-all;\n",
       "}\n",
       "\n",
       ".xr-icon-database,\n",
       ".xr-icon-file-text2,\n",
       ".xr-no-icon {\n",
       "  display: inline-block;\n",
       "  vertical-align: middle;\n",
       "  width: 1em;\n",
       "  height: 1.5em !important;\n",
       "  stroke-width: 0;\n",
       "  stroke: currentColor;\n",
       "  fill: currentColor;\n",
       "}\n",
       "
<xarray.Dataset>\n",
       "Dimensions:                  (time: 14965, y: 584, x: 284, nv: 2)\n",
       "Coordinates:\n",
       "    lat                      (y, x) float32 ...\n",
       "    lon                      (y, x) float32 ...\n",
       "  * time                     (time) datetime64[ns] 1980-01-01T12:00:00 ... 20...\n",
       "  * x                        (x) float32 -5.802e+06 -5.801e+06 ... -5.519e+06\n",
       "  * y                        (y) float32 -3.9e+04 -4e+04 ... -6.21e+05 -6.22e+05\n",
       "Dimensions without coordinates: nv\n",
       "Data variables:\n",
       "    dayl                     (time, y, x) float32 ...\n",
       "    lambert_conformal_conic  int16 ...\n",
       "    prcp                     (time, y, x) float32 ...\n",
       "    srad                     (time, y, x) float32 ...\n",
       "    swe                      (time, y, x) float32 ...\n",
       "    time_bnds                (time, nv) datetime64[ns] ...\n",
       "    tmax                     (time, y, x) float32 ...\n",
       "    tmin                     (time, y, x) float32 ...\n",
       "    vp                       (time, y, x) float32 ...\n",
       "    yearday                  (time) int16 ...\n",
       "Attributes:\n",
       "    Conventions:       CF-1.6\n",
       "    Version_data:      Daymet Data Version 4.0\n",
       "    Version_software:  Daymet Software Version 4.0\n",
       "    citation:          Please see http://daymet.ornl.gov/ for current Daymet ...\n",
       "    references:        Please see http://daymet.ornl.gov/ for current informa...\n",
       "    source:            Daymet Software Version 4.0\n",
       "    start_year:        1980

xarray.Dataset

- Dimensions:

- time: 14965
- y: 584
- x: 284
- nv: 2

- Coordinates: (5)

- 
lat

(y, x)

float32

...

long_name :

latitude coordinate

standard_name :

latitude

units :

degrees_north

[165856 values with dtype=float32]

- 
lon

(y, x)

float32

...

long_name :

longitude coordinate

standard_name :

longitude

units :

degrees_east

[165856 values with dtype=float32]

- 
time

(time)

datetime64[ns]

1980-01-01T12:00:00 ... 2020-12-...

bounds :

time_bnds

long_name :

24-hour day based on local time

standard_name :

time

array(['1980-01-01T12:00:00.000000000', '1980-01-02T12:00:00.000000000',\n",
       "       '1980-01-03T12:00:00.000000000', ..., '2020-12-28T12:00:00.000000000',\n",
       "       '2020-12-29T12:00:00.000000000', '2020-12-30T12:00:00.000000000'],\n",
       "      dtype='datetime64[ns]')

- 
x

(x)

float32

-5.802e+06 ... -5.519e+06

long_name :

x coordinate of projection

standard_name :

projection_x_coordinate

units :

m

array([-5802250., -5801250., -5800250., ..., -5521250., -5520250., -5519250.],\n",
       "      dtype=float32)

- 
y

(y)

float32

-3.9e+04 -4e+04 ... -6.22e+05

long_name :

y coordinate of projection

standard_name :

projection_y_coordinate

units :

m

array([ -39000.,  -40000.,  -41000., ..., -620000., -621000., -622000.],\n",
       "      dtype=float32)

- Data variables: (10)

- 
dayl

(time, y, x)

float32

...

cell_methods :

area: mean

grid_mapping :

lambert_conformal_conic

long_name :

daylength

units :

s

[2482035040 values with dtype=float32]

- 
lambert_conformal_conic

()

int16

...

false_easting :

0.0

false_northing :

0.0

grid_mapping_name :

lambert_conformal_conic

inverse_flattening :

298.257223563

latitude_of_projection_origin :

42.5

longitude_of_central_meridian :

-100.0

semi_major_axis :

6378137.0

standard_parallel :

[25.0, 60.0]

[1 values with dtype=int16]

- 
prcp

(time, y, x)

float32

...

cell_methods :

area: mean time: sum

grid_mapping :

lambert_conformal_conic

long_name :

daily total precipitation

units :

mm/day

[2482035040 values with dtype=float32]

- 
srad

(time, y, x)

float32

...

cell_methods :

area: mean time: mean

grid_mapping :

lambert_conformal_conic

long_name :

daylight average incident shortwave radiation

units :

W/m2

[2482035040 values with dtype=float32]

- 
swe

(time, y, x)

float32

...

cell_methods :

area: mean time: mean

grid_mapping :

lambert_conformal_conic

long_name :

snow water equivalent

units :

kg/m2

[2482035040 values with dtype=float32]

- 
time_bnds

(time, nv)

datetime64[ns]

...

[29930 values with dtype=datetime64[ns]]

- 
tmax

(time, y, x)

float32

...

cell_methods :

area: mean time: maximum

grid_mapping :

lambert_conformal_conic

long_name :

daily maximum temperature

units :

degrees C

[2482035040 values with dtype=float32]

- 
tmin

(time, y, x)

float32

...

cell_methods :

area: mean time: minimum

grid_mapping :

lambert_conformal_conic

long_name :

daily minimum temperature

units :

degrees C

[2482035040 values with dtype=float32]

- 
vp

(time, y, x)

float32

...

cell_methods :

area: mean time: mean

grid_mapping :

lambert_conformal_conic

long_name :

daily average vapor pressure

units :

Pa

[2482035040 values with dtype=float32]

- 
yearday

(time)

int16

...

long_name :

day of year (DOY) starting with day 1 on Januaray 1st

[14965 values with dtype=int16]

- Indexes: (3)

- 

time

PandasIndex

PandasIndex(DatetimeIndex(['1980-01-01 12:00:00', '1980-01-02 12:00:00',\n",
       "               '1980-01-03 12:00:00', '1980-01-04 12:00:00',\n",
       "               '1980-01-05 12:00:00', '1980-01-06 12:00:00',\n",
       "               '1980-01-07 12:00:00', '1980-01-08 12:00:00',\n",
       "               '1980-01-09 12:00:00', '1980-01-10 12:00:00',\n",
       "               ...\n",
       "               '2020-12-21 12:00:00', '2020-12-22 12:00:00',\n",
       "               '2020-12-23 12:00:00', '2020-12-24 12:00:00',\n",
       "               '2020-12-25 12:00:00', '2020-12-26 12:00:00',\n",
       "               '2020-12-27 12:00:00', '2020-12-28 12:00:00',\n",
       "               '2020-12-29 12:00:00', '2020-12-30 12:00:00'],\n",
       "              dtype='datetime64[ns]', name='time', length=14965, freq=None))

- 

x

PandasIndex

PandasIndex(Float64Index([-5802250.0, -5801250.0, -5800250.0, -5799250.0, -5798250.0,\n",
       "              -5797250.0, -5796250.0, -5795250.0, -5794250.0, -5793250.0,\n",
       "              ...\n",
       "              -5528250.0, -5527250.0, -5526250.0, -5525250.0, -5524250.0,\n",
       "              -5523250.0, -5522250.0, -5521250.0, -5520250.0, -5519250.0],\n",
       "             dtype='float64', name='x', length=284))

- 

y

PandasIndex

PandasIndex(Float64Index([ -39000.0,  -40000.0,  -41000.0,  -42000.0,  -43000.0,  -44000.0,\n",
       "               -45000.0,  -46000.0,  -47000.0,  -48000.0,\n",
       "              ...\n",
       "              -613000.0, -614000.0, -615000.0, -616000.0, -617000.0, -618000.0,\n",
       "              -619000.0, -620000.0, -621000.0, -622000.0],\n",
       "             dtype='float64', name='y', length=584))

- Attributes: (7)

Conventions :

CF-1.6

Version_data :

Daymet Data Version 4.0

Version_software :

Daymet Software Version 4.0

citation :

Please see http://daymet.ornl.gov/ for current Daymet data citation information

references :

Please see http://daymet.ornl.gov/ for current information on Daymet references

source :

Daymet Software Version 4.0

start_year :

1980

"
      ],
      "text/plain": [
       "<xarray.Dataset>\n",
       "Dimensions:                  (time: 14965, y: 584, x: 284, nv: 2)\n",
       "Coordinates:\n",
       "    lat                      (y, x) float32 ...\n",
       "    lon                      (y, x) float32 ...\n",
       "  * time                     (time) datetime64[ns] 1980-01-01T12:00:00 ... 20...\n",
       "  * x                        (x) float32 -5.802e+06 -5.801e+06 ... -5.519e+06\n",
       "  * y                        (y) float32 -3.9e+04 -4e+04 ... -6.21e+05 -6.22e+05\n",
       "Dimensions without coordinates: nv\n",
       "Data variables:\n",
       "    dayl                     (time, y, x) float32 ...\n",
       "    lambert_conformal_conic  int16 ...\n",
       "    prcp                     (time, y, x) float32 ...\n",
       "    srad                     (time, y, x) float32 ...\n",
       "    swe                      (time, y, x) float32 ...\n",
       "    time_bnds                (time, nv) datetime64[ns] ...\n",
       "    tmax                     (time, y, x) float32 ...\n",
       "    tmin                     (time, y, x) float32 ...\n",
       "    vp                       (time, y, x) float32 ...\n",
       "    yearday                  (time) int16 ...\n",
       "Attributes:\n",
       "    Conventions:       CF-1.6\n",
       "    Version_data:      Daymet Data Version 4.0\n",
       "    Version_software:  Daymet Software Version 4.0\n",
       "    citation:          Please see http://daymet.ornl.gov/ for current Daymet ...\n",
       "    references:        Please see http://daymet.ornl.gov/ for current informa...\n",
       "    source:            Daymet Software Version 4.0\n",
       "    start_year:        1980"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "daymet_collection = pystac.Collection.from_file(\n",
    "    \"https://planetarycomputer.microsoft.com/api/stac/v1/collections/daymet-daily-hi\"\n",
    ")\n",
    "daymet_asset = daymet_collection.assets[\"zarr-abfs\"]\n",
    "\n",
    "xr.open_dataset(daymet_asset)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fd4e0c53-90b0-4276-9caf-9014aa0a31f9",
   "metadata": {},
   "source": [
    "### Reference file\n",
    "\n",
    "If the collection has a reference file we can use that"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "00efc688-a8b8-4b45-8ee8-1aa076a870f4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "
\n",
       "/* CSS stylesheet for displaying xarray objects in jupyterlab.\n",
       " *\n",
       " */\n",
       "\n",
       ":root {\n",
       "  --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));\n",
       "  --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));\n",
       "  --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));\n",
       "  --xr-border-color: var(--jp-border-color2, #e0e0e0);\n",
       "  --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);\n",
       "  --xr-background-color: var(--jp-layout-color0, white);\n",
       "  --xr-background-color-row-even: var(--jp-layout-color1, white);\n",
       "  --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);\n",
       "}\n",
       "\n",
       "html[theme=dark],\n",
       "body[data-theme=dark],\n",
       "body.vscode-dark {\n",
       "  --xr-font-color0: rgba(255, 255, 255, 1);\n",
       "  --xr-font-color2: rgba(255, 255, 255, 0.54);\n",
       "  --xr-font-color3: rgba(255, 255, 255, 0.38);\n",
       "  --xr-border-color: #1F1F1F;\n",
       "  --xr-disabled-color: #515151;\n",
       "  --xr-background-color: #111111;\n",
       "  --xr-background-color-row-even: #111111;\n",
       "  --xr-background-color-row-odd: #313131;\n",
       "}\n",
       "\n",
       ".xr-wrap {\n",
       "  display: block !important;\n",
       "  min-width: 300px;\n",
       "  max-width: 700px;\n",
       "}\n",
       "\n",
       ".xr-text-repr-fallback {\n",
       "  /* fallback to plain text repr when CSS is not injected (untrusted notebook) */\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-header {\n",
       "  padding-top: 6px;\n",
       "  padding-bottom: 6px;\n",
       "  margin-bottom: 4px;\n",
       "  border-bottom: solid 1px var(--xr-border-color);\n",
       "}\n",
       "\n",
       ".xr-header > div,\n",
       ".xr-header > ul {\n",
       "  display: inline;\n",
       "  margin-top: 0;\n",
       "  margin-bottom: 0;\n",
       "}\n",
       "\n",
       ".xr-obj-type,\n",
       ".xr-array-name {\n",
       "  margin-left: 2px;\n",
       "  margin-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-obj-type {\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-sections {\n",
       "  padding-left: 0 !important;\n",
       "  display: grid;\n",
       "  grid-template-columns: 150px auto auto 1fr 20px 20px;\n",
       "}\n",
       "\n",
       ".xr-section-item {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-section-item input {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-section-item input + label {\n",
       "  color: var(--xr-disabled-color);\n",
       "}\n",
       "\n",
       ".xr-section-item input:enabled + label {\n",
       "  cursor: pointer;\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-section-item input:enabled + label:hover {\n",
       "  color: var(--xr-font-color0);\n",
       "}\n",
       "\n",
       ".xr-section-summary {\n",
       "  grid-column: 1;\n",
       "  color: var(--xr-font-color2);\n",
       "  font-weight: 500;\n",
       "}\n",
       "\n",
       ".xr-section-summary > span {\n",
       "  display: inline-block;\n",
       "  padding-left: 0.5em;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:disabled + label {\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-section-summary-in + label:before {\n",
       "  display: inline-block;\n",
       "  content: '►';\n",
       "  font-size: 11px;\n",
       "  width: 15px;\n",
       "  text-align: center;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:disabled + label:before {\n",
       "  color: var(--xr-disabled-color);\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked + label:before {\n",
       "  content: '▼';\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked + label > span {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-section-summary,\n",
       ".xr-section-inline-details {\n",
       "  padding-top: 4px;\n",
       "  padding-bottom: 4px;\n",
       "}\n",
       "\n",
       ".xr-section-inline-details {\n",
       "  grid-column: 2 / -1;\n",
       "}\n",
       "\n",
       ".xr-section-details {\n",
       "  display: none;\n",
       "  grid-column: 1 / -1;\n",
       "  margin-bottom: 5px;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked ~ .xr-section-details {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-array-wrap {\n",
       "  grid-column: 1 / -1;\n",
       "  display: grid;\n",
       "  grid-template-columns: 20px auto;\n",
       "}\n",
       "\n",
       ".xr-array-wrap > label {\n",
       "  grid-column: 1;\n",
       "  vertical-align: top;\n",
       "}\n",
       "\n",
       ".xr-preview {\n",
       "  color: var(--xr-font-color3);\n",
       "}\n",
       "\n",
       ".xr-array-preview,\n",
       ".xr-array-data {\n",
       "  padding: 0 5px !important;\n",
       "  grid-column: 2;\n",
       "}\n",
       "\n",
       ".xr-array-data,\n",
       ".xr-array-in:checked ~ .xr-array-preview {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-array-in:checked ~ .xr-array-data,\n",
       ".xr-array-preview {\n",
       "  display: inline-block;\n",
       "}\n",
       "\n",
       ".xr-dim-list {\n",
       "  display: inline-block !important;\n",
       "  list-style: none;\n",
       "  padding: 0 !important;\n",
       "  margin: 0;\n",
       "}\n",
       "\n",
       ".xr-dim-list li {\n",
       "  display: inline-block;\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "}\n",
       "\n",
       ".xr-dim-list:before {\n",
       "  content: '(';\n",
       "}\n",
       "\n",
       ".xr-dim-list:after {\n",
       "  content: ')';\n",
       "}\n",
       "\n",
       ".xr-dim-list li:not(:last-child):after {\n",
       "  content: ',';\n",
       "  padding-right: 5px;\n",
       "}\n",
       "\n",
       ".xr-has-index {\n",
       "  font-weight: bold;\n",
       "}\n",
       "\n",
       ".xr-var-list,\n",
       ".xr-var-item {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-var-item > div,\n",
       ".xr-var-item label,\n",
       ".xr-var-item > .xr-var-name span {\n",
       "  background-color: var(--xr-background-color-row-even);\n",
       "  margin-bottom: 0;\n",
       "}\n",
       "\n",
       ".xr-var-item > .xr-var-name:hover span {\n",
       "  padding-right: 5px;\n",
       "}\n",
       "\n",
       ".xr-var-list > li:nth-child(odd) > div,\n",
       ".xr-var-list > li:nth-child(odd) > label,\n",
       ".xr-var-list > li:nth-child(odd) > .xr-var-name span {\n",
       "  background-color: var(--xr-background-color-row-odd);\n",
       "}\n",
       "\n",
       ".xr-var-name {\n",
       "  grid-column: 1;\n",
       "}\n",
       "\n",
       ".xr-var-dims {\n",
       "  grid-column: 2;\n",
       "}\n",
       "\n",
       ".xr-var-dtype {\n",
       "  grid-column: 3;\n",
       "  text-align: right;\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-var-preview {\n",
       "  grid-column: 4;\n",
       "}\n",
       "\n",
       ".xr-index-preview {\n",
       "  grid-column: 2 / 5;\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-var-name,\n",
       ".xr-var-dims,\n",
       ".xr-var-dtype,\n",
       ".xr-preview,\n",
       ".xr-attrs dt {\n",
       "  white-space: nowrap;\n",
       "  overflow: hidden;\n",
       "  text-overflow: ellipsis;\n",
       "  padding-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-var-name:hover,\n",
       ".xr-var-dims:hover,\n",
       ".xr-var-dtype:hover,\n",
       ".xr-attrs dt:hover {\n",
       "  overflow: visible;\n",
       "  width: auto;\n",
       "  z-index: 1;\n",
       "}\n",
       "\n",
       ".xr-var-attrs,\n",
       ".xr-var-data,\n",
       ".xr-index-data {\n",
       "  display: none;\n",
       "  background-color: var(--xr-background-color) !important;\n",
       "  padding-bottom: 5px !important;\n",
       "}\n",
       "\n",
       ".xr-var-attrs-in:checked ~ .xr-var-attrs,\n",
       ".xr-var-data-in:checked ~ .xr-var-data,\n",
       ".xr-index-data-in:checked ~ .xr-index-data {\n",
       "  display: block;\n",
       "}\n",
       "\n",
       ".xr-var-data > table {\n",
       "  float: right;\n",
       "}\n",
       "\n",
       ".xr-var-name span,\n",
       ".xr-var-data,\n",
       ".xr-index-name div,\n",
       ".xr-index-data,\n",
       ".xr-attrs {\n",
       "  padding-left: 25px !important;\n",
       "}\n",
       "\n",
       ".xr-attrs,\n",
       ".xr-var-attrs,\n",
       ".xr-var-data,\n",
       ".xr-index-data {\n",
       "  grid-column: 1 / -1;\n",
       "}\n",
       "\n",
       "dl.xr-attrs {\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "  display: grid;\n",
       "  grid-template-columns: 125px auto;\n",
       "}\n",
       "\n",
       ".xr-attrs dt,\n",
       ".xr-attrs dd {\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "  float: left;\n",
       "  padding-right: 10px;\n",
       "  width: auto;\n",
       "}\n",
       "\n",
       ".xr-attrs dt {\n",
       "  font-weight: normal;\n",
       "  grid-column: 1;\n",
       "}\n",
       "\n",
       ".xr-attrs dt:hover span {\n",
       "  display: inline-block;\n",
       "  background: var(--xr-background-color);\n",
       "  padding-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-attrs dd {\n",
       "  grid-column: 2;\n",
       "  white-space: pre-wrap;\n",
       "  word-break: break-all;\n",
       "}\n",
       "\n",
       ".xr-icon-database,\n",
       ".xr-icon-file-text2,\n",
       ".xr-no-icon {\n",
       "  display: inline-block;\n",
       "  vertical-align: middle;\n",
       "  width: 1em;\n",
       "  height: 1.5em !important;\n",
       "  stroke-width: 0;\n",
       "  stroke: currentColor;\n",
       "  fill: currentColor;\n",
       "}\n",
       "
<xarray.Dataset>\n",
       "Dimensions:  (time: 23741, lat: 600, lon: 1440)\n",
       "Coordinates:\n",
       "  * lat      (lat) float64 -59.88 -59.62 -59.38 -59.12 ... 89.38 89.62 89.88\n",
       "  * lon      (lon) float64 0.125 0.375 0.625 0.875 ... 359.1 359.4 359.6 359.9\n",
       "  * time     (time) datetime64[us] 1950-01-01T12:00:00 ... 2014-12-31T12:00:00\n",
       "Data variables:\n",
       "    hurs     (time, lat, lon) float32 ...\n",
       "    huss     (time, lat, lon) float32 ...\n",
       "    pr       (time, lat, lon) float32 ...\n",
       "    rlds     (time, lat, lon) float32 ...\n",
       "    rsds     (time, lat, lon) float32 ...\n",
       "    sfcWind  (time, lat, lon) float32 ...\n",
       "    tas      (time, lat, lon) float32 ...\n",
       "    tasmax   (time, lat, lon) float32 ...\n",
       "    tasmin   (time, lat, lon) float32 ...\n",
       "Attributes: (12/22)\n",
       "    Conventions:           CF-1.7\n",
       "    activity:              NEX-GDDP-CMIP6\n",
       "    cmip6_institution_id:  CSIRO-ARCCSS\n",
       "    cmip6_license:         CC-BY-SA 4.0\n",
       "    cmip6_source_id:       ACCESS-CM2\n",
       "    contact:               Dr. Rama Nemani: rama.nemani@nasa.gov, Dr. Bridget...\n",
       "    ...                    ...\n",
       "    scenario:              historical\n",
       "    source:                BCSD\n",
       "    title:                 ACCESS-CM2, r1i1p1f1, historical, global downscale...\n",
       "    tracking_id:           16d27564-470f-41ea-8077-f4cc3efa5bfe\n",
       "    variant_label:         r1i1p1f1\n",
       "    version:               1.0

xarray.Dataset

- Dimensions:

- time: 23741
- lat: 600
- lon: 1440

- Coordinates: (3)

- 
lat

(lat)

float64

-59.88 -59.62 ... 89.62 89.88

axis :

Y

long_name :

latitude

standard_name :

latitude

units :

degrees_north

array([-59.875, -59.625, -59.375, ...,  89.375,  89.625,  89.875])

- 
lon

(lon)

float64

0.125 0.375 0.625 ... 359.6 359.9

axis :

X

long_name :

longitude

standard_name :

longitude

units :

degrees_east

array([1.25000e-01, 3.75000e-01, 6.25000e-01, ..., 3.59375e+02, 3.59625e+02,\n",
       "       3.59875e+02])

- 
time

(time)

datetime64[us]

1950-01-01T12:00:00 ... 2014-12-...

axis :

T

long_name :

time

standard_name :

time

_FillValue :

1970-01-01T00:00:00.000000

array(['1950-01-01T12:00:00.000000', '1950-01-02T12:00:00.000000',\n",
       "       '1950-01-03T12:00:00.000000', ..., '2014-12-29T12:00:00.000000',\n",
       "       '2014-12-30T12:00:00.000000', '2014-12-31T12:00:00.000000'],\n",
       "      dtype='datetime64[us]')

- Data variables: (9)

- 
hurs

(time, lat, lon)

float32

...

cell_measures :

area: areacella

cell_methods :

area: time: mean

comment :

The relative humidity with respect to liquid water for T> 0 C, and with respect to ice for T<0 C.

long_name :

Near-Surface Relative Humidity

standard_name :

relative_humidity

units :

%

[20512224000 values with dtype=float32]

- 
huss

(time, lat, lon)

float32

...

cell_measures :

area: areacella

cell_methods :

area: time: mean

comment :

Near-surface (usually, 2 meter) specific humidity.

long_name :

Near-Surface Specific Humidity

standard_name :

specific_humidity

units :

1

[20512224000 values with dtype=float32]

- 
pr

(time, lat, lon)

float32

...

cell_measures :

area: areacella

cell_methods :

area: time: mean

comment :

includes both liquid and solid phases

long_name :

Precipitation

standard_name :

precipitation_flux

units :

kg m-2 s-1

[20512224000 values with dtype=float32]

- 
rlds

(time, lat, lon)

float32

...

cell_measures :

area: areacella

cell_methods :

area: time: mean

comment :

The surface called 'surface' means the lower boundary of the atmosphere. 'longwave' means longwave radiation. Downwelling radiation is radiation from above. It does not mean 'net downward'. When thought of as being incident on a surface, a radiative flux is sometimes called 'irradiance'. In addition, it is identical with the quantity measured by a cosine-collector light-meter and sometimes called 'vector irradiance'. In accordance with common usage in geophysical disciplines, 'flux' implies per unit area, called 'flux density' in physics.

long_name :

Surface Downwelling Longwave Radiation

standard_name :

surface_downwelling_longwave_flux_in_air

units :

W m-2

[20512224000 values with dtype=float32]

- 
rsds

(time, lat, lon)

float32

...

cell_measures :

area: areacella

cell_methods :

area: time: mean

comment :

Surface solar irradiance for UV calculations.

long_name :

Surface Downwelling Shortwave Radiation

standard_name :

surface_downwelling_shortwave_flux_in_air

units :

W m-2

[20512224000 values with dtype=float32]

- 
sfcWind

(time, lat, lon)

float32

...

cell_measures :

area: areacella

cell_methods :

area: time: mean

comment :

near-surface (usually, 10 meters) wind speed.

long_name :

Daily-Mean Near-Surface Wind Speed

standard_name :

wind_speed

units :

m s-1

[20512224000 values with dtype=float32]

- 
tas

(time, lat, lon)

float32

...

cell_measures :

area: areacella

cell_methods :

area: mean time: maximum

comment :

near-surface (usually, 2 meter) air temperature; derived from downscaled tasmax & tasmin

long_name :

Daily Near-Surface Air Temperature

standard_name :

air_temperature

units :

K

[20512224000 values with dtype=float32]

- 
tasmax

(time, lat, lon)

float32

...

cell_measures :

area: areacella

cell_methods :

area: mean time: maximum

comment :

maximum near-surface (usually, 2 meter) air temperature (add cell_method attribute 'time: max')

long_name :

Daily Maximum Near-Surface Air Temperature

standard_name :

air_temperature

units :

K

[20512224000 values with dtype=float32]

- 
tasmin

(time, lat, lon)

float32

...

cell_measures :

area: areacella

cell_methods :

area: mean time: minimum

comment :

minimum near-surface (usually, 2 meter) air temperature (add cell_method attribute 'time: min')

long_name :

Daily Minimum Near-Surface Air Temperature

standard_name :

air_temperature

units :

K

[20512224000 values with dtype=float32]

- Indexes: (3)

- 

lat

PandasIndex

PandasIndex(Float64Index([-59.875, -59.625, -59.375, -59.125, -58.875, -58.625, -58.375,\n",
       "              -58.125, -57.875, -57.625,\n",
       "              ...\n",
       "               87.625,  87.875,  88.125,  88.375,  88.625,  88.875,  89.125,\n",
       "               89.375,  89.625,  89.875],\n",
       "             dtype='float64', name='lat', length=600))

- 

lon

PandasIndex

PandasIndex(Float64Index([  0.125,   0.375,   0.625,   0.875,   1.125,   1.375,   1.625,\n",
       "                1.875,   2.125,   2.375,\n",
       "              ...\n",
       "              357.625, 357.875, 358.125, 358.375, 358.625, 358.875, 359.125,\n",
       "              359.375, 359.625, 359.875],\n",
       "             dtype='float64', name='lon', length=1440))

- 

time

PandasIndex

PandasIndex(DatetimeIndex(['1950-01-01 12:00:00', '1950-01-02 12:00:00',\n",
       "               '1950-01-03 12:00:00', '1950-01-04 12:00:00',\n",
       "               '1950-01-05 12:00:00', '1950-01-06 12:00:00',\n",
       "               '1950-01-07 12:00:00', '1950-01-08 12:00:00',\n",
       "               '1950-01-09 12:00:00', '1950-01-10 12:00:00',\n",
       "               ...\n",
       "               '2014-12-22 12:00:00', '2014-12-23 12:00:00',\n",
       "               '2014-12-24 12:00:00', '2014-12-25 12:00:00',\n",
       "               '2014-12-26 12:00:00', '2014-12-27 12:00:00',\n",
       "               '2014-12-28 12:00:00', '2014-12-29 12:00:00',\n",
       "               '2014-12-30 12:00:00', '2014-12-31 12:00:00'],\n",
       "              dtype='datetime64[ns]', name='time', length=23741, freq=None))

- Attributes: (22)

Conventions :

CF-1.7

activity :

NEX-GDDP-CMIP6

cmip6_institution_id :

CSIRO-ARCCSS

cmip6_license :

CC-BY-SA 4.0

cmip6_source_id :

ACCESS-CM2

contact :

Dr. Rama Nemani: rama.nemani@nasa.gov, Dr. Bridget Thrasher: bridget@climateanalyticsgroup.org

creation_date :

2021-10-04T13:59:21.654137+00:00

disclaimer :

This data is considered provisional and subject to change. This data is provided as is without any warranty of any kind, either express or implied, arising by law or otherwise, including but not limited to warranties of completeness, non-infringement, accuracy, merchantability, or fitness for a particular purpose. The user assumes all risk associated with the use of, or inability to use, this data.

external_variables :

areacella

frequency :

day

history :

2021-10-04T13:59:21.654137+00:00: install global attributes

institution :

NASA Earth Exchange, NASA Ames Research Center, Moffett Field, CA 94035

product :

output

realm :

atmos

references :

BCSD method: Thrasher et al., 2012, Hydrol. Earth Syst. Sci.,16, 3309-3314. Ref period obs: latest version of the Princeton Global Meteorological Forcings (http://hydrology.princeton.edu/data.php), based on Sheffield et al., 2006, J. Climate, 19 (13), 3088-3111.

resolution_id :

0.25 degree

scenario :

historical

source :

BCSD

title :

ACCESS-CM2, r1i1p1f1, historical, global downscaled CMIP6 climate projection data

tracking_id :

16d27564-470f-41ea-8077-f4cc3efa5bfe

variant_label :

r1i1p1f1

version :

1.0

"
      ],
      "text/plain": [
       "<xarray.Dataset>\n",
       "Dimensions:  (time: 23741, lat: 600, lon: 1440)\n",
       "Coordinates:\n",
       "  * lat      (lat) float64 -59.88 -59.62 -59.38 -59.12 ... 89.38 89.62 89.88\n",
       "  * lon      (lon) float64 0.125 0.375 0.625 0.875 ... 359.1 359.4 359.6 359.9\n",
       "  * time     (time) datetime64[us] 1950-01-01T12:00:00 ... 2014-12-31T12:00:00\n",
       "Data variables:\n",
       "    hurs     (time, lat, lon) float32 ...\n",
       "    huss     (time, lat, lon) float32 ...\n",
       "    pr       (time, lat, lon) float32 ...\n",
       "    rlds     (time, lat, lon) float32 ...\n",
       "    rsds     (time, lat, lon) float32 ...\n",
       "    sfcWind  (time, lat, lon) float32 ...\n",
       "    tas      (time, lat, lon) float32 ...\n",
       "    tasmax   (time, lat, lon) float32 ...\n",
       "    tasmin   (time, lat, lon) float32 ...\n",
       "Attributes: (12/22)\n",
       "    Conventions:           CF-1.7\n",
       "    activity:              NEX-GDDP-CMIP6\n",
       "    cmip6_institution_id:  CSIRO-ARCCSS\n",
       "    cmip6_license:         CC-BY-SA 4.0\n",
       "    cmip6_source_id:       ACCESS-CM2\n",
       "    contact:               Dr. Rama Nemani: rama.nemani@nasa.gov, Dr. Bridget...\n",
       "    ...                    ...\n",
       "    scenario:              historical\n",
       "    source:                BCSD\n",
       "    title:                 ACCESS-CM2, r1i1p1f1, historical, global downscale...\n",
       "    tracking_id:           16d27564-470f-41ea-8077-f4cc3efa5bfe\n",
       "    variant_label:         r1i1p1f1\n",
       "    version:               1.0"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cmip6_collection = pystac.Collection.from_file(\n",
    "    \"https://planetarycomputer.microsoft.com/api/stac/v1/collections/nasa-nex-gddp-cmip6\"\n",
    ")\n",
    "cmip6_asset = cmip6_collection.assets[\"ACCESS-CM2.historical\"]\n",
    "\n",
    "xr.open_dataset(cmip6_asset)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.8.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
