Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions notebooks/compositing_debug.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "10573c5d",
"metadata": {},
"outputs": [],
"source": [
"import xarray as xr\n",
"import rioxarray\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"from pixelverse.download.sentinel2 import get_s2_times_series"
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "64c5aaf1",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
]
}
],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0901d96c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Found 2 items for month 6\n",
"scene level percent cloud cover: [25.208652, 45.391417]\n"
]
}
],
"source": [
"SAMPLE_AOI_BBOX = (34.30401965358922, 0.483473285913126, 34.3178177763533, 0.497271408677202)\n",
"# Get items (lazily loaded)\n",
"items_by_month = get_s2_times_series(bbox=SAMPLE_AOI_BBOX, year=2023, cloudcover_max=60, months=[6])"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "ecb54b08",
"metadata": {},
"outputs": [],
"source": [
"items_by_month "
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "af82a807",
"metadata": {},
"outputs": [],
"source": [
"rgb = items_by_month[[\"red\", \"green\", \"blue\"]].isel(time=0)\n",
"rgb_scaled = (255 * rgb / 3000).clip(0, 255).astype(\"uint8\")\n",
"rgb_scaled.rio.to_raster('./s2_rgb_month_test.tif')"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "dc860c00",
"metadata": {},
"outputs": [],
"source": [
"# Display RGB composite scaled to 3000\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"rgb = items_by_month[[\"red\", \"green\", \"blue\"]].isel(time=0)\n",
"rgb_array = np.stack([rgb[\"red\"].values, rgb[\"green\"].values, rgb[\"blue\"].values], axis=-1)\n",
"rgb_scaled = np.clip(rgb_array / 3000, 0, 1)\n",
"\n",
"plt.figure(figsize=(10, 10))\n",
"plt.imshow(rgb_scaled)\n",
"plt.axis('off')\n",
"plt.title('RGB Composite - Month 1')\n",
"plt.tight_layout()\n",
"plt.show()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4b798a20",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "bd858d7e",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"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.13.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading
Loading