Skip to content
Merged
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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,11 @@ data/credentials-wildfire.json

#minio stuff
data/minio/.minio.sys/

data/.Trash-0
containers/notebooks/app/.Trash-0

.DS_STORE

data/alert_samples/
data/triangulated_sequences/
2 changes: 1 addition & 1 deletion containers/notebooks/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use an official Python runtime as a parent image
FROM python:3.8
FROM python:3.11

# Set the working directory to /app
WORKDIR /app
Expand Down
169 changes: 131 additions & 38 deletions containers/notebooks/app/Download_Sequences_from_a_DistantAlertAPI.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "649157c6-0ce3-4324-a7b6-15c911ddaf36",
"metadata": {},
"outputs": [],
"source": [
"SEQUENCE_ID_LIST = [13802, 9456]\n",
"BASE_DIRECTORY = \"alerts\" # directory where to put sequences data"
"SEQUENCE_ID_LIST = [15462, 15463, 15561, 15526, 13880, 13572, 13537, 12997, 12562, 15376, 15526]\n",
"BASE_DIRECTORY = \"../data/alert_samples\" # directory where to put sequences data"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "4e511d97-245c-45cc-9216-a16d31b663aa",
"metadata": {},
"outputs": [],
Expand All @@ -49,7 +49,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "ac07ba29-68d0-42d2-bafe-e94d961ec6c2",
"metadata": {},
"outputs": [],
Expand All @@ -72,48 +72,141 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "d3c12b1d-54f1-4d8d-b591-dc04ecc35db2",
"execution_count": 4,
"id": "07192f5f-9a69-41a4-9a97-1f1fcefaaf5b",
"metadata": {},
"outputs": [],
"source": [
"for seq_id in SEQUENCE_ID_LIST: \n",
" sequences = api_client.fetch_sequences_detections(sequence_id=seq_id).json()\n",
"def dl_seqs_in_target_dir(sequence_id_list, target_dir, api_client):\n",
" \"\"\"\n",
" Download sequences from sequence_id_list to target_dir, using an instanciated api_client (of distant Pyronear alert API)\n",
"\n",
" cam_name = [item['name'] for item in cameras if item['id'] == sequences[0]['camera_id']][0]\n",
" created_at_rounded = sequences[0][\"created_at\"].split('.')[0].replace(':', '-').replace('T', '_')\n",
" \"\"\"\n",
" \n",
" print(f\"== Download Alerts data for sequence ID {seq_id} - camera {cam_name} at {created_at_rounded}\")\n",
" for seq_id in sequence_id_list: \n",
" sequences = api_client.fetch_sequences_detections(sequence_id=seq_id, limit=10, desc=False).json()\n",
" \n",
" alert_dir = os.path.join(f\"{cam_name}_{created_at_rounded}\")\n",
" image_dir = os.path.join(base_dir,alert_dir, \"images\")\n",
" pred_dir = os.path.join(base_dir, alert_dir, \"labels_predictions\")\n",
" os.makedirs(image_dir, exist_ok=True)\n",
" os.makedirs(pred_dir, exist_ok=True)\n",
"\n",
" for seq in sequences:\n",
" cam_name = [item['name'] for item in cameras if item['id'] == sequences[0]['camera_id']][0]\n",
" created_at_rounded = sequences[0][\"created_at\"].split('.')[0].replace(':', '-').replace('T', '_')\n",
" cam_id_distant_api = sequences[0][\"camera_id\"]\n",
" print(f\"== Download Alerts data for sequence ID {seq_id} - camera {cam_name} at {created_at_rounded}\")\n",
" \n",
" # bbox\n",
" #yolo_format_bbox = ' '.join(map(str,ast.literal_eval(seq[\"bboxes\"])[0]))\n",
" bboxes = seq[\"bboxes\"]\n",
" alert_dir = os.path.join(f\"{cam_id_distant_api}_{cam_name}_{created_at_rounded}\")\n",
" image_dir = os.path.join(target_dir,alert_dir, \"images\")\n",
" pred_dir = os.path.join(target_dir, alert_dir, \"labels_predictions\")\n",
" os.makedirs(image_dir, exist_ok=True)\n",
" os.makedirs(pred_dir, exist_ok=True)\n",
" \n",
" for seq in sequences:\n",
" \n",
" # bbox\n",
" #yolo_format_bbox = ' '.join(map(str,ast.literal_eval(seq[\"bboxes\"])[0]))\n",
" bboxes = seq[\"bboxes\"]\n",
" \n",
" bbox_file_name = seq[\"bucket_key\"][:-4] + \".txt\"\n",
" \n",
" with open(os.path.join(target_dir, alert_dir, \"labels_predictions\",bbox_file_name), 'w') as f:\n",
" f.write(bboxes)\n",
" \n",
" url = seq['url']\n",
" nom_fichier = seq[\"bucket_key\"]\n",
" # image\n",
" response = requests.get(url, stream=True)\n",
" if response.status_code == 200:\n",
" full_img_path = os.path.join(image_dir, nom_fichier)\n",
" with open(full_img_path, 'wb') as f:\n",
" for chunk in response.iter_content(1024):\n",
" f.write(chunk)\n",
" else:\n",
" print(f\"Error during download.\")\n",
" print(\"Download complete\")\n",
" "
]
},
{
"cell_type": "markdown",
"id": "9503b5d5-9930-4c9e-9fbe-1eb1e563fd44",
"metadata": {},
"source": [
"# Download sequences from SEQUENCE_ID_LIST list"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "b2d033e9-7ce2-4cf4-995e-01ea2c15e235",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"== Download Alerts data for sequence ID 15462 - camera serre-de-barre-01 at 2025-09-29_13-56-58\n",
"== Download Alerts data for sequence ID 15463 - camera brison-03 at 2025-09-29_13-58-36\n",
"== Download Alerts data for sequence ID 15561 - camera pouncho-agast-01 at 2025-10-01_06-18-57\n",
"== Download Alerts data for sequence ID 15526 - camera pouncho-agast-01 at 2025-09-30_15-29-49\n",
"== Download Alerts data for sequence ID 13880 - camera fontaneilles-01 at 2025-09-04_07-34-32\n",
"== Download Alerts data for sequence ID 13572 - camera pouncho-agast-01 at 2025-08-29_06-59-39\n",
"== Download Alerts data for sequence ID 13537 - camera pouncho-agast-01 at 2025-08-28_15-31-17\n",
"== Download Alerts data for sequence ID 12997 - camera pouncho-agast-01 at 2025-08-17_15-52-27\n",
"== Download Alerts data for sequence ID 12562 - camera pouncho-agast-01 at 2025-08-06_12-32-09\n",
"== Download Alerts data for sequence ID 15376 - camera pouncho-agast-02 at 2025-09-28_10-52-39\n",
"== Download Alerts data for sequence ID 15526 - camera pouncho-agast-01 at 2025-09-30_15-29-49\n",
"Download complete\n"
]
}
],
"source": [
"single_alerts = os.path.join(BASE_DIRECTORY, \"single_sequences\")\n",
"os.makedirs(single_alerts, exist_ok=True)\n",
"\n",
" bbox_file_name = seq[\"bucket_key\"][:-4] + \".txt\"\n",
" \n",
" with open(os.path.join(base_dir, alert_dir, \"labels_predictions\",bbox_file_name), 'w') as f:\n",
" f.write(bboxes)\n",
"dl_seqs_in_target_dir(SEQUENCE_ID_LIST, single_alerts, api_client)"
]
},
{
"cell_type": "markdown",
"id": "e9d109db-324c-4268-bae6-27c5960def55",
"metadata": {},
"source": [
"## Download triangulated alerts\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "68a2cff8-f847-4e6c-8c74-37b7ecffc9af",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"== Download Alerts data for sequence ID 10535 - camera moret-sur-loing-01 at 2025-07-14_11-22-05\n",
"== Download Alerts data for sequence ID 10537 - camera nemours-02 at 2025-07-14_11-24-10\n",
"== Download Alerts data for sequence ID 10538 - camera croix-augas-02 at 2025-07-14_11-24-31\n",
"== Download Alerts data for sequence ID 15462 - camera serre-de-barre-01 at 2025-09-29_13-56-58\n",
"== Download Alerts data for sequence ID 15463 - camera brison-03 at 2025-09-29_13-58-36\n",
"Download complete\n"
]
}
],
"source": [
"\n",
" url = seq['url']\n",
" nom_fichier = seq[\"bucket_key\"]\n",
" # image\n",
" response = requests.get(url, stream=True)\n",
" if response.status_code == 200:\n",
" full_img_path = os.path.join(image_dir, nom_fichier)\n",
" with open(full_img_path, 'wb') as f:\n",
" for chunk in response.iter_content(1024):\n",
" f.write(chunk)\n",
" else:\n",
" print(f\"Error during download.\")"
"TRIANGULATED_SEQUENCE_LIST = [10535, 10537, 10538, 15462, 15463]\n",
"TRIANGULATED_DIRECTORY= \"triangulated_sequences\"\n",
"triangulated_dir = os.path.join(BASE_DIRECTORY, TRIANGULATED_DIRECTORY)\n",
"os.makedirs(triangulated_dir, exist_ok=True)\n",
"\n",
"dl_seqs_in_target_dir(TRIANGULATED_SEQUENCE_LIST, triangulated_dir, api_client)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ffd56f84-ec77-4843-837a-06de85232c94",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -132,7 +225,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.20"
"version": "3.13.7"
}
},
"nbformat": 4,
Expand Down
Loading