egrace479 commited on
Commit
3b830cd
·
1 Parent(s): 006fd75

Notebooks to explore mismatch between catalog files and media manifest they should represent.

Browse files
notebooks/ToL_media_mismatch.ipynb ADDED
@@ -0,0 +1,1501 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "import pandas as pd"
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "markdown",
14
+ "metadata": {},
15
+ "source": [
16
+ "Load in full images to ease process."
17
+ ]
18
+ },
19
+ {
20
+ "cell_type": "code",
21
+ "execution_count": 2,
22
+ "metadata": {},
23
+ "outputs": [],
24
+ "source": [
25
+ "df = pd.read_csv(\"../data/predicted-catalog.csv\", low_memory = False)"
26
+ ]
27
+ },
28
+ {
29
+ "cell_type": "code",
30
+ "execution_count": 3,
31
+ "metadata": {},
32
+ "outputs": [
33
+ {
34
+ "data": {
35
+ "text/html": [
36
+ "<div>\n",
37
+ "<style scoped>\n",
38
+ " .dataframe tbody tr th:only-of-type {\n",
39
+ " vertical-align: middle;\n",
40
+ " }\n",
41
+ "\n",
42
+ " .dataframe tbody tr th {\n",
43
+ " vertical-align: top;\n",
44
+ " }\n",
45
+ "\n",
46
+ " .dataframe thead th {\n",
47
+ " text-align: right;\n",
48
+ " }\n",
49
+ "</style>\n",
50
+ "<table border=\"1\" class=\"dataframe\">\n",
51
+ " <thead>\n",
52
+ " <tr style=\"text-align: right;\">\n",
53
+ " <th></th>\n",
54
+ " <th>split</th>\n",
55
+ " <th>treeoflife_id</th>\n",
56
+ " <th>eol_content_id</th>\n",
57
+ " <th>eol_page_id</th>\n",
58
+ " <th>bioscan_part</th>\n",
59
+ " <th>bioscan_filename</th>\n",
60
+ " <th>inat21_filename</th>\n",
61
+ " <th>inat21_cls_name</th>\n",
62
+ " <th>inat21_cls_num</th>\n",
63
+ " <th>kingdom</th>\n",
64
+ " <th>phylum</th>\n",
65
+ " <th>class</th>\n",
66
+ " <th>order</th>\n",
67
+ " <th>family</th>\n",
68
+ " <th>genus</th>\n",
69
+ " <th>species</th>\n",
70
+ " <th>common</th>\n",
71
+ " </tr>\n",
72
+ " </thead>\n",
73
+ " <tbody>\n",
74
+ " <tr>\n",
75
+ " <th>0</th>\n",
76
+ " <td>train</td>\n",
77
+ " <td>f2f0aa29-e87b-469c-bf5b-51a3611ab001</td>\n",
78
+ " <td>22131926.0</td>\n",
79
+ " <td>269504.0</td>\n",
80
+ " <td>NaN</td>\n",
81
+ " <td>NaN</td>\n",
82
+ " <td>NaN</td>\n",
83
+ " <td>NaN</td>\n",
84
+ " <td>NaN</td>\n",
85
+ " <td>Animalia</td>\n",
86
+ " <td>Arthropoda</td>\n",
87
+ " <td>Insecta</td>\n",
88
+ " <td>Lepidoptera</td>\n",
89
+ " <td>Lycaenidae</td>\n",
90
+ " <td>Orthomiella</td>\n",
91
+ " <td>rantaizana</td>\n",
92
+ " <td>Chinese Straight-wing Blue</td>\n",
93
+ " </tr>\n",
94
+ " <tr>\n",
95
+ " <th>1</th>\n",
96
+ " <td>train</td>\n",
97
+ " <td>5faa4f55-32e9-4872-953d-567e5d232e52</td>\n",
98
+ " <td>22291283.0</td>\n",
99
+ " <td>6101931.0</td>\n",
100
+ " <td>NaN</td>\n",
101
+ " <td>NaN</td>\n",
102
+ " <td>NaN</td>\n",
103
+ " <td>NaN</td>\n",
104
+ " <td>NaN</td>\n",
105
+ " <td>Plantae</td>\n",
106
+ " <td>Tracheophyta</td>\n",
107
+ " <td>Polypodiopsida</td>\n",
108
+ " <td>Polypodiales</td>\n",
109
+ " <td>Woodsiaceae</td>\n",
110
+ " <td>Woodsia</td>\n",
111
+ " <td>subcordata</td>\n",
112
+ " <td>Woodsia subcordata</td>\n",
113
+ " </tr>\n",
114
+ " <tr>\n",
115
+ " <th>2</th>\n",
116
+ " <td>train</td>\n",
117
+ " <td>2282f2bf-2b52-4522-b588-dd6f356d5fd6</td>\n",
118
+ " <td>21802775.0</td>\n",
119
+ " <td>45513632.0</td>\n",
120
+ " <td>NaN</td>\n",
121
+ " <td>NaN</td>\n",
122
+ " <td>NaN</td>\n",
123
+ " <td>NaN</td>\n",
124
+ " <td>NaN</td>\n",
125
+ " <td>Animalia</td>\n",
126
+ " <td>Chordata</td>\n",
127
+ " <td>Aves</td>\n",
128
+ " <td>Passeriformes</td>\n",
129
+ " <td>Laniidae</td>\n",
130
+ " <td>Lanius</td>\n",
131
+ " <td>minor</td>\n",
132
+ " <td>Lesser Grey Shrike</td>\n",
133
+ " </tr>\n",
134
+ " <tr>\n",
135
+ " <th>3</th>\n",
136
+ " <td>train</td>\n",
137
+ " <td>76b57c36-2181-4e6d-a5c4-b40e22a09449</td>\n",
138
+ " <td>12784812.0</td>\n",
139
+ " <td>51655800.0</td>\n",
140
+ " <td>NaN</td>\n",
141
+ " <td>NaN</td>\n",
142
+ " <td>NaN</td>\n",
143
+ " <td>NaN</td>\n",
144
+ " <td>NaN</td>\n",
145
+ " <td>NaN</td>\n",
146
+ " <td>NaN</td>\n",
147
+ " <td>NaN</td>\n",
148
+ " <td>NaN</td>\n",
149
+ " <td>NaN</td>\n",
150
+ " <td>NaN</td>\n",
151
+ " <td>tenuis</td>\n",
152
+ " <td>Tenuis</td>\n",
153
+ " </tr>\n",
154
+ " <tr>\n",
155
+ " <th>4</th>\n",
156
+ " <td>train</td>\n",
157
+ " <td>f57d3ab6-2cf5-484b-a590-e2a3d49a3ca2</td>\n",
158
+ " <td>29713643.0</td>\n",
159
+ " <td>45515896.0</td>\n",
160
+ " <td>NaN</td>\n",
161
+ " <td>NaN</td>\n",
162
+ " <td>NaN</td>\n",
163
+ " <td>NaN</td>\n",
164
+ " <td>NaN</td>\n",
165
+ " <td>Animalia</td>\n",
166
+ " <td>Chordata</td>\n",
167
+ " <td>Aves</td>\n",
168
+ " <td>Casuariiformes</td>\n",
169
+ " <td>Casuariidae</td>\n",
170
+ " <td>Casuarius</td>\n",
171
+ " <td>casuarius</td>\n",
172
+ " <td>Southern Cassowary</td>\n",
173
+ " </tr>\n",
174
+ " </tbody>\n",
175
+ "</table>\n",
176
+ "</div>"
177
+ ],
178
+ "text/plain": [
179
+ " split treeoflife_id eol_content_id eol_page_id \\\n",
180
+ "0 train f2f0aa29-e87b-469c-bf5b-51a3611ab001 22131926.0 269504.0 \n",
181
+ "1 train 5faa4f55-32e9-4872-953d-567e5d232e52 22291283.0 6101931.0 \n",
182
+ "2 train 2282f2bf-2b52-4522-b588-dd6f356d5fd6 21802775.0 45513632.0 \n",
183
+ "3 train 76b57c36-2181-4e6d-a5c4-b40e22a09449 12784812.0 51655800.0 \n",
184
+ "4 train f57d3ab6-2cf5-484b-a590-e2a3d49a3ca2 29713643.0 45515896.0 \n",
185
+ "\n",
186
+ " bioscan_part bioscan_filename inat21_filename inat21_cls_name \\\n",
187
+ "0 NaN NaN NaN NaN \n",
188
+ "1 NaN NaN NaN NaN \n",
189
+ "2 NaN NaN NaN NaN \n",
190
+ "3 NaN NaN NaN NaN \n",
191
+ "4 NaN NaN NaN NaN \n",
192
+ "\n",
193
+ " inat21_cls_num kingdom phylum class order \\\n",
194
+ "0 NaN Animalia Arthropoda Insecta Lepidoptera \n",
195
+ "1 NaN Plantae Tracheophyta Polypodiopsida Polypodiales \n",
196
+ "2 NaN Animalia Chordata Aves Passeriformes \n",
197
+ "3 NaN NaN NaN NaN NaN \n",
198
+ "4 NaN Animalia Chordata Aves Casuariiformes \n",
199
+ "\n",
200
+ " family genus species common \n",
201
+ "0 Lycaenidae Orthomiella rantaizana Chinese Straight-wing Blue \n",
202
+ "1 Woodsiaceae Woodsia subcordata Woodsia subcordata \n",
203
+ "2 Laniidae Lanius minor Lesser Grey Shrike \n",
204
+ "3 NaN NaN tenuis Tenuis \n",
205
+ "4 Casuariidae Casuarius casuarius Southern Cassowary "
206
+ ]
207
+ },
208
+ "execution_count": 3,
209
+ "metadata": {},
210
+ "output_type": "execute_result"
211
+ }
212
+ ],
213
+ "source": [
214
+ "df.head()"
215
+ ]
216
+ },
217
+ {
218
+ "cell_type": "code",
219
+ "execution_count": 4,
220
+ "metadata": {},
221
+ "outputs": [
222
+ {
223
+ "name": "stdout",
224
+ "output_type": "stream",
225
+ "text": [
226
+ "<class 'pandas.core.frame.DataFrame'>\n",
227
+ "RangeIndex: 10092530 entries, 0 to 10092529\n",
228
+ "Data columns (total 17 columns):\n",
229
+ " # Column Non-Null Count Dtype \n",
230
+ "--- ------ -------------- ----- \n",
231
+ " 0 split 10092530 non-null object \n",
232
+ " 1 treeoflife_id 10092530 non-null object \n",
233
+ " 2 eol_content_id 6277374 non-null float64\n",
234
+ " 3 eol_page_id 6277374 non-null float64\n",
235
+ " 4 bioscan_part 1128313 non-null float64\n",
236
+ " 5 bioscan_filename 1128313 non-null object \n",
237
+ " 6 inat21_filename 2686843 non-null object \n",
238
+ " 7 inat21_cls_name 2686843 non-null object \n",
239
+ " 8 inat21_cls_num 2686843 non-null float64\n",
240
+ " 9 kingdom 9831721 non-null object \n",
241
+ " 10 phylum 9833317 non-null object \n",
242
+ " 11 class 9813548 non-null object \n",
243
+ " 12 order 9807409 non-null object \n",
244
+ " 13 family 9775447 non-null object \n",
245
+ " 14 genus 8908268 non-null object \n",
246
+ " 15 species 8749857 non-null object \n",
247
+ " 16 common 10092530 non-null object \n",
248
+ "dtypes: float64(4), object(13)\n",
249
+ "memory usage: 1.3+ GB\n"
250
+ ]
251
+ }
252
+ ],
253
+ "source": [
254
+ "df.info(show_counts = True)"
255
+ ]
256
+ },
257
+ {
258
+ "cell_type": "markdown",
259
+ "metadata": {},
260
+ "source": [
261
+ "The `train_small` is duplicates of `train`, so we will drop those to analyze the full training set plus val."
262
+ ]
263
+ },
264
+ {
265
+ "cell_type": "markdown",
266
+ "metadata": {},
267
+ "source": [
268
+ "`predicted-catalog` doesn't have `train_small`, hence, it's a smaller file."
269
+ ]
270
+ },
271
+ {
272
+ "cell_type": "markdown",
273
+ "metadata": {},
274
+ "source": [
275
+ "Let's add a column indicating the original data source so we can also get some stats by datasource, specifically focusing on EOL since we know licensing for BIOSCAN-1M and iNat21."
276
+ ]
277
+ },
278
+ {
279
+ "cell_type": "code",
280
+ "execution_count": 5,
281
+ "metadata": {},
282
+ "outputs": [],
283
+ "source": [
284
+ "# Add data_source column for easier slicing\n",
285
+ "df.loc[df['inat21_filename'].notna(), 'data_source'] = 'iNat21'\n",
286
+ "df.loc[df['bioscan_filename'].notna(), 'data_source'] = 'BIOSCAN'\n",
287
+ "df.loc[df['eol_content_id'].notna(), 'data_source'] = 'EOL'"
288
+ ]
289
+ },
290
+ {
291
+ "cell_type": "markdown",
292
+ "metadata": {},
293
+ "source": [
294
+ "#### Get just EOL CSV for Media Manifest Merge"
295
+ ]
296
+ },
297
+ {
298
+ "cell_type": "code",
299
+ "execution_count": 6,
300
+ "metadata": {},
301
+ "outputs": [],
302
+ "source": [
303
+ "eol_df = df.loc[df['data_source'] == 'EOL']"
304
+ ]
305
+ },
306
+ {
307
+ "cell_type": "code",
308
+ "execution_count": 7,
309
+ "metadata": {},
310
+ "outputs": [
311
+ {
312
+ "data": {
313
+ "text/html": [
314
+ "<div>\n",
315
+ "<style scoped>\n",
316
+ " .dataframe tbody tr th:only-of-type {\n",
317
+ " vertical-align: middle;\n",
318
+ " }\n",
319
+ "\n",
320
+ " .dataframe tbody tr th {\n",
321
+ " vertical-align: top;\n",
322
+ " }\n",
323
+ "\n",
324
+ " .dataframe thead th {\n",
325
+ " text-align: right;\n",
326
+ " }\n",
327
+ "</style>\n",
328
+ "<table border=\"1\" class=\"dataframe\">\n",
329
+ " <thead>\n",
330
+ " <tr style=\"text-align: right;\">\n",
331
+ " <th></th>\n",
332
+ " <th>split</th>\n",
333
+ " <th>treeoflife_id</th>\n",
334
+ " <th>eol_content_id</th>\n",
335
+ " <th>eol_page_id</th>\n",
336
+ " <th>bioscan_part</th>\n",
337
+ " <th>bioscan_filename</th>\n",
338
+ " <th>inat21_filename</th>\n",
339
+ " <th>inat21_cls_name</th>\n",
340
+ " <th>inat21_cls_num</th>\n",
341
+ " <th>kingdom</th>\n",
342
+ " <th>phylum</th>\n",
343
+ " <th>class</th>\n",
344
+ " <th>order</th>\n",
345
+ " <th>family</th>\n",
346
+ " <th>genus</th>\n",
347
+ " <th>species</th>\n",
348
+ " <th>common</th>\n",
349
+ " <th>data_source</th>\n",
350
+ " </tr>\n",
351
+ " </thead>\n",
352
+ " <tbody>\n",
353
+ " <tr>\n",
354
+ " <th>0</th>\n",
355
+ " <td>train</td>\n",
356
+ " <td>f2f0aa29-e87b-469c-bf5b-51a3611ab001</td>\n",
357
+ " <td>22131926.0</td>\n",
358
+ " <td>269504.0</td>\n",
359
+ " <td>NaN</td>\n",
360
+ " <td>NaN</td>\n",
361
+ " <td>NaN</td>\n",
362
+ " <td>NaN</td>\n",
363
+ " <td>NaN</td>\n",
364
+ " <td>Animalia</td>\n",
365
+ " <td>Arthropoda</td>\n",
366
+ " <td>Insecta</td>\n",
367
+ " <td>Lepidoptera</td>\n",
368
+ " <td>Lycaenidae</td>\n",
369
+ " <td>Orthomiella</td>\n",
370
+ " <td>rantaizana</td>\n",
371
+ " <td>Chinese Straight-wing Blue</td>\n",
372
+ " <td>EOL</td>\n",
373
+ " </tr>\n",
374
+ " <tr>\n",
375
+ " <th>1</th>\n",
376
+ " <td>train</td>\n",
377
+ " <td>5faa4f55-32e9-4872-953d-567e5d232e52</td>\n",
378
+ " <td>22291283.0</td>\n",
379
+ " <td>6101931.0</td>\n",
380
+ " <td>NaN</td>\n",
381
+ " <td>NaN</td>\n",
382
+ " <td>NaN</td>\n",
383
+ " <td>NaN</td>\n",
384
+ " <td>NaN</td>\n",
385
+ " <td>Plantae</td>\n",
386
+ " <td>Tracheophyta</td>\n",
387
+ " <td>Polypodiopsida</td>\n",
388
+ " <td>Polypodiales</td>\n",
389
+ " <td>Woodsiaceae</td>\n",
390
+ " <td>Woodsia</td>\n",
391
+ " <td>subcordata</td>\n",
392
+ " <td>Woodsia subcordata</td>\n",
393
+ " <td>EOL</td>\n",
394
+ " </tr>\n",
395
+ " <tr>\n",
396
+ " <th>2</th>\n",
397
+ " <td>train</td>\n",
398
+ " <td>2282f2bf-2b52-4522-b588-dd6f356d5fd6</td>\n",
399
+ " <td>21802775.0</td>\n",
400
+ " <td>45513632.0</td>\n",
401
+ " <td>NaN</td>\n",
402
+ " <td>NaN</td>\n",
403
+ " <td>NaN</td>\n",
404
+ " <td>NaN</td>\n",
405
+ " <td>NaN</td>\n",
406
+ " <td>Animalia</td>\n",
407
+ " <td>Chordata</td>\n",
408
+ " <td>Aves</td>\n",
409
+ " <td>Passeriformes</td>\n",
410
+ " <td>Laniidae</td>\n",
411
+ " <td>Lanius</td>\n",
412
+ " <td>minor</td>\n",
413
+ " <td>Lesser Grey Shrike</td>\n",
414
+ " <td>EOL</td>\n",
415
+ " </tr>\n",
416
+ " <tr>\n",
417
+ " <th>3</th>\n",
418
+ " <td>train</td>\n",
419
+ " <td>76b57c36-2181-4e6d-a5c4-b40e22a09449</td>\n",
420
+ " <td>12784812.0</td>\n",
421
+ " <td>51655800.0</td>\n",
422
+ " <td>NaN</td>\n",
423
+ " <td>NaN</td>\n",
424
+ " <td>NaN</td>\n",
425
+ " <td>NaN</td>\n",
426
+ " <td>NaN</td>\n",
427
+ " <td>NaN</td>\n",
428
+ " <td>NaN</td>\n",
429
+ " <td>NaN</td>\n",
430
+ " <td>NaN</td>\n",
431
+ " <td>NaN</td>\n",
432
+ " <td>NaN</td>\n",
433
+ " <td>tenuis</td>\n",
434
+ " <td>Tenuis</td>\n",
435
+ " <td>EOL</td>\n",
436
+ " </tr>\n",
437
+ " <tr>\n",
438
+ " <th>4</th>\n",
439
+ " <td>train</td>\n",
440
+ " <td>f57d3ab6-2cf5-484b-a590-e2a3d49a3ca2</td>\n",
441
+ " <td>29713643.0</td>\n",
442
+ " <td>45515896.0</td>\n",
443
+ " <td>NaN</td>\n",
444
+ " <td>NaN</td>\n",
445
+ " <td>NaN</td>\n",
446
+ " <td>NaN</td>\n",
447
+ " <td>NaN</td>\n",
448
+ " <td>Animalia</td>\n",
449
+ " <td>Chordata</td>\n",
450
+ " <td>Aves</td>\n",
451
+ " <td>Casuariiformes</td>\n",
452
+ " <td>Casuariidae</td>\n",
453
+ " <td>Casuarius</td>\n",
454
+ " <td>casuarius</td>\n",
455
+ " <td>Southern Cassowary</td>\n",
456
+ " <td>EOL</td>\n",
457
+ " </tr>\n",
458
+ " </tbody>\n",
459
+ "</table>\n",
460
+ "</div>"
461
+ ],
462
+ "text/plain": [
463
+ " split treeoflife_id eol_content_id eol_page_id \\\n",
464
+ "0 train f2f0aa29-e87b-469c-bf5b-51a3611ab001 22131926.0 269504.0 \n",
465
+ "1 train 5faa4f55-32e9-4872-953d-567e5d232e52 22291283.0 6101931.0 \n",
466
+ "2 train 2282f2bf-2b52-4522-b588-dd6f356d5fd6 21802775.0 45513632.0 \n",
467
+ "3 train 76b57c36-2181-4e6d-a5c4-b40e22a09449 12784812.0 51655800.0 \n",
468
+ "4 train f57d3ab6-2cf5-484b-a590-e2a3d49a3ca2 29713643.0 45515896.0 \n",
469
+ "\n",
470
+ " bioscan_part bioscan_filename inat21_filename inat21_cls_name \\\n",
471
+ "0 NaN NaN NaN NaN \n",
472
+ "1 NaN NaN NaN NaN \n",
473
+ "2 NaN NaN NaN NaN \n",
474
+ "3 NaN NaN NaN NaN \n",
475
+ "4 NaN NaN NaN NaN \n",
476
+ "\n",
477
+ " inat21_cls_num kingdom phylum class order \\\n",
478
+ "0 NaN Animalia Arthropoda Insecta Lepidoptera \n",
479
+ "1 NaN Plantae Tracheophyta Polypodiopsida Polypodiales \n",
480
+ "2 NaN Animalia Chordata Aves Passeriformes \n",
481
+ "3 NaN NaN NaN NaN NaN \n",
482
+ "4 NaN Animalia Chordata Aves Casuariiformes \n",
483
+ "\n",
484
+ " family genus species common \\\n",
485
+ "0 Lycaenidae Orthomiella rantaizana Chinese Straight-wing Blue \n",
486
+ "1 Woodsiaceae Woodsia subcordata Woodsia subcordata \n",
487
+ "2 Laniidae Lanius minor Lesser Grey Shrike \n",
488
+ "3 NaN NaN tenuis Tenuis \n",
489
+ "4 Casuariidae Casuarius casuarius Southern Cassowary \n",
490
+ "\n",
491
+ " data_source \n",
492
+ "0 EOL \n",
493
+ "1 EOL \n",
494
+ "2 EOL \n",
495
+ "3 EOL \n",
496
+ "4 EOL "
497
+ ]
498
+ },
499
+ "execution_count": 7,
500
+ "metadata": {},
501
+ "output_type": "execute_result"
502
+ }
503
+ ],
504
+ "source": [
505
+ "eol_df.head()"
506
+ ]
507
+ },
508
+ {
509
+ "cell_type": "markdown",
510
+ "metadata": {},
511
+ "source": [
512
+ "We don't need the BIOSCAN or iNat21 columns, nor the taxa columns."
513
+ ]
514
+ },
515
+ {
516
+ "cell_type": "code",
517
+ "execution_count": 8,
518
+ "metadata": {},
519
+ "outputs": [
520
+ {
521
+ "data": {
522
+ "text/plain": [
523
+ "Index(['treeoflife_id', 'eol_content_id', 'eol_page_id'], dtype='object')"
524
+ ]
525
+ },
526
+ "execution_count": 8,
527
+ "metadata": {},
528
+ "output_type": "execute_result"
529
+ }
530
+ ],
531
+ "source": [
532
+ "eol_license_cols = eol_df.columns[1:4]\n",
533
+ "eol_license_cols"
534
+ ]
535
+ },
536
+ {
537
+ "cell_type": "code",
538
+ "execution_count": 9,
539
+ "metadata": {},
540
+ "outputs": [],
541
+ "source": [
542
+ "eol_df = eol_df[eol_license_cols]"
543
+ ]
544
+ },
545
+ {
546
+ "cell_type": "code",
547
+ "execution_count": 10,
548
+ "metadata": {},
549
+ "outputs": [
550
+ {
551
+ "data": {
552
+ "text/plain": [
553
+ "treeoflife_id 6277374\n",
554
+ "eol_content_id 6277374\n",
555
+ "eol_page_id 504018\n",
556
+ "dtype: int64"
557
+ ]
558
+ },
559
+ "execution_count": 10,
560
+ "metadata": {},
561
+ "output_type": "execute_result"
562
+ }
563
+ ],
564
+ "source": [
565
+ "eol_df.nunique()"
566
+ ]
567
+ },
568
+ {
569
+ "cell_type": "markdown",
570
+ "metadata": {},
571
+ "source": [
572
+ "Number of unique `eol_content_id`s and `treeoflife_id`s match, and match with total number of `eol_content_id`s shown above in the info for the full dataset."
573
+ ]
574
+ },
575
+ {
576
+ "cell_type": "markdown",
577
+ "metadata": {},
578
+ "source": [
579
+ "### Merge with Media Manifest\n",
580
+ "Let's merge with the [media manifest](https://huggingface.co/datasets/imageomics/eol/blob/be7b7e6c372f6547e30030e9576d9cc638320099/data/interim/media_manifest.csv) from which all these images should have been downloaded from to get a clear picture of what is or isn't in the manifest."
581
+ ]
582
+ },
583
+ {
584
+ "cell_type": "code",
585
+ "execution_count": 11,
586
+ "metadata": {},
587
+ "outputs": [
588
+ {
589
+ "name": "stdout",
590
+ "output_type": "stream",
591
+ "text": [
592
+ "<class 'pandas.core.frame.DataFrame'>\n",
593
+ "RangeIndex: 6574224 entries, 0 to 6574223\n",
594
+ "Data columns (total 6 columns):\n",
595
+ " # Column Non-Null Count Dtype \n",
596
+ "--- ------ -------------- ----- \n",
597
+ " 0 EOL content ID 6574224 non-null int64 \n",
598
+ " 1 EOL page ID 6574224 non-null int64 \n",
599
+ " 2 Medium Source URL 6574222 non-null object\n",
600
+ " 3 EOL Full-Size Copy URL 6574224 non-null object\n",
601
+ " 4 License Name 6574224 non-null object\n",
602
+ " 5 Copyright Owner 5942181 non-null object\n",
603
+ "dtypes: int64(2), object(4)\n",
604
+ "memory usage: 300.9+ MB\n"
605
+ ]
606
+ }
607
+ ],
608
+ "source": [
609
+ "media = pd.read_csv(\"../data/media_manifest (july 26).csv\", dtype = {\"EOL content ID\": \"int64\", \"EOL page ID\": \"int64\"}, low_memory = False)\n",
610
+ "media.info(show_counts = True)"
611
+ ]
612
+ },
613
+ {
614
+ "cell_type": "markdown",
615
+ "metadata": {},
616
+ "source": [
617
+ "We want to make sure the EOL content and page IDs have matching types, so we'll set them to `int64` in `eol_df` too."
618
+ ]
619
+ },
620
+ {
621
+ "cell_type": "code",
622
+ "execution_count": 12,
623
+ "metadata": {},
624
+ "outputs": [
625
+ {
626
+ "name": "stdout",
627
+ "output_type": "stream",
628
+ "text": [
629
+ "<class 'pandas.core.frame.DataFrame'>\n",
630
+ "Index: 6277374 entries, 0 to 6277373\n",
631
+ "Data columns (total 3 columns):\n",
632
+ " # Column Dtype \n",
633
+ "--- ------ ----- \n",
634
+ " 0 treeoflife_id object\n",
635
+ " 1 eol_content_id int64 \n",
636
+ " 2 eol_page_id int64 \n",
637
+ "dtypes: int64(2), object(1)\n",
638
+ "memory usage: 191.6+ MB\n"
639
+ ]
640
+ }
641
+ ],
642
+ "source": [
643
+ "eol_df = eol_df.astype({\"eol_content_id\": \"int64\", \"eol_page_id\": \"int64\"})\n",
644
+ "eol_df.info()"
645
+ ]
646
+ },
647
+ {
648
+ "cell_type": "markdown",
649
+ "metadata": {},
650
+ "source": [
651
+ "Notice that we have about 300K more entries in the media manifest, which is about expected from the [comparison of predicted-catalog to the original full list](https://huggingface.co/datasets/imageomics/ToL-EDA/blob/main/notebooks/ToL_predicted-catalog_EDA.ipynb)."
652
+ ]
653
+ },
654
+ {
655
+ "cell_type": "markdown",
656
+ "metadata": {},
657
+ "source": [
658
+ "Rename media columns for easier matching."
659
+ ]
660
+ },
661
+ {
662
+ "cell_type": "code",
663
+ "execution_count": 13,
664
+ "metadata": {},
665
+ "outputs": [],
666
+ "source": [
667
+ "media.rename(columns = {\"EOL content ID\": \"eol_content_id\", \"EOL page ID\": \"eol_page_id\"}, inplace = True)"
668
+ ]
669
+ },
670
+ {
671
+ "cell_type": "markdown",
672
+ "metadata": {},
673
+ "source": [
674
+ "Check consistency of merge when matching both `eol_content_id` and `eol_page_id`."
675
+ ]
676
+ },
677
+ {
678
+ "cell_type": "code",
679
+ "execution_count": 14,
680
+ "metadata": {},
681
+ "outputs": [],
682
+ "source": [
683
+ "merge_cols = [\"eol_content_id\", \"eol_page_id\"]"
684
+ ]
685
+ },
686
+ {
687
+ "cell_type": "code",
688
+ "execution_count": 15,
689
+ "metadata": {},
690
+ "outputs": [
691
+ {
692
+ "name": "stdout",
693
+ "output_type": "stream",
694
+ "text": [
695
+ "<class 'pandas.core.frame.DataFrame'>\n",
696
+ "RangeIndex: 6163903 entries, 0 to 6163902\n",
697
+ "Data columns (total 7 columns):\n",
698
+ " # Column Non-Null Count Dtype \n",
699
+ "--- ------ -------------- ----- \n",
700
+ " 0 treeoflife_id 6163903 non-null object\n",
701
+ " 1 eol_content_id 6163903 non-null int64 \n",
702
+ " 2 eol_page_id 6163903 non-null int64 \n",
703
+ " 3 Medium Source URL 6163903 non-null object\n",
704
+ " 4 EOL Full-Size Copy URL 6163903 non-null object\n",
705
+ " 5 License Name 6163903 non-null object\n",
706
+ " 6 Copyright Owner 5549428 non-null object\n",
707
+ "dtypes: int64(2), object(5)\n",
708
+ "memory usage: 329.2+ MB\n"
709
+ ]
710
+ }
711
+ ],
712
+ "source": [
713
+ "eol_df_media_cp = pd.merge(eol_df, media, how = \"inner\", left_on = merge_cols, right_on = merge_cols)\n",
714
+ "eol_df_media_cp.info(show_counts = True)"
715
+ ]
716
+ },
717
+ {
718
+ "cell_type": "markdown",
719
+ "metadata": {},
720
+ "source": [
721
+ "Okay, so we do have a mis-match of about 113K images where the content IDs and page IDs don't both match.\n",
722
+ "\n",
723
+ "Let's save this to a CSV."
724
+ ]
725
+ },
726
+ {
727
+ "cell_type": "code",
728
+ "execution_count": 16,
729
+ "metadata": {},
730
+ "outputs": [],
731
+ "source": [
732
+ "eol_df_media_cp.to_csv(\"../data/eol_files/eol_cp_match_media.csv\", index = False)"
733
+ ]
734
+ },
735
+ {
736
+ "cell_type": "markdown",
737
+ "metadata": {},
738
+ "source": [
739
+ "Note that merging on just content IDs is going to give the same numbers."
740
+ ]
741
+ },
742
+ {
743
+ "cell_type": "code",
744
+ "execution_count": 17,
745
+ "metadata": {},
746
+ "outputs": [
747
+ {
748
+ "name": "stdout",
749
+ "output_type": "stream",
750
+ "text": [
751
+ "<class 'pandas.core.frame.DataFrame'>\n",
752
+ "RangeIndex: 6163903 entries, 0 to 6163902\n",
753
+ "Data columns (total 8 columns):\n",
754
+ " # Column Non-Null Count Dtype \n",
755
+ "--- ------ -------------- ----- \n",
756
+ " 0 treeoflife_id 6163903 non-null object\n",
757
+ " 1 eol_content_id 6163903 non-null int64 \n",
758
+ " 2 eol_page_id_x 6163903 non-null int64 \n",
759
+ " 3 eol_page_id_y 6163903 non-null int64 \n",
760
+ " 4 Medium Source URL 6163903 non-null object\n",
761
+ " 5 EOL Full-Size Copy URL 6163903 non-null object\n",
762
+ " 6 License Name 6163903 non-null object\n",
763
+ " 7 Copyright Owner 5549428 non-null object\n",
764
+ "dtypes: int64(3), object(5)\n",
765
+ "memory usage: 376.2+ MB\n"
766
+ ]
767
+ }
768
+ ],
769
+ "source": [
770
+ "eol_media_content = pd.merge(eol_df,\n",
771
+ " media,\n",
772
+ " how = \"inner\",\n",
773
+ " left_on = \"eol_content_id\",\n",
774
+ " right_on = \"eol_content_id\")\n",
775
+ "eol_media_content.info(show_counts = True)"
776
+ ]
777
+ },
778
+ {
779
+ "cell_type": "markdown",
780
+ "metadata": {},
781
+ "source": [
782
+ "The interesting thing is when we look at the uniqueness. There are less _**unique**_ `Medium Source URLs`, suggesting that there are duplicated images that have different content IDs and unique `EOL Full-Size Copy URL`s, so EOL presumably has them duplicated."
783
+ ]
784
+ },
785
+ {
786
+ "cell_type": "code",
787
+ "execution_count": 18,
788
+ "metadata": {},
789
+ "outputs": [
790
+ {
791
+ "data": {
792
+ "text/plain": [
793
+ "treeoflife_id 6163903\n",
794
+ "eol_content_id 6163903\n",
795
+ "eol_page_id 503865\n",
796
+ "Medium Source URL 6153828\n",
797
+ "EOL Full-Size Copy URL 6163903\n",
798
+ "License Name 16\n",
799
+ "Copyright Owner 345470\n",
800
+ "dtype: int64"
801
+ ]
802
+ },
803
+ "execution_count": 18,
804
+ "metadata": {},
805
+ "output_type": "execute_result"
806
+ }
807
+ ],
808
+ "source": [
809
+ "eol_df_media_cp.nunique()"
810
+ ]
811
+ },
812
+ {
813
+ "cell_type": "markdown",
814
+ "metadata": {},
815
+ "source": [
816
+ "We'll look into this a little further down. First, let's get a list of all the `treeoflife_id`s that do match to the media manifest so we can make a CSV with all the images that _**aren't**_ matching."
817
+ ]
818
+ },
819
+ {
820
+ "cell_type": "code",
821
+ "execution_count": 19,
822
+ "metadata": {},
823
+ "outputs": [
824
+ {
825
+ "data": {
826
+ "text/plain": [
827
+ "['f2f0aa29-e87b-469c-bf5b-51a3611ab001',\n",
828
+ " '5faa4f55-32e9-4872-953d-567e5d232e52',\n",
829
+ " '2282f2bf-2b52-4522-b588-dd6f356d5fd6',\n",
830
+ " '76b57c36-2181-4e6d-a5c4-b40e22a09449',\n",
831
+ " 'f57d3ab6-2cf5-484b-a590-e2a3d49a3ca2']"
832
+ ]
833
+ },
834
+ "execution_count": 19,
835
+ "metadata": {},
836
+ "output_type": "execute_result"
837
+ }
838
+ ],
839
+ "source": [
840
+ "tol_ids_in_media = list(eol_df_media_cp.treeoflife_id)\n",
841
+ "tol_ids_in_media[:5]"
842
+ ]
843
+ },
844
+ {
845
+ "cell_type": "code",
846
+ "execution_count": 20,
847
+ "metadata": {},
848
+ "outputs": [
849
+ {
850
+ "data": {
851
+ "text/html": [
852
+ "<div>\n",
853
+ "<style scoped>\n",
854
+ " .dataframe tbody tr th:only-of-type {\n",
855
+ " vertical-align: middle;\n",
856
+ " }\n",
857
+ "\n",
858
+ " .dataframe tbody tr th {\n",
859
+ " vertical-align: top;\n",
860
+ " }\n",
861
+ "\n",
862
+ " .dataframe thead th {\n",
863
+ " text-align: right;\n",
864
+ " }\n",
865
+ "</style>\n",
866
+ "<table border=\"1\" class=\"dataframe\">\n",
867
+ " <thead>\n",
868
+ " <tr style=\"text-align: right;\">\n",
869
+ " <th></th>\n",
870
+ " <th>treeoflife_id</th>\n",
871
+ " <th>eol_content_id</th>\n",
872
+ " <th>eol_page_id</th>\n",
873
+ " </tr>\n",
874
+ " </thead>\n",
875
+ " <tbody>\n",
876
+ " <tr>\n",
877
+ " <th>0</th>\n",
878
+ " <td>f2f0aa29-e87b-469c-bf5b-51a3611ab001</td>\n",
879
+ " <td>22131926</td>\n",
880
+ " <td>269504</td>\n",
881
+ " </tr>\n",
882
+ " <tr>\n",
883
+ " <th>1</th>\n",
884
+ " <td>5faa4f55-32e9-4872-953d-567e5d232e52</td>\n",
885
+ " <td>22291283</td>\n",
886
+ " <td>6101931</td>\n",
887
+ " </tr>\n",
888
+ " <tr>\n",
889
+ " <th>2</th>\n",
890
+ " <td>2282f2bf-2b52-4522-b588-dd6f356d5fd6</td>\n",
891
+ " <td>21802775</td>\n",
892
+ " <td>45513632</td>\n",
893
+ " </tr>\n",
894
+ " <tr>\n",
895
+ " <th>3</th>\n",
896
+ " <td>76b57c36-2181-4e6d-a5c4-b40e22a09449</td>\n",
897
+ " <td>12784812</td>\n",
898
+ " <td>51655800</td>\n",
899
+ " </tr>\n",
900
+ " <tr>\n",
901
+ " <th>4</th>\n",
902
+ " <td>f57d3ab6-2cf5-484b-a590-e2a3d49a3ca2</td>\n",
903
+ " <td>29713643</td>\n",
904
+ " <td>45515896</td>\n",
905
+ " </tr>\n",
906
+ " </tbody>\n",
907
+ "</table>\n",
908
+ "</div>"
909
+ ],
910
+ "text/plain": [
911
+ " treeoflife_id eol_content_id eol_page_id\n",
912
+ "0 f2f0aa29-e87b-469c-bf5b-51a3611ab001 22131926 269504\n",
913
+ "1 5faa4f55-32e9-4872-953d-567e5d232e52 22291283 6101931\n",
914
+ "2 2282f2bf-2b52-4522-b588-dd6f356d5fd6 21802775 45513632\n",
915
+ "3 76b57c36-2181-4e6d-a5c4-b40e22a09449 12784812 51655800\n",
916
+ "4 f57d3ab6-2cf5-484b-a590-e2a3d49a3ca2 29713643 45515896"
917
+ ]
918
+ },
919
+ "execution_count": 20,
920
+ "metadata": {},
921
+ "output_type": "execute_result"
922
+ }
923
+ ],
924
+ "source": [
925
+ "eol_df.head()"
926
+ ]
927
+ },
928
+ {
929
+ "cell_type": "markdown",
930
+ "metadata": {},
931
+ "source": [
932
+ "Let's save a copy of the EOL section with content and page IDs that are mismatched."
933
+ ]
934
+ },
935
+ {
936
+ "cell_type": "code",
937
+ "execution_count": 21,
938
+ "metadata": {},
939
+ "outputs": [
940
+ {
941
+ "name": "stdout",
942
+ "output_type": "stream",
943
+ "text": [
944
+ "<class 'pandas.core.frame.DataFrame'>\n",
945
+ "Index: 113471 entries, 126 to 6277290\n",
946
+ "Data columns (total 3 columns):\n",
947
+ " # Column Non-Null Count Dtype \n",
948
+ "--- ------ -------------- ----- \n",
949
+ " 0 treeoflife_id 113471 non-null object\n",
950
+ " 1 eol_content_id 113471 non-null int64 \n",
951
+ " 2 eol_page_id 113471 non-null int64 \n",
952
+ "dtypes: int64(2), object(1)\n",
953
+ "memory usage: 3.5+ MB\n"
954
+ ]
955
+ }
956
+ ],
957
+ "source": [
958
+ "eol_df_missing_media = eol_df.loc[~eol_df.treeoflife_id.isin(tol_ids_in_media)]\n",
959
+ "eol_df_missing_media.info(show_counts = True)"
960
+ ]
961
+ },
962
+ {
963
+ "cell_type": "markdown",
964
+ "metadata": {},
965
+ "source": [
966
+ "How many pages are these distributed across?"
967
+ ]
968
+ },
969
+ {
970
+ "cell_type": "code",
971
+ "execution_count": 22,
972
+ "metadata": {},
973
+ "outputs": [
974
+ {
975
+ "data": {
976
+ "text/plain": [
977
+ "treeoflife_id 113471\n",
978
+ "eol_content_id 113471\n",
979
+ "eol_page_id 9762\n",
980
+ "dtype: int64"
981
+ ]
982
+ },
983
+ "execution_count": 22,
984
+ "metadata": {},
985
+ "output_type": "execute_result"
986
+ }
987
+ ],
988
+ "source": [
989
+ "eol_df_missing_media.nunique()"
990
+ ]
991
+ },
992
+ {
993
+ "cell_type": "code",
994
+ "execution_count": 23,
995
+ "metadata": {},
996
+ "outputs": [],
997
+ "source": [
998
+ "eol_df_missing_media.to_csv(\"../data/eol_files/eol_cp_not_media.csv\", index = False)"
999
+ ]
1000
+ },
1001
+ {
1002
+ "cell_type": "markdown",
1003
+ "metadata": {},
1004
+ "source": [
1005
+ "### Check out the Duplication of Medium Source URLs"
1006
+ ]
1007
+ },
1008
+ {
1009
+ "cell_type": "code",
1010
+ "execution_count": 24,
1011
+ "metadata": {},
1012
+ "outputs": [],
1013
+ "source": [
1014
+ "# Identify unique Medium Source URLs\n",
1015
+ "eol_df_media_cp['duplicate'] = eol_df_media_cp.duplicated(subset = \"Medium Source URL\", keep = 'first')\n",
1016
+ "eol_df_media_unique = eol_df_media_cp.loc[~eol_df_media_cp['duplicate']]"
1017
+ ]
1018
+ },
1019
+ {
1020
+ "cell_type": "code",
1021
+ "execution_count": 25,
1022
+ "metadata": {},
1023
+ "outputs": [
1024
+ {
1025
+ "name": "stdout",
1026
+ "output_type": "stream",
1027
+ "text": [
1028
+ "<class 'pandas.core.frame.DataFrame'>\n",
1029
+ "Index: 6153828 entries, 0 to 6163902\n",
1030
+ "Data columns (total 8 columns):\n",
1031
+ " # Column Non-Null Count Dtype \n",
1032
+ "--- ------ -------------- ----- \n",
1033
+ " 0 treeoflife_id 6153828 non-null object\n",
1034
+ " 1 eol_content_id 6153828 non-null int64 \n",
1035
+ " 2 eol_page_id 6153828 non-null int64 \n",
1036
+ " 3 Medium Source URL 6153828 non-null object\n",
1037
+ " 4 EOL Full-Size Copy URL 6153828 non-null object\n",
1038
+ " 5 License Name 6153828 non-null object\n",
1039
+ " 6 Copyright Owner 5539739 non-null object\n",
1040
+ " 7 duplicate 6153828 non-null bool \n",
1041
+ "dtypes: bool(1), int64(2), object(5)\n",
1042
+ "memory usage: 381.5+ MB\n"
1043
+ ]
1044
+ }
1045
+ ],
1046
+ "source": [
1047
+ "eol_df_media_unique.info(show_counts = True)"
1048
+ ]
1049
+ },
1050
+ {
1051
+ "cell_type": "markdown",
1052
+ "metadata": {},
1053
+ "source": [
1054
+ "It's about 10K images that are duplicated. Let's see how many `Medium Source URL`s it is."
1055
+ ]
1056
+ },
1057
+ {
1058
+ "cell_type": "code",
1059
+ "execution_count": 26,
1060
+ "metadata": {},
1061
+ "outputs": [
1062
+ {
1063
+ "data": {
1064
+ "text/plain": [
1065
+ "treeoflife_id 10075\n",
1066
+ "eol_content_id 10075\n",
1067
+ "eol_page_id 5391\n",
1068
+ "Medium Source URL 5833\n",
1069
+ "EOL Full-Size Copy URL 10075\n",
1070
+ "License Name 9\n",
1071
+ "Copyright Owner 545\n",
1072
+ "duplicate 1\n",
1073
+ "dtype: int64"
1074
+ ]
1075
+ },
1076
+ "execution_count": 26,
1077
+ "metadata": {},
1078
+ "output_type": "execute_result"
1079
+ }
1080
+ ],
1081
+ "source": [
1082
+ "eol_df_media_cp.loc[eol_df_media_cp['duplicate']].nunique()"
1083
+ ]
1084
+ },
1085
+ {
1086
+ "cell_type": "markdown",
1087
+ "metadata": {},
1088
+ "source": [
1089
+ "There are 5,833 unique `Medium Source URLs` that are duplicated."
1090
+ ]
1091
+ },
1092
+ {
1093
+ "cell_type": "markdown",
1094
+ "metadata": {},
1095
+ "source": [
1096
+ "### Check how this compares to Catalog \n",
1097
+ "Let's see if the missing images are all in TreeOfLife-10M, or a mix between it and Rare Species."
1098
+ ]
1099
+ },
1100
+ {
1101
+ "cell_type": "code",
1102
+ "execution_count": 27,
1103
+ "metadata": {},
1104
+ "outputs": [],
1105
+ "source": [
1106
+ "cat_df = pd.read_csv(\"../data/catalog.csv\", low_memory = False)\n",
1107
+ "# Remove duplicates in train_small\n",
1108
+ "cat_df = cat_df.loc[cat_df.split != 'train_small']"
1109
+ ]
1110
+ },
1111
+ {
1112
+ "cell_type": "code",
1113
+ "execution_count": 28,
1114
+ "metadata": {},
1115
+ "outputs": [],
1116
+ "source": [
1117
+ "# Add data_source column for easier slicing\n",
1118
+ "cat_df.loc[cat_df['inat21_filename'].notna(), 'data_source'] = 'iNat21'\n",
1119
+ "cat_df.loc[cat_df['bioscan_filename'].notna(), 'data_source'] = 'BIOSCAN'\n",
1120
+ "cat_df.loc[cat_df['eol_content_id'].notna(), 'data_source'] = 'EOL'"
1121
+ ]
1122
+ },
1123
+ {
1124
+ "cell_type": "code",
1125
+ "execution_count": 29,
1126
+ "metadata": {},
1127
+ "outputs": [],
1128
+ "source": [
1129
+ "eol_cat_df = cat_df.loc[cat_df.data_source == \"EOL\"]"
1130
+ ]
1131
+ },
1132
+ {
1133
+ "cell_type": "markdown",
1134
+ "metadata": {},
1135
+ "source": [
1136
+ "Reduce down to just relevant columns and recast the EOL content and page IDs as `int64`."
1137
+ ]
1138
+ },
1139
+ {
1140
+ "cell_type": "code",
1141
+ "execution_count": 30,
1142
+ "metadata": {},
1143
+ "outputs": [],
1144
+ "source": [
1145
+ "eol_cat_df = eol_cat_df[eol_license_cols]"
1146
+ ]
1147
+ },
1148
+ {
1149
+ "cell_type": "code",
1150
+ "execution_count": 31,
1151
+ "metadata": {},
1152
+ "outputs": [],
1153
+ "source": [
1154
+ "eol_cat_df = eol_cat_df.astype({\"eol_content_id\": \"int64\", \"eol_page_id\": \"int64\"})"
1155
+ ]
1156
+ },
1157
+ {
1158
+ "cell_type": "code",
1159
+ "execution_count": 32,
1160
+ "metadata": {},
1161
+ "outputs": [
1162
+ {
1163
+ "name": "stdout",
1164
+ "output_type": "stream",
1165
+ "text": [
1166
+ "<class 'pandas.core.frame.DataFrame'>\n",
1167
+ "Index: 6250420 entries, 956715 to 11000930\n",
1168
+ "Data columns (total 3 columns):\n",
1169
+ " # Column Dtype \n",
1170
+ "--- ------ ----- \n",
1171
+ " 0 treeoflife_id object\n",
1172
+ " 1 eol_content_id int64 \n",
1173
+ " 2 eol_page_id int64 \n",
1174
+ "dtypes: int64(2), object(1)\n",
1175
+ "memory usage: 190.7+ MB\n"
1176
+ ]
1177
+ }
1178
+ ],
1179
+ "source": [
1180
+ "eol_cat_df.info()"
1181
+ ]
1182
+ },
1183
+ {
1184
+ "cell_type": "code",
1185
+ "execution_count": 33,
1186
+ "metadata": {},
1187
+ "outputs": [
1188
+ {
1189
+ "name": "stdout",
1190
+ "output_type": "stream",
1191
+ "text": [
1192
+ "<class 'pandas.core.frame.DataFrame'>\n",
1193
+ "Index: 112575 entries, 956761 to 10998986\n",
1194
+ "Data columns (total 3 columns):\n",
1195
+ " # Column Non-Null Count Dtype \n",
1196
+ "--- ------ -------------- ----- \n",
1197
+ " 0 treeoflife_id 112575 non-null object\n",
1198
+ " 1 eol_content_id 112575 non-null int64 \n",
1199
+ " 2 eol_page_id 112575 non-null int64 \n",
1200
+ "dtypes: int64(2), object(1)\n",
1201
+ "memory usage: 3.4+ MB\n"
1202
+ ]
1203
+ }
1204
+ ],
1205
+ "source": [
1206
+ "eol_cat_df.loc[eol_cat_df[\"treeoflife_id\"].isin(list(eol_df_missing_media.treeoflife_id))].info(show_counts = True)"
1207
+ ]
1208
+ },
1209
+ {
1210
+ "cell_type": "markdown",
1211
+ "metadata": {},
1212
+ "source": [
1213
+ "They are _**almost**_ entirely in TreeOfLife-10M, but _some_ may be in Rare Species.\n",
1214
+ "\n",
1215
+ "#### Quick check for the duplicates here"
1216
+ ]
1217
+ },
1218
+ {
1219
+ "cell_type": "code",
1220
+ "execution_count": 34,
1221
+ "metadata": {},
1222
+ "outputs": [
1223
+ {
1224
+ "data": {
1225
+ "text/plain": [
1226
+ "['e37fc4b8-73ef-4a8c-8a65-cf65f9f1174e',\n",
1227
+ " '5e3edcd1-8150-4534-8f69-f63c447afd7d',\n",
1228
+ " '776a596f-96a1-47d8-b510-db8fb41be44d',\n",
1229
+ " '7ce491fa-7573-46e8-b11a-ebac6d702bda',\n",
1230
+ " 'd4ca1530-685d-46e8-969c-44a74f0a00d4']"
1231
+ ]
1232
+ },
1233
+ "execution_count": 34,
1234
+ "metadata": {},
1235
+ "output_type": "execute_result"
1236
+ }
1237
+ ],
1238
+ "source": [
1239
+ "tol_ids_duplicated = list(eol_df_media_cp.loc[eol_df_media_cp['duplicate'], \"treeoflife_id\"].values)\n",
1240
+ "tol_ids_duplicated[:5]"
1241
+ ]
1242
+ },
1243
+ {
1244
+ "cell_type": "code",
1245
+ "execution_count": 35,
1246
+ "metadata": {},
1247
+ "outputs": [
1248
+ {
1249
+ "data": {
1250
+ "text/html": [
1251
+ "<div>\n",
1252
+ "<style scoped>\n",
1253
+ " .dataframe tbody tr th:only-of-type {\n",
1254
+ " vertical-align: middle;\n",
1255
+ " }\n",
1256
+ "\n",
1257
+ " .dataframe tbody tr th {\n",
1258
+ " vertical-align: top;\n",
1259
+ " }\n",
1260
+ "\n",
1261
+ " .dataframe thead th {\n",
1262
+ " text-align: right;\n",
1263
+ " }\n",
1264
+ "</style>\n",
1265
+ "<table border=\"1\" class=\"dataframe\">\n",
1266
+ " <thead>\n",
1267
+ " <tr style=\"text-align: right;\">\n",
1268
+ " <th></th>\n",
1269
+ " <th>treeoflife_id</th>\n",
1270
+ " <th>eol_content_id</th>\n",
1271
+ " <th>eol_page_id</th>\n",
1272
+ " <th>Medium Source URL</th>\n",
1273
+ " <th>EOL Full-Size Copy URL</th>\n",
1274
+ " <th>License Name</th>\n",
1275
+ " <th>Copyright Owner</th>\n",
1276
+ " <th>duplicate</th>\n",
1277
+ " </tr>\n",
1278
+ " </thead>\n",
1279
+ " <tbody>\n",
1280
+ " <tr>\n",
1281
+ " <th>33275</th>\n",
1282
+ " <td>e37fc4b8-73ef-4a8c-8a65-cf65f9f1174e</td>\n",
1283
+ " <td>13611057</td>\n",
1284
+ " <td>37146541</td>\n",
1285
+ " <td>https://pensoft.net/J_FILES/1/articles/5492/ex...</td>\n",
1286
+ " <td>https://content.eol.org/data/media/d4/f0/a9/58...</td>\n",
1287
+ " <td>cc-by-3.0</td>\n",
1288
+ " <td>James K. Liebherr</td>\n",
1289
+ " <td>True</td>\n",
1290
+ " </tr>\n",
1291
+ " <tr>\n",
1292
+ " <th>36445</th>\n",
1293
+ " <td>5e3edcd1-8150-4534-8f69-f63c447afd7d</td>\n",
1294
+ " <td>13620019</td>\n",
1295
+ " <td>16355052</td>\n",
1296
+ " <td>https://pensoft.net/J_FILES/1/articles/7546/ex...</td>\n",
1297
+ " <td>https://content.eol.org/data/media/d5/13/ac/58...</td>\n",
1298
+ " <td>cc-by-3.0</td>\n",
1299
+ " <td>Jin-Kyung Choi, Jong-Wook Lee</td>\n",
1300
+ " <td>True</td>\n",
1301
+ " </tr>\n",
1302
+ " <tr>\n",
1303
+ " <th>52304</th>\n",
1304
+ " <td>776a596f-96a1-47d8-b510-db8fb41be44d</td>\n",
1305
+ " <td>13610902</td>\n",
1306
+ " <td>732357</td>\n",
1307
+ " <td>https://pensoft.net/J_FILES/1/articles/5352/ex...</td>\n",
1308
+ " <td>https://content.eol.org/data/media/d4/f0/11/58...</td>\n",
1309
+ " <td>cc-by-3.0</td>\n",
1310
+ " <td>Mary Liz Jameson, Alain Drumont</td>\n",
1311
+ " <td>True</td>\n",
1312
+ " </tr>\n",
1313
+ " <tr>\n",
1314
+ " <th>67099</th>\n",
1315
+ " <td>7ce491fa-7573-46e8-b11a-ebac6d702bda</td>\n",
1316
+ " <td>14119729</td>\n",
1317
+ " <td>62672726</td>\n",
1318
+ " <td>https://live.staticflickr.com/4302/35924815981...</td>\n",
1319
+ " <td>https://content.eol.org/data/media/d7/93/6e/54...</td>\n",
1320
+ " <td>cc-publicdomain</td>\n",
1321
+ " <td>Biodiversity Heritage Library</td>\n",
1322
+ " <td>True</td>\n",
1323
+ " </tr>\n",
1324
+ " <tr>\n",
1325
+ " <th>73915</th>\n",
1326
+ " <td>d4ca1530-685d-46e8-969c-44a74f0a00d4</td>\n",
1327
+ " <td>13613433</td>\n",
1328
+ " <td>60227621</td>\n",
1329
+ " <td>https://pensoft.net/J_FILES/1/articles/5999/ex...</td>\n",
1330
+ " <td>https://content.eol.org/data/media/d4/f9/f4/58...</td>\n",
1331
+ " <td>cc-by-3.0</td>\n",
1332
+ " <td>Oleg Pekarsky</td>\n",
1333
+ " <td>True</td>\n",
1334
+ " </tr>\n",
1335
+ " </tbody>\n",
1336
+ "</table>\n",
1337
+ "</div>"
1338
+ ],
1339
+ "text/plain": [
1340
+ " treeoflife_id eol_content_id eol_page_id \\\n",
1341
+ "33275 e37fc4b8-73ef-4a8c-8a65-cf65f9f1174e 13611057 37146541 \n",
1342
+ "36445 5e3edcd1-8150-4534-8f69-f63c447afd7d 13620019 16355052 \n",
1343
+ "52304 776a596f-96a1-47d8-b510-db8fb41be44d 13610902 732357 \n",
1344
+ "67099 7ce491fa-7573-46e8-b11a-ebac6d702bda 14119729 62672726 \n",
1345
+ "73915 d4ca1530-685d-46e8-969c-44a74f0a00d4 13613433 60227621 \n",
1346
+ "\n",
1347
+ " Medium Source URL \\\n",
1348
+ "33275 https://pensoft.net/J_FILES/1/articles/5492/ex... \n",
1349
+ "36445 https://pensoft.net/J_FILES/1/articles/7546/ex... \n",
1350
+ "52304 https://pensoft.net/J_FILES/1/articles/5352/ex... \n",
1351
+ "67099 https://live.staticflickr.com/4302/35924815981... \n",
1352
+ "73915 https://pensoft.net/J_FILES/1/articles/5999/ex... \n",
1353
+ "\n",
1354
+ " EOL Full-Size Copy URL License Name \\\n",
1355
+ "33275 https://content.eol.org/data/media/d4/f0/a9/58... cc-by-3.0 \n",
1356
+ "36445 https://content.eol.org/data/media/d5/13/ac/58... cc-by-3.0 \n",
1357
+ "52304 https://content.eol.org/data/media/d4/f0/11/58... cc-by-3.0 \n",
1358
+ "67099 https://content.eol.org/data/media/d7/93/6e/54... cc-publicdomain \n",
1359
+ "73915 https://content.eol.org/data/media/d4/f9/f4/58... cc-by-3.0 \n",
1360
+ "\n",
1361
+ " Copyright Owner duplicate \n",
1362
+ "33275 James K. Liebherr True \n",
1363
+ "36445 Jin-Kyung Choi, Jong-Wook Lee True \n",
1364
+ "52304 Mary Liz Jameson, Alain Drumont True \n",
1365
+ "67099 Biodiversity Heritage Library True \n",
1366
+ "73915 Oleg Pekarsky True "
1367
+ ]
1368
+ },
1369
+ "execution_count": 35,
1370
+ "metadata": {},
1371
+ "output_type": "execute_result"
1372
+ }
1373
+ ],
1374
+ "source": [
1375
+ "eol_df_media_cp.loc[eol_df_media_cp['duplicate']].head()"
1376
+ ]
1377
+ },
1378
+ {
1379
+ "cell_type": "code",
1380
+ "execution_count": 36,
1381
+ "metadata": {},
1382
+ "outputs": [
1383
+ {
1384
+ "name": "stdout",
1385
+ "output_type": "stream",
1386
+ "text": [
1387
+ "<class 'pandas.core.frame.DataFrame'>\n",
1388
+ "Index: 10068 entries, 956913 to 10996963\n",
1389
+ "Data columns (total 3 columns):\n",
1390
+ " # Column Non-Null Count Dtype \n",
1391
+ "--- ------ -------------- ----- \n",
1392
+ " 0 treeoflife_id 10068 non-null object\n",
1393
+ " 1 eol_content_id 10068 non-null int64 \n",
1394
+ " 2 eol_page_id 10068 non-null int64 \n",
1395
+ "dtypes: int64(2), object(1)\n",
1396
+ "memory usage: 314.6+ KB\n"
1397
+ ]
1398
+ }
1399
+ ],
1400
+ "source": [
1401
+ "eol_cat_df.loc[eol_cat_df[\"treeoflife_id\"].isin(tol_ids_duplicated)].info(show_counts = True)"
1402
+ ]
1403
+ },
1404
+ {
1405
+ "cell_type": "markdown",
1406
+ "metadata": {},
1407
+ "source": [
1408
+ "All but 7 of the duplicates are here too."
1409
+ ]
1410
+ },
1411
+ {
1412
+ "cell_type": "markdown",
1413
+ "metadata": {},
1414
+ "source": [
1415
+ "Let's save a version of the merged manifest with all duplicates (as in, _**every**_ image that's duplicated is listed, not just the 2nd through however many to appear)."
1416
+ ]
1417
+ },
1418
+ {
1419
+ "cell_type": "code",
1420
+ "execution_count": 37,
1421
+ "metadata": {},
1422
+ "outputs": [
1423
+ {
1424
+ "name": "stdout",
1425
+ "output_type": "stream",
1426
+ "text": [
1427
+ "<class 'pandas.core.frame.DataFrame'>\n",
1428
+ "Index: 15908 entries, 1691 to 6163695\n",
1429
+ "Data columns (total 8 columns):\n",
1430
+ " # Column Non-Null Count Dtype \n",
1431
+ "--- ------ -------------- ----- \n",
1432
+ " 0 treeoflife_id 15908 non-null object\n",
1433
+ " 1 eol_content_id 15908 non-null int64 \n",
1434
+ " 2 eol_page_id 15908 non-null int64 \n",
1435
+ " 3 Medium Source URL 15908 non-null object\n",
1436
+ " 4 EOL Full-Size Copy URL 15908 non-null object\n",
1437
+ " 5 License Name 15908 non-null object\n",
1438
+ " 6 Copyright Owner 15148 non-null object\n",
1439
+ " 7 duplicate 15908 non-null bool \n",
1440
+ "dtypes: bool(1), int64(2), object(5)\n",
1441
+ "memory usage: 1009.8+ KB\n"
1442
+ ]
1443
+ }
1444
+ ],
1445
+ "source": [
1446
+ "# Identify unique Medium Source URLs\n",
1447
+ "eol_df_media_copies = eol_df_media_cp.copy()\n",
1448
+ "eol_df_media_copies['duplicate'] = eol_df_media_copies.duplicated(subset = \"Medium Source URL\", keep = False)\n",
1449
+ "eol_df_media_duplicates = eol_df_media_copies.loc[eol_df_media_copies['duplicate']]\n",
1450
+ "eol_df_media_duplicates.info(show_counts = True)"
1451
+ ]
1452
+ },
1453
+ {
1454
+ "cell_type": "markdown",
1455
+ "metadata": {},
1456
+ "source": [
1457
+ "Now we'll save this to CSV (without the duplicate column since they're all duplicates)."
1458
+ ]
1459
+ },
1460
+ {
1461
+ "cell_type": "code",
1462
+ "execution_count": 38,
1463
+ "metadata": {},
1464
+ "outputs": [],
1465
+ "source": [
1466
+ "eol_df_media_duplicates[eol_df_media_duplicates.columns[:7]].to_csv(\"../data/eol_files/eol_media_duplicates.csv\", index = False)"
1467
+ ]
1468
+ },
1469
+ {
1470
+ "cell_type": "code",
1471
+ "execution_count": null,
1472
+ "metadata": {},
1473
+ "outputs": [],
1474
+ "source": []
1475
+ }
1476
+ ],
1477
+ "metadata": {
1478
+ "jupytext": {
1479
+ "formats": "ipynb,py:percent"
1480
+ },
1481
+ "kernelspec": {
1482
+ "display_name": "Python 3 (ipykernel)",
1483
+ "language": "python",
1484
+ "name": "python3"
1485
+ },
1486
+ "language_info": {
1487
+ "codemirror_mode": {
1488
+ "name": "ipython",
1489
+ "version": 3
1490
+ },
1491
+ "file_extension": ".py",
1492
+ "mimetype": "text/x-python",
1493
+ "name": "python",
1494
+ "nbconvert_exporter": "python",
1495
+ "pygments_lexer": "ipython3",
1496
+ "version": "3.11.3"
1497
+ }
1498
+ },
1499
+ "nbformat": 4,
1500
+ "nbformat_minor": 4
1501
+ }
notebooks/ToL_media_mismatch.py ADDED
@@ -0,0 +1,243 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ---
2
+ # jupyter:
3
+ # jupytext:
4
+ # formats: ipynb,py:percent
5
+ # text_representation:
6
+ # extension: .py
7
+ # format_name: percent
8
+ # format_version: '1.3'
9
+ # jupytext_version: 1.16.0
10
+ # kernelspec:
11
+ # display_name: Python 3 (ipykernel)
12
+ # language: python
13
+ # name: python3
14
+ # ---
15
+
16
+ # %%
17
+ import pandas as pd
18
+
19
+ # %% [markdown]
20
+ # Load in full images to ease process.
21
+
22
+ # %%
23
+ df = pd.read_csv("../data/predicted-catalog.csv", low_memory = False)
24
+
25
+ # %%
26
+ df.head()
27
+
28
+ # %%
29
+ df.info(show_counts = True)
30
+
31
+ # %% [markdown]
32
+ # The `train_small` is duplicates of `train`, so we will drop those to analyze the full training set plus val.
33
+
34
+ # %% [markdown]
35
+ # `predicted-catalog` doesn't have `train_small`, hence, it's a smaller file.
36
+
37
+ # %% [markdown]
38
+ # Let's add a column indicating the original data source so we can also get some stats by datasource, specifically focusing on EOL since we know licensing for BIOSCAN-1M and iNat21.
39
+
40
+ # %%
41
+ # Add data_source column for easier slicing
42
+ df.loc[df['inat21_filename'].notna(), 'data_source'] = 'iNat21'
43
+ df.loc[df['bioscan_filename'].notna(), 'data_source'] = 'BIOSCAN'
44
+ df.loc[df['eol_content_id'].notna(), 'data_source'] = 'EOL'
45
+
46
+ # %% [markdown]
47
+ # #### Get just EOL CSV for Media Manifest Merge
48
+
49
+ # %%
50
+ eol_df = df.loc[df['data_source'] == 'EOL']
51
+
52
+ # %%
53
+ eol_df.head()
54
+
55
+ # %% [markdown]
56
+ # We don't need the BIOSCAN or iNat21 columns, nor the taxa columns.
57
+
58
+ # %%
59
+ eol_license_cols = eol_df.columns[1:4]
60
+ eol_license_cols
61
+
62
+ # %%
63
+ eol_df = eol_df[eol_license_cols]
64
+
65
+ # %%
66
+ eol_df.nunique()
67
+
68
+ # %% [markdown]
69
+ # Number of unique `eol_content_id`s and `treeoflife_id`s match, and match with total number of `eol_content_id`s shown above in the info for the full dataset.
70
+
71
+ # %% [markdown]
72
+ # ### Merge with Media Manifest
73
+ # Let's merge with the [media manifest](https://huggingface.co/datasets/imageomics/eol/blob/be7b7e6c372f6547e30030e9576d9cc638320099/data/interim/media_manifest.csv) from which all these images should have been downloaded from to get a clear picture of what is or isn't in the manifest.
74
+
75
+ # %%
76
+ media = pd.read_csv("../data/media_manifest (july 26).csv", dtype = {"EOL content ID": "int64", "EOL page ID": "int64"}, low_memory = False)
77
+ media.info(show_counts = True)
78
+
79
+ # %% [markdown]
80
+ # We want to make sure the EOL content and page IDs have matching types, so we'll set them to `int64` in `eol_df` too.
81
+
82
+ # %%
83
+ eol_df = eol_df.astype({"eol_content_id": "int64", "eol_page_id": "int64"})
84
+ eol_df.info()
85
+
86
+ # %% [markdown]
87
+ # Notice that we have about 300K more entries in the media manifest, which is about expected from the [comparison of predicted-catalog to the original full list](https://huggingface.co/datasets/imageomics/ToL-EDA/blob/main/notebooks/ToL_predicted-catalog_EDA.ipynb).
88
+
89
+ # %% [markdown]
90
+ # Rename media columns for easier matching.
91
+
92
+ # %%
93
+ media.rename(columns = {"EOL content ID": "eol_content_id", "EOL page ID": "eol_page_id"}, inplace = True)
94
+
95
+ # %% [markdown]
96
+ # Check consistency of merge when matching both `eol_content_id` and `eol_page_id`.
97
+
98
+ # %%
99
+ merge_cols = ["eol_content_id", "eol_page_id"]
100
+
101
+ # %%
102
+ eol_df_media_cp = pd.merge(eol_df, media, how = "inner", left_on = merge_cols, right_on = merge_cols)
103
+ eol_df_media_cp.info(show_counts = True)
104
+
105
+ # %% [markdown]
106
+ # Okay, so we do have a mis-match of about 113K images where the content IDs and page IDs don't both match.
107
+ #
108
+ # Let's save this to a CSV.
109
+
110
+ # %%
111
+ eol_df_media_cp.to_csv("../data/eol_files/eol_cp_match_media.csv", index = False)
112
+
113
+ # %% [markdown]
114
+ # Note that merging on just content IDs is going to give the same numbers.
115
+
116
+ # %%
117
+ eol_media_content = pd.merge(eol_df,
118
+ media,
119
+ how = "inner",
120
+ left_on = "eol_content_id",
121
+ right_on = "eol_content_id")
122
+ eol_media_content.info(show_counts = True)
123
+
124
+ # %% [markdown]
125
+ # The interesting thing is when we look at the uniqueness. There are less _**unique**_ `Medium Source URLs`, suggesting that there are duplicated images that have different content IDs and unique `EOL Full-Size Copy URL`s, so EOL presumably has them duplicated.
126
+
127
+ # %%
128
+ eol_df_media_cp.nunique()
129
+
130
+ # %% [markdown]
131
+ # We'll look into this a little further down. First, let's get a list of all the `treeoflife_id`s that do match to the media manifest so we can make a CSV with all the images that _**aren't**_ matching.
132
+
133
+ # %%
134
+ tol_ids_in_media = list(eol_df_media_cp.treeoflife_id)
135
+ tol_ids_in_media[:5]
136
+
137
+ # %%
138
+ eol_df.head()
139
+
140
+ # %% [markdown]
141
+ # Let's save a copy of the EOL section with content and page IDs that are mismatched.
142
+
143
+ # %%
144
+ eol_df_missing_media = eol_df.loc[~eol_df.treeoflife_id.isin(tol_ids_in_media)]
145
+ eol_df_missing_media.info(show_counts = True)
146
+
147
+ # %% [markdown]
148
+ # How many pages are these distributed across?
149
+
150
+ # %%
151
+ eol_df_missing_media.nunique()
152
+
153
+ # %%
154
+ eol_df_missing_media.to_csv("../data/eol_files/eol_cp_not_media.csv", index = False)
155
+
156
+ # %% [markdown]
157
+ # ### Check out the Duplication of Medium Source URLs
158
+
159
+ # %%
160
+ # Identify unique Medium Source URLs
161
+ eol_df_media_cp['duplicate'] = eol_df_media_cp.duplicated(subset = "Medium Source URL", keep = 'first')
162
+ eol_df_media_unique = eol_df_media_cp.loc[~eol_df_media_cp['duplicate']]
163
+
164
+ # %%
165
+ eol_df_media_unique.info(show_counts = True)
166
+
167
+ # %% [markdown]
168
+ # It's about 10K images that are duplicated. Let's see how many `Medium Source URL`s it is.
169
+
170
+ # %%
171
+ eol_df_media_cp.loc[eol_df_media_cp['duplicate']].nunique()
172
+
173
+ # %% [markdown]
174
+ # There are 5,833 unique `Medium Source URLs` that are duplicated.
175
+
176
+ # %% [markdown]
177
+ # ### Check how this compares to Catalog
178
+ # Let's see if the missing images are all in TreeOfLife-10M, or a mix between it and Rare Species.
179
+
180
+ # %%
181
+ cat_df = pd.read_csv("../data/catalog.csv", low_memory = False)
182
+ # Remove duplicates in train_small
183
+ cat_df = cat_df.loc[cat_df.split != 'train_small']
184
+
185
+ # %%
186
+ # Add data_source column for easier slicing
187
+ cat_df.loc[cat_df['inat21_filename'].notna(), 'data_source'] = 'iNat21'
188
+ cat_df.loc[cat_df['bioscan_filename'].notna(), 'data_source'] = 'BIOSCAN'
189
+ cat_df.loc[cat_df['eol_content_id'].notna(), 'data_source'] = 'EOL'
190
+
191
+ # %%
192
+ eol_cat_df = cat_df.loc[cat_df.data_source == "EOL"]
193
+
194
+ # %% [markdown]
195
+ # Reduce down to just relevant columns and recast the EOL content and page IDs as `int64`.
196
+
197
+ # %%
198
+ eol_cat_df = eol_cat_df[eol_license_cols]
199
+
200
+ # %%
201
+ eol_cat_df = eol_cat_df.astype({"eol_content_id": "int64", "eol_page_id": "int64"})
202
+
203
+ # %%
204
+ eol_cat_df.info()
205
+
206
+ # %%
207
+ eol_cat_df.loc[eol_cat_df["treeoflife_id"].isin(list(eol_df_missing_media.treeoflife_id))].info(show_counts = True)
208
+
209
+ # %% [markdown]
210
+ # They are _**almost**_ entirely in TreeOfLife-10M, but _some_ may be in Rare Species.
211
+ #
212
+ # #### Quick check for the duplicates here
213
+
214
+ # %%
215
+ tol_ids_duplicated = list(eol_df_media_cp.loc[eol_df_media_cp['duplicate'], "treeoflife_id"].values)
216
+ tol_ids_duplicated[:5]
217
+
218
+ # %%
219
+ eol_df_media_cp.loc[eol_df_media_cp['duplicate']].head()
220
+
221
+ # %%
222
+ eol_cat_df.loc[eol_cat_df["treeoflife_id"].isin(tol_ids_duplicated)].info(show_counts = True)
223
+
224
+ # %% [markdown]
225
+ # All but 7 of the duplicates are here too.
226
+
227
+ # %% [markdown]
228
+ # Let's save a version of the merged manifest with all duplicates (as in, _**every**_ image that's duplicated is listed, not just the 2nd through however many to appear).
229
+
230
+ # %%
231
+ # Identify unique Medium Source URLs
232
+ eol_df_media_copies = eol_df_media_cp.copy()
233
+ eol_df_media_copies['duplicate'] = eol_df_media_copies.duplicated(subset = "Medium Source URL", keep = False)
234
+ eol_df_media_duplicates = eol_df_media_copies.loc[eol_df_media_copies['duplicate']]
235
+ eol_df_media_duplicates.info(show_counts = True)
236
+
237
+ # %% [markdown]
238
+ # Now we'll save this to CSV (without the duplicate column since they're all duplicates).
239
+
240
+ # %%
241
+ eol_df_media_duplicates[eol_df_media_duplicates.columns[:7]].to_csv("../data/eol_files/eol_media_duplicates.csv", index = False)
242
+
243
+ # %%