Created
November 10, 2021 15:36
-
-
Save TomAugspurger/06ea84bd63b19f86cd5560d9c6a8ff9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"id": "85512a6e-ea2f-46d3-aff1-3f0257fc4727", | |
"metadata": {}, | |
"source": [ | |
"# Writing xarray -> COGs\n", | |
"\n", | |
"Hi all,\n", | |
"\n", | |
"I'm looking for guidance / best practices on writing an xarray object to (a collection of) COGs. Let's start with a common case of a DataArray that's indexed by `(time, band, y, x)`. Let's also assume that it's a chunked DataArray, with a chunksize of 1 for `time` and `band`, and it might be chunked along `y` and `x` as well.\n", | |
"\n", | |
"My high-level questions:\n", | |
"\n", | |
"1. Does rioxarray's `.rio.to_raster(path, driver=\"COG\")` have the right defaults? Anything special we should do to make sure we write \"good\" COGs for a single chunk?\n", | |
"2. Is there an established convention for organizing a directory of COG files that represent a 4-d datacube?\n", | |
"\n", | |
"I'm particularly interested in item 2, since I'd like to easily generate STAC Items for this collection of COGs. With a well-structured directory convention, we can easily group multiple STAC Assets (one per COG) that cover the same area in space and time into a STAC item. My proposed naming convention is\n", | |
"\n", | |
"```\n", | |
"<prefix>/time=<time>/band=<band>-y=<y-coord>-x=<x-coord>.tif\n", | |
"```\n", | |
"\n", | |
"This works well for xarray: we have coordinate information available when writing the chunk, so we can safely generate a unique name for a chunk using the `(time, band, y, x)` coordinates of, say, the top-left value in the chunk.\n", | |
"\n", | |
"To make things concrete, here's a small example. I've dumped some code in https://github.com/TomAugspurger/xcog to make this a bit easier to read." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"id": "b69a01e5-2d3c-4270-8d27-fa88898c4d3e", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"!pip install -q -U --no-deps git+https://github.com/TomAugspurger/xcog" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "52af5420-546d-4cdd-81bc-605d91ad2599", | |
"metadata": {}, | |
"source": [ | |
"## Data generation\n", | |
"\n", | |
"We'll mock up some data that has the right structure for pystac / rioxarray to do their thing." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"id": "7652a6b8-a939-49ab-8405-232a0233fe23", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div><svg style=\"position: absolute; width: 0; height: 0; overflow: hidden\">\n", | |
"<defs>\n", | |
"<symbol id=\"icon-database\" viewBox=\"0 0 32 32\">\n", | |
"<path d=\"M16 0c-8.837 0-16 2.239-16 5v4c0 2.761 7.163 5 16 5s16-2.239 16-5v-4c0-2.761-7.163-5-16-5z\"></path>\n", | |
"<path d=\"M16 17c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n", | |
"<path d=\"M16 26c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n", | |
"</symbol>\n", | |
"<symbol id=\"icon-file-text2\" viewBox=\"0 0 32 32\">\n", | |
"<path d=\"M28.681 7.159c-0.694-0.947-1.662-2.053-2.724-3.116s-2.169-2.030-3.116-2.724c-1.612-1.182-2.393-1.319-2.841-1.319h-15.5c-1.378 0-2.5 1.121-2.5 2.5v27c0 1.378 1.122 2.5 2.5 2.5h23c1.378 0 2.5-1.122 2.5-2.5v-19.5c0-0.448-0.137-1.23-1.319-2.841zM24.543 5.457c0.959 0.959 1.712 1.825 2.268 2.543h-4.811v-4.811c0.718 0.556 1.584 1.309 2.543 2.268zM28 29.5c0 0.271-0.229 0.5-0.5 0.5h-23c-0.271 0-0.5-0.229-0.5-0.5v-27c0-0.271 0.229-0.5 0.5-0.5 0 0 15.499-0 15.5 0v7c0 0.552 0.448 1 1 1h7v19.5z\"></path>\n", | |
"<path d=\"M23 26h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n", | |
"<path d=\"M23 22h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n", | |
"<path d=\"M23 18h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n", | |
"</symbol>\n", | |
"</defs>\n", | |
"</svg>\n", | |
"<style>/* 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.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;\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-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", | |
" 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", | |
" 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-attrs {\n", | |
" padding-left: 25px !important;\n", | |
"}\n", | |
"\n", | |
".xr-attrs,\n", | |
".xr-var-attrs,\n", | |
".xr-var-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", | |
" 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", | |
"</style><pre class='xr-text-repr-fallback'><xarray.DataArray 'uniform-872193f5d2193eb685484694f7ebc695' (time: 2, band: 3, y: 10980, x: 10980)>\n", | |
"dask.array<uniform, shape=(2, 3, 10980, 10980), dtype=float64, chunksize=(1, 1, 5490, 5490), chunktype=numpy.ndarray>\n", | |
"Coordinates:\n", | |
" * time (time) datetime64[ns] 2021-01-01T17:07:19.024000 202...\n", | |
" * band (band) <U3 'B02' 'B03' 'B04'\n", | |
" * y (y) float64 4.8e+06 4.8e+06 ... 4.69e+06 4.69e+06\n", | |
" * x (x) float64 4e+05 4e+05 4e+05 ... 5.097e+05 5.098e+05\n", | |
" common_name (band) <U5 'blue' 'green' 'red'\n", | |
" center_wavelength (band) float64 0.49 0.56 0.665\n", | |
" full_width_half_max (band) float64 0.098 0.045 0.038\n", | |
"Attributes:\n", | |
" crs: epsg:32615</pre><div class='xr-wrap' hidden><div class='xr-header'><div class='xr-obj-type'>xarray.DataArray</div><div class='xr-array-name'>'uniform-872193f5d2193eb685484694f7ebc695'</div><ul class='xr-dim-list'><li><span class='xr-has-index'>time</span>: 2</li><li><span class='xr-has-index'>band</span>: 3</li><li><span class='xr-has-index'>y</span>: 10980</li><li><span class='xr-has-index'>x</span>: 10980</li></ul></div><ul class='xr-sections'><li class='xr-section-item'><div class='xr-array-wrap'><input id='section-c99fdb08-903d-40ac-ae18-13864a303205' class='xr-array-in' type='checkbox' checked><label for='section-c99fdb08-903d-40ac-ae18-13864a303205' title='Show/hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-array-preview xr-preview'><span>dask.array<chunksize=(1, 1, 5490, 5490), meta=np.ndarray></span></div><div class='xr-array-data'><table>\n", | |
" <tr>\n", | |
" <td>\n", | |
" <table>\n", | |
" <thead>\n", | |
" <tr>\n", | |
" <td> </td>\n", | |
" <th> Array </th>\n", | |
" <th> Chunk </th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" \n", | |
" <tr>\n", | |
" <th> Bytes </th>\n", | |
" <td> 5.39 GiB </td>\n", | |
" <td> 229.95 MiB </td>\n", | |
" </tr>\n", | |
" \n", | |
" <tr>\n", | |
" <th> Shape </th>\n", | |
" <td> (2, 3, 10980, 10980) </td>\n", | |
" <td> (1, 1, 5490, 5490) </td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th> Count </th>\n", | |
" <td> 24 Tasks </td>\n", | |
" <td> 24 Chunks </td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th> Type </th>\n", | |
" <td> float64 </td>\n", | |
" <td> numpy.ndarray </td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
" </table>\n", | |
" </td>\n", | |
" <td>\n", | |
" <svg width=\"374\" height=\"184\" style=\"stroke:rgb(0,0,0);stroke-width:1\" >\n", | |
"\n", | |
" <!-- Horizontal lines -->\n", | |
" <line x1=\"0\" y1=\"0\" x2=\"25\" y2=\"0\" style=\"stroke-width:2\" />\n", | |
" <line x1=\"0\" y1=\"25\" x2=\"25\" y2=\"25\" style=\"stroke-width:2\" />\n", | |
"\n", | |
" <!-- Vertical lines -->\n", | |
" <line x1=\"0\" y1=\"0\" x2=\"0\" y2=\"25\" style=\"stroke-width:2\" />\n", | |
" <line x1=\"12\" y1=\"0\" x2=\"12\" y2=\"25\" />\n", | |
" <line x1=\"25\" y1=\"0\" x2=\"25\" y2=\"25\" style=\"stroke-width:2\" />\n", | |
"\n", | |
" <!-- Colored Rectangle -->\n", | |
" <polygon points=\"0.0,0.0 25.412616514582485,0.0 25.412616514582485,25.412616514582485 0.0,25.412616514582485\" style=\"fill:#ECB172A0;stroke-width:0\"/>\n", | |
"\n", | |
" <!-- Text -->\n", | |
" <text x=\"12.706308\" y=\"45.412617\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" >2</text>\n", | |
" <text x=\"45.412617\" y=\"12.706308\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" transform=\"rotate(0,45.412617,12.706308)\">1</text>\n", | |
"\n", | |
"\n", | |
" <!-- Horizontal lines -->\n", | |
" <line x1=\"95\" y1=\"0\" x2=\"109\" y2=\"14\" style=\"stroke-width:2\" />\n", | |
" <line x1=\"95\" y1=\"60\" x2=\"109\" y2=\"74\" />\n", | |
" <line x1=\"95\" y1=\"120\" x2=\"109\" y2=\"134\" style=\"stroke-width:2\" />\n", | |
"\n", | |
" <!-- Vertical lines -->\n", | |
" <line x1=\"95\" y1=\"0\" x2=\"95\" y2=\"120\" style=\"stroke-width:2\" />\n", | |
" <line x1=\"99\" y1=\"4\" x2=\"99\" y2=\"124\" />\n", | |
" <line x1=\"104\" y1=\"9\" x2=\"104\" y2=\"129\" />\n", | |
" <line x1=\"109\" y1=\"14\" x2=\"109\" y2=\"134\" style=\"stroke-width:2\" />\n", | |
"\n", | |
" <!-- Colored Rectangle -->\n", | |
" <polygon points=\"95.0,0.0 109.9485979497544,14.948597949754403 109.9485979497544,134.9485979497544 95.0,120.0\" style=\"fill:#ECB172A0;stroke-width:0\"/>\n", | |
"\n", | |
" <!-- Horizontal lines -->\n", | |
" <line x1=\"95\" y1=\"0\" x2=\"215\" y2=\"0\" style=\"stroke-width:2\" />\n", | |
" <line x1=\"99\" y1=\"4\" x2=\"219\" y2=\"4\" />\n", | |
" <line x1=\"104\" y1=\"9\" x2=\"224\" y2=\"9\" />\n", | |
" <line x1=\"109\" y1=\"14\" x2=\"229\" y2=\"14\" style=\"stroke-width:2\" />\n", | |
"\n", | |
" <!-- Vertical lines -->\n", | |
" <line x1=\"95\" y1=\"0\" x2=\"109\" y2=\"14\" style=\"stroke-width:2\" />\n", | |
" <line x1=\"155\" y1=\"0\" x2=\"169\" y2=\"14\" />\n", | |
" <line x1=\"215\" y1=\"0\" x2=\"229\" y2=\"14\" style=\"stroke-width:2\" />\n", | |
"\n", | |
" <!-- Colored Rectangle -->\n", | |
" <polygon points=\"95.0,0.0 215.0,0.0 229.9485979497544,14.948597949754403 109.9485979497544,14.948597949754403\" style=\"fill:#ECB172A0;stroke-width:0\"/>\n", | |
"\n", | |
" <!-- Horizontal lines -->\n", | |
" <line x1=\"109\" y1=\"14\" x2=\"229\" y2=\"14\" style=\"stroke-width:2\" />\n", | |
" <line x1=\"109\" y1=\"74\" x2=\"229\" y2=\"74\" />\n", | |
" <line x1=\"109\" y1=\"134\" x2=\"229\" y2=\"134\" style=\"stroke-width:2\" />\n", | |
"\n", | |
" <!-- Vertical lines -->\n", | |
" <line x1=\"109\" y1=\"14\" x2=\"109\" y2=\"134\" style=\"stroke-width:2\" />\n", | |
" <line x1=\"169\" y1=\"14\" x2=\"169\" y2=\"134\" />\n", | |
" <line x1=\"229\" y1=\"14\" x2=\"229\" y2=\"134\" style=\"stroke-width:2\" />\n", | |
"\n", | |
" <!-- Colored Rectangle -->\n", | |
" <polygon points=\"109.9485979497544,14.948597949754403 229.9485979497544,14.948597949754403 229.9485979497544,134.9485979497544 109.9485979497544,134.9485979497544\" style=\"fill:#ECB172A0;stroke-width:0\"/>\n", | |
"\n", | |
" <!-- Text -->\n", | |
" <text x=\"169.948598\" y=\"154.948598\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" >10980</text>\n", | |
" <text x=\"249.948598\" y=\"74.948598\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" transform=\"rotate(-90,249.948598,74.948598)\">10980</text>\n", | |
" <text x=\"92.474299\" y=\"147.474299\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" transform=\"rotate(45,92.474299,147.474299)\">3</text>\n", | |
"</svg>\n", | |
" </td>\n", | |
" </tr>\n", | |
"</table></div></div></li><li class='xr-section-item'><input id='section-80341b82-ef52-47b7-9e2a-e5cd213f43f1' class='xr-section-summary-in' type='checkbox' checked><label for='section-80341b82-ef52-47b7-9e2a-e5cd213f43f1' class='xr-section-summary' >Coordinates: <span>(7)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>time</span></div><div class='xr-var-dims'>(time)</div><div class='xr-var-dtype'>datetime64[ns]</div><div class='xr-var-preview xr-preview'>2021-01-01T17:07:19.024000 2021-...</div><input id='attrs-1c91040c-0a16-499d-89dc-3d8ae267002a' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-1c91040c-0a16-499d-89dc-3d8ae267002a' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-732d1759-f040-446e-bc61-5f01ce4d9fa3' class='xr-var-data-in' type='checkbox'><label for='data-732d1759-f040-446e-bc61-5f01ce4d9fa3' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array(['2021-01-01T17:07:19.024000000', '2021-01-04T17:17:19.024000000'],\n", | |
" dtype='datetime64[ns]')</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>band</span></div><div class='xr-var-dims'>(band)</div><div class='xr-var-dtype'><U3</div><div class='xr-var-preview xr-preview'>'B02' 'B03' 'B04'</div><input id='attrs-d607ab2a-e03d-4933-89c6-98bc17fa6401' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-d607ab2a-e03d-4933-89c6-98bc17fa6401' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-f9b79500-08fb-449d-a990-25560d7de4a2' class='xr-var-data-in' type='checkbox'><label for='data-f9b79500-08fb-449d-a990-25560d7de4a2' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array(['B02', 'B03', 'B04'], dtype='<U3')</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>y</span></div><div class='xr-var-dims'>(y)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>4.8e+06 4.8e+06 ... 4.69e+06</div><input id='attrs-6cd36916-90a4-46d6-9148-7e8a1b9dc932' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-6cd36916-90a4-46d6-9148-7e8a1b9dc932' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-944c359f-d5b8-4d5d-9ca3-1d03ec8d075b' class='xr-var-data-in' type='checkbox'><label for='data-944c359f-d5b8-4d5d-9ca3-1d03ec8d075b' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([4800000., 4799990., 4799980., ..., 4690230., 4690220., 4690210.])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>x</span></div><div class='xr-var-dims'>(x)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>4e+05 4e+05 ... 5.097e+05 5.098e+05</div><input id='attrs-e252a225-7798-4665-b1cb-0a346f740abf' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-e252a225-7798-4665-b1cb-0a346f740abf' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-f66b1dc6-736d-48ad-8853-d0034e4f08b6' class='xr-var-data-in' type='checkbox'><label for='data-f66b1dc6-736d-48ad-8853-d0034e4f08b6' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([399960., 399970., 399980., ..., 509730., 509740., 509750.])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>common_name</span></div><div class='xr-var-dims'>(band)</div><div class='xr-var-dtype'><U5</div><div class='xr-var-preview xr-preview'>'blue' 'green' 'red'</div><input id='attrs-2009d362-c408-4b24-abc1-5f0c87965313' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-2009d362-c408-4b24-abc1-5f0c87965313' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-5d7a6683-96c4-4110-8dbe-0fbc43efdfc0' class='xr-var-data-in' type='checkbox'><label for='data-5d7a6683-96c4-4110-8dbe-0fbc43efdfc0' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array(['blue', 'green', 'red'], dtype='<U5')</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>center_wavelength</span></div><div class='xr-var-dims'>(band)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>0.49 0.56 0.665</div><input id='attrs-bb043e57-2f90-451a-bc05-599c8ab1eea8' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-bb043e57-2f90-451a-bc05-599c8ab1eea8' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-3c581b8b-6680-448e-ae5a-1fb4d3ee6299' class='xr-var-data-in' type='checkbox'><label for='data-3c581b8b-6680-448e-ae5a-1fb4d3ee6299' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([0.49 , 0.56 , 0.665])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>full_width_half_max</span></div><div class='xr-var-dims'>(band)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>0.098 0.045 0.038</div><input id='attrs-cebe6b91-5914-46d3-b402-2e65afcaaf91' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-cebe6b91-5914-46d3-b402-2e65afcaaf91' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-d845f9c3-365f-4ffc-9bb7-06540cbb6e7d' class='xr-var-data-in' type='checkbox'><label for='data-d845f9c3-365f-4ffc-9bb7-06540cbb6e7d' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([0.098, 0.045, 0.038])</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-bf145f08-b339-4ac6-b20f-02301a7680da' class='xr-section-summary-in' type='checkbox' checked><label for='section-bf145f08-b339-4ac6-b20f-02301a7680da' class='xr-section-summary' >Attributes: <span>(1)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'><dt><span>crs :</span></dt><dd>epsg:32615</dd></dl></div></li></ul></div></div>" | |
], | |
"text/plain": [ | |
"<xarray.DataArray 'uniform-872193f5d2193eb685484694f7ebc695' (time: 2, band: 3, y: 10980, x: 10980)>\n", | |
"dask.array<uniform, shape=(2, 3, 10980, 10980), dtype=float64, chunksize=(1, 1, 5490, 5490), chunktype=numpy.ndarray>\n", | |
"Coordinates:\n", | |
" * time (time) datetime64[ns] 2021-01-01T17:07:19.024000 202...\n", | |
" * band (band) <U3 'B02' 'B03' 'B04'\n", | |
" * y (y) float64 4.8e+06 4.8e+06 ... 4.69e+06 4.69e+06\n", | |
" * x (x) float64 4e+05 4e+05 4e+05 ... 5.097e+05 5.098e+05\n", | |
" common_name (band) <U5 'blue' 'green' 'red'\n", | |
" center_wavelength (band) float64 0.49 0.56 0.665\n", | |
" full_width_half_max (band) float64 0.098 0.045 0.038\n", | |
"Attributes:\n", | |
" crs: epsg:32615" | |
] | |
}, | |
"execution_count": 2, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"import xarray as xr\n", | |
"import numpy as np\n", | |
"import dask.array as da\n", | |
"import stackstac\n", | |
"import rioxarray\n", | |
"import pystac\n", | |
"import pandas as pd\n", | |
"\n", | |
"values = da.random.uniform(size=(2, 3, 10980, 10980), chunks=(1, 1, 5490, 5490))\n", | |
"\n", | |
"x = np.arange(399960, 509751, step=10.)\n", | |
"y = np.arange(4800000, 4690210 - 1, step=-10.)\n", | |
"band = np.array([\"B02\", \"B03\", \"B04\"])\n", | |
"time = pd.to_datetime([\"2021-01-01T17:07:19.024000000\", \"2021-01-04T17:17:19.024000000\"])\n", | |
"\n", | |
"data = xr.DataArray(\n", | |
" values,\n", | |
" dims=(\"time\", \"band\", \"y\", \"x\"),\n", | |
" coords={\n", | |
" \"time\": xr.DataArray(time, name=\"time\", dims=\"time\"),\n", | |
" \"band\": xr.DataArray(band, name=\"band\", dims=\"band\"),\n", | |
" \"y\": xr.DataArray(y, name=\"y\", dims=\"y\"),\n", | |
" \"x\": xr.DataArray(x, name=\"x\", dims=\"x\"),\n", | |
" \"common_name\": xr.DataArray(['blue', 'green', 'red'], dims=\"band\", name=\"common_name\"),\n", | |
" \"center_wavelength\":xr.DataArray([0.49 , 0.56 , 0.665], dims=\"band\", name=\"center_wavelength\"),\n", | |
" \"full_width_half_max\": xr.DataArray([0.098, 0.045, 0.038], dims=\"band\", name=\"full_width_half_max\"),\n", | |
" },\n", | |
" attrs={\n", | |
" \"crs\": \"epsg:32615\",\n", | |
" },\n", | |
")\n", | |
"data" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "9830d18e-8080-4ef6-a1fb-299284cf84f1", | |
"metadata": {}, | |
"source": [ | |
"## Data writing\n", | |
"\n", | |
"We're using `xcog` here, a simple little library with some utilities for writing out chunks. We'll write to local disk, but we should be able to use any fsspec-compatible file-system." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"id": "b297ce01-0eca-4b00-ace2-436fa9d03fd5", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"ERROR 4: `/vsimem/fc548ba3-e3e8-44b2-aeae-5360710ecb04/fc548ba3-e3e8-44b2-aeae-5360710ecb04.tif' not recognized as a supported file format.\n", | |
"ERROR 4: `/vsimem/0819c8a4-98ba-4a31-a0b6-eb725a963e75/0819c8a4-98ba-4a31-a0b6-eb725a963e75.tif' not recognized as a supported file format.\n", | |
"ERROR 4: `/vsimem/3109c1b8-771b-4860-8399-0e8c8b90ebd8/3109c1b8-771b-4860-8399-0e8c8b90ebd8.tif' not recognized as a supported file format.\n", | |
"ERROR 4: `/vsimem/a079620a-7a01-4caf-8c34-31ec62fadb0d/a079620a-7a01-4caf-8c34-31ec62fadb0d.tif' not recognized as a supported file format.\n", | |
"ERROR 4: `/vsimem/21421136-c716-441d-8942-0a439b37596e/21421136-c716-441d-8942-0a439b37596e.tif' not recognized as a supported file format.\n", | |
"ERROR 4: `/vsimem/827a2d04-4d7d-4c14-9c5a-f4b6c6f9e859/827a2d04-4d7d-4c14-9c5a-f4b6c6f9e859.tif' not recognized as a supported file format.\n", | |
"ERROR 4: `/vsimem/0f2a19c9-ac69-4527-ac95-e381887faefd/0f2a19c9-ac69-4527-ac95-e381887faefd.tif' not recognized as a supported file format.\n", | |
"ERROR 4: `/vsimem/e36c69b0-2f07-4d7b-a715-89c8242e8e64/e36c69b0-2f07-4d7b-a715-89c8242e8e64.tif' not recognized as a supported file format.\n", | |
"ERROR 4: `/vsimem/86166231-faa0-4c15-9d74-8c76da4ad1aa/86166231-faa0-4c15-9d74-8c76da4ad1aa.tif' not recognized as a supported file format.\n", | |
"ERROR 4: `/vsimem/3b7c7a76-f683-4478-b916-11b8ba96220d/3b7c7a76-f683-4478-b916-11b8ba96220d.tif' not recognized as a supported file format.\n", | |
"ERROR 4: `/vsimem/64c99d93-b882-4c35-a0b1-e3b32df59428/64c99d93-b882-4c35-a0b1-e3b32df59428.tif' not recognized as a supported file format.\n", | |
"ERROR 4: `/vsimem/b21d29cd-5134-43e8-af92-8523fd6d91d6/b21d29cd-5134-43e8-af92-8523fd6d91d6.tif' not recognized as a supported file format.\n", | |
"ERROR 4: `/vsimem/737da978-6649-4150-91f4-c1de38537165/737da978-6649-4150-91f4-c1de38537165.tif' not recognized as a supported file format.\n", | |
"ERROR 4: `/vsimem/af35e916-fa26-454f-bc3c-05029d274d63/af35e916-fa26-454f-bc3c-05029d274d63.tif' not recognized as a supported file format.\n", | |
"ERROR 4: `/vsimem/8032fb15-9cf2-4fc7-b4d6-209e9ce973c5/8032fb15-9cf2-4fc7-b4d6-209e9ce973c5.tif' not recognized as a supported file format.\n", | |
"ERROR 4: `/vsimem/2ba7f5fd-21e4-4e1b-b13c-e709b2ee93c1/2ba7f5fd-21e4-4e1b-b13c-e709b2ee93c1.tif' not recognized as a supported file format.\n", | |
"ERROR 4: `/vsimem/df983957-d325-4896-9cfd-122553d5eb71/df983957-d325-4896-9cfd-122553d5eb71.tif' not recognized as a supported file format.\n", | |
"ERROR 4: `/vsimem/9248e932-a01c-4756-be3f-6edeb6b35607/9248e932-a01c-4756-be3f-6edeb6b35607.tif' not recognized as a supported file format.\n", | |
"ERROR 4: `/vsimem/83e1621a-0c4f-42c8-8e4f-a24b87d0b85d/83e1621a-0c4f-42c8-8e4f-a24b87d0b85d.tif' not recognized as a supported file format.\n", | |
"ERROR 4: `/vsimem/9dd138d0-7709-4499-bbb2-c2f28579f9dd/9dd138d0-7709-4499-bbb2-c2f28579f9dd.tif' not recognized as a supported file format.\n", | |
"ERROR 4: `/vsimem/fecafa99-14c8-4cf4-9ba7-68ebc5e3ccfb/fecafa99-14c8-4cf4-9ba7-68ebc5e3ccfb.tif' not recognized as a supported file format.\n", | |
"ERROR 4: `/vsimem/5aee567d-e3d0-4fd3-9e80-9d56a4269fb9/5aee567d-e3d0-4fd3-9e80-9d56a4269fb9.tif' not recognized as a supported file format.\n", | |
"ERROR 4: `/vsimem/5d5d5910-46c2-4368-9a84-a8de12e74104/5d5d5910-46c2-4368-9a84-a8de12e74104.tif' not recognized as a supported file format.\n", | |
"ERROR 4: `/vsimem/648504f2-4f1b-4627-9d34-aabe4bc603d5/648504f2-4f1b-4627-9d34-aabe4bc603d5.tif' not recognized as a supported file format.\n" | |
] | |
} | |
], | |
"source": [ | |
"from pathlib import Path\n", | |
"import xcog\n", | |
"\n", | |
"\n", | |
"dst = Path(\"/tmp/cogs/\")\n", | |
"dst.mkdir(parents=True, exist_ok=True)\n", | |
"\n", | |
"items = xcog.to_cog_and_stac(data, prefix=str(dst), storage_options=dict(auto_mkdir=True))" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "538ebd92-fe70-454e-8fe7-08b6bd76b17a", | |
"metadata": {}, | |
"source": [ | |
"Here's the COGs we wrote out, including their directory structure:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"id": "3a5753f1-7452-4b9f-92fe-1e6b70811909", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\u001b[01;34m/tmp/cogs/\u001b[00m\n", | |
"├── \u001b[01;34mtime=2021-01-01T17:07:19.024000\u001b[00m\n", | |
"│ ├── \u001b[01;35mband=B02-y=4745100.0-x=399960.0.tif\u001b[00m\n", | |
"│ ├── \u001b[01;35mband=B02-y=4745100.0-x=454860.0.tif\u001b[00m\n", | |
"│ ├── \u001b[01;35mband=B02-y=4800000.0-x=399960.0.tif\u001b[00m\n", | |
"│ ├── \u001b[01;35mband=B02-y=4800000.0-x=454860.0.tif\u001b[00m\n", | |
"│ ├── \u001b[01;35mband=B03-y=4745100.0-x=399960.0.tif\u001b[00m\n", | |
"│ ├── \u001b[01;35mband=B03-y=4745100.0-x=454860.0.tif\u001b[00m\n", | |
"│ ├── \u001b[01;35mband=B03-y=4800000.0-x=399960.0.tif\u001b[00m\n", | |
"│ ├── \u001b[01;35mband=B03-y=4800000.0-x=454860.0.tif\u001b[00m\n", | |
"│ ├── \u001b[01;35mband=B04-y=4745100.0-x=399960.0.tif\u001b[00m\n", | |
"│ ├── \u001b[01;35mband=B04-y=4745100.0-x=454860.0.tif\u001b[00m\n", | |
"│ ├── \u001b[01;35mband=B04-y=4800000.0-x=399960.0.tif\u001b[00m\n", | |
"│ └── \u001b[01;35mband=B04-y=4800000.0-x=454860.0.tif\u001b[00m\n", | |
"└── \u001b[01;34mtime=2021-01-04T17:17:19.024000\u001b[00m\n", | |
" ├── \u001b[01;35mband=B02-y=4745100.0-x=399960.0.tif\u001b[00m\n", | |
" ├── \u001b[01;35mband=B02-y=4745100.0-x=454860.0.tif\u001b[00m\n", | |
" ├── \u001b[01;35mband=B02-y=4800000.0-x=399960.0.tif\u001b[00m\n", | |
" ├── \u001b[01;35mband=B02-y=4800000.0-x=454860.0.tif\u001b[00m\n", | |
" ├── \u001b[01;35mband=B03-y=4745100.0-x=399960.0.tif\u001b[00m\n", | |
" ├── \u001b[01;35mband=B03-y=4745100.0-x=454860.0.tif\u001b[00m\n", | |
" ├── \u001b[01;35mband=B03-y=4800000.0-x=399960.0.tif\u001b[00m\n", | |
" ├── \u001b[01;35mband=B03-y=4800000.0-x=454860.0.tif\u001b[00m\n", | |
" ├── \u001b[01;35mband=B04-y=4745100.0-x=399960.0.tif\u001b[00m\n", | |
" ├── \u001b[01;35mband=B04-y=4745100.0-x=454860.0.tif\u001b[00m\n", | |
" ├── \u001b[01;35mband=B04-y=4800000.0-x=399960.0.tif\u001b[00m\n", | |
" └── \u001b[01;35mband=B04-y=4800000.0-x=454860.0.tif\u001b[00m\n", | |
"\n", | |
"2 directories, 24 files\n" | |
] | |
} | |
], | |
"source": [ | |
"!tree /tmp/cogs/" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "ae995f2f-290f-42c8-a5bf-da122715620e", | |
"metadata": {}, | |
"source": [ | |
"## Read back STAC + COGs\n", | |
"\n", | |
"`to_cog_and_stac` returned a list of STAC items with one STAC item per `(time, y, x)` chunk. Notably, the separate bands have been merged into a single STAC item." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 17, | |
"id": "9ba23451-46b2-4fa4-ae1d-67615b1656c0", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"{'B02': <Asset href=/tmp/cogs/time=2021-01-01T17:07:19.024000/band=B02-y=4745100.0-x=399960.0.tif>,\n", | |
" 'B03': <Asset href=/tmp/cogs/time=2021-01-01T17:07:19.024000/band=B03-y=4745100.0-x=399960.0.tif>,\n", | |
" 'B04': <Asset href=/tmp/cogs/time=2021-01-01T17:07:19.024000/band=B04-y=4745100.0-x=399960.0.tif>}" | |
] | |
}, | |
"execution_count": 17, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"items[0].assets" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "64f46da9-e81a-45de-af93-a238a4d62c22", | |
"metadata": {}, | |
"source": [ | |
"And those can be fed back to stackstac, so kind of a round-trip from DataArray -> {STAC + COG} -> DataArray" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 19, | |
"id": "9ae51c1b-9800-49a8-9ae8-2b54316b9e01", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div><svg style=\"position: absolute; width: 0; height: 0; overflow: hidden\">\n", | |
"<defs>\n", | |
"<symbol id=\"icon-database\" viewBox=\"0 0 32 32\">\n", | |
"<path d=\"M16 0c-8.837 0-16 2.239-16 5v4c0 2.761 7.163 5 16 5s16-2.239 16-5v-4c0-2.761-7.163-5-16-5z\"></path>\n", | |
"<path d=\"M16 17c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n", | |
"<path d=\"M16 26c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n", | |
"</symbol>\n", | |
"<symbol id=\"icon-file-text2\" viewBox=\"0 0 32 32\">\n", | |
"<path d=\"M28.681 7.159c-0.694-0.947-1.662-2.053-2.724-3.116s-2.169-2.030-3.116-2.724c-1.612-1.182-2.393-1.319-2.841-1.319h-15.5c-1.378 0-2.5 1.121-2.5 2.5v27c0 1.378 1.122 2.5 2.5 2.5h23c1.378 0 2.5-1.122 2.5-2.5v-19.5c0-0.448-0.137-1.23-1.319-2.841zM24.543 5.457c0.959 0.959 1.712 1.825 2.268 2.543h-4.811v-4.811c0.718 0.556 1.584 1.309 2.543 2.268zM28 29.5c0 0.271-0.229 0.5-0.5 0.5h-23c-0.271 0-0.5-0.229-0.5-0.5v-27c0-0.271 0.229-0.5 0.5-0.5 0 0 15.499-0 15.5 0v7c0 0.552 0.448 1 1 1h7v19.5z\"></path>\n", | |
"<path d=\"M23 26h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n", | |
"<path d=\"M23 22h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n", | |
"<path d=\"M23 18h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n", | |
"</symbol>\n", | |
"</defs>\n", | |
"</svg>\n", | |
"<style>/* 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.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;\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-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", | |
" 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", | |
" 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-attrs {\n", | |
" padding-left: 25px !important;\n", | |
"}\n", | |
"\n", | |
".xr-attrs,\n", | |
".xr-var-attrs,\n", | |
".xr-var-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", | |
" 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", | |
"</style><pre class='xr-text-repr-fallback'><xarray.DataArray 'stackstac-84d23d14f1f12d1d04d3683dabc9a86f' (time: 2, band: 3, y: 10981, x: 10981)>\n", | |
"dask.array<concatenate, shape=(2, 3, 10981, 10981), dtype=float64, chunksize=(1, 1, 5490, 5490), chunktype=numpy.ndarray>\n", | |
"Coordinates:\n", | |
" * band (band) <U3 'B02' 'B03' 'B04'\n", | |
" * x (x) float64 4e+05 4e+05 4e+05 ... 5.097e+05 5.097e+05 5.098e+05\n", | |
" * y (y) float64 4.8e+06 4.8e+06 4.8e+06 ... 4.69e+06 4.69e+06\n", | |
" proj:epsg int64 32615\n", | |
" epsg int64 32615\n", | |
" * time (time) datetime64[ns] 2021-01-01T17:07:19.024000 2021-01-04T17...\n", | |
"Attributes:\n", | |
" spec: RasterSpec(epsg=32615, bounds=(399950.0, 4690200.0, 509760.0...\n", | |
" crs: epsg:32615\n", | |
" transform: | 10.00, 0.00, 399950.00|\\n| 0.00,-10.00, 4800010.00|\\n| 0.0...\n", | |
" resolution: 10.0</pre><div class='xr-wrap' hidden><div class='xr-header'><div class='xr-obj-type'>xarray.DataArray</div><div class='xr-array-name'>'stackstac-84d23d14f1f12d1d04d3683dabc9a86f'</div><ul class='xr-dim-list'><li><span class='xr-has-index'>time</span>: 2</li><li><span class='xr-has-index'>band</span>: 3</li><li><span class='xr-has-index'>y</span>: 10981</li><li><span class='xr-has-index'>x</span>: 10981</li></ul></div><ul class='xr-sections'><li class='xr-section-item'><div class='xr-array-wrap'><input id='section-804c8826-a425-4bda-9250-66575dcccfab' class='xr-array-in' type='checkbox' checked><label for='section-804c8826-a425-4bda-9250-66575dcccfab' title='Show/hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-array-preview xr-preview'><span>dask.array<chunksize=(1, 1, 5490, 5490), meta=np.ndarray></span></div><div class='xr-array-data'><table>\n", | |
" <tr>\n", | |
" <td>\n", | |
" <table>\n", | |
" <thead>\n", | |
" <tr>\n", | |
" <td> </td>\n", | |
" <th> Array </th>\n", | |
" <th> Chunk </th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" \n", | |
" <tr>\n", | |
" <th> Bytes </th>\n", | |
" <td> 5.39 GiB </td>\n", | |
" <td> 229.95 MiB </td>\n", | |
" </tr>\n", | |
" \n", | |
" <tr>\n", | |
" <th> Shape </th>\n", | |
" <td> (2, 3, 10981, 10981) </td>\n", | |
" <td> (1, 1, 5490, 5490) </td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th> Count </th>\n", | |
" <td> 1137 Tasks </td>\n", | |
" <td> 54 Chunks </td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th> Type </th>\n", | |
" <td> float64 </td>\n", | |
" <td> numpy.ndarray </td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
" </table>\n", | |
" </td>\n", | |
" <td>\n", | |
" <svg width=\"374\" height=\"184\" style=\"stroke:rgb(0,0,0);stroke-width:1\" >\n", | |
"\n", | |
" <!-- Horizontal lines -->\n", | |
" <line x1=\"0\" y1=\"0\" x2=\"25\" y2=\"0\" style=\"stroke-width:2\" />\n", | |
" <line x1=\"0\" y1=\"25\" x2=\"25\" y2=\"25\" style=\"stroke-width:2\" />\n", | |
"\n", | |
" <!-- Vertical lines -->\n", | |
" <line x1=\"0\" y1=\"0\" x2=\"0\" y2=\"25\" style=\"stroke-width:2\" />\n", | |
" <line x1=\"12\" y1=\"0\" x2=\"12\" y2=\"25\" />\n", | |
" <line x1=\"25\" y1=\"0\" x2=\"25\" y2=\"25\" style=\"stroke-width:2\" />\n", | |
"\n", | |
" <!-- Colored Rectangle -->\n", | |
" <polygon points=\"0.0,0.0 25.412616514582485,0.0 25.412616514582485,25.412616514582485 0.0,25.412616514582485\" style=\"fill:#ECB172A0;stroke-width:0\"/>\n", | |
"\n", | |
" <!-- Text -->\n", | |
" <text x=\"12.706308\" y=\"45.412617\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" >2</text>\n", | |
" <text x=\"45.412617\" y=\"12.706308\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" transform=\"rotate(0,45.412617,12.706308)\">1</text>\n", | |
"\n", | |
"\n", | |
" <!-- Horizontal lines -->\n", | |
" <line x1=\"95\" y1=\"0\" x2=\"109\" y2=\"14\" style=\"stroke-width:2\" />\n", | |
" <line x1=\"95\" y1=\"59\" x2=\"109\" y2=\"74\" />\n", | |
" <line x1=\"95\" y1=\"119\" x2=\"109\" y2=\"134\" />\n", | |
" <line x1=\"95\" y1=\"120\" x2=\"109\" y2=\"134\" style=\"stroke-width:2\" />\n", | |
"\n", | |
" <!-- Vertical lines -->\n", | |
" <line x1=\"95\" y1=\"0\" x2=\"95\" y2=\"120\" style=\"stroke-width:2\" />\n", | |
" <line x1=\"99\" y1=\"4\" x2=\"99\" y2=\"124\" />\n", | |
" <line x1=\"104\" y1=\"9\" x2=\"104\" y2=\"129\" />\n", | |
" <line x1=\"109\" y1=\"14\" x2=\"109\" y2=\"134\" style=\"stroke-width:2\" />\n", | |
"\n", | |
" <!-- Colored Rectangle -->\n", | |
" <polygon points=\"95.0,0.0 109.9485979497544,14.948597949754403 109.9485979497544,134.9485979497544 95.0,120.0\" style=\"fill:#ECB172A0;stroke-width:0\"/>\n", | |
"\n", | |
" <!-- Horizontal lines -->\n", | |
" <line x1=\"95\" y1=\"0\" x2=\"215\" y2=\"0\" style=\"stroke-width:2\" />\n", | |
" <line x1=\"99\" y1=\"4\" x2=\"219\" y2=\"4\" />\n", | |
" <line x1=\"104\" y1=\"9\" x2=\"224\" y2=\"9\" />\n", | |
" <line x1=\"109\" y1=\"14\" x2=\"229\" y2=\"14\" style=\"stroke-width:2\" />\n", | |
"\n", | |
" <!-- Vertical lines -->\n", | |
" <line x1=\"95\" y1=\"0\" x2=\"109\" y2=\"14\" style=\"stroke-width:2\" />\n", | |
" <line x1=\"154\" y1=\"0\" x2=\"169\" y2=\"14\" />\n", | |
" <line x1=\"214\" y1=\"0\" x2=\"229\" y2=\"14\" />\n", | |
" <line x1=\"215\" y1=\"0\" x2=\"229\" y2=\"14\" style=\"stroke-width:2\" />\n", | |
"\n", | |
" <!-- Colored Rectangle -->\n", | |
" <polygon points=\"95.0,0.0 215.0,0.0 229.9485979497544,14.948597949754403 109.9485979497544,14.948597949754403\" style=\"fill:#ECB172A0;stroke-width:0\"/>\n", | |
"\n", | |
" <!-- Horizontal lines -->\n", | |
" <line x1=\"109\" y1=\"14\" x2=\"229\" y2=\"14\" style=\"stroke-width:2\" />\n", | |
" <line x1=\"109\" y1=\"74\" x2=\"229\" y2=\"74\" />\n", | |
" <line x1=\"109\" y1=\"134\" x2=\"229\" y2=\"134\" />\n", | |
" <line x1=\"109\" y1=\"134\" x2=\"229\" y2=\"134\" style=\"stroke-width:2\" />\n", | |
"\n", | |
" <!-- Vertical lines -->\n", | |
" <line x1=\"109\" y1=\"14\" x2=\"109\" y2=\"134\" style=\"stroke-width:2\" />\n", | |
" <line x1=\"169\" y1=\"14\" x2=\"169\" y2=\"134\" />\n", | |
" <line x1=\"229\" y1=\"14\" x2=\"229\" y2=\"134\" />\n", | |
" <line x1=\"229\" y1=\"14\" x2=\"229\" y2=\"134\" style=\"stroke-width:2\" />\n", | |
"\n", | |
" <!-- Colored Rectangle -->\n", | |
" <polygon points=\"109.9485979497544,14.948597949754403 229.9485979497544,14.948597949754403 229.9485979497544,134.9485979497544 109.9485979497544,134.9485979497544\" style=\"fill:#ECB172A0;stroke-width:0\"/>\n", | |
"\n", | |
" <!-- Text -->\n", | |
" <text x=\"169.948598\" y=\"154.948598\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" >10981</text>\n", | |
" <text x=\"249.948598\" y=\"74.948598\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" transform=\"rotate(-90,249.948598,74.948598)\">10981</text>\n", | |
" <text x=\"92.474299\" y=\"147.474299\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" transform=\"rotate(45,92.474299,147.474299)\">3</text>\n", | |
"</svg>\n", | |
" </td>\n", | |
" </tr>\n", | |
"</table></div></div></li><li class='xr-section-item'><input id='section-955d0604-b160-41a5-adaa-e005e8aa4fb7' class='xr-section-summary-in' type='checkbox' checked><label for='section-955d0604-b160-41a5-adaa-e005e8aa4fb7' class='xr-section-summary' >Coordinates: <span>(6)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>band</span></div><div class='xr-var-dims'>(band)</div><div class='xr-var-dtype'><U3</div><div class='xr-var-preview xr-preview'>'B02' 'B03' 'B04'</div><input id='attrs-d98829ad-8441-4e18-92a8-f4527e49a6d8' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-d98829ad-8441-4e18-92a8-f4527e49a6d8' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-dc2ca122-6474-42ea-9f25-ba74d15995bb' class='xr-var-data-in' type='checkbox'><label for='data-dc2ca122-6474-42ea-9f25-ba74d15995bb' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array(['B02', 'B03', 'B04'], dtype='<U3')</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>x</span></div><div class='xr-var-dims'>(x)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>4e+05 4e+05 ... 5.097e+05 5.098e+05</div><input id='attrs-2f2b12a1-e320-4842-b0bf-84f78f14fc50' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-2f2b12a1-e320-4842-b0bf-84f78f14fc50' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-144c3cb2-adf5-4964-bdd9-9a55f6aeab79' class='xr-var-data-in' type='checkbox'><label for='data-144c3cb2-adf5-4964-bdd9-9a55f6aeab79' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([399950., 399960., 399970., ..., 509730., 509740., 509750.])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>y</span></div><div class='xr-var-dims'>(y)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>4.8e+06 4.8e+06 ... 4.69e+06</div><input id='attrs-150bf90d-09fe-4cfa-89cb-ca1619c6307f' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-150bf90d-09fe-4cfa-89cb-ca1619c6307f' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-76e87b37-e992-4bdc-8328-758a2e81aa03' class='xr-var-data-in' type='checkbox'><label for='data-76e87b37-e992-4bdc-8328-758a2e81aa03' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([4800010., 4800000., 4799990., ..., 4690230., 4690220., 4690210.])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>proj:epsg</span></div><div class='xr-var-dims'>()</div><div class='xr-var-dtype'>int64</div><div class='xr-var-preview xr-preview'>32615</div><input id='attrs-e4683d17-9056-4448-a17b-7d65fa254796' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-e4683d17-9056-4448-a17b-7d65fa254796' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-b8204705-00e2-4025-87ab-1c442a62a596' class='xr-var-data-in' type='checkbox'><label for='data-b8204705-00e2-4025-87ab-1c442a62a596' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array(32615)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>epsg</span></div><div class='xr-var-dims'>()</div><div class='xr-var-dtype'>int64</div><div class='xr-var-preview xr-preview'>32615</div><input id='attrs-3ab69bbf-e777-4ae8-b68a-43d318084c28' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-3ab69bbf-e777-4ae8-b68a-43d318084c28' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-f13e303f-54ce-47d7-9c9a-3c5c04eaec61' class='xr-var-data-in' type='checkbox'><label for='data-f13e303f-54ce-47d7-9c9a-3c5c04eaec61' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array(32615)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>time</span></div><div class='xr-var-dims'>(time)</div><div class='xr-var-dtype'>datetime64[ns]</div><div class='xr-var-preview xr-preview'>2021-01-01T17:07:19.024000 2021-...</div><input id='attrs-c51ca80e-2af3-41a6-b9ee-03f445edfb6b' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-c51ca80e-2af3-41a6-b9ee-03f445edfb6b' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-7ab9cc18-6239-483b-b32e-82ae7d27a7b6' class='xr-var-data-in' type='checkbox'><label for='data-7ab9cc18-6239-483b-b32e-82ae7d27a7b6' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array(['2021-01-01T17:07:19.024000000', '2021-01-04T17:17:19.024000000'],\n", | |
" dtype='datetime64[ns]')</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-5b736c59-1bc6-46d4-99b7-cd2b86d7fa09' class='xr-section-summary-in' type='checkbox' checked><label for='section-5b736c59-1bc6-46d4-99b7-cd2b86d7fa09' class='xr-section-summary' >Attributes: <span>(4)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'><dt><span>spec :</span></dt><dd>RasterSpec(epsg=32615, bounds=(399950.0, 4690200.0, 509760.0, 4800010.0), resolutions_xy=(10.0, 10.0))</dd><dt><span>crs :</span></dt><dd>epsg:32615</dd><dt><span>transform :</span></dt><dd>| 10.00, 0.00, 399950.00|\n", | |
"| 0.00,-10.00, 4800010.00|\n", | |
"| 0.00, 0.00, 1.00|</dd><dt><span>resolution :</span></dt><dd>10.0</dd></dl></div></li></ul></div></div>" | |
], | |
"text/plain": [ | |
"<xarray.DataArray 'stackstac-84d23d14f1f12d1d04d3683dabc9a86f' (time: 2, band: 3, y: 10981, x: 10981)>\n", | |
"dask.array<concatenate, shape=(2, 3, 10981, 10981), dtype=float64, chunksize=(1, 1, 5490, 5490), chunktype=numpy.ndarray>\n", | |
"Coordinates:\n", | |
" * band (band) <U3 'B02' 'B03' 'B04'\n", | |
" * x (x) float64 4e+05 4e+05 4e+05 ... 5.097e+05 5.097e+05 5.098e+05\n", | |
" * y (y) float64 4.8e+06 4.8e+06 4.8e+06 ... 4.69e+06 4.69e+06\n", | |
" proj:epsg int64 32615\n", | |
" epsg int64 32615\n", | |
" * time (time) datetime64[ns] 2021-01-01T17:07:19.024000 2021-01-04T17...\n", | |
"Attributes:\n", | |
" spec: RasterSpec(epsg=32615, bounds=(399950.0, 4690200.0, 509760.0...\n", | |
" crs: epsg:32615\n", | |
" transform: | 10.00, 0.00, 399950.00|\\n| 0.00,-10.00, 4800010.00|\\n| 0.0...\n", | |
" resolution: 10.0" | |
] | |
}, | |
"execution_count": 19, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"stackstac.stack([x.to_dict() for x in items], chunksize=5490).groupby(\"time\").apply(stackstac.mosaic)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "7996e2d9-0243-448b-ab49-29954900982b", | |
"metadata": {}, | |
"source": [ | |
"(We'll ignore the fact that we're off by one on the size)." | |
] | |
} | |
], | |
"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.12" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment