Created
May 7, 2025 22:38
-
-
Save alexgleith/8279e8e4a46c41ddd5ccb8d7e1dedd13 to your computer and use it in GitHub Desktop.
Export ACA data from GEE
This file contains hidden or 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": "37bc5ab7", | |
"metadata": {}, | |
"source": [ | |
"# Export tiles as Xarray" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "197a581b", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import ee\n", | |
"import xarray as xr\n", | |
"import numpy as np\n", | |
"import odc.geo.xr # noqa: F401" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "d333b35d", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Authenticate and initialize\n", | |
"# ee.Authenticate()\n", | |
"ee.Initialize(opt_url=\"https://earthengine-highvolume.googleapis.com\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"id": "43ef4e2e", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"dataset = \"ACA/reef_habitat/v2_0\"\n", | |
"ic = ee.ImageCollection(ee.Image(dataset))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"id": "29acaf93", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"/opt/homebrew/lib/python3.11/site-packages/xee/ext.py:688: UserWarning: Unable to retrieve 'system:time_start' values from an ImageCollection due to: No 'system:time_start' values found in the 'ImageCollection'.\n", | |
" warnings.warn(\n", | |
"/var/folders/0h/8_60bs_52tx9q2mdgszb37gw0000gn/T/ipykernel_48612/491851988.py:11: UserWarning: The specified chunks separate the stored chunks along dimension \"lon\" starting at index 10000. This could degrade performance. Instead, consider rechunking after loading.\n", | |
" ds = xr.open_dataset(\n", | |
"/var/folders/0h/8_60bs_52tx9q2mdgszb37gw0000gn/T/ipykernel_48612/491851988.py:11: UserWarning: The specified chunks separate the stored chunks along dimension \"lat\" starting at index 10000. This could degrade performance. Instead, consider rechunking after loading.\n", | |
" ds = xr.open_dataset(\n" | |
] | |
}, | |
{ | |
"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", | |
"html[data-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 0 20px 0 20px;\n", | |
"}\n", | |
"\n", | |
".xr-section-item {\n", | |
" display: contents;\n", | |
"}\n", | |
"\n", | |
".xr-section-item input {\n", | |
" display: inline-block;\n", | |
" opacity: 0;\n", | |
" height: 0;\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:focus + label {\n", | |
" border: 2px solid var(--xr-font-color0);\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", | |
"</style><pre class='xr-text-repr-fallback'><xarray.DataArray 'reef_mask' (lon: 40000, lat: 40000)> Size: 2GB\n", | |
"dask.array<astype, shape=(40000, 40000), dtype=uint8, chunksize=(10000, 10000), chunktype=numpy.ndarray>\n", | |
"Coordinates:\n", | |
" time int64 8B 0\n", | |
" * lon (lon) float64 320kB 140.0 140.0 140.0 140.0 ... 142.0 142.0 142.0\n", | |
" * lat (lat) float64 320kB -10.0 -10.0 -10.0 -10.0 ... -12.0 -12.0 -12.0\n", | |
"Attributes:\n", | |
" id: reef_mask\n", | |
" data_type: {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max'...\n", | |
" dimensions: [8015004, 1437907]\n", | |
" crs: EPSG:4326\n", | |
" crs_transform: [4.491576420597607e-05, 0, -180.00001488697754, 0, -4.491...</pre><div class='xr-wrap' style='display:none'><div class='xr-header'><div class='xr-obj-type'>xarray.DataArray</div><div class='xr-array-name'>'reef_mask'</div><ul class='xr-dim-list'><li><span class='xr-has-index'>lon</span>: 40000</li><li><span class='xr-has-index'>lat</span>: 40000</li></ul></div><ul class='xr-sections'><li class='xr-section-item'><div class='xr-array-wrap'><input id='section-ed02cea5-cb59-4819-b276-6587f77c4c77' class='xr-array-in' type='checkbox' checked><label for='section-ed02cea5-cb59-4819-b276-6587f77c4c77' 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=(10000, 10000), meta=np.ndarray></span></div><div class='xr-array-data'><table>\n", | |
" <tr>\n", | |
" <td>\n", | |
" <table style=\"border-collapse: collapse;\">\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> 1.49 GiB </td>\n", | |
" <td> 95.37 MiB </td>\n", | |
" </tr>\n", | |
" \n", | |
" <tr>\n", | |
" <th> Shape </th>\n", | |
" <td> (40000, 40000) </td>\n", | |
" <td> (10000, 10000) </td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th> Dask graph </th>\n", | |
" <td colspan=\"2\"> 16 chunks in 4 graph layers </td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th> Data type </th>\n", | |
" <td colspan=\"2\"> uint8 numpy.ndarray </td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
" </table>\n", | |
" </td>\n", | |
" <td>\n", | |
" <svg width=\"170\" height=\"170\" style=\"stroke:rgb(0,0,0);stroke-width:1\" >\n", | |
"\n", | |
" <!-- Horizontal lines -->\n", | |
" <line x1=\"0\" y1=\"0\" x2=\"120\" y2=\"0\" style=\"stroke-width:2\" />\n", | |
" <line x1=\"0\" y1=\"30\" x2=\"120\" y2=\"30\" />\n", | |
" <line x1=\"0\" y1=\"60\" x2=\"120\" y2=\"60\" />\n", | |
" <line x1=\"0\" y1=\"90\" x2=\"120\" y2=\"90\" />\n", | |
" <line x1=\"0\" y1=\"120\" x2=\"120\" y2=\"120\" style=\"stroke-width:2\" />\n", | |
"\n", | |
" <!-- Vertical lines -->\n", | |
" <line x1=\"0\" y1=\"0\" x2=\"0\" y2=\"120\" style=\"stroke-width:2\" />\n", | |
" <line x1=\"30\" y1=\"0\" x2=\"30\" y2=\"120\" />\n", | |
" <line x1=\"60\" y1=\"0\" x2=\"60\" y2=\"120\" />\n", | |
" <line x1=\"90\" y1=\"0\" x2=\"90\" y2=\"120\" />\n", | |
" <line x1=\"120\" y1=\"0\" x2=\"120\" y2=\"120\" style=\"stroke-width:2\" />\n", | |
"\n", | |
" <!-- Colored Rectangle -->\n", | |
" <polygon points=\"0.0,0.0 120.0,0.0 120.0,120.0 0.0,120.0\" style=\"fill:#ECB172A0;stroke-width:0\"/>\n", | |
"\n", | |
" <!-- Text -->\n", | |
" <text x=\"60.000000\" y=\"140.000000\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" >40000</text>\n", | |
" <text x=\"140.000000\" y=\"60.000000\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" transform=\"rotate(-90,140.000000,60.000000)\">40000</text>\n", | |
"</svg>\n", | |
" </td>\n", | |
" </tr>\n", | |
"</table></div></div></li><li class='xr-section-item'><input id='section-1aac9e17-cc5b-4b7c-bec9-a8e9a622cd0a' class='xr-section-summary-in' type='checkbox' checked><label for='section-1aac9e17-cc5b-4b7c-bec9-a8e9a622cd0a' class='xr-section-summary' >Coordinates: <span>(3)</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>time</span></div><div class='xr-var-dims'>()</div><div class='xr-var-dtype'>int64</div><div class='xr-var-preview xr-preview'>0</div><input id='attrs-ebee7baf-85bb-4d30-be5a-75bb521577b7' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-ebee7baf-85bb-4d30-be5a-75bb521577b7' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-b53fa533-2020-4117-8c83-ccc43d696548' class='xr-var-data-in' type='checkbox'><label for='data-b53fa533-2020-4117-8c83-ccc43d696548' 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)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>lon</span></div><div class='xr-var-dims'>(lon)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>140.0 140.0 140.0 ... 142.0 142.0</div><input id='attrs-42ec0f4e-13e5-4d8d-850f-e23d8f4da5ed' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-42ec0f4e-13e5-4d8d-850f-e23d8f4da5ed' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-b7bf5f1c-9745-4e77-a2a6-1b3719118a52' class='xr-var-data-in' type='checkbox'><label for='data-b7bf5f1c-9745-4e77-a2a6-1b3719118a52' 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([140.000025, 140.000075, 140.000125, ..., 141.999875, 141.999925,\n", | |
" 141.999975], shape=(40000,))</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>lat</span></div><div class='xr-var-dims'>(lat)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>-10.0 -10.0 -10.0 ... -12.0 -12.0</div><input id='attrs-8b65f303-a2fb-4f89-9743-d99537637d92' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-8b65f303-a2fb-4f89-9743-d99537637d92' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-b80c2602-dbe6-4278-80d3-54b284a32311' class='xr-var-data-in' type='checkbox'><label for='data-b80c2602-dbe6-4278-80d3-54b284a32311' 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([-10.000025, -10.000075, -10.000125, ..., -11.999875, -11.999925,\n", | |
" -11.999975], shape=(40000,))</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-d8528812-ec04-4253-8d22-f360f6e6bf03' class='xr-section-summary-in' type='checkbox' ><label for='section-d8528812-ec04-4253-8d22-f360f6e6bf03' class='xr-section-summary' >Indexes: <span>(2)</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-index-name'><div>lon</div></div><div class='xr-index-preview'>PandasIndex</div><input type='checkbox' disabled/><label></label><input id='index-013cc990-2677-44da-b969-47d7e235deee' class='xr-index-data-in' type='checkbox'/><label for='index-013cc990-2677-44da-b969-47d7e235deee' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(Index([ 140.000025, 140.000075, 140.000125,\n", | |
" 140.000175, 140.000225, 140.000275,\n", | |
" 140.000325, 140.000375, 140.000425,\n", | |
" 140.000475,\n", | |
" ...\n", | |
" 141.999525, 141.99957500000002, 141.999625,\n", | |
" 141.999675, 141.999725, 141.999775,\n", | |
" 141.99982500000002, 141.999875, 141.99992500000002,\n", | |
" 141.999975],\n", | |
" dtype='float64', name='lon', length=40000))</pre></div></li><li class='xr-var-item'><div class='xr-index-name'><div>lat</div></div><div class='xr-index-preview'>PandasIndex</div><input type='checkbox' disabled/><label></label><input id='index-d8a52bc7-b8e2-4709-ab4e-0eff123d9f99' class='xr-index-data-in' type='checkbox'/><label for='index-d8a52bc7-b8e2-4709-ab4e-0eff123d9f99' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(Index([ -10.000025, -10.000075, -10.000125,\n", | |
" -10.000175, -10.000225, -10.000275,\n", | |
" -10.000325, -10.000375, -10.000425,\n", | |
" -10.000475,\n", | |
" ...\n", | |
" -11.999525, -11.999575, -11.999625,\n", | |
" -11.999675, -11.999725, -11.999775,\n", | |
" -11.999825, -11.999875000000001, -11.999925000000001,\n", | |
" -11.999975000000001],\n", | |
" dtype='float64', name='lat', length=40000))</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-e748385b-1359-4868-9ed8-17c886c1c9a6' class='xr-section-summary-in' type='checkbox' checked><label for='section-e748385b-1359-4868-9ed8-17c886c1c9a6' class='xr-section-summary' >Attributes: <span>(5)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'><dt><span>id :</span></dt><dd>reef_mask</dd><dt><span>data_type :</span></dt><dd>{'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 255}</dd><dt><span>dimensions :</span></dt><dd>[8015004, 1437907]</dd><dt><span>crs :</span></dt><dd>EPSG:4326</dd><dt><span>crs_transform :</span></dt><dd>[4.491576420597607e-05, 0, -180.00001488697754, 0, -4.491576420597607e-05, 32.85956460933639]</dd></dl></div></li></ul></div></div>" | |
], | |
"text/plain": [ | |
"<xarray.DataArray 'reef_mask' (lon: 40000, lat: 40000)> Size: 2GB\n", | |
"dask.array<astype, shape=(40000, 40000), dtype=uint8, chunksize=(10000, 10000), chunktype=numpy.ndarray>\n", | |
"Coordinates:\n", | |
" time int64 8B 0\n", | |
" * lon (lon) float64 320kB 140.0 140.0 140.0 140.0 ... 142.0 142.0 142.0\n", | |
" * lat (lat) float64 320kB -10.0 -10.0 -10.0 -10.0 ... -12.0 -12.0 -12.0\n", | |
"Attributes:\n", | |
" id: reef_mask\n", | |
" data_type: {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max'...\n", | |
" dimensions: [8015004, 1437907]\n", | |
" crs: EPSG:4326\n", | |
" crs_transform: [4.491576420597607e-05, 0, -180.00001488697754, 0, -4.491..." | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Region of interest. Eventually, we need to do all of -180 to 180 and -32 to 32\n", | |
"left = 140.0\n", | |
"bottom = -12.0\n", | |
"right = 142.0\n", | |
"top = -10.0\n", | |
"\n", | |
"# Close to full resolution\n", | |
"res = 0.00005\n", | |
"transform = [res, 0, left, 0, -res, top]\n", | |
"\n", | |
"ds = xr.open_dataset(\n", | |
" ic,\n", | |
" engine='ee',\n", | |
" geometry=[left, bottom, right, top],\n", | |
" projection=ee.Projection(\n", | |
" crs=\"epsg:4326\", transform=transform\n", | |
" ),\n", | |
" chunks={\"time\": 1, \"lon\": 10000, \"lat\": 10000},\n", | |
").squeeze()\n", | |
"\n", | |
"reef_mask = ds.reef_mask.astype(\"uint8\")\n", | |
"reef_mask" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "b80bf2ff", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"reef_mask.odc.nodata = 0\n", | |
"reef_mask.astype(np.uint8).odc.write_cog(\"test.tif\", overwrite=True)" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"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.11.11" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment