|
19 | 19 | }, |
20 | 20 | { |
21 | 21 | "cell_type": "code", |
22 | | - "execution_count": null, |
| 22 | + "execution_count": 1, |
23 | 23 | "id": "649157c6-0ce3-4324-a7b6-15c911ddaf36", |
24 | 24 | "metadata": {}, |
25 | 25 | "outputs": [], |
26 | 26 | "source": [ |
27 | | - "SEQUENCE_ID_LIST = [13802, 9456]\n", |
28 | | - "BASE_DIRECTORY = \"alerts\" # directory where to put sequences data" |
| 27 | + "SEQUENCE_ID_LIST = [15462, 15463, 15561, 15526, 13880, 13572, 13537, 12997, 12562, 15376, 15526]\n", |
| 28 | + "BASE_DIRECTORY = \"../data/alert_samples\" # directory where to put sequences data" |
29 | 29 | ] |
30 | 30 | }, |
31 | 31 | { |
32 | 32 | "cell_type": "code", |
33 | | - "execution_count": null, |
| 33 | + "execution_count": 2, |
34 | 34 | "id": "4e511d97-245c-45cc-9216-a16d31b663aa", |
35 | 35 | "metadata": {}, |
36 | 36 | "outputs": [], |
|
49 | 49 | }, |
50 | 50 | { |
51 | 51 | "cell_type": "code", |
52 | | - "execution_count": null, |
| 52 | + "execution_count": 3, |
53 | 53 | "id": "ac07ba29-68d0-42d2-bafe-e94d961ec6c2", |
54 | 54 | "metadata": {}, |
55 | 55 | "outputs": [], |
|
72 | 72 | }, |
73 | 73 | { |
74 | 74 | "cell_type": "code", |
75 | | - "execution_count": null, |
76 | | - "id": "d3c12b1d-54f1-4d8d-b591-dc04ecc35db2", |
| 75 | + "execution_count": 4, |
| 76 | + "id": "07192f5f-9a69-41a4-9a97-1f1fcefaaf5b", |
77 | 77 | "metadata": {}, |
78 | 78 | "outputs": [], |
79 | 79 | "source": [ |
80 | | - "for seq_id in SEQUENCE_ID_LIST: \n", |
81 | | - " sequences = api_client.fetch_sequences_detections(sequence_id=seq_id).json()\n", |
| 80 | + "def dl_seqs_in_target_dir(sequence_id_list, target_dir, api_client):\n", |
| 81 | + " \"\"\"\n", |
| 82 | + " Download sequences from sequence_id_list to target_dir, using an instanciated api_client (of distant Pyronear alert API)\n", |
82 | 83 | "\n", |
83 | | - " cam_name = [item['name'] for item in cameras if item['id'] == sequences[0]['camera_id']][0]\n", |
84 | | - " created_at_rounded = sequences[0][\"created_at\"].split('.')[0].replace(':', '-').replace('T', '_')\n", |
| 84 | + " \"\"\"\n", |
85 | 85 | " \n", |
86 | | - " print(f\"== Download Alerts data for sequence ID {seq_id} - camera {cam_name} at {created_at_rounded}\")\n", |
| 86 | + " for seq_id in sequence_id_list: \n", |
| 87 | + " sequences = api_client.fetch_sequences_detections(sequence_id=seq_id, limit=10, desc=False).json()\n", |
87 | 88 | " \n", |
88 | | - " alert_dir = os.path.join(f\"{cam_name}_{created_at_rounded}\")\n", |
89 | | - " image_dir = os.path.join(base_dir,alert_dir, \"images\")\n", |
90 | | - " pred_dir = os.path.join(base_dir, alert_dir, \"labels_predictions\")\n", |
91 | | - " os.makedirs(image_dir, exist_ok=True)\n", |
92 | | - " os.makedirs(pred_dir, exist_ok=True)\n", |
93 | | - "\n", |
94 | | - " for seq in sequences:\n", |
| 89 | + " cam_name = [item['name'] for item in cameras if item['id'] == sequences[0]['camera_id']][0]\n", |
| 90 | + " created_at_rounded = sequences[0][\"created_at\"].split('.')[0].replace(':', '-').replace('T', '_')\n", |
| 91 | + " cam_id_distant_api = sequences[0][\"camera_id\"]\n", |
| 92 | + " print(f\"== Download Alerts data for sequence ID {seq_id} - camera {cam_name} at {created_at_rounded}\")\n", |
95 | 93 | " \n", |
96 | | - " # bbox\n", |
97 | | - " #yolo_format_bbox = ' '.join(map(str,ast.literal_eval(seq[\"bboxes\"])[0]))\n", |
98 | | - " bboxes = seq[\"bboxes\"]\n", |
| 94 | + " alert_dir = os.path.join(f\"{cam_id_distant_api}_{cam_name}_{created_at_rounded}\")\n", |
| 95 | + " image_dir = os.path.join(target_dir,alert_dir, \"images\")\n", |
| 96 | + " pred_dir = os.path.join(target_dir, alert_dir, \"labels_predictions\")\n", |
| 97 | + " os.makedirs(image_dir, exist_ok=True)\n", |
| 98 | + " os.makedirs(pred_dir, exist_ok=True)\n", |
| 99 | + " \n", |
| 100 | + " for seq in sequences:\n", |
| 101 | + " \n", |
| 102 | + " # bbox\n", |
| 103 | + " #yolo_format_bbox = ' '.join(map(str,ast.literal_eval(seq[\"bboxes\"])[0]))\n", |
| 104 | + " bboxes = seq[\"bboxes\"]\n", |
| 105 | + " \n", |
| 106 | + " bbox_file_name = seq[\"bucket_key\"][:-4] + \".txt\"\n", |
| 107 | + " \n", |
| 108 | + " with open(os.path.join(target_dir, alert_dir, \"labels_predictions\",bbox_file_name), 'w') as f:\n", |
| 109 | + " f.write(bboxes)\n", |
| 110 | + " \n", |
| 111 | + " url = seq['url']\n", |
| 112 | + " nom_fichier = seq[\"bucket_key\"]\n", |
| 113 | + " # image\n", |
| 114 | + " response = requests.get(url, stream=True)\n", |
| 115 | + " if response.status_code == 200:\n", |
| 116 | + " full_img_path = os.path.join(image_dir, nom_fichier)\n", |
| 117 | + " with open(full_img_path, 'wb') as f:\n", |
| 118 | + " for chunk in response.iter_content(1024):\n", |
| 119 | + " f.write(chunk)\n", |
| 120 | + " else:\n", |
| 121 | + " print(f\"Error during download.\")\n", |
| 122 | + " print(\"Download complete\")\n", |
| 123 | + " " |
| 124 | + ] |
| 125 | + }, |
| 126 | + { |
| 127 | + "cell_type": "markdown", |
| 128 | + "id": "9503b5d5-9930-4c9e-9fbe-1eb1e563fd44", |
| 129 | + "metadata": {}, |
| 130 | + "source": [ |
| 131 | + "# Download sequences from SEQUENCE_ID_LIST list" |
| 132 | + ] |
| 133 | + }, |
| 134 | + { |
| 135 | + "cell_type": "code", |
| 136 | + "execution_count": 5, |
| 137 | + "id": "b2d033e9-7ce2-4cf4-995e-01ea2c15e235", |
| 138 | + "metadata": {}, |
| 139 | + "outputs": [ |
| 140 | + { |
| 141 | + "name": "stdout", |
| 142 | + "output_type": "stream", |
| 143 | + "text": [ |
| 144 | + "== Download Alerts data for sequence ID 15462 - camera serre-de-barre-01 at 2025-09-29_13-56-58\n", |
| 145 | + "== Download Alerts data for sequence ID 15463 - camera brison-03 at 2025-09-29_13-58-36\n", |
| 146 | + "== Download Alerts data for sequence ID 15561 - camera pouncho-agast-01 at 2025-10-01_06-18-57\n", |
| 147 | + "== Download Alerts data for sequence ID 15526 - camera pouncho-agast-01 at 2025-09-30_15-29-49\n", |
| 148 | + "== Download Alerts data for sequence ID 13880 - camera fontaneilles-01 at 2025-09-04_07-34-32\n", |
| 149 | + "== Download Alerts data for sequence ID 13572 - camera pouncho-agast-01 at 2025-08-29_06-59-39\n", |
| 150 | + "== Download Alerts data for sequence ID 13537 - camera pouncho-agast-01 at 2025-08-28_15-31-17\n", |
| 151 | + "== Download Alerts data for sequence ID 12997 - camera pouncho-agast-01 at 2025-08-17_15-52-27\n", |
| 152 | + "== Download Alerts data for sequence ID 12562 - camera pouncho-agast-01 at 2025-08-06_12-32-09\n", |
| 153 | + "== Download Alerts data for sequence ID 15376 - camera pouncho-agast-02 at 2025-09-28_10-52-39\n", |
| 154 | + "== Download Alerts data for sequence ID 15526 - camera pouncho-agast-01 at 2025-09-30_15-29-49\n", |
| 155 | + "Download complete\n" |
| 156 | + ] |
| 157 | + } |
| 158 | + ], |
| 159 | + "source": [ |
| 160 | + "single_alerts = os.path.join(BASE_DIRECTORY, \"single_sequences\")\n", |
| 161 | + "os.makedirs(single_alerts, exist_ok=True)\n", |
99 | 162 | "\n", |
100 | | - " bbox_file_name = seq[\"bucket_key\"][:-4] + \".txt\"\n", |
101 | | - " \n", |
102 | | - " with open(os.path.join(base_dir, alert_dir, \"labels_predictions\",bbox_file_name), 'w') as f:\n", |
103 | | - " f.write(bboxes)\n", |
| 163 | + "dl_seqs_in_target_dir(SEQUENCE_ID_LIST, single_alerts, api_client)" |
| 164 | + ] |
| 165 | + }, |
| 166 | + { |
| 167 | + "cell_type": "markdown", |
| 168 | + "id": "e9d109db-324c-4268-bae6-27c5960def55", |
| 169 | + "metadata": {}, |
| 170 | + "source": [ |
| 171 | + "## Download triangulated alerts\n" |
| 172 | + ] |
| 173 | + }, |
| 174 | + { |
| 175 | + "cell_type": "code", |
| 176 | + "execution_count": 6, |
| 177 | + "id": "68a2cff8-f847-4e6c-8c74-37b7ecffc9af", |
| 178 | + "metadata": {}, |
| 179 | + "outputs": [ |
| 180 | + { |
| 181 | + "name": "stdout", |
| 182 | + "output_type": "stream", |
| 183 | + "text": [ |
| 184 | + "== Download Alerts data for sequence ID 10535 - camera moret-sur-loing-01 at 2025-07-14_11-22-05\n", |
| 185 | + "== Download Alerts data for sequence ID 10537 - camera nemours-02 at 2025-07-14_11-24-10\n", |
| 186 | + "== Download Alerts data for sequence ID 10538 - camera croix-augas-02 at 2025-07-14_11-24-31\n", |
| 187 | + "== Download Alerts data for sequence ID 15462 - camera serre-de-barre-01 at 2025-09-29_13-56-58\n", |
| 188 | + "== Download Alerts data for sequence ID 15463 - camera brison-03 at 2025-09-29_13-58-36\n", |
| 189 | + "Download complete\n" |
| 190 | + ] |
| 191 | + } |
| 192 | + ], |
| 193 | + "source": [ |
104 | 194 | "\n", |
105 | | - " url = seq['url']\n", |
106 | | - " nom_fichier = seq[\"bucket_key\"]\n", |
107 | | - " # image\n", |
108 | | - " response = requests.get(url, stream=True)\n", |
109 | | - " if response.status_code == 200:\n", |
110 | | - " full_img_path = os.path.join(image_dir, nom_fichier)\n", |
111 | | - " with open(full_img_path, 'wb') as f:\n", |
112 | | - " for chunk in response.iter_content(1024):\n", |
113 | | - " f.write(chunk)\n", |
114 | | - " else:\n", |
115 | | - " print(f\"Error during download.\")" |
| 195 | + "TRIANGULATED_SEQUENCE_LIST = [10535, 10537, 10538, 15462, 15463]\n", |
| 196 | + "TRIANGULATED_DIRECTORY= \"triangulated_sequences\"\n", |
| 197 | + "triangulated_dir = os.path.join(BASE_DIRECTORY, TRIANGULATED_DIRECTORY)\n", |
| 198 | + "os.makedirs(triangulated_dir, exist_ok=True)\n", |
| 199 | + "\n", |
| 200 | + "dl_seqs_in_target_dir(TRIANGULATED_SEQUENCE_LIST, triangulated_dir, api_client)" |
116 | 201 | ] |
| 202 | + }, |
| 203 | + { |
| 204 | + "cell_type": "code", |
| 205 | + "execution_count": null, |
| 206 | + "id": "ffd56f84-ec77-4843-837a-06de85232c94", |
| 207 | + "metadata": {}, |
| 208 | + "outputs": [], |
| 209 | + "source": [] |
117 | 210 | } |
118 | 211 | ], |
119 | 212 | "metadata": { |
|
132 | 225 | "name": "python", |
133 | 226 | "nbconvert_exporter": "python", |
134 | 227 | "pygments_lexer": "ipython3", |
135 | | - "version": "3.8.20" |
| 228 | + "version": "3.13.7" |
136 | 229 | } |
137 | 230 | }, |
138 | 231 | "nbformat": 4, |
|
0 commit comments