Major Changes: - NEW: Scripts 09 & 10 for KPI calculation and enhanced reporting - NEW: Shell script wrappers (01-10) for easier execution - NEW: R packages flextable and officer for enhanced Word reports - NEW: DEPLOYMENT_README.md with complete deployment guide - RENAMED: Numbered R scripts (02, 03, 04) for clarity - REMOVED: Old package management scripts (using renv only) - UPDATED: Workflow now uses scripts 09->10 instead of 05 Files Changed: 90+ files New Packages: flextable, officer New Scripts: 09_run_calculate_kpis.sh, 10_run_kpi_report.sh Documentation: DEPLOYMENT_README.md, EMAIL_TO_ADMIN.txt See DEPLOYMENT_README.md for full deployment instructions.
762 lines
34 KiB
Plaintext
762 lines
34 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "0c18e312-8421-47d7-84f9-ed7d5e47e7ee",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"source": [
|
|
"#### Load packages and connect to SentinelHub"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 38,
|
|
"id": "b7ca7102-5fd9-481f-90cd-3ba60e288649",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# $ pip install sentinelhub\n",
|
|
"# pip install gdal\n",
|
|
"\n",
|
|
"import os\n",
|
|
"import json\n",
|
|
"import datetime\n",
|
|
"import numpy as np\n",
|
|
"import matplotlib.pyplot as plt\n",
|
|
"from pathlib import Path\n",
|
|
"from osgeo import gdal\n",
|
|
"\n",
|
|
"from sentinelhub import MimeType, CRS, BBox, SentinelHubRequest, SentinelHubDownloadClient, \\\n",
|
|
" DataCollection, bbox_to_dimensions, DownloadRequest, SHConfig, BBoxSplitter, read_data, Geometry, SentinelHubCatalog\n",
|
|
"\n",
|
|
"config = SHConfig()\n",
|
|
"catalog = SentinelHubCatalog(config=config)\n",
|
|
"\n",
|
|
"import time\n",
|
|
"import shutil\n",
|
|
"\n",
|
|
"import geopandas as gpd\n",
|
|
"from shapely.geometry import MultiLineString, MultiPolygon, Polygon, box, shape\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 39,
|
|
"id": "5491a840-779c-4f0c-8164-c3de738b3298",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"config.sh_client_id = '1a72d811-4f0e-4447-8282-df09608cff44'\n",
|
|
"config.sh_client_secret = 'FcBlRL29i9ZmTzhmKTv1etSMFs5PxSos'"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 40,
|
|
"id": "eb1fb662-0e25-4ca9-8317-c6953290842b",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"collection_id = 'c691479f-358c-46b1-b0f0-e12b70a9856c'\n",
|
|
"byoc = DataCollection.define_byoc(\n",
|
|
" collection_id,\n",
|
|
" name='planet_data2',\n",
|
|
" is_timeless=True)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "6adb603d-8182-48c6-a051-869e16ee7bba",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"source": [
|
|
"#### Set some variables\n",
|
|
"The only place anything might need to be changed."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 41,
|
|
"id": "060396e0-e5ee-4b54-b211-5d8bfcba167f",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"#project = 'Mkulazi_trail' #or xinavane or chemba_test_8b\n",
|
|
"#project = 'xinavane' #or xinavane or chemba_test_8b\n",
|
|
"project = 'aura' #or xinavane or chemba_test_8b\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 42,
|
|
"id": "c9f79e81-dff8-4109-8d26-6c423142dcf2",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Adjust the number of days needed\n",
|
|
"days = 7"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 43,
|
|
"id": "e18bdf8f-be4b-44ab-baaa-de5de60d92cb",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"#delete all the satellite outputs -> then True\n",
|
|
"empty_folder_question = True"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "81bbb513-0bd2-4277-83e8-6f94051ce70b",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"source": [
|
|
"#### Define functions\n",
|
|
"After this block, no manual changes to parameters are required. \n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 44,
|
|
"id": "3f7c8e04-4569-457b-b39d-283582c4ba36",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"BASE_PATH = Path('../laravel_app/storage/app') / os.getenv('PROJECT_DIR',project) \n",
|
|
"BASE_PATH_SINGLE_IMAGES = Path(BASE_PATH / 'single_images')\n",
|
|
"folder_for_merged_tifs = str(BASE_PATH / 'merged_tif')\n",
|
|
"folder_for_virtual_raster = str(BASE_PATH / 'merged_virtual')\n",
|
|
"#geojson_file = Path(BASE_PATH /'Data'/ 'pivot.geojson') #the geojsons should have the same name\n",
|
|
"geojson_file = Path(BASE_PATH /'Data'/ ('pivot_2.geojson' if project == \"esa\" else 'pivot.geojson')) #the geojsons should have the same name\n",
|
|
" \n",
|
|
"# Check if the folders exist, and if not, create them\n",
|
|
"if not os.path.exists(BASE_PATH_SINGLE_IMAGES):\n",
|
|
" os.makedirs(BASE_PATH_SINGLE_IMAGES)\n",
|
|
" \n",
|
|
"if not os.path.exists(folder_for_merged_tifs):\n",
|
|
" os.makedirs(folder_for_merged_tifs)\n",
|
|
"\n",
|
|
"if not os.path.exists(folder_for_virtual_raster):\n",
|
|
" os.makedirs(folder_for_virtual_raster)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 45,
|
|
"id": "244b5752-4f02-4347-9278-f6a0a46b88f4",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"evalscript_original = \"\"\"\n",
|
|
" //VERSION=3\n",
|
|
"\n",
|
|
" function setup() {\n",
|
|
" return {\n",
|
|
" input: [{\n",
|
|
" bands: [\"red\", \"green\", \"blue\", \"nir\", \"udm1\"]\n",
|
|
" }],\n",
|
|
" output: {\n",
|
|
" bands: 4\n",
|
|
" //sampleType: \"FLOAT32\"\n",
|
|
" }\n",
|
|
" };\n",
|
|
" }\n",
|
|
"\n",
|
|
" function evaluatePixel(sample) {\n",
|
|
" // Scale the bands and return as arrays\n",
|
|
" var scaledBlue = [2.5 * sample.blue / 10000];\n",
|
|
" var scaledGreen = [2.5 * sample.green / 10000];\n",
|
|
" var scaledRed = [2.5 * sample.red / 10000];\n",
|
|
" var scaledNIR = [2.5 * sample.nir / 10000];\n",
|
|
" \n",
|
|
" // Only use udm1 mask (Planet's usable data mask)\n",
|
|
" if (sample.udm1 == 0) {\n",
|
|
" return [scaledRed, scaledGreen, scaledBlue, scaledNIR];\n",
|
|
" } else {\n",
|
|
" return [NaN, NaN, NaN, NaN];\n",
|
|
" }\n",
|
|
" }\n",
|
|
"\"\"\"\n",
|
|
"\n",
|
|
"def get_true_color_request_day(time_interval, bbox, size):\n",
|
|
" return SentinelHubRequest(\n",
|
|
" evalscript=evalscript_original,\n",
|
|
" input_data=[\n",
|
|
" SentinelHubRequest.input_data(\n",
|
|
" data_collection=DataCollection.planet_data2,\n",
|
|
" time_interval=(time_interval, time_interval)\n",
|
|
" )\n",
|
|
" ],\n",
|
|
" responses=[\n",
|
|
" SentinelHubRequest.output_response('default', MimeType.TIFF)\n",
|
|
" ],\n",
|
|
" bbox=bbox,\n",
|
|
" size=size,\n",
|
|
" config=config,\n",
|
|
" data_folder=str(BASE_PATH_SINGLE_IMAGES / time_interval),\n",
|
|
"\n",
|
|
" )\n",
|
|
"\n",
|
|
"\n",
|
|
"def download_function(slot, bbox, size):\n",
|
|
" # create a list of requests\n",
|
|
" list_of_requests = [get_true_color_request_day(slot, bbox, size)]\n",
|
|
" list_of_requests = [request.download_list[0] for request in list_of_requests]\n",
|
|
"\n",
|
|
" # download data chemba west with multiple threads\n",
|
|
" data = SentinelHubDownloadClient(config=config).download(list_of_requests, max_threads=15)\n",
|
|
" print(f' Image downloaded for ' +slot + ' and bbox ' + str(bbox))\n",
|
|
" \n",
|
|
" time.sleep(.1)\n",
|
|
" \n",
|
|
"\n",
|
|
"def merge_files(slot):\n",
|
|
" \n",
|
|
" # List the downloaded Tiffs in the different subfolders with pathlib (native library)\n",
|
|
" file_list = [f\"{x}/response.tiff\" for x in Path(BASE_PATH_SINGLE_IMAGES / slot).iterdir()]\n",
|
|
" \n",
|
|
" #print(file_list)\n",
|
|
"\n",
|
|
" folder_for_merged_tifs = str(BASE_PATH / 'merged_tif' / f\"{slot}.tif\")\n",
|
|
" folder_for_virtual_raster = str(BASE_PATH / 'merged_virtual' / f\"merged{slot}.vrt\")\n",
|
|
"\n",
|
|
" # Create a virtual raster\n",
|
|
" vrt_all = gdal.BuildVRT(folder_for_virtual_raster, file_list)\n",
|
|
" vrt_all = gdal.BuildVRT(folder_for_virtual_raster, file_list)\n",
|
|
"\n",
|
|
" # Convert to JPEG\n",
|
|
" gdal.Translate(folder_for_merged_tifs,folder_for_virtual_raster)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 46,
|
|
"id": "848dc773-70d6-4ae6-b05c-d6ebfb41624d",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Monthly time windows:\n",
|
|
"\n",
|
|
"2025-09-24\n",
|
|
"2025-09-25\n",
|
|
"2025-09-26\n",
|
|
"2025-09-27\n",
|
|
"2025-09-28\n",
|
|
"2025-09-29\n",
|
|
"2025-09-30\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"days_needed = int(os.environ.get(\"DAYS\", days))\n",
|
|
"date_str = os.environ.get(\"DATE\")\n",
|
|
"\n",
|
|
"if date_str:\n",
|
|
" # Parse de datumstring naar een datetime.date object\n",
|
|
" end = datetime.datetime.strptime(date_str, \"%Y-%m-%d\").date()\n",
|
|
"else:\n",
|
|
" # Gebruik de huidige datum als fallback\n",
|
|
" end = datetime.date.today() \n",
|
|
"\n",
|
|
"start = end - datetime.timedelta(days=days_needed - 1)\n",
|
|
"\n",
|
|
"slots = [(start + datetime.timedelta(days=i)).strftime('%Y-%m-%d') for i in range(days_needed)]\n",
|
|
"\n",
|
|
"print('Monthly time windows:\\n')\n",
|
|
"if len(slots) > 10:\n",
|
|
" for slot in slots[:3]:\n",
|
|
" print(slot)\n",
|
|
" print(\"...\")\n",
|
|
" for slot in slots[-3:]:\n",
|
|
" print(slot)\n",
|
|
"else:\n",
|
|
" for slot in slots:\n",
|
|
" print(slot)\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "f8ea846f-783b-4460-a951-7b522273555f",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Download images\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 47,
|
|
"id": "c803e373-2567-4233-af7d-0d2d6f7d4f8e",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"geo_json = gpd.read_file(str(geojson_file))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 48,
|
|
"id": "dc24d54e-2272-4f30-bcf5-4d8fc381915c",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"geometries = [Geometry(geometry, crs=CRS.WGS84) for geometry in geo_json.geometry]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 49,
|
|
"id": "cd071b42-d0cd-4e54-8f88-ad1a339748e3",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"shapely_geometries = [geometry.geometry for geometry in geometries]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 50,
|
|
"id": "301d12e4-e47a-4034-aec0-aa5673e64935",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Area bounding box: BBox(((35.16355804199998, -0.169299186999979), (35.25300975, -0.085633863)), crs=CRS('4326'))\n",
|
|
"\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"bbox_splitter = BBoxSplitter(\n",
|
|
" shapely_geometries, CRS.WGS84, (5, 5), reduce_bbox_sizes=True\n",
|
|
") # bounding box will be split into a grid of 5x4 bounding boxes\n",
|
|
"\n",
|
|
"# based on https://github.com/sentinel-hub/sentinelhub-py/blob/master/examples/large_area_utilities.ipynb \n",
|
|
"\n",
|
|
"print(\"Area bounding box: {}\\n\".format(bbox_splitter.get_area_bbox().__repr__()))\n",
|
|
"\n",
|
|
"bbox_list = bbox_splitter.get_bbox_list()\n",
|
|
"info_list = bbox_splitter.get_info_list()\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 51,
|
|
"id": "431f6856-8d7e-4868-b627-20deeb47d77e",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"image/svg+xml": [
|
|
"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"100.0\" height=\"100.0\" viewBox=\"35.163481079599975 -0.12942067140001187 0.002077984800024524 0.0012193748000007554\" preserveAspectRatio=\"xMinYMin meet\"><g transform=\"matrix(1,0,0,-1,0,-0.257621968000023)\"><path fill-rule=\"evenodd\" fill=\"#66cc99\" stroke=\"#555555\" stroke-width=\"4.1559696000490476e-05\" opacity=\"0.6\" d=\"M 35.164844845,-0.128278259000012 L 35.165482102,-0.129021881000028 L 35.164251411,-0.129343709000011 L 35.16355804199998,-0.12867928999998 L 35.164844845,-0.128278259000012 z\" /></g></svg>"
|
|
],
|
|
"text/plain": [
|
|
"<POLYGON ((35.165 -0.128, 35.165 -0.129, 35.164 -0.129, 35.164 -0.129, 35.16...>"
|
|
]
|
|
},
|
|
"execution_count": 51,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"geometry_list = bbox_splitter.get_geometry_list()\n",
|
|
"\n",
|
|
"geometry_list[0]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 52,
|
|
"id": "18655785",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Function to check if images are available for a given date\n",
|
|
"def is_image_available(date):\n",
|
|
" for bbox in bbox_list:\n",
|
|
" search_iterator = catalog.search(\n",
|
|
" collection=byoc,\n",
|
|
" bbox=bbox, # Define your bounding box\n",
|
|
" time=(date, date)\n",
|
|
" )\n",
|
|
" if len(list(search_iterator)) > 0:\n",
|
|
" return True\n",
|
|
" return False\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 53,
|
|
"id": "a6fc418f",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Filter slots to only include dates with available images\n",
|
|
"available_slots = [slot for slot in slots if is_image_available(slot)]\n",
|
|
"\n",
|
|
"# Store the first 5 available slots for comparison later (if available)\n",
|
|
"comparison_slots = available_slots[:min(5, len(available_slots))]\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 54,
|
|
"id": "ebc416be",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"['2025-09-24', '2025-09-25', '2025-09-26', '2025-09-27', '2025-09-28', '2025-09-29']\n",
|
|
"Total slots: 7\n",
|
|
"Available slots: 6\n",
|
|
"Excluded slots due to empty dates: 1\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print(available_slots)\n",
|
|
"print(f\"Total slots: {len(slots)}\")\n",
|
|
"print(f\"Available slots: {len(available_slots)}\")\n",
|
|
"print(f\"Excluded slots due to empty dates: {len(slots) - len(available_slots)}\")\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 55,
|
|
"id": "b0cabe8f-e1f2-4b18-8ac0-c2565d0ff16b",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def show_splitter(splitter, alpha=0.2, area_buffer=0.2, show_legend=False):\n",
|
|
" area_bbox = splitter.get_area_bbox()\n",
|
|
" minx, miny, maxx, maxy = area_bbox\n",
|
|
" lng, lat = area_bbox.middle\n",
|
|
" w, h = maxx - minx, maxy - miny\n",
|
|
" minx = minx - area_buffer * w\n",
|
|
" miny = miny - area_buffer * h\n",
|
|
" maxx = maxx + area_buffer * w\n",
|
|
" maxy = maxy + area_buffer * h\n",
|
|
"\n",
|
|
" fig = plt.figure(figsize=(10, 10))\n",
|
|
" ax = fig.add_subplot(111)\n",
|
|
"\n",
|
|
" base_map = Basemap(\n",
|
|
" projection=\"mill\",\n",
|
|
" lat_0=lat,\n",
|
|
" lon_0=lng,\n",
|
|
" llcrnrlon=minx,\n",
|
|
" llcrnrlat=miny,\n",
|
|
" urcrnrlon=maxx,\n",
|
|
" urcrnrlat=maxy,\n",
|
|
" resolution=\"l\",\n",
|
|
" epsg=4326,\n",
|
|
" )\n",
|
|
" base_map.drawcoastlines(color=(0, 0, 0, 0))\n",
|
|
"\n",
|
|
" area_shape = splitter.get_area_shape()\n",
|
|
"\n",
|
|
" if isinstance(area_shape, Polygon):\n",
|
|
" polygon_iter = [area_shape]\n",
|
|
" elif isinstance(area_shape, MultiPolygon):\n",
|
|
" polygon_iter = area_shape.geoms\n",
|
|
" else:\n",
|
|
" raise ValueError(f\"Geometry of type {type(area_shape)} is not supported\")\n",
|
|
"\n",
|
|
" for polygon in polygon_iter:\n",
|
|
" if isinstance(polygon.boundary, MultiLineString):\n",
|
|
" for linestring in polygon.boundary:\n",
|
|
" ax.add_patch(PltPolygon(np.array(linestring), closed=True, facecolor=(0, 0, 0, 0), edgecolor=\"red\"))\n",
|
|
" else:\n",
|
|
" ax.add_patch(\n",
|
|
" PltPolygon(np.array(polygon.boundary.coords), closed=True, facecolor=(0, 0, 0, 0), edgecolor=\"red\")\n",
|
|
" )\n",
|
|
"\n",
|
|
" bbox_list = splitter.get_bbox_list()\n",
|
|
" info_list = splitter.get_info_list()\n",
|
|
"\n",
|
|
" cm = plt.get_cmap(\"jet\", len(bbox_list))\n",
|
|
" legend_shapes = []\n",
|
|
" for i, bbox in enumerate(bbox_list):\n",
|
|
" wgs84_bbox = bbox.transform(CRS.WGS84).get_polygon()\n",
|
|
"\n",
|
|
" tile_color = tuple(list(cm(i))[:3] + [alpha])\n",
|
|
" ax.add_patch(PltPolygon(np.array(wgs84_bbox), closed=True, facecolor=tile_color, edgecolor=\"green\"))\n",
|
|
"\n",
|
|
" if show_legend:\n",
|
|
" legend_shapes.append(plt.Rectangle((0, 0), 1, 1, fc=cm(i)))\n",
|
|
"\n",
|
|
" if show_legend:\n",
|
|
" legend_names = []\n",
|
|
" for info in info_list:\n",
|
|
" legend_name = \"{},{}\".format(info[\"index_x\"], info[\"index_y\"])\n",
|
|
"\n",
|
|
" for prop in [\"grid_index\", \"tile\"]:\n",
|
|
" if prop in info:\n",
|
|
" legend_name = \"{},{}\".format(info[prop], legend_name)\n",
|
|
"\n",
|
|
" legend_names.append(legend_name)\n",
|
|
"\n",
|
|
" plt.legend(legend_shapes, legend_names)\n",
|
|
" plt.tight_layout()\n",
|
|
" plt.show()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 56,
|
|
"id": "41b7369c-f768-44ba-983e-eb8eae4f3afd",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"c:\\Users\\timon\\anaconda3\\Lib\\site-packages\\sentinelhub\\geometry.py:137: SHDeprecationWarning: Initializing `BBox` objects from `BBox` objects will no longer be possible in future versions.\n",
|
|
" return cls._tuple_from_bbox(bbox)\n",
|
|
"C:\\Users\\timon\\AppData\\Local\\Temp\\ipykernel_22880\\1551185686.py:59: SHDeprecationWarning: The string representation of `BBox` will change to match its `repr` representation.\n",
|
|
" print(f' Image downloaded for ' +slot + ' and bbox ' + str(bbox))\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
" Image downloaded for 2025-09-24 and bbox 35.16355804199998,-0.129343709000011,35.165482102,-0.128278259000012\n",
|
|
" Image downloaded for 2025-09-24 and bbox 35.19342203000002,-0.145566114000019,35.19815707700002,-0.141901112000028\n",
|
|
" Image downloaded for 2025-09-24 and bbox 35.186062252,-0.11468985800002,35.19125232599998,-0.112838832000023\n",
|
|
" Image downloaded for 2025-09-24 and bbox 35.216724886,-0.16921497048746426,35.21722906679999,-0.168239035\n",
|
|
" Image downloaded for 2025-09-24 and bbox 35.215712869000015,-0.144763049,35.21692640200001,-0.143002134000028\n",
|
|
" Image downloaded for 2025-09-24 and bbox 35.208590781,-0.087364975000014,35.210532812,-0.085633863\n",
|
|
" Image downloaded for 2025-09-24 and bbox 35.21722906679999,-0.169299186999979,35.22781605,-0.16564269700001\n",
|
|
" Image downloaded for 2025-09-24 and bbox 35.23161692399998,-0.136799790999987,35.23314344099998,-0.1358330573999874\n",
|
|
" Image downloaded for 2025-09-24 and bbox 35.231617117966266,-0.1358330573999874,35.232720503778594,-0.13495027099998\n",
|
|
" Image downloaded for 2025-09-24 and bbox 35.25088550999999,-0.160822344999985,35.25300975,-0.156598042999974\n",
|
|
" Image downloaded for 2025-09-25 and bbox 35.16355804199998,-0.129343709000011,35.165482102,-0.128278259000012\n",
|
|
" Image downloaded for 2025-09-25 and bbox 35.19342203000002,-0.145566114000019,35.19815707700002,-0.141901112000028\n",
|
|
" Image downloaded for 2025-09-25 and bbox 35.186062252,-0.11468985800002,35.19125232599998,-0.112838832000023\n",
|
|
" Image downloaded for 2025-09-25 and bbox 35.216724886,-0.16921497048746426,35.21722906679999,-0.168239035\n",
|
|
" Image downloaded for 2025-09-25 and bbox 35.215712869000015,-0.144763049,35.21692640200001,-0.143002134000028\n",
|
|
" Image downloaded for 2025-09-25 and bbox 35.208590781,-0.087364975000014,35.210532812,-0.085633863\n",
|
|
" Image downloaded for 2025-09-25 and bbox 35.21722906679999,-0.169299186999979,35.22781605,-0.16564269700001\n",
|
|
" Image downloaded for 2025-09-25 and bbox 35.23161692399998,-0.136799790999987,35.23314344099998,-0.1358330573999874\n",
|
|
" Image downloaded for 2025-09-25 and bbox 35.231617117966266,-0.1358330573999874,35.232720503778594,-0.13495027099998\n",
|
|
" Image downloaded for 2025-09-25 and bbox 35.25088550999999,-0.160822344999985,35.25300975,-0.156598042999974\n",
|
|
" Image downloaded for 2025-09-26 and bbox 35.16355804199998,-0.129343709000011,35.165482102,-0.128278259000012\n",
|
|
" Image downloaded for 2025-09-26 and bbox 35.19342203000002,-0.145566114000019,35.19815707700002,-0.141901112000028\n",
|
|
" Image downloaded for 2025-09-26 and bbox 35.186062252,-0.11468985800002,35.19125232599998,-0.112838832000023\n",
|
|
" Image downloaded for 2025-09-26 and bbox 35.216724886,-0.16921497048746426,35.21722906679999,-0.168239035\n",
|
|
" Image downloaded for 2025-09-26 and bbox 35.215712869000015,-0.144763049,35.21692640200001,-0.143002134000028\n",
|
|
" Image downloaded for 2025-09-26 and bbox 35.208590781,-0.087364975000014,35.210532812,-0.085633863\n",
|
|
" Image downloaded for 2025-09-26 and bbox 35.21722906679999,-0.169299186999979,35.22781605,-0.16564269700001\n",
|
|
" Image downloaded for 2025-09-26 and bbox 35.23161692399998,-0.136799790999987,35.23314344099998,-0.1358330573999874\n",
|
|
" Image downloaded for 2025-09-26 and bbox 35.231617117966266,-0.1358330573999874,35.232720503778594,-0.13495027099998\n",
|
|
" Image downloaded for 2025-09-26 and bbox 35.25088550999999,-0.160822344999985,35.25300975,-0.156598042999974\n",
|
|
" Image downloaded for 2025-09-27 and bbox 35.16355804199998,-0.129343709000011,35.165482102,-0.128278259000012\n",
|
|
" Image downloaded for 2025-09-27 and bbox 35.19342203000002,-0.145566114000019,35.19815707700002,-0.141901112000028\n",
|
|
" Image downloaded for 2025-09-27 and bbox 35.186062252,-0.11468985800002,35.19125232599998,-0.112838832000023\n",
|
|
" Image downloaded for 2025-09-27 and bbox 35.216724886,-0.16921497048746426,35.21722906679999,-0.168239035\n",
|
|
" Image downloaded for 2025-09-27 and bbox 35.215712869000015,-0.144763049,35.21692640200001,-0.143002134000028\n",
|
|
" Image downloaded for 2025-09-27 and bbox 35.208590781,-0.087364975000014,35.210532812,-0.085633863\n",
|
|
" Image downloaded for 2025-09-27 and bbox 35.21722906679999,-0.169299186999979,35.22781605,-0.16564269700001\n",
|
|
" Image downloaded for 2025-09-27 and bbox 35.23161692399998,-0.136799790999987,35.23314344099998,-0.1358330573999874\n",
|
|
" Image downloaded for 2025-09-27 and bbox 35.231617117966266,-0.1358330573999874,35.232720503778594,-0.13495027099998\n",
|
|
" Image downloaded for 2025-09-27 and bbox 35.25088550999999,-0.160822344999985,35.25300975,-0.156598042999974\n",
|
|
" Image downloaded for 2025-09-28 and bbox 35.16355804199998,-0.129343709000011,35.165482102,-0.128278259000012\n",
|
|
" Image downloaded for 2025-09-28 and bbox 35.19342203000002,-0.145566114000019,35.19815707700002,-0.141901112000028\n",
|
|
" Image downloaded for 2025-09-28 and bbox 35.186062252,-0.11468985800002,35.19125232599998,-0.112838832000023\n",
|
|
" Image downloaded for 2025-09-28 and bbox 35.216724886,-0.16921497048746426,35.21722906679999,-0.168239035\n",
|
|
" Image downloaded for 2025-09-28 and bbox 35.215712869000015,-0.144763049,35.21692640200001,-0.143002134000028\n",
|
|
" Image downloaded for 2025-09-28 and bbox 35.208590781,-0.087364975000014,35.210532812,-0.085633863\n",
|
|
" Image downloaded for 2025-09-28 and bbox 35.21722906679999,-0.169299186999979,35.22781605,-0.16564269700001\n",
|
|
" Image downloaded for 2025-09-28 and bbox 35.23161692399998,-0.136799790999987,35.23314344099998,-0.1358330573999874\n",
|
|
" Image downloaded for 2025-09-28 and bbox 35.231617117966266,-0.1358330573999874,35.232720503778594,-0.13495027099998\n",
|
|
" Image downloaded for 2025-09-28 and bbox 35.25088550999999,-0.160822344999985,35.25300975,-0.156598042999974\n",
|
|
" Image downloaded for 2025-09-29 and bbox 35.16355804199998,-0.129343709000011,35.165482102,-0.128278259000012\n",
|
|
" Image downloaded for 2025-09-29 and bbox 35.19342203000002,-0.145566114000019,35.19815707700002,-0.141901112000028\n",
|
|
" Image downloaded for 2025-09-29 and bbox 35.186062252,-0.11468985800002,35.19125232599998,-0.112838832000023\n",
|
|
" Image downloaded for 2025-09-29 and bbox 35.216724886,-0.16921497048746426,35.21722906679999,-0.168239035\n",
|
|
" Image downloaded for 2025-09-29 and bbox 35.215712869000015,-0.144763049,35.21692640200001,-0.143002134000028\n",
|
|
" Image downloaded for 2025-09-29 and bbox 35.208590781,-0.087364975000014,35.210532812,-0.085633863\n",
|
|
" Image downloaded for 2025-09-29 and bbox 35.21722906679999,-0.169299186999979,35.22781605,-0.16564269700001\n",
|
|
" Image downloaded for 2025-09-29 and bbox 35.23161692399998,-0.136799790999987,35.23314344099998,-0.1358330573999874\n",
|
|
" Image downloaded for 2025-09-29 and bbox 35.231617117966266,-0.1358330573999874,35.232720503778594,-0.13495027099998\n",
|
|
" Image downloaded for 2025-09-29 and bbox 35.25088550999999,-0.160822344999985,35.25300975,-0.156598042999974\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"# Load areas outside the loop if they remain constant\n",
|
|
"#bbox_area = json.dumps(chosen_area)\n",
|
|
"#areas = json.loads(os.getenv('BBOX', bbox_area))\n",
|
|
"resolution = 3\n",
|
|
"\n",
|
|
"for slot in available_slots:\n",
|
|
" for bbox in bbox_list:\n",
|
|
" bbox = BBox(bbox=bbox, crs=CRS.WGS84)\n",
|
|
" size = bbox_to_dimensions(bbox, resolution=resolution)\n",
|
|
" download_function(slot, bbox, size)\n",
|
|
" time.sleep(0.2)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 57,
|
|
"id": "68db3c15-6f94-432e-b315-c329e4251b21",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"for slot in available_slots:\n",
|
|
" merge_files(slot)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "4274d8e7-1ea3-46db-9528-069ede0b2132",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"source": [
|
|
"#### Delete intermediate files\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 58,
|
|
"id": "cb3fa856-a550-4899-844a-e69209bba3ad",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Emptied folder: ..\\laravel_app\\storage\\app\\aura\\merged_virtual\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-04-25\\\\37ce883de72e7ea4e5db310659249afe'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-04-26\\\\056d651121bad1bca62c5d14d53db39b'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-04-28\\\\15003b17913ecb076b87ebcfe8b852a1'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-04-29\\\\0ad319685145738356440ffa60ee05e1'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-04-30\\\\0aba91aff99fdf6d275aa678209dc949'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-05-01\\\\2a970008493e784349dd2aff01dc719d'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-05-02\\\\19531b16909aeb9d8d3388329a34fa3b'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-05-05\\\\09b5ab5b5fa47c89bb73babd09a588e3'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-05-06\\\\009f0f0100d00f4188ab6d83f88f72a5'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-05-07\\\\12330850d8389db905b335ac34028e36'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-05-09\\\\01915e4caba800f2c27344e97b2235be'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-05-10\\\\0410b1f6b14a778613430466eb7ad6de'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-05-11\\\\0f06c11f2eff290ffa2350155392897c'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-05-13\\\\04b312cc3520482017b438a93bd35d83'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-05-14\\\\3e6c898a261bd223bb88e1d500fb2205'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-05-15\\\\30173c5a1a22af7181263fa85988d5d7'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-05-16\\\\047cac717167884be8f88774073373b3'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-05-17\\\\0f1a22133295603a2c0424545ddb6f63'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-05-18\\\\319759fe3f9894327c302f546f3b8f05'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-05-19\\\\0a23f5edb7885accfe0d941962f034b2'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-05-20\\\\02b5c1f242fc2774812bf5caaacde542'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-05-21\\\\143523149ad4bd08248d190068bb8580'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-05-22\\\\02af7f74a75f48e3217417c5c28e5cbe'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-05-24\\\\218f6daa002010bd22144e4db883435d'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-05-25\\\\154e916d4b7a9e56be9a971f5234aa8f'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-05-26\\\\1db5f0f7b2113ac38d40de204e575a92'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-05-27\\\\007af5c52a19e32084859b8dccddd36e'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-05-28\\\\0b7b22d7e93a4523896472c3c57684d3'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-05-29\\\\01992d808e1db004bc13732bef24c160'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-05-31\\\\115005e7b953c87b5afb378c2b9523a4'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-06-01\\\\02484511825d62d65ac2005ccb800077'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-06-02\\\\4204a901299e200229b3d68e8022ea62'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-06-03\\\\02e1a22ba0329a7d721e3e1ac428931b'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-06-05\\\\28a31ecf8ca5432fb2fb889e1e383969'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-06-07\\\\15a677ad344ed4ab156980fedff88820'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-06-09\\\\05d469a686fe127b4cfa32f8509f70f5'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-06-10\\\\148e5b0ea59516f00070850a808773f6'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-06-11\\\\2d3813f2bac34eac4011dd3a977715d6'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-06-12\\\\11774fbda11458e6b7c177e67b6b8c20'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-06-13\\\\05d30cf1cc0d1cd808211c56f749dfe7'\n",
|
|
"Error: [WinError 5] Toegang geweigerd: '..\\\\laravel_app\\\\storage\\\\app\\\\aura\\\\single_images\\\\2025-06-14\\\\06d82f3a2ac198df592f40b965ba7abc'\n",
|
|
"Emptied folder: ..\\laravel_app\\storage\\app\\aura\\single_images\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"# List of folder names\n",
|
|
"\n",
|
|
"folders_to_empty = [BASE_PATH / 'merged_virtual', BASE_PATH_SINGLE_IMAGES]\n",
|
|
" \n",
|
|
"# Function to empty folders\n",
|
|
"\n",
|
|
"# Function to empty folders\n",
|
|
"def empty_folders(folders, run=True):\n",
|
|
" if not run:\n",
|
|
" print(\"Skipping empty_folders function.\")\n",
|
|
" return\n",
|
|
" \n",
|
|
" for folder in folders:\n",
|
|
" try:\n",
|
|
" for filename in os.listdir(folder):\n",
|
|
" file_path = os.path.join(folder, filename)\n",
|
|
" try:\n",
|
|
" if os.path.isfile(file_path):\n",
|
|
" os.unlink(file_path)\n",
|
|
" elif os.path.isdir(file_path):\n",
|
|
" shutil.rmtree(file_path)\n",
|
|
" except Exception as e:\n",
|
|
" print(f\"Error: {e}\")\n",
|
|
" print(f\"Emptied folder: {folder}\")\n",
|
|
" except OSError as e:\n",
|
|
" print(f\"Error: {e}\")\n",
|
|
"\n",
|
|
"# Call the function to empty folders only if the 'run' parameter is set to True\n",
|
|
"empty_folders(folders_to_empty, run=empty_folder_question)\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "fa849800",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "base",
|
|
"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.12.3"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|