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

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

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

.DS_STORE
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.13.7
Comment thread
fe51 marked this conversation as resolved.
Outdated

# Set the working directory to /app
WORKDIR /app
Expand Down
205 changes: 166 additions & 39 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": 38,
"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/alerts_samples\" # directory where to put sequences data"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 39,
"id": "4e511d97-245c-45cc-9216-a16d31b663aa",
"metadata": {},
"outputs": [],
Expand All @@ -49,7 +49,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 40,
"id": "ac07ba29-68d0-42d2-bafe-e94d961ec6c2",
"metadata": {},
"outputs": [],
Expand All @@ -72,48 +72,175 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "d3c12b1d-54f1-4d8d-b591-dc04ecc35db2",
"execution_count": 41,
"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).json()\n",
Comment thread
fe51 marked this conversation as resolved.
Outdated
" \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": 43,
"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_14-23-28\n",
"== Download Alerts data for sequence ID 15463 - camera brison-03 at 2025-09-29_14-02-22\n",
"== Download Alerts data for sequence ID 15561 - camera pouncho-agast-01 at 2025-10-01_06-21-57\n",
"== Download Alerts data for sequence ID 15526 - camera pouncho-agast-01 at 2025-09-30_15-31-49\n",
"== Download Alerts data for sequence ID 13880 - camera fontaneilles-01 at 2025-09-04_07-34-37\n",
"== Download Alerts data for sequence ID 13572 - camera pouncho-agast-01 at 2025-08-29_07-00-38\n",
"== Download Alerts data for sequence ID 13537 - camera pouncho-agast-01 at 2025-08-28_15-31-28\n",
"== Download Alerts data for sequence ID 12997 - camera pouncho-agast-01 at 2025-08-17_16-52-26\n",
"== Download Alerts data for sequence ID 12562 - camera pouncho-agast-01 at 2025-08-06_12-52-42\n",
"== Download Alerts data for sequence ID 15376 - camera pouncho-agast-02 at 2025-09-28_11-20-15\n",
"== Download Alerts data for sequence ID 15526 - camera pouncho-agast-01 at 2025-09-30_15-31-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",
"\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.\")"
"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": 45,
"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_12-33-39\n",
"== Download Alerts data for sequence ID 10537 - camera nemours-02 at 2025-07-14_11-57-39\n",
"== Download Alerts data for sequence ID 10538 - camera croix-augas-02 at 2025-07-14_12-25-03\n",
"== Download Alerts data for sequence ID 15462 - camera serre-de-barre-01 at 2025-09-29_14-23-28\n",
"== Download Alerts data for sequence ID 15463 - camera brison-03 at 2025-09-29_14-02-22\n",
"Download complete\n"
]
}
],
"source": [
"TRIANGULATED_SEQUENCE_DICT = {\"77_140725_1\":\n",
" {\"seq\":[10535, 10537, 10538],\n",
" \"cone_azimuth\":{41:163.3878, 65:8.2793, 66:276.5041},\n",
" }\n",
" }\n",
"\n",
"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": 27,
"id": "0bd25eb3-8239-4307-9975-7dfb808f5283",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"== Download Alerts data for sequence ID 10535 - camera moret-sur-loing-01 at 2025-07-14_12-33-39\n",
"== Download Alerts data for sequence ID 10537 - camera nemours-02 at 2025-07-14_11-57-39\n",
"== Download Alerts data for sequence ID 10538 - camera croix-augas-02 at 2025-07-14_12-25-03\n",
"Download complete\n"
]
}
],
"source": [
"for key, values in TRIANGULATED_SEQUENCE_DICT.items():\n",
"\n",
" triangulated_seq_dir = os.path.join(TRIANGULATED_DIRECTORY, key)\n",
" os.makedirs(triangulated_seq_dir, exist_ok=True)\n",
"\n",
" # WRITE cone_azimuth as json or text in the fodler TODO\n",
" # Download triangulated sequences in same folder\n",
" dl_seqs_in_target_dir(values['seq'], triangulated_seq_dir, api_client)\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ffd56f84-ec77-4843-837a-06de85232c94",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -132,7 +259,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.20"
"version": "3.13.7"
}
},
"nbformat": 4,
Expand Down
Loading