{ "cells": [ { "cell_type": "markdown", "id": "3b3d19e7", "metadata": {}, "source": [ "# Sentinel-2 Time Series" ] }, { "cell_type": "code", "execution_count": 1, "id": "299a52a6", "metadata": {}, "outputs": [], "source": [ "from pcxarray import pc_query, prepare_timeseries\n", "from pcxarray.utils import load_census_shapefile\n", "from distributed import Client # dask distributed client\n", "import matplotlib.pyplot as plt\n", "from IPython.display import HTML\n", "from matplotlib.animation import FuncAnimation" ] }, { "cell_type": "code", "execution_count": 2, "id": "de4c8d1f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Dask client dashboard: http://127.0.0.1:8787/status\n" ] } ], "source": [ "client = Client(processes=True)\n", "print(f\"Dask client dashboard: {client.dashboard_link}\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "f9bbf254", "metadata": {}, "outputs": [], "source": [ "okt_gdf = load_census_shapefile(level=\"county\", verify=False)\n", "okt_gdf = okt_gdf[okt_gdf['NAME'] == \"Oktibbeha\"]\n", "okt_gdf = okt_gdf.to_crs(\"EPSG:32616\") # UTM zone 16N\n", "\n", "selected_geom = okt_gdf.geometry.union_all()" ] }, { "cell_type": "code", "execution_count": 4, "id": "1948188d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Found 548 items in the query.\n" ] } ], "source": [ "items_gdf = pc_query(\n", " collections=[\"sentinel-2-l2a\"],\n", " geometry=selected_geom,\n", " datetime='2024', # grab all of 2024\n", " crs=okt_gdf.crs,\n", " # query={\"eo:cloud_cover\": {\"lt\": 50}} # OPTIONAL: filter by cloud cover\n", ")\n", "print(f\"Found {len(items_gdf)} items in the query.\")" ] }, { "cell_type": "code", "execution_count": 5, "id": "d8bfea5e", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Constructing dask computation graph: 0%| | 0/134 [00:00, ?timestep/s]" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Constructing dask computation graph: 100%|██████████| 134/134 [00:21<00:00, 6.25timestep/s]\n" ] }, { "data": { "text/html": [ "
<xarray.DataArray 'reproject-dbd79c696dd74ace8557a2a62da24a95' (time: 134,\n",
" band: 4,\n",
" y: 3128, x: 3932)> Size: 26GB\n",
"dask.array<rechunk-merge, shape=(134, 4, 3128, 3932), dtype=float32, chunksize=(16, 1, 2048, 2048), chunktype=numpy.ndarray>\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 1kB 2024-01-02 2024-01-05 ... 2024-12-30\n",
" spatial_ref int32 4B 32616\n",
" * band (band) <U3 48B 'B02' 'B04' 'B08' 'SCL'\n",
" * y (y) float64 25kB 3.716e+06 3.716e+06 ... 3.684e+06 3.684e+06\n",
" * x (x) float64 31kB 3.055e+05 3.055e+05 ... 3.448e+05 3.448e+05\n",
"Attributes:\n",
" AREA_OR_POINT: Area\n",
" scale_factor: 1.0\n",
" add_offset: 0.0\n",
" _FillValue: nan