Skip to content

Instantly share code, notes, and snippets.

@emileten
Created March 10, 2023 07:52
Show Gist options
  • Save emileten/3f0415b0fe2563851e4a49b44e5a4d6f to your computer and use it in GitHub Desktop.
Save emileten/3f0415b0fe2563851e4a49b44e5a4d6f to your computer and use it in GitHub Desktop.
stackstac returns xarray data array with duplicated time coordinates
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "04a3fb1b-c791-4d4c-8214-6511dea3a004",
"metadata": {},
"source": [
"### stackstac.stac is still returning duplicated time coordinate values"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "92e8f307-3e4f-48a9-a32b-7938551d6aa7",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"((4, 1, 185098, 134598),\n",
" <xarray.DataArray 'time' (time: 4)>\n",
" array(['2020-06-01T00:00:00.000000000', '2020-06-01T00:00:00.000000000',\n",
" '2020-06-01T00:00:00.000000000', '2020-06-01T00:00:00.000000000'],\n",
" dtype='datetime64[ns]')\n",
" Coordinates: (12/13)\n",
" * time (time) datetime64[ns] 2020-06-01 ... 2020-06-01\n",
" id (time) <U8 '15S-2020' '15R-2020' '14S-2020' '14R-2020'\n",
" io:supercell_id (time) <U3 '15S' '15R' '14S' '14R'\n",
" proj:epsg (time) int64 32615 32615 32614 32614\n",
" end_datetime <U20 '2021-01-01T00:00:00Z'\n",
" label:type <U6 'raster'\n",
" ... ...\n",
" io:tile_id (time) <U3 '15S' '15R' '14S' '14R'\n",
" label:classes object {'name': '', 'classes': ['nodata', 'water', 'tr...\n",
" label:description <U4 'lulc'\n",
" start_datetime <U20 '2020-01-01T00:00:00Z'\n",
" raster:bands object {'nodata': 0, 'spatial_resolution': 10}\n",
" epsg int64 3857)"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import numpy as np\n",
"import planetary_computer as pc\n",
"import pystac_client\n",
"import stackstac\n",
"\n",
"catalog = pystac_client.Client.open(\n",
" \"https://planetarycomputer.microsoft.com/api/stac/v1/\"\n",
")\n",
"point = {\"type\": \"Point\", \"coordinates\": [-97.807733, 33.2133019]}\n",
"\n",
"io_lulc_search = catalog.search(collections=[\"io-lulc\"], intersects=point)\n",
"io_lulc_items = [pc.sign(item).to_dict() for item in io_lulc_search.get_items()]\n",
"data = stackstac.stack(io_lulc_items, assets=[\"data\"], epsg=3857)\n",
"\n",
"data.shape, data.time"
]
}
],
"metadata": {
"interpreter": {
"hash": "327a3064184c72cf2315f340faf7cd6d38902e235df73e5f8747aa73527562c0"
},
"kernelspec": {
"display_name": "mambabase",
"language": "python",
"name": "mambabase"
},
"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.10.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment