egrace479 commited on
Commit
3794f51
·
verified ·
1 Parent(s): 9caee01

Add notebooks exploring the link files, combining with catalogs

Browse files

RS for rare species and align reduced looks at catalog and predicted catalog

eol_realign/notebooks/links_align_reduced.ipynb ADDED
@@ -0,0 +1,938 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 2,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "import pandas as pd"
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "markdown",
14
+ "metadata": {},
15
+ "source": [
16
+ "### Read in Links CSV files"
17
+ ]
18
+ },
19
+ {
20
+ "cell_type": "code",
21
+ "execution_count": 3,
22
+ "metadata": {},
23
+ "outputs": [],
24
+ "source": [
25
+ "links_inner = pd.read_csv(\"../data/links_inner.csv\", low_memory=False)\n",
26
+ "links_manifest_cargo = pd.read_csv(\"../data/links_manifest_cargo_on_md5.csv\", low_memory=False)"
27
+ ]
28
+ },
29
+ {
30
+ "cell_type": "code",
31
+ "execution_count": 4,
32
+ "metadata": {},
33
+ "outputs": [
34
+ {
35
+ "name": "stdout",
36
+ "output_type": "stream",
37
+ "text": [
38
+ "<class 'pandas.core.frame.DataFrame'>\n",
39
+ "RangeIndex: 6840530 entries, 0 to 6840529\n",
40
+ "Data columns (total 34 columns):\n",
41
+ " # Column Non-Null Count Dtype \n",
42
+ "--- ------ -------------- ----- \n",
43
+ " 0 eol_content_id 6840530 non-null int64 \n",
44
+ " 1 eol_page_id 6840530 non-null int64 \n",
45
+ " 2 medium_source_url 6840530 non-null object \n",
46
+ " 3 eol_full_size_copy_url 6840530 non-null object \n",
47
+ " 4 license_name 6840530 non-null object \n",
48
+ " 5 copyright_owner 6207911 non-null object \n",
49
+ " 6 expected_image_filename 6840530 non-null object \n",
50
+ " 7 source_0706 6840530 non-null bool \n",
51
+ " 8 source_0726 6840530 non-null bool \n",
52
+ " 9 source_1206 6840530 non-null bool \n",
53
+ " 10 combined_id_manifest 6840530 non-null object \n",
54
+ " 11 md5 6840530 non-null object \n",
55
+ " 12 combined_id_manifest_checksums 6840530 non-null object \n",
56
+ " 13 eol_content_id_cargo 6840530 non-null int64 \n",
57
+ " 14 eol_page_id_cargo 6840530 non-null int64 \n",
58
+ " 15 combined_id_cargo 6840530 non-null object \n",
59
+ " 16 split 6840530 non-null object \n",
60
+ " 17 treeoflife_id 6840530 non-null object \n",
61
+ " 18 eol_content_id_catalog 6840530 non-null int64 \n",
62
+ " 19 eol_page_id_catalog 6840530 non-null int64 \n",
63
+ " 20 bioscan_part 0 non-null float64\n",
64
+ " 21 bioscan_filename 0 non-null float64\n",
65
+ " 22 inat21_filename 0 non-null float64\n",
66
+ " 23 inat21_cls_name 0 non-null float64\n",
67
+ " 24 inat21_cls_num 0 non-null float64\n",
68
+ " 25 kingdom 6550801 non-null object \n",
69
+ " 26 phylum 6552534 non-null object \n",
70
+ " 27 class 6531337 non-null object \n",
71
+ " 28 order 6524949 non-null object \n",
72
+ " 29 family 6505404 non-null object \n",
73
+ " 30 genus 6485458 non-null object \n",
74
+ " 31 species 6405635 non-null object \n",
75
+ " 32 common 6840530 non-null object \n",
76
+ " 33 combined_id_catalog 6840530 non-null object \n",
77
+ "dtypes: bool(3), float64(5), int64(6), object(20)\n",
78
+ "memory usage: 1.6+ GB\n"
79
+ ]
80
+ }
81
+ ],
82
+ "source": [
83
+ "links_inner.info(show_counts=True)"
84
+ ]
85
+ },
86
+ {
87
+ "cell_type": "code",
88
+ "execution_count": 5,
89
+ "metadata": {},
90
+ "outputs": [
91
+ {
92
+ "name": "stdout",
93
+ "output_type": "stream",
94
+ "text": [
95
+ "<class 'pandas.core.frame.DataFrame'>\n",
96
+ "RangeIndex: 7513329 entries, 0 to 7513328\n",
97
+ "Data columns (total 16 columns):\n",
98
+ " # Column Non-Null Count Dtype \n",
99
+ "--- ------ -------------- ----- \n",
100
+ " 0 eol_content_id 7513329 non-null int64 \n",
101
+ " 1 eol_page_id 7513329 non-null int64 \n",
102
+ " 2 medium_source_url 7513329 non-null object\n",
103
+ " 3 eol_full_size_copy_url 7513329 non-null object\n",
104
+ " 4 license_name 7513329 non-null object\n",
105
+ " 5 copyright_owner 6860238 non-null object\n",
106
+ " 6 expected_image_filename 7513329 non-null object\n",
107
+ " 7 source_0706 7513329 non-null bool \n",
108
+ " 8 source_0726 7513329 non-null bool \n",
109
+ " 9 source_1206 7513329 non-null bool \n",
110
+ " 10 combined_id_manifest 7513329 non-null object\n",
111
+ " 11 md5 7513329 non-null object\n",
112
+ " 12 combined_id_manifest_checksums 7513329 non-null object\n",
113
+ " 13 eol_content_id_cargo 7513329 non-null int64 \n",
114
+ " 14 eol_page_id_cargo 7513329 non-null int64 \n",
115
+ " 15 combined_id_cargo 7513329 non-null object\n",
116
+ "dtypes: bool(3), int64(4), object(9)\n",
117
+ "memory usage: 766.7+ MB\n"
118
+ ]
119
+ }
120
+ ],
121
+ "source": [
122
+ "links_manifest_cargo.info(show_counts=True)"
123
+ ]
124
+ },
125
+ {
126
+ "cell_type": "code",
127
+ "execution_count": 6,
128
+ "metadata": {},
129
+ "outputs": [
130
+ {
131
+ "name": "stdout",
132
+ "output_type": "stream",
133
+ "text": [
134
+ "<class 'pandas.core.frame.DataFrame'>\n",
135
+ "Index: 822516 entries, 93 to 7513188\n",
136
+ "Data columns (total 16 columns):\n",
137
+ " # Column Non-Null Count Dtype \n",
138
+ "--- ------ -------------- ----- \n",
139
+ " 0 eol_content_id 822516 non-null int64 \n",
140
+ " 1 eol_page_id 822516 non-null int64 \n",
141
+ " 2 medium_source_url 822516 non-null object\n",
142
+ " 3 eol_full_size_copy_url 822516 non-null object\n",
143
+ " 4 license_name 822516 non-null object\n",
144
+ " 5 copyright_owner 797108 non-null object\n",
145
+ " 6 expected_image_filename 822516 non-null object\n",
146
+ " 7 source_0706 822516 non-null bool \n",
147
+ " 8 source_0726 822516 non-null bool \n",
148
+ " 9 source_1206 822516 non-null bool \n",
149
+ " 10 combined_id_manifest 822516 non-null object\n",
150
+ " 11 md5 822516 non-null object\n",
151
+ " 12 combined_id_manifest_checksums 822516 non-null object\n",
152
+ " 13 eol_content_id_cargo 822516 non-null int64 \n",
153
+ " 14 eol_page_id_cargo 822516 non-null int64 \n",
154
+ " 15 combined_id_cargo 822516 non-null object\n",
155
+ "dtypes: bool(3), int64(4), object(9)\n",
156
+ "memory usage: 90.2+ MB\n"
157
+ ]
158
+ }
159
+ ],
160
+ "source": [
161
+ "links_mismatch = links_manifest_cargo.loc[links_manifest_cargo[\"combined_id_cargo\"] != links_manifest_cargo[\"combined_id_manifest_checksums\"]]\n",
162
+ "links_mismatch.info(show_counts = True)"
163
+ ]
164
+ },
165
+ {
166
+ "cell_type": "code",
167
+ "execution_count": 7,
168
+ "metadata": {},
169
+ "outputs": [
170
+ {
171
+ "data": {
172
+ "text/plain": [
173
+ "md5 624561\n",
174
+ "combined_id_manifest_checksums 712504\n",
175
+ "combined_id_cargo 703409\n",
176
+ "dtype: int64"
177
+ ]
178
+ },
179
+ "execution_count": 7,
180
+ "metadata": {},
181
+ "output_type": "execute_result"
182
+ }
183
+ ],
184
+ "source": [
185
+ "links_mismatch[[\"md5\", \"combined_id_manifest_checksums\", \"combined_id_cargo\"]].nunique()"
186
+ ]
187
+ },
188
+ {
189
+ "cell_type": "code",
190
+ "execution_count": 8,
191
+ "metadata": {},
192
+ "outputs": [],
193
+ "source": [
194
+ "links_mismatch.to_csv(\"../data/links_cargo_manifest_IDmismatch.csv\", index = False)"
195
+ ]
196
+ },
197
+ {
198
+ "cell_type": "code",
199
+ "execution_count": 46,
200
+ "metadata": {},
201
+ "outputs": [],
202
+ "source": [
203
+ "catalog = pd.read_csv(\"../../data/catalog.csv\", low_memory=False)"
204
+ ]
205
+ },
206
+ {
207
+ "cell_type": "code",
208
+ "execution_count": 47,
209
+ "metadata": {},
210
+ "outputs": [],
211
+ "source": [
212
+ "# remove train_small and all non-EOL entries\n",
213
+ "catalog = catalog.loc[catalog.split != \"train_small\"]\n",
214
+ "eol_catalog = catalog.loc[catalog.eol_content_id.notna()]"
215
+ ]
216
+ },
217
+ {
218
+ "cell_type": "code",
219
+ "execution_count": 48,
220
+ "metadata": {},
221
+ "outputs": [
222
+ {
223
+ "data": {
224
+ "text/plain": [
225
+ "split 2\n",
226
+ "treeoflife_id 6250420\n",
227
+ "eol_content_id 6250420\n",
228
+ "eol_page_id 503589\n",
229
+ "dtype: int64"
230
+ ]
231
+ },
232
+ "execution_count": 48,
233
+ "metadata": {},
234
+ "output_type": "execute_result"
235
+ }
236
+ ],
237
+ "source": [
238
+ "eol_catalog[list(eol_catalog.columns)[:4]].nunique()"
239
+ ]
240
+ },
241
+ {
242
+ "cell_type": "code",
243
+ "execution_count": 49,
244
+ "metadata": {},
245
+ "outputs": [],
246
+ "source": [
247
+ "eol_cols = [col for col in list(eol_catalog.columns) if \"bioscan\" not in col and \"inat\" not in col]"
248
+ ]
249
+ },
250
+ {
251
+ "cell_type": "code",
252
+ "execution_count": 50,
253
+ "metadata": {},
254
+ "outputs": [
255
+ {
256
+ "name": "stdout",
257
+ "output_type": "stream",
258
+ "text": [
259
+ "<class 'pandas.core.frame.DataFrame'>\n",
260
+ "Index: 6250420 entries, 956715 to 11000930\n",
261
+ "Data columns (total 12 columns):\n",
262
+ " # Column Non-Null Count Dtype \n",
263
+ "--- ------ -------------- ----- \n",
264
+ " 0 split 6250420 non-null object \n",
265
+ " 1 treeoflife_id 6250420 non-null object \n",
266
+ " 2 eol_content_id 6250420 non-null float64\n",
267
+ " 3 eol_page_id 6250420 non-null float64\n",
268
+ " 4 kingdom 5989611 non-null object \n",
269
+ " 5 phylum 5991207 non-null object \n",
270
+ " 6 class 5971438 non-null object \n",
271
+ " 7 order 5965299 non-null object \n",
272
+ " 8 family 5948728 non-null object \n",
273
+ " 9 genus 5940313 non-null object \n",
274
+ " 10 species 5951613 non-null object \n",
275
+ " 11 common 6250420 non-null object \n",
276
+ "dtypes: float64(2), object(10)\n",
277
+ "memory usage: 619.9+ MB\n"
278
+ ]
279
+ }
280
+ ],
281
+ "source": [
282
+ "eol_catalog = eol_catalog[eol_cols]\n",
283
+ "eol_catalog.info(show_counts=True)"
284
+ ]
285
+ },
286
+ {
287
+ "cell_type": "markdown",
288
+ "metadata": {},
289
+ "source": [
290
+ "Must recast IDs as `int64`"
291
+ ]
292
+ },
293
+ {
294
+ "cell_type": "code",
295
+ "execution_count": 51,
296
+ "metadata": {},
297
+ "outputs": [
298
+ {
299
+ "name": "stdout",
300
+ "output_type": "stream",
301
+ "text": [
302
+ "<class 'pandas.core.frame.DataFrame'>\n",
303
+ "Index: 6250420 entries, 956715 to 11000930\n",
304
+ "Data columns (total 4 columns):\n",
305
+ " # Column Dtype \n",
306
+ "--- ------ ----- \n",
307
+ " 0 split object\n",
308
+ " 1 treeoflife_id object\n",
309
+ " 2 eol_content_id int64 \n",
310
+ " 3 eol_page_id int64 \n",
311
+ "dtypes: int64(2), object(2)\n",
312
+ "memory usage: 238.4+ MB\n"
313
+ ]
314
+ }
315
+ ],
316
+ "source": [
317
+ "eol_catalog = eol_catalog.astype({\"eol_content_id\": \"int64\", \"eol_page_id\": \"int64\"})\n",
318
+ "eol_catalog[eol_cols[:4]].info()"
319
+ ]
320
+ },
321
+ {
322
+ "cell_type": "code",
323
+ "execution_count": 52,
324
+ "metadata": {
325
+ "lines_to_next_cell": 2
326
+ },
327
+ "outputs": [],
328
+ "source": [
329
+ "# make combined ID for catalog and add suffix to eol content and page IDs\n",
330
+ "eol_catalog['combined_id_catalog'] = eol_catalog['eol_content_id'].astype(str) + '_' + eol_catalog['eol_page_id'].astype(str)\n",
331
+ "eol_catalog.rename(columns={'eol_content_id': 'eol_content_id_catalog', 'eol_page_id': 'eol_page_id_catalog'}, inplace=True)"
332
+ ]
333
+ },
334
+ {
335
+ "cell_type": "code",
336
+ "execution_count": 53,
337
+ "metadata": {},
338
+ "outputs": [
339
+ {
340
+ "data": {
341
+ "text/plain": [
342
+ "6219044"
343
+ ]
344
+ },
345
+ "execution_count": 53,
346
+ "metadata": {},
347
+ "output_type": "execute_result"
348
+ }
349
+ ],
350
+ "source": [
351
+ "matched_catalog_ids = list(links_inner.combined_id_catalog.unique())\n",
352
+ "len(matched_catalog_ids)"
353
+ ]
354
+ },
355
+ {
356
+ "cell_type": "code",
357
+ "execution_count": 54,
358
+ "metadata": {},
359
+ "outputs": [
360
+ {
361
+ "data": {
362
+ "text/plain": [
363
+ "['100_45516037',\n",
364
+ " '10000_45511252',\n",
365
+ " '10001_45509451',\n",
366
+ " '10002_45509648',\n",
367
+ " '10003_45510902']"
368
+ ]
369
+ },
370
+ "execution_count": 54,
371
+ "metadata": {},
372
+ "output_type": "execute_result"
373
+ }
374
+ ],
375
+ "source": [
376
+ "matched_catalog_ids[:5]"
377
+ ]
378
+ },
379
+ {
380
+ "cell_type": "markdown",
381
+ "metadata": {},
382
+ "source": [
383
+ "So we have about 30K unmatched, let's find those in the catalog and then we'll try to merge with our mismatched cargo & manifest."
384
+ ]
385
+ },
386
+ {
387
+ "cell_type": "code",
388
+ "execution_count": 55,
389
+ "metadata": {},
390
+ "outputs": [
391
+ {
392
+ "data": {
393
+ "text/plain": [
394
+ "10017874 20995677_64638554\n",
395
+ "8964610 21191962_130898\n",
396
+ "8441264 14142414_1117599\n",
397
+ "9354726 28866899_2762658\n",
398
+ "10681937 20538304_2752336\n",
399
+ "Name: combined_id_catalog, dtype: object"
400
+ ]
401
+ },
402
+ "execution_count": 55,
403
+ "metadata": {},
404
+ "output_type": "execute_result"
405
+ }
406
+ ],
407
+ "source": [
408
+ "eol_catalog['combined_id_catalog'].sample(5)"
409
+ ]
410
+ },
411
+ {
412
+ "cell_type": "code",
413
+ "execution_count": 56,
414
+ "metadata": {},
415
+ "outputs": [
416
+ {
417
+ "name": "stdout",
418
+ "output_type": "stream",
419
+ "text": [
420
+ "<class 'pandas.core.frame.DataFrame'>\n",
421
+ "Index: 31376 entries, 956874 to 10996978\n",
422
+ "Data columns (total 13 columns):\n",
423
+ " # Column Non-Null Count Dtype \n",
424
+ "--- ------ -------------- ----- \n",
425
+ " 0 split 31376 non-null object\n",
426
+ " 1 treeoflife_id 31376 non-null object\n",
427
+ " 2 eol_content_id_catalog 31376 non-null int64 \n",
428
+ " 3 eol_page_id_catalog 31376 non-null int64 \n",
429
+ " 4 kingdom 31203 non-null object\n",
430
+ " 5 phylum 31208 non-null object\n",
431
+ " 6 class 30783 non-null object\n",
432
+ " 7 order 31158 non-null object\n",
433
+ " 8 family 30924 non-null object\n",
434
+ " 9 genus 30822 non-null object\n",
435
+ " 10 species 30029 non-null object\n",
436
+ " 11 common 31376 non-null object\n",
437
+ " 12 combined_id_catalog 31376 non-null object\n",
438
+ "dtypes: int64(2), object(11)\n",
439
+ "memory usage: 3.4+ MB\n"
440
+ ]
441
+ }
442
+ ],
443
+ "source": [
444
+ "mismatched_catalog = eol_catalog.loc[~eol_catalog[\"combined_id_catalog\"].isin(matched_catalog_ids)]\n",
445
+ "mismatched_catalog.info(show_counts = True)"
446
+ ]
447
+ },
448
+ {
449
+ "cell_type": "code",
450
+ "execution_count": 57,
451
+ "metadata": {},
452
+ "outputs": [
453
+ {
454
+ "data": {
455
+ "text/plain": [
456
+ "split 2\n",
457
+ "treeoflife_id 31376\n",
458
+ "eol_content_id_catalog 31376\n",
459
+ "eol_page_id_catalog 7531\n",
460
+ "kingdom 7\n",
461
+ "phylum 33\n",
462
+ "class 88\n",
463
+ "order 374\n",
464
+ "family 1269\n",
465
+ "genus 3827\n",
466
+ "species 5550\n",
467
+ "common 7372\n",
468
+ "combined_id_catalog 31376\n",
469
+ "dtype: int64"
470
+ ]
471
+ },
472
+ "execution_count": 57,
473
+ "metadata": {},
474
+ "output_type": "execute_result"
475
+ }
476
+ ],
477
+ "source": [
478
+ "mismatched_catalog.nunique()"
479
+ ]
480
+ },
481
+ {
482
+ "cell_type": "markdown",
483
+ "metadata": {},
484
+ "source": [
485
+ "## Merge with Mismatched Cargo-Manifest\n",
486
+ "\n",
487
+ "let's merge with `links_mismatch` to see if the mismatched cargo and manifest combined IDs can be linked up."
488
+ ]
489
+ },
490
+ {
491
+ "cell_type": "code",
492
+ "execution_count": 58,
493
+ "metadata": {},
494
+ "outputs": [
495
+ {
496
+ "name": "stdout",
497
+ "output_type": "stream",
498
+ "text": [
499
+ "<class 'pandas.core.frame.DataFrame'>\n",
500
+ "RangeIndex: 29 entries, 0 to 28\n",
501
+ "Data columns (total 29 columns):\n",
502
+ " # Column Non-Null Count Dtype \n",
503
+ "--- ------ -------------- ----- \n",
504
+ " 0 split 29 non-null object\n",
505
+ " 1 treeoflife_id 29 non-null object\n",
506
+ " 2 eol_content_id_catalog 29 non-null int64 \n",
507
+ " 3 eol_page_id_catalog 29 non-null int64 \n",
508
+ " 4 kingdom 29 non-null object\n",
509
+ " 5 phylum 29 non-null object\n",
510
+ " 6 class 29 non-null object\n",
511
+ " 7 order 29 non-null object\n",
512
+ " 8 family 29 non-null object\n",
513
+ " 9 genus 29 non-null object\n",
514
+ " 10 species 29 non-null object\n",
515
+ " 11 common 29 non-null object\n",
516
+ " 12 combined_id_catalog 29 non-null object\n",
517
+ " 13 eol_content_id 29 non-null int64 \n",
518
+ " 14 eol_page_id 29 non-null int64 \n",
519
+ " 15 medium_source_url 29 non-null object\n",
520
+ " 16 eol_full_size_copy_url 29 non-null object\n",
521
+ " 17 license_name 29 non-null object\n",
522
+ " 18 copyright_owner 28 non-null object\n",
523
+ " 19 expected_image_filename 29 non-null object\n",
524
+ " 20 source_0706 29 non-null bool \n",
525
+ " 21 source_0726 29 non-null bool \n",
526
+ " 22 source_1206 29 non-null bool \n",
527
+ " 23 combined_id_manifest 29 non-null object\n",
528
+ " 24 md5 29 non-null object\n",
529
+ " 25 combined_id_manifest_checksums 29 non-null object\n",
530
+ " 26 eol_content_id_cargo 29 non-null int64 \n",
531
+ " 27 eol_page_id_cargo 29 non-null int64 \n",
532
+ " 28 combined_id_cargo 29 non-null object\n",
533
+ "dtypes: bool(3), int64(6), object(20)\n",
534
+ "memory usage: 6.1+ KB\n"
535
+ ]
536
+ }
537
+ ],
538
+ "source": [
539
+ "links_catalog_mismatch = pd.merge(mismatched_catalog,\n",
540
+ " links_mismatch,\n",
541
+ " left_on = \"combined_id_catalog\",\n",
542
+ " right_on = \"combined_id_manifest_checksums\",\n",
543
+ " how = \"inner\")\n",
544
+ "links_catalog_mismatch.info(show_counts = True)"
545
+ ]
546
+ },
547
+ {
548
+ "cell_type": "code",
549
+ "execution_count": 59,
550
+ "metadata": {},
551
+ "outputs": [
552
+ {
553
+ "data": {
554
+ "text/plain": [
555
+ "9251313 9447041_5660435\n",
556
+ "10368203 28965413_916574\n",
557
+ "3357181 28940017_45513086\n",
558
+ "10907940 10517333_3036072\n",
559
+ "10208533 9444575_1178182\n",
560
+ "5434229 10517050_46480886\n",
561
+ "2638483 9446016_46468616\n",
562
+ "Name: combined_id_catalog, dtype: object"
563
+ ]
564
+ },
565
+ "execution_count": 59,
566
+ "metadata": {},
567
+ "output_type": "execute_result"
568
+ }
569
+ ],
570
+ "source": [
571
+ "mismatched_catalog.combined_id_catalog.sample(7)"
572
+ ]
573
+ },
574
+ {
575
+ "cell_type": "markdown",
576
+ "metadata": {},
577
+ "source": [
578
+ "These pages are reasonably full too: [5660435](https://eol.org/pages/5660435)."
579
+ ]
580
+ },
581
+ {
582
+ "cell_type": "markdown",
583
+ "metadata": {},
584
+ "source": [
585
+ "## Check on Rare Species Catalog"
586
+ ]
587
+ },
588
+ {
589
+ "cell_type": "code",
590
+ "execution_count": 60,
591
+ "metadata": {},
592
+ "outputs": [
593
+ {
594
+ "name": "stdout",
595
+ "output_type": "stream",
596
+ "text": [
597
+ "<class 'pandas.core.frame.DataFrame'>\n",
598
+ "RangeIndex: 12000 entries, 0 to 11999\n",
599
+ "Data columns (total 11 columns):\n",
600
+ " # Column Non-Null Count Dtype \n",
601
+ "--- ------ -------------- ----- \n",
602
+ " 0 rarespecies_id 12000 non-null object\n",
603
+ " 1 eol_content_id 12000 non-null int64 \n",
604
+ " 2 eol_page_id 12000 non-null int64 \n",
605
+ " 3 kingdom 12000 non-null object\n",
606
+ " 4 phylum 12000 non-null object\n",
607
+ " 5 class 12000 non-null object\n",
608
+ " 6 order 12000 non-null object\n",
609
+ " 7 family 12000 non-null object\n",
610
+ " 8 genus 12000 non-null object\n",
611
+ " 9 species 12000 non-null object\n",
612
+ " 10 sciName 12000 non-null object\n",
613
+ "dtypes: int64(2), object(9)\n",
614
+ "memory usage: 1.0+ MB\n"
615
+ ]
616
+ }
617
+ ],
618
+ "source": [
619
+ "rs_catalog = pd.read_csv(\"../../rare_species/data/rarespecies-catalog.csv\",\n",
620
+ " low_memory=False,\n",
621
+ " dtype = {\"eol_content_id\": \"int64\", \"eol_page_id\": \"int64\"})\n",
622
+ "rs_catalog.info(show_counts = True)"
623
+ ]
624
+ },
625
+ {
626
+ "cell_type": "code",
627
+ "execution_count": 61,
628
+ "metadata": {},
629
+ "outputs": [],
630
+ "source": [
631
+ "rs_catalog[\"combined_id_rs\"] = rs_catalog[\"eol_content_id\"].astype(str) + \"_\" + rs_catalog[\"eol_page_id\"].astype(str)\n",
632
+ "rs_catalog.rename(columns={'eol_content_id': 'eol_content_id_rs', 'eol_page_id': 'eol_page_id_rs'}, inplace=True)"
633
+ ]
634
+ },
635
+ {
636
+ "cell_type": "code",
637
+ "execution_count": 62,
638
+ "metadata": {},
639
+ "outputs": [
640
+ {
641
+ "name": "stdout",
642
+ "output_type": "stream",
643
+ "text": [
644
+ "<class 'pandas.core.frame.DataFrame'>\n",
645
+ "RangeIndex: 12552 entries, 0 to 12551\n",
646
+ "Data columns (total 28 columns):\n",
647
+ " # Column Non-Null Count Dtype \n",
648
+ "--- ------ -------------- ----- \n",
649
+ " 0 rarespecies_id 12552 non-null object\n",
650
+ " 1 eol_content_id_rs 12552 non-null int64 \n",
651
+ " 2 eol_page_id_rs 12552 non-null int64 \n",
652
+ " 3 kingdom 12552 non-null object\n",
653
+ " 4 phylum 12552 non-null object\n",
654
+ " 5 class 12552 non-null object\n",
655
+ " 6 order 12552 non-null object\n",
656
+ " 7 family 12552 non-null object\n",
657
+ " 8 genus 12552 non-null object\n",
658
+ " 9 species 12552 non-null object\n",
659
+ " 10 sciName 12552 non-null object\n",
660
+ " 11 combined_id_rs 12552 non-null object\n",
661
+ " 12 eol_content_id 12552 non-null int64 \n",
662
+ " 13 eol_page_id 12552 non-null int64 \n",
663
+ " 14 medium_source_url 12552 non-null object\n",
664
+ " 15 eol_full_size_copy_url 12552 non-null object\n",
665
+ " 16 license_name 12552 non-null object\n",
666
+ " 17 copyright_owner 11171 non-null object\n",
667
+ " 18 expected_image_filename 12552 non-null object\n",
668
+ " 19 source_0706 12552 non-null bool \n",
669
+ " 20 source_0726 12552 non-null bool \n",
670
+ " 21 source_1206 12552 non-null bool \n",
671
+ " 22 combined_id_manifest 12552 non-null object\n",
672
+ " 23 md5 12552 non-null object\n",
673
+ " 24 combined_id_manifest_checksums 12552 non-null object\n",
674
+ " 25 eol_content_id_cargo 12552 non-null int64 \n",
675
+ " 26 eol_page_id_cargo 12552 non-null int64 \n",
676
+ " 27 combined_id_cargo 12552 non-null object\n",
677
+ "dtypes: bool(3), int64(6), object(19)\n",
678
+ "memory usage: 2.4+ MB\n"
679
+ ]
680
+ }
681
+ ],
682
+ "source": [
683
+ "rs_links = pd.merge(rs_catalog,\n",
684
+ " links_manifest_cargo,\n",
685
+ " left_on = \"combined_id_rs\",\n",
686
+ " right_on = \"combined_id_cargo\",\n",
687
+ " how = \"inner\")\n",
688
+ "rs_links.info(show_counts = True)"
689
+ ]
690
+ },
691
+ {
692
+ "cell_type": "code",
693
+ "execution_count": 63,
694
+ "metadata": {},
695
+ "outputs": [
696
+ {
697
+ "data": {
698
+ "text/plain": [
699
+ "rarespecies_id 11826\n",
700
+ "eol_content_id_rs 11826\n",
701
+ "eol_page_id_rs 400\n",
702
+ "kingdom 1\n",
703
+ "phylum 5\n",
704
+ "class 15\n",
705
+ "order 85\n",
706
+ "family 202\n",
707
+ "genus 316\n",
708
+ "species 385\n",
709
+ "sciName 400\n",
710
+ "combined_id_rs 11826\n",
711
+ "eol_content_id 12221\n",
712
+ "eol_page_id 447\n",
713
+ "medium_source_url 12056\n",
714
+ "eol_full_size_copy_url 12119\n",
715
+ "license_name 15\n",
716
+ "copyright_owner 3724\n",
717
+ "expected_image_filename 12221\n",
718
+ "source_0706 2\n",
719
+ "source_0726 2\n",
720
+ "source_1206 2\n",
721
+ "combined_id_manifest 12221\n",
722
+ "md5 11663\n",
723
+ "combined_id_manifest_checksums 12221\n",
724
+ "eol_content_id_cargo 11826\n",
725
+ "eol_page_id_cargo 400\n",
726
+ "combined_id_cargo 11826\n",
727
+ "dtype: int64"
728
+ ]
729
+ },
730
+ "execution_count": 63,
731
+ "metadata": {},
732
+ "output_type": "execute_result"
733
+ }
734
+ ],
735
+ "source": [
736
+ "rs_links.nunique()"
737
+ ]
738
+ },
739
+ {
740
+ "cell_type": "markdown",
741
+ "metadata": {},
742
+ "source": [
743
+ "Let's check the mismatched cargo/manifest entries for those last 174..."
744
+ ]
745
+ },
746
+ {
747
+ "cell_type": "code",
748
+ "execution_count": 64,
749
+ "metadata": {},
750
+ "outputs": [
751
+ {
752
+ "data": {
753
+ "text/plain": [
754
+ "11826"
755
+ ]
756
+ },
757
+ "execution_count": 64,
758
+ "metadata": {},
759
+ "output_type": "execute_result"
760
+ }
761
+ ],
762
+ "source": [
763
+ "matched_rs_ids = list(rs_links.combined_id_rs.unique())\n",
764
+ "len(matched_rs_ids)"
765
+ ]
766
+ },
767
+ {
768
+ "cell_type": "code",
769
+ "execution_count": 65,
770
+ "metadata": {},
771
+ "outputs": [
772
+ {
773
+ "data": {
774
+ "text/plain": [
775
+ "['22519448_914532',\n",
776
+ " '28677580_1057176',\n",
777
+ " '20714475_47047909',\n",
778
+ " '29975068_45509269']"
779
+ ]
780
+ },
781
+ "execution_count": 65,
782
+ "metadata": {},
783
+ "output_type": "execute_result"
784
+ }
785
+ ],
786
+ "source": [
787
+ "matched_rs_ids[:4]"
788
+ ]
789
+ },
790
+ {
791
+ "cell_type": "code",
792
+ "execution_count": 66,
793
+ "metadata": {},
794
+ "outputs": [
795
+ {
796
+ "data": {
797
+ "text/plain": [
798
+ "4010 20184952_311570\n",
799
+ "8096 29473123_323892\n",
800
+ "5217 29580624_45514697\n",
801
+ "890 21629967_46559745\n",
802
+ "Name: combined_id_rs, dtype: object"
803
+ ]
804
+ },
805
+ "execution_count": 66,
806
+ "metadata": {},
807
+ "output_type": "execute_result"
808
+ }
809
+ ],
810
+ "source": [
811
+ "rs_catalog[\"combined_id_rs\"].sample(4)"
812
+ ]
813
+ },
814
+ {
815
+ "cell_type": "code",
816
+ "execution_count": 67,
817
+ "metadata": {},
818
+ "outputs": [
819
+ {
820
+ "name": "stdout",
821
+ "output_type": "stream",
822
+ "text": [
823
+ "<class 'pandas.core.frame.DataFrame'>\n",
824
+ "Index: 174 entries, 163 to 11990\n",
825
+ "Data columns (total 12 columns):\n",
826
+ " # Column Non-Null Count Dtype \n",
827
+ "--- ------ -------------- ----- \n",
828
+ " 0 rarespecies_id 174 non-null object\n",
829
+ " 1 eol_content_id_rs 174 non-null int64 \n",
830
+ " 2 eol_page_id_rs 174 non-null int64 \n",
831
+ " 3 kingdom 174 non-null object\n",
832
+ " 4 phylum 174 non-null object\n",
833
+ " 5 class 174 non-null object\n",
834
+ " 6 order 174 non-null object\n",
835
+ " 7 family 174 non-null object\n",
836
+ " 8 genus 174 non-null object\n",
837
+ " 9 species 174 non-null object\n",
838
+ " 10 sciName 174 non-null object\n",
839
+ " 11 combined_id_rs 174 non-null object\n",
840
+ "dtypes: int64(2), object(10)\n",
841
+ "memory usage: 17.7+ KB\n"
842
+ ]
843
+ }
844
+ ],
845
+ "source": [
846
+ "mismatched_rs = rs_catalog.loc[~rs_catalog[\"combined_id_rs\"].isin(matched_rs_ids)]\n",
847
+ "mismatched_rs.info(show_counts = True)"
848
+ ]
849
+ },
850
+ {
851
+ "cell_type": "code",
852
+ "execution_count": 68,
853
+ "metadata": {},
854
+ "outputs": [
855
+ {
856
+ "name": "stdout",
857
+ "output_type": "stream",
858
+ "text": [
859
+ "<class 'pandas.core.frame.DataFrame'>\n",
860
+ "RangeIndex: 0 entries\n",
861
+ "Data columns (total 28 columns):\n",
862
+ " # Column Non-Null Count Dtype \n",
863
+ "--- ------ -------------- ----- \n",
864
+ " 0 rarespecies_id 0 non-null object\n",
865
+ " 1 eol_content_id_rs 0 non-null int64 \n",
866
+ " 2 eol_page_id_rs 0 non-null int64 \n",
867
+ " 3 kingdom 0 non-null object\n",
868
+ " 4 phylum 0 non-null object\n",
869
+ " 5 class 0 non-null object\n",
870
+ " 6 order 0 non-null object\n",
871
+ " 7 family 0 non-null object\n",
872
+ " 8 genus 0 non-null object\n",
873
+ " 9 species 0 non-null object\n",
874
+ " 10 sciName 0 non-null object\n",
875
+ " 11 combined_id_rs 0 non-null object\n",
876
+ " 12 eol_content_id 0 non-null int64 \n",
877
+ " 13 eol_page_id 0 non-null int64 \n",
878
+ " 14 medium_source_url 0 non-null object\n",
879
+ " 15 eol_full_size_copy_url 0 non-null object\n",
880
+ " 16 license_name 0 non-null object\n",
881
+ " 17 copyright_owner 0 non-null object\n",
882
+ " 18 expected_image_filename 0 non-null object\n",
883
+ " 19 source_0706 0 non-null bool \n",
884
+ " 20 source_0726 0 non-null bool \n",
885
+ " 21 source_1206 0 non-null bool \n",
886
+ " 22 combined_id_manifest 0 non-null object\n",
887
+ " 23 md5 0 non-null object\n",
888
+ " 24 combined_id_manifest_checksums 0 non-null object\n",
889
+ " 25 eol_content_id_cargo 0 non-null int64 \n",
890
+ " 26 eol_page_id_cargo 0 non-null int64 \n",
891
+ " 27 combined_id_cargo 0 non-null object\n",
892
+ "dtypes: bool(3), int64(6), object(19)\n",
893
+ "memory usage: 132.0+ bytes\n"
894
+ ]
895
+ }
896
+ ],
897
+ "source": [
898
+ "links_rs_mismatch = pd.merge(mismatched_rs,\n",
899
+ " links_mismatch,\n",
900
+ " left_on = \"combined_id_rs\",\n",
901
+ " right_on = \"combined_id_manifest_checksums\",\n",
902
+ " how = \"inner\")\n",
903
+ "links_rs_mismatch.info(show_counts = True)"
904
+ ]
905
+ },
906
+ {
907
+ "cell_type": "code",
908
+ "execution_count": null,
909
+ "metadata": {},
910
+ "outputs": [],
911
+ "source": []
912
+ }
913
+ ],
914
+ "metadata": {
915
+ "jupytext": {
916
+ "formats": "ipynb,py:percent"
917
+ },
918
+ "kernelspec": {
919
+ "display_name": "tol",
920
+ "language": "python",
921
+ "name": "python3"
922
+ },
923
+ "language_info": {
924
+ "codemirror_mode": {
925
+ "name": "ipython",
926
+ "version": 3
927
+ },
928
+ "file_extension": ".py",
929
+ "mimetype": "text/x-python",
930
+ "name": "python",
931
+ "nbconvert_exporter": "python",
932
+ "pygments_lexer": "ipython3",
933
+ "version": "3.11.3"
934
+ }
935
+ },
936
+ "nbformat": 4,
937
+ "nbformat_minor": 2
938
+ }
eol_realign/notebooks/links_align_reduced.py ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: tol
12
+ # language: python
13
+ # name: python3
14
+ # ---
15
+
16
+ # %%
17
+ import pandas as pd
18
+
19
+ # %% [markdown]
20
+ # ### Read in Links CSV files
21
+
22
+ # %%
23
+ links_inner = pd.read_csv("../data/links_inner.csv", low_memory=False)
24
+ links_manifest_cargo = pd.read_csv("../data/links_manifest_cargo_on_md5.csv", low_memory=False)
25
+
26
+ # %%
27
+ links_inner.info(show_counts=True)
28
+
29
+ # %%
30
+ links_manifest_cargo.info(show_counts=True)
31
+
32
+ # %%
33
+ links_mismatch = links_manifest_cargo.loc[links_manifest_cargo["combined_id_cargo"] != links_manifest_cargo["combined_id_manifest_checksums"]]
34
+ links_mismatch.info(show_counts = True)
35
+
36
+ # %%
37
+ links_mismatch[["md5", "combined_id_manifest_checksums", "combined_id_cargo"]].nunique()
38
+
39
+ # %%
40
+ links_mismatch.to_csv("../data/links_cargo_manifest_IDmismatch.csv", index = False)
41
+
42
+ # %%
43
+ catalog = pd.read_csv("../../data/catalog.csv", low_memory=False)
44
+
45
+ # %%
46
+ # remove train_small and all non-EOL entries
47
+ catalog = catalog.loc[catalog.split != "train_small"]
48
+ eol_catalog = catalog.loc[catalog.eol_content_id.notna()]
49
+
50
+ # %%
51
+ eol_catalog[list(eol_catalog.columns)[:4]].nunique()
52
+
53
+ # %%
54
+ eol_cols = [col for col in list(eol_catalog.columns) if "bioscan" not in col and "inat" not in col]
55
+
56
+ # %%
57
+ eol_catalog = eol_catalog[eol_cols]
58
+ eol_catalog.info(show_counts=True)
59
+
60
+ # %% [markdown]
61
+ # Must recast IDs as `int64`
62
+
63
+ # %%
64
+ eol_catalog = eol_catalog.astype({"eol_content_id": "int64", "eol_page_id": "int64"})
65
+ eol_catalog[eol_cols[:4]].info()
66
+
67
+ # %%
68
+ # make combined ID for catalog and add suffix to eol content and page IDs
69
+ eol_catalog['combined_id_catalog'] = eol_catalog['eol_content_id'].astype(str) + '_' + eol_catalog['eol_page_id'].astype(str)
70
+ eol_catalog.rename(columns={'eol_content_id': 'eol_content_id_catalog', 'eol_page_id': 'eol_page_id_catalog'}, inplace=True)
71
+
72
+
73
+ # %%
74
+ matched_catalog_ids = list(links_inner.combined_id_catalog.unique())
75
+ len(matched_catalog_ids)
76
+
77
+ # %%
78
+ matched_catalog_ids[:5]
79
+
80
+ # %% [markdown]
81
+ # So we have about 30K unmatched, let's find those in the catalog and then we'll try to merge with our mismatched cargo & manifest.
82
+
83
+ # %%
84
+ eol_catalog['combined_id_catalog'].sample(5)
85
+
86
+ # %%
87
+ mismatched_catalog = eol_catalog.loc[~eol_catalog["combined_id_catalog"].isin(matched_catalog_ids)]
88
+ mismatched_catalog.info(show_counts = True)
89
+
90
+ # %%
91
+ mismatched_catalog.nunique()
92
+
93
+ # %% [markdown]
94
+ # ## Merge with Mismatched Cargo-Manifest
95
+ #
96
+ # let's merge with `links_mismatch` to see if the mismatched cargo and manifest combined IDs can be linked up.
97
+
98
+ # %%
99
+ links_catalog_mismatch = pd.merge(mismatched_catalog,
100
+ links_mismatch,
101
+ left_on = "combined_id_catalog",
102
+ right_on = "combined_id_manifest_checksums",
103
+ how = "inner")
104
+ links_catalog_mismatch.info(show_counts = True)
105
+
106
+ # %%
107
+ mismatched_catalog.combined_id_catalog.sample(7)
108
+
109
+ # %% [markdown]
110
+ # These pages are reasonably full too: [5660435](https://eol.org/pages/5660435).
111
+
112
+ # %% [markdown]
113
+ # ## Check on Rare Species Catalog
114
+
115
+ # %%
116
+ rs_catalog = pd.read_csv("../../rare_species/data/rarespecies-catalog.csv",
117
+ low_memory=False,
118
+ dtype = {"eol_content_id": "int64", "eol_page_id": "int64"})
119
+ rs_catalog.info(show_counts = True)
120
+
121
+ # %%
122
+ rs_catalog["combined_id_rs"] = rs_catalog["eol_content_id"].astype(str) + "_" + rs_catalog["eol_page_id"].astype(str)
123
+ rs_catalog.rename(columns={'eol_content_id': 'eol_content_id_rs', 'eol_page_id': 'eol_page_id_rs'}, inplace=True)
124
+
125
+ # %%
126
+ rs_links = pd.merge(rs_catalog,
127
+ links_manifest_cargo,
128
+ left_on = "combined_id_rs",
129
+ right_on = "combined_id_cargo",
130
+ how = "inner")
131
+ rs_links.info(show_counts = True)
132
+
133
+ # %%
134
+ rs_links.nunique()
135
+
136
+ # %% [markdown]
137
+ # Let's check the mismatched cargo/manifest entries for those last 174...
138
+
139
+ # %%
140
+ matched_rs_ids = list(rs_links.combined_id_rs.unique())
141
+ len(matched_rs_ids)
142
+
143
+ # %%
144
+ matched_rs_ids[:4]
145
+
146
+ # %%
147
+ rs_catalog["combined_id_rs"].sample(4)
148
+
149
+ # %%
150
+ mismatched_rs = rs_catalog.loc[~rs_catalog["combined_id_rs"].isin(matched_rs_ids)]
151
+ mismatched_rs.info(show_counts = True)
152
+
153
+ # %%
154
+ links_rs_mismatch = pd.merge(mismatched_rs,
155
+ links_mismatch,
156
+ left_on = "combined_id_rs",
157
+ right_on = "combined_id_manifest_checksums",
158
+ how = "inner")
159
+ links_rs_mismatch.info(show_counts = True)
160
+
161
+ # %%
eol_realign/notebooks/links_rs_duplicates.ipynb ADDED
@@ -0,0 +1,1742 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "### Read in Links CSV file"
17
+ ]
18
+ },
19
+ {
20
+ "cell_type": "code",
21
+ "execution_count": 2,
22
+ "metadata": {},
23
+ "outputs": [],
24
+ "source": [
25
+ "links_manifest_cargo = pd.read_csv(\"../data/links_manifest_cargo_on_md5.csv\", low_memory=False)"
26
+ ]
27
+ },
28
+ {
29
+ "cell_type": "code",
30
+ "execution_count": 3,
31
+ "metadata": {},
32
+ "outputs": [
33
+ {
34
+ "name": "stdout",
35
+ "output_type": "stream",
36
+ "text": [
37
+ "<class 'pandas.core.frame.DataFrame'>\n",
38
+ "RangeIndex: 7513329 entries, 0 to 7513328\n",
39
+ "Data columns (total 16 columns):\n",
40
+ " # Column Non-Null Count Dtype \n",
41
+ "--- ------ -------------- ----- \n",
42
+ " 0 eol_content_id 7513329 non-null int64 \n",
43
+ " 1 eol_page_id 7513329 non-null int64 \n",
44
+ " 2 medium_source_url 7513329 non-null object\n",
45
+ " 3 eol_full_size_copy_url 7513329 non-null object\n",
46
+ " 4 license_name 7513329 non-null object\n",
47
+ " 5 copyright_owner 6860238 non-null object\n",
48
+ " 6 expected_image_filename 7513329 non-null object\n",
49
+ " 7 source_0706 7513329 non-null bool \n",
50
+ " 8 source_0726 7513329 non-null bool \n",
51
+ " 9 source_1206 7513329 non-null bool \n",
52
+ " 10 combined_id_manifest 7513329 non-null object\n",
53
+ " 11 md5 7513329 non-null object\n",
54
+ " 12 combined_id_manifest_checksums 7513329 non-null object\n",
55
+ " 13 eol_content_id_cargo 7513329 non-null int64 \n",
56
+ " 14 eol_page_id_cargo 7513329 non-null int64 \n",
57
+ " 15 combined_id_cargo 7513329 non-null object\n",
58
+ "dtypes: bool(3), int64(4), object(9)\n",
59
+ "memory usage: 766.7+ MB\n"
60
+ ]
61
+ }
62
+ ],
63
+ "source": [
64
+ "links_manifest_cargo.info(show_counts=True)"
65
+ ]
66
+ },
67
+ {
68
+ "cell_type": "markdown",
69
+ "metadata": {},
70
+ "source": [
71
+ "## Check on Rare Species Catalog"
72
+ ]
73
+ },
74
+ {
75
+ "cell_type": "code",
76
+ "execution_count": 4,
77
+ "metadata": {},
78
+ "outputs": [
79
+ {
80
+ "name": "stdout",
81
+ "output_type": "stream",
82
+ "text": [
83
+ "<class 'pandas.core.frame.DataFrame'>\n",
84
+ "RangeIndex: 12000 entries, 0 to 11999\n",
85
+ "Data columns (total 11 columns):\n",
86
+ " # Column Non-Null Count Dtype \n",
87
+ "--- ------ -------------- ----- \n",
88
+ " 0 rarespecies_id 12000 non-null object\n",
89
+ " 1 eol_content_id 12000 non-null int64 \n",
90
+ " 2 eol_page_id 12000 non-null int64 \n",
91
+ " 3 kingdom 12000 non-null object\n",
92
+ " 4 phylum 12000 non-null object\n",
93
+ " 5 class 12000 non-null object\n",
94
+ " 6 order 12000 non-null object\n",
95
+ " 7 family 12000 non-null object\n",
96
+ " 8 genus 12000 non-null object\n",
97
+ " 9 species 12000 non-null object\n",
98
+ " 10 sciName 12000 non-null object\n",
99
+ "dtypes: int64(2), object(9)\n",
100
+ "memory usage: 1.0+ MB\n"
101
+ ]
102
+ }
103
+ ],
104
+ "source": [
105
+ "rs_catalog = pd.read_csv(\"../../rare_species/data/rarespecies-catalog.csv\",\n",
106
+ " low_memory=False,\n",
107
+ " dtype = {\"eol_content_id\": \"int64\", \"eol_page_id\": \"int64\"})\n",
108
+ "rs_catalog.info(show_counts = True)"
109
+ ]
110
+ },
111
+ {
112
+ "cell_type": "code",
113
+ "execution_count": 5,
114
+ "metadata": {},
115
+ "outputs": [],
116
+ "source": [
117
+ "rs_catalog[\"combined_id_rs\"] = rs_catalog[\"eol_content_id\"].astype(str) + \"_\" + rs_catalog[\"eol_page_id\"].astype(str)\n",
118
+ "rs_catalog.rename(columns={'eol_content_id': 'eol_content_id_rs', 'eol_page_id': 'eol_page_id_rs'}, inplace=True)"
119
+ ]
120
+ },
121
+ {
122
+ "cell_type": "code",
123
+ "execution_count": 6,
124
+ "metadata": {},
125
+ "outputs": [
126
+ {
127
+ "name": "stdout",
128
+ "output_type": "stream",
129
+ "text": [
130
+ "<class 'pandas.core.frame.DataFrame'>\n",
131
+ "RangeIndex: 12552 entries, 0 to 12551\n",
132
+ "Data columns (total 28 columns):\n",
133
+ " # Column Non-Null Count Dtype \n",
134
+ "--- ------ -------------- ----- \n",
135
+ " 0 rarespecies_id 12552 non-null object\n",
136
+ " 1 eol_content_id_rs 12552 non-null int64 \n",
137
+ " 2 eol_page_id_rs 12552 non-null int64 \n",
138
+ " 3 kingdom 12552 non-null object\n",
139
+ " 4 phylum 12552 non-null object\n",
140
+ " 5 class 12552 non-null object\n",
141
+ " 6 order 12552 non-null object\n",
142
+ " 7 family 12552 non-null object\n",
143
+ " 8 genus 12552 non-null object\n",
144
+ " 9 species 12552 non-null object\n",
145
+ " 10 sciName 12552 non-null object\n",
146
+ " 11 combined_id_rs 12552 non-null object\n",
147
+ " 12 eol_content_id 12552 non-null int64 \n",
148
+ " 13 eol_page_id 12552 non-null int64 \n",
149
+ " 14 medium_source_url 12552 non-null object\n",
150
+ " 15 eol_full_size_copy_url 12552 non-null object\n",
151
+ " 16 license_name 12552 non-null object\n",
152
+ " 17 copyright_owner 11171 non-null object\n",
153
+ " 18 expected_image_filename 12552 non-null object\n",
154
+ " 19 source_0706 12552 non-null bool \n",
155
+ " 20 source_0726 12552 non-null bool \n",
156
+ " 21 source_1206 12552 non-null bool \n",
157
+ " 22 combined_id_manifest 12552 non-null object\n",
158
+ " 23 md5 12552 non-null object\n",
159
+ " 24 combined_id_manifest_checksums 12552 non-null object\n",
160
+ " 25 eol_content_id_cargo 12552 non-null int64 \n",
161
+ " 26 eol_page_id_cargo 12552 non-null int64 \n",
162
+ " 27 combined_id_cargo 12552 non-null object\n",
163
+ "dtypes: bool(3), int64(6), object(19)\n",
164
+ "memory usage: 2.4+ MB\n"
165
+ ]
166
+ }
167
+ ],
168
+ "source": [
169
+ "rs_links = pd.merge(rs_catalog,\n",
170
+ " links_manifest_cargo,\n",
171
+ " left_on = \"combined_id_rs\",\n",
172
+ " right_on = \"combined_id_cargo\",\n",
173
+ " how = \"inner\")\n",
174
+ "rs_links.info(show_counts = True)"
175
+ ]
176
+ },
177
+ {
178
+ "cell_type": "code",
179
+ "execution_count": 7,
180
+ "metadata": {},
181
+ "outputs": [
182
+ {
183
+ "data": {
184
+ "text/plain": [
185
+ "rarespecies_id 11826\n",
186
+ "eol_content_id_rs 11826\n",
187
+ "eol_page_id_rs 400\n",
188
+ "kingdom 1\n",
189
+ "phylum 5\n",
190
+ "class 15\n",
191
+ "order 85\n",
192
+ "family 202\n",
193
+ "genus 316\n",
194
+ "species 385\n",
195
+ "sciName 400\n",
196
+ "combined_id_rs 11826\n",
197
+ "eol_content_id 12221\n",
198
+ "eol_page_id 447\n",
199
+ "medium_source_url 12056\n",
200
+ "eol_full_size_copy_url 12119\n",
201
+ "license_name 15\n",
202
+ "copyright_owner 3724\n",
203
+ "expected_image_filename 12221\n",
204
+ "source_0706 2\n",
205
+ "source_0726 2\n",
206
+ "source_1206 2\n",
207
+ "combined_id_manifest 12221\n",
208
+ "md5 11663\n",
209
+ "combined_id_manifest_checksums 12221\n",
210
+ "eol_content_id_cargo 11826\n",
211
+ "eol_page_id_cargo 400\n",
212
+ "combined_id_cargo 11826\n",
213
+ "dtype: int64"
214
+ ]
215
+ },
216
+ "execution_count": 7,
217
+ "metadata": {},
218
+ "output_type": "execute_result"
219
+ }
220
+ ],
221
+ "source": [
222
+ "rs_links.nunique()"
223
+ ]
224
+ },
225
+ {
226
+ "cell_type": "markdown",
227
+ "metadata": {},
228
+ "source": [
229
+ "Let's check the mismatched cargo/manifest entries for those last 174..."
230
+ ]
231
+ },
232
+ {
233
+ "cell_type": "code",
234
+ "execution_count": 8,
235
+ "metadata": {},
236
+ "outputs": [
237
+ {
238
+ "data": {
239
+ "text/plain": [
240
+ "11826"
241
+ ]
242
+ },
243
+ "execution_count": 8,
244
+ "metadata": {},
245
+ "output_type": "execute_result"
246
+ }
247
+ ],
248
+ "source": [
249
+ "matched_rs_ids = list(rs_links.combined_id_rs.unique())\n",
250
+ "len(matched_rs_ids)"
251
+ ]
252
+ },
253
+ {
254
+ "cell_type": "code",
255
+ "execution_count": 9,
256
+ "metadata": {},
257
+ "outputs": [
258
+ {
259
+ "data": {
260
+ "text/plain": [
261
+ "['22519448_914532',\n",
262
+ " '28677580_1057176',\n",
263
+ " '20714475_47047909',\n",
264
+ " '29975068_45509269']"
265
+ ]
266
+ },
267
+ "execution_count": 9,
268
+ "metadata": {},
269
+ "output_type": "execute_result"
270
+ }
271
+ ],
272
+ "source": [
273
+ "matched_rs_ids[:4]"
274
+ ]
275
+ },
276
+ {
277
+ "cell_type": "code",
278
+ "execution_count": 10,
279
+ "metadata": {},
280
+ "outputs": [
281
+ {
282
+ "data": {
283
+ "text/plain": [
284
+ "4310 20080369_46579618\n",
285
+ "842 27592101_46560177\n",
286
+ "1111 20945361_570181\n",
287
+ "3609 10819533_46516728\n",
288
+ "Name: combined_id_rs, dtype: object"
289
+ ]
290
+ },
291
+ "execution_count": 10,
292
+ "metadata": {},
293
+ "output_type": "execute_result"
294
+ }
295
+ ],
296
+ "source": [
297
+ "rs_catalog[\"combined_id_rs\"].sample(4)"
298
+ ]
299
+ },
300
+ {
301
+ "cell_type": "code",
302
+ "execution_count": 11,
303
+ "metadata": {},
304
+ "outputs": [
305
+ {
306
+ "name": "stdout",
307
+ "output_type": "stream",
308
+ "text": [
309
+ "<class 'pandas.core.frame.DataFrame'>\n",
310
+ "Index: 174 entries, 163 to 11990\n",
311
+ "Data columns (total 12 columns):\n",
312
+ " # Column Non-Null Count Dtype \n",
313
+ "--- ------ -------------- ----- \n",
314
+ " 0 rarespecies_id 174 non-null object\n",
315
+ " 1 eol_content_id_rs 174 non-null int64 \n",
316
+ " 2 eol_page_id_rs 174 non-null int64 \n",
317
+ " 3 kingdom 174 non-null object\n",
318
+ " 4 phylum 174 non-null object\n",
319
+ " 5 class 174 non-null object\n",
320
+ " 6 order 174 non-null object\n",
321
+ " 7 family 174 non-null object\n",
322
+ " 8 genus 174 non-null object\n",
323
+ " 9 species 174 non-null object\n",
324
+ " 10 sciName 174 non-null object\n",
325
+ " 11 combined_id_rs 174 non-null object\n",
326
+ "dtypes: int64(2), object(10)\n",
327
+ "memory usage: 17.7+ KB\n"
328
+ ]
329
+ }
330
+ ],
331
+ "source": [
332
+ "mismatched_rs = rs_catalog.loc[~rs_catalog[\"combined_id_rs\"].isin(matched_rs_ids)]\n",
333
+ "mismatched_rs.info(show_counts = True)"
334
+ ]
335
+ },
336
+ {
337
+ "cell_type": "code",
338
+ "execution_count": 12,
339
+ "metadata": {},
340
+ "outputs": [
341
+ {
342
+ "data": {
343
+ "text/plain": [
344
+ "rarespecies_id 174\n",
345
+ "eol_content_id_rs 174\n",
346
+ "eol_page_id_rs 34\n",
347
+ "kingdom 1\n",
348
+ "phylum 2\n",
349
+ "class 7\n",
350
+ "order 22\n",
351
+ "family 28\n",
352
+ "genus 31\n",
353
+ "species 33\n",
354
+ "sciName 34\n",
355
+ "combined_id_rs 174\n",
356
+ "dtype: int64"
357
+ ]
358
+ },
359
+ "execution_count": 12,
360
+ "metadata": {},
361
+ "output_type": "execute_result"
362
+ }
363
+ ],
364
+ "source": [
365
+ "mismatched_rs.nunique()"
366
+ ]
367
+ },
368
+ {
369
+ "cell_type": "code",
370
+ "execution_count": 13,
371
+ "metadata": {},
372
+ "outputs": [
373
+ {
374
+ "data": {
375
+ "text/plain": [
376
+ "sciName\n",
377
+ "Aonyx capensis 27\n",
378
+ "Zoogoneticus tequila 27\n",
379
+ "Sousa plumbea 17\n",
380
+ "Sylvilagus transitionalis 16\n",
381
+ "Scaphirhynchus albus 16\n",
382
+ "Raja asterias 9\n",
383
+ "Tursiops aduncus 6\n",
384
+ "Dalatias licha 6\n",
385
+ "Alopias vulpinus 5\n",
386
+ "Hexanchus griseus 5\n",
387
+ "Myliobatis aquila 5\n",
388
+ "Bathytoshia centroura 4\n",
389
+ "Rostroraja alba 3\n",
390
+ "Sylvilagus brasiliensis 3\n",
391
+ "Microcebus rufus 2\n",
392
+ "Glyptemys muhlenbergii 2\n",
393
+ "Crocodylus rhombifer 2\n",
394
+ "Cercopithecus mona 2\n",
395
+ "Harpia harpyja 2\n",
396
+ "Certhidea olivacea 1\n",
397
+ "Lachnolaimus maximus 1\n",
398
+ "Carcharhinus amblyrhynchos 1\n",
399
+ "Mantella aurantiaca 1\n",
400
+ "Piliocolobus tephrosceles 1\n",
401
+ "Raja undulata 1\n",
402
+ "Luehdorfia japonica 1\n",
403
+ "Trogon bairdii 1\n",
404
+ "Phoebastria albatrus 1\n",
405
+ "Carcharhinus melanopterus 1\n",
406
+ "Cetorhinus maximus 1\n",
407
+ "Desmognathus imitator 1\n",
408
+ "Phyllobates vittatus 1\n",
409
+ "Centrochelys sulcata 1\n",
410
+ "Eulemur fulvus 1\n",
411
+ "Name: count, dtype: int64"
412
+ ]
413
+ },
414
+ "execution_count": 13,
415
+ "metadata": {},
416
+ "output_type": "execute_result"
417
+ }
418
+ ],
419
+ "source": [
420
+ "mismatched_rs.sciName.value_counts()"
421
+ ]
422
+ },
423
+ {
424
+ "cell_type": "code",
425
+ "execution_count": 14,
426
+ "metadata": {},
427
+ "outputs": [],
428
+ "source": [
429
+ "big_sciNames_missing = [\"Aonyx capensis\",\n",
430
+ " \"Zoogoneticus tequila\",\n",
431
+ " \"Sousa plumbea\",\n",
432
+ " \"Sylvilagus transitionalis\",\n",
433
+ " \"Scaphirhynchus albus\",\n",
434
+ " \"Raja asterias\"]"
435
+ ]
436
+ },
437
+ {
438
+ "cell_type": "code",
439
+ "execution_count": 15,
440
+ "metadata": {},
441
+ "outputs": [
442
+ {
443
+ "data": {
444
+ "text/plain": [
445
+ "[array([46559139]),\n",
446
+ " array([208913]),\n",
447
+ " array([46559307]),\n",
448
+ " array([1011315]),\n",
449
+ " array([205909]),\n",
450
+ " array([46560546])]"
451
+ ]
452
+ },
453
+ "execution_count": 15,
454
+ "metadata": {},
455
+ "output_type": "execute_result"
456
+ }
457
+ ],
458
+ "source": [
459
+ "pg_ids = []\n",
460
+ "for sciName in big_sciNames_missing:\n",
461
+ " pg_ids.append(rs_links.loc[rs_links[\"sciName\"] == sciName, \"eol_page_id\"].unique())\n",
462
+ "pg_ids"
463
+ ]
464
+ },
465
+ {
466
+ "cell_type": "code",
467
+ "execution_count": 16,
468
+ "metadata": {},
469
+ "outputs": [
470
+ {
471
+ "data": {
472
+ "text/plain": [
473
+ "[(46559139, 16),\n",
474
+ " (208913, 4),\n",
475
+ " (46559307, 22),\n",
476
+ " (1011315, 22),\n",
477
+ " (205909, 28),\n",
478
+ " (46560546, 24)]"
479
+ ]
480
+ },
481
+ "execution_count": 16,
482
+ "metadata": {},
483
+ "output_type": "execute_result"
484
+ }
485
+ ],
486
+ "source": [
487
+ "num_images_by_pg = []\n",
488
+ "for pg_id in pg_ids:\n",
489
+ " num_images = links_manifest_cargo.loc[links_manifest_cargo[\"eol_page_id\"] == pg_id[0]].shape[0]\n",
490
+ " num_images_by_pg.append((pg_id[0], num_images))\n",
491
+ "\n",
492
+ "num_images_by_pg"
493
+ ]
494
+ },
495
+ {
496
+ "cell_type": "markdown",
497
+ "metadata": {},
498
+ "source": [
499
+ "The media for both of these last two is online: https://eol.org/pages/46560546/media, https://eol.org/pages/205909/media"
500
+ ]
501
+ },
502
+ {
503
+ "cell_type": "code",
504
+ "execution_count": 17,
505
+ "metadata": {},
506
+ "outputs": [
507
+ {
508
+ "data": {
509
+ "text/html": [
510
+ "<div>\n",
511
+ "<style scoped>\n",
512
+ " .dataframe tbody tr th:only-of-type {\n",
513
+ " vertical-align: middle;\n",
514
+ " }\n",
515
+ "\n",
516
+ " .dataframe tbody tr th {\n",
517
+ " vertical-align: top;\n",
518
+ " }\n",
519
+ "\n",
520
+ " .dataframe thead th {\n",
521
+ " text-align: right;\n",
522
+ " }\n",
523
+ "</style>\n",
524
+ "<table border=\"1\" class=\"dataframe\">\n",
525
+ " <thead>\n",
526
+ " <tr style=\"text-align: right;\">\n",
527
+ " <th></th>\n",
528
+ " <th>rarespecies_id</th>\n",
529
+ " <th>eol_content_id_rs</th>\n",
530
+ " <th>eol_page_id_rs</th>\n",
531
+ " <th>kingdom</th>\n",
532
+ " <th>phylum</th>\n",
533
+ " <th>class</th>\n",
534
+ " <th>order</th>\n",
535
+ " <th>family</th>\n",
536
+ " <th>genus</th>\n",
537
+ " <th>species</th>\n",
538
+ " <th>sciName</th>\n",
539
+ " <th>combined_id_rs</th>\n",
540
+ " </tr>\n",
541
+ " </thead>\n",
542
+ " <tbody>\n",
543
+ " <tr>\n",
544
+ " <th>7726</th>\n",
545
+ " <td>667586ab-145a-4076-9669-535447aa2b6c</td>\n",
546
+ " <td>30098504</td>\n",
547
+ " <td>205909</td>\n",
548
+ " <td>Animalia</td>\n",
549
+ " <td>Chordata</td>\n",
550
+ " <td>Actinopterygii</td>\n",
551
+ " <td>Acipenseriformes</td>\n",
552
+ " <td>Acipenseridae</td>\n",
553
+ " <td>Scaphirhynchus</td>\n",
554
+ " <td>albus</td>\n",
555
+ " <td>Scaphirhynchus albus</td>\n",
556
+ " <td>30098504_205909</td>\n",
557
+ " </tr>\n",
558
+ " <tr>\n",
559
+ " <th>1413</th>\n",
560
+ " <td>d239159f-cb15-4c30-8aeb-d8177f8cf34a</td>\n",
561
+ " <td>30098492</td>\n",
562
+ " <td>205909</td>\n",
563
+ " <td>Animalia</td>\n",
564
+ " <td>Chordata</td>\n",
565
+ " <td>Actinopterygii</td>\n",
566
+ " <td>Acipenseriformes</td>\n",
567
+ " <td>Acipenseridae</td>\n",
568
+ " <td>Scaphirhynchus</td>\n",
569
+ " <td>albus</td>\n",
570
+ " <td>Scaphirhynchus albus</td>\n",
571
+ " <td>30098492_205909</td>\n",
572
+ " </tr>\n",
573
+ " <tr>\n",
574
+ " <th>7916</th>\n",
575
+ " <td>2d342a7c-7e0c-4981-9630-019bb90183be</td>\n",
576
+ " <td>30098499</td>\n",
577
+ " <td>205909</td>\n",
578
+ " <td>Animalia</td>\n",
579
+ " <td>Chordata</td>\n",
580
+ " <td>Actinopterygii</td>\n",
581
+ " <td>Acipenseriformes</td>\n",
582
+ " <td>Acipenseridae</td>\n",
583
+ " <td>Scaphirhynchus</td>\n",
584
+ " <td>albus</td>\n",
585
+ " <td>Scaphirhynchus albus</td>\n",
586
+ " <td>30098499_205909</td>\n",
587
+ " </tr>\n",
588
+ " <tr>\n",
589
+ " <th>6909</th>\n",
590
+ " <td>d33f93de-31ec-434a-985e-a9cdeb79b557</td>\n",
591
+ " <td>30098484</td>\n",
592
+ " <td>205909</td>\n",
593
+ " <td>Animalia</td>\n",
594
+ " <td>Chordata</td>\n",
595
+ " <td>Actinopterygii</td>\n",
596
+ " <td>Acipenseriformes</td>\n",
597
+ " <td>Acipenseridae</td>\n",
598
+ " <td>Scaphirhynchus</td>\n",
599
+ " <td>albus</td>\n",
600
+ " <td>Scaphirhynchus albus</td>\n",
601
+ " <td>30098484_205909</td>\n",
602
+ " </tr>\n",
603
+ " <tr>\n",
604
+ " <th>6564</th>\n",
605
+ " <td>bd27fc74-caa5-4fe3-9dbc-776127bd03e7</td>\n",
606
+ " <td>30098489</td>\n",
607
+ " <td>205909</td>\n",
608
+ " <td>Animalia</td>\n",
609
+ " <td>Chordata</td>\n",
610
+ " <td>Actinopterygii</td>\n",
611
+ " <td>Acipenseriformes</td>\n",
612
+ " <td>Acipenseridae</td>\n",
613
+ " <td>Scaphirhynchus</td>\n",
614
+ " <td>albus</td>\n",
615
+ " <td>Scaphirhynchus albus</td>\n",
616
+ " <td>30098489_205909</td>\n",
617
+ " </tr>\n",
618
+ " </tbody>\n",
619
+ "</table>\n",
620
+ "</div>"
621
+ ],
622
+ "text/plain": [
623
+ " rarespecies_id eol_content_id_rs eol_page_id_rs \\\n",
624
+ "7726 667586ab-145a-4076-9669-535447aa2b6c 30098504 205909 \n",
625
+ "1413 d239159f-cb15-4c30-8aeb-d8177f8cf34a 30098492 205909 \n",
626
+ "7916 2d342a7c-7e0c-4981-9630-019bb90183be 30098499 205909 \n",
627
+ "6909 d33f93de-31ec-434a-985e-a9cdeb79b557 30098484 205909 \n",
628
+ "6564 bd27fc74-caa5-4fe3-9dbc-776127bd03e7 30098489 205909 \n",
629
+ "\n",
630
+ " kingdom phylum class order family \\\n",
631
+ "7726 Animalia Chordata Actinopterygii Acipenseriformes Acipenseridae \n",
632
+ "1413 Animalia Chordata Actinopterygii Acipenseriformes Acipenseridae \n",
633
+ "7916 Animalia Chordata Actinopterygii Acipenseriformes Acipenseridae \n",
634
+ "6909 Animalia Chordata Actinopterygii Acipenseriformes Acipenseridae \n",
635
+ "6564 Animalia Chordata Actinopterygii Acipenseriformes Acipenseridae \n",
636
+ "\n",
637
+ " genus species sciName combined_id_rs \n",
638
+ "7726 Scaphirhynchus albus Scaphirhynchus albus 30098504_205909 \n",
639
+ "1413 Scaphirhynchus albus Scaphirhynchus albus 30098492_205909 \n",
640
+ "7916 Scaphirhynchus albus Scaphirhynchus albus 30098499_205909 \n",
641
+ "6909 Scaphirhynchus albus Scaphirhynchus albus 30098484_205909 \n",
642
+ "6564 Scaphirhynchus albus Scaphirhynchus albus 30098489_205909 "
643
+ ]
644
+ },
645
+ "execution_count": 17,
646
+ "metadata": {},
647
+ "output_type": "execute_result"
648
+ }
649
+ ],
650
+ "source": [
651
+ "big_mismatch = mismatched_rs.loc[mismatched_rs[\"sciName\"].isin(big_sciNames_missing)]\n",
652
+ "big_mismatch.loc[big_mismatch[\"eol_page_id_rs\"] == 205909].sample(5)"
653
+ ]
654
+ },
655
+ {
656
+ "cell_type": "markdown",
657
+ "metadata": {},
658
+ "source": [
659
+ "sampling some, they're \"not in any collections\": https://eol.org/media/30098484"
660
+ ]
661
+ },
662
+ {
663
+ "cell_type": "code",
664
+ "execution_count": 18,
665
+ "metadata": {},
666
+ "outputs": [
667
+ {
668
+ "data": {
669
+ "text/html": [
670
+ "<div>\n",
671
+ "<style scoped>\n",
672
+ " .dataframe tbody tr th:only-of-type {\n",
673
+ " vertical-align: middle;\n",
674
+ " }\n",
675
+ "\n",
676
+ " .dataframe tbody tr th {\n",
677
+ " vertical-align: top;\n",
678
+ " }\n",
679
+ "\n",
680
+ " .dataframe thead th {\n",
681
+ " text-align: right;\n",
682
+ " }\n",
683
+ "</style>\n",
684
+ "<table border=\"1\" class=\"dataframe\">\n",
685
+ " <thead>\n",
686
+ " <tr style=\"text-align: right;\">\n",
687
+ " <th></th>\n",
688
+ " <th>rarespecies_id</th>\n",
689
+ " <th>eol_content_id_rs</th>\n",
690
+ " <th>eol_page_id_rs</th>\n",
691
+ " <th>kingdom</th>\n",
692
+ " <th>phylum</th>\n",
693
+ " <th>class</th>\n",
694
+ " <th>order</th>\n",
695
+ " <th>family</th>\n",
696
+ " <th>genus</th>\n",
697
+ " <th>species</th>\n",
698
+ " <th>sciName</th>\n",
699
+ " <th>combined_id_rs</th>\n",
700
+ " </tr>\n",
701
+ " </thead>\n",
702
+ " <tbody>\n",
703
+ " <tr>\n",
704
+ " <th>3655</th>\n",
705
+ " <td>12633820-3a3a-4c77-bd38-7221bd18b747</td>\n",
706
+ " <td>27648157</td>\n",
707
+ " <td>46560546</td>\n",
708
+ " <td>Animalia</td>\n",
709
+ " <td>Chordata</td>\n",
710
+ " <td>Chondrichthyes</td>\n",
711
+ " <td>Rajiformes</td>\n",
712
+ " <td>Rajidae</td>\n",
713
+ " <td>Raja</td>\n",
714
+ " <td>asterias</td>\n",
715
+ " <td>Raja asterias</td>\n",
716
+ " <td>27648157_46560546</td>\n",
717
+ " </tr>\n",
718
+ " <tr>\n",
719
+ " <th>4243</th>\n",
720
+ " <td>8a7eae46-57af-4132-b914-78556479db67</td>\n",
721
+ " <td>27648161</td>\n",
722
+ " <td>46560546</td>\n",
723
+ " <td>Animalia</td>\n",
724
+ " <td>Chordata</td>\n",
725
+ " <td>Chondrichthyes</td>\n",
726
+ " <td>Rajiformes</td>\n",
727
+ " <td>Rajidae</td>\n",
728
+ " <td>Raja</td>\n",
729
+ " <td>asterias</td>\n",
730
+ " <td>Raja asterias</td>\n",
731
+ " <td>27648161_46560546</td>\n",
732
+ " </tr>\n",
733
+ " <tr>\n",
734
+ " <th>2347</th>\n",
735
+ " <td>de4a6ca0-6fc2-40de-907e-c99b98a9ca3e</td>\n",
736
+ " <td>27648164</td>\n",
737
+ " <td>46560546</td>\n",
738
+ " <td>Animalia</td>\n",
739
+ " <td>Chordata</td>\n",
740
+ " <td>Chondrichthyes</td>\n",
741
+ " <td>Rajiformes</td>\n",
742
+ " <td>Rajidae</td>\n",
743
+ " <td>Raja</td>\n",
744
+ " <td>asterias</td>\n",
745
+ " <td>Raja asterias</td>\n",
746
+ " <td>27648164_46560546</td>\n",
747
+ " </tr>\n",
748
+ " <tr>\n",
749
+ " <th>3481</th>\n",
750
+ " <td>2bcba9f3-a3a4-4a2b-a4f4-84e35be0e35f</td>\n",
751
+ " <td>27648163</td>\n",
752
+ " <td>46560546</td>\n",
753
+ " <td>Animalia</td>\n",
754
+ " <td>Chordata</td>\n",
755
+ " <td>Chondrichthyes</td>\n",
756
+ " <td>Rajiformes</td>\n",
757
+ " <td>Rajidae</td>\n",
758
+ " <td>Raja</td>\n",
759
+ " <td>asterias</td>\n",
760
+ " <td>Raja asterias</td>\n",
761
+ " <td>27648163_46560546</td>\n",
762
+ " </tr>\n",
763
+ " <tr>\n",
764
+ " <th>1358</th>\n",
765
+ " <td>d436ec20-202d-44ec-9081-ca59afef356f</td>\n",
766
+ " <td>27648166</td>\n",
767
+ " <td>46560546</td>\n",
768
+ " <td>Animalia</td>\n",
769
+ " <td>Chordata</td>\n",
770
+ " <td>Chondrichthyes</td>\n",
771
+ " <td>Rajiformes</td>\n",
772
+ " <td>Rajidae</td>\n",
773
+ " <td>Raja</td>\n",
774
+ " <td>asterias</td>\n",
775
+ " <td>Raja asterias</td>\n",
776
+ " <td>27648166_46560546</td>\n",
777
+ " </tr>\n",
778
+ " </tbody>\n",
779
+ "</table>\n",
780
+ "</div>"
781
+ ],
782
+ "text/plain": [
783
+ " rarespecies_id eol_content_id_rs eol_page_id_rs \\\n",
784
+ "3655 12633820-3a3a-4c77-bd38-7221bd18b747 27648157 46560546 \n",
785
+ "4243 8a7eae46-57af-4132-b914-78556479db67 27648161 46560546 \n",
786
+ "2347 de4a6ca0-6fc2-40de-907e-c99b98a9ca3e 27648164 46560546 \n",
787
+ "3481 2bcba9f3-a3a4-4a2b-a4f4-84e35be0e35f 27648163 46560546 \n",
788
+ "1358 d436ec20-202d-44ec-9081-ca59afef356f 27648166 46560546 \n",
789
+ "\n",
790
+ " kingdom phylum class order family genus species \\\n",
791
+ "3655 Animalia Chordata Chondrichthyes Rajiformes Rajidae Raja asterias \n",
792
+ "4243 Animalia Chordata Chondrichthyes Rajiformes Rajidae Raja asterias \n",
793
+ "2347 Animalia Chordata Chondrichthyes Rajiformes Rajidae Raja asterias \n",
794
+ "3481 Animalia Chordata Chondrichthyes Rajiformes Rajidae Raja asterias \n",
795
+ "1358 Animalia Chordata Chondrichthyes Rajiformes Rajidae Raja asterias \n",
796
+ "\n",
797
+ " sciName combined_id_rs \n",
798
+ "3655 Raja asterias 27648157_46560546 \n",
799
+ "4243 Raja asterias 27648161_46560546 \n",
800
+ "2347 Raja asterias 27648164_46560546 \n",
801
+ "3481 Raja asterias 27648163_46560546 \n",
802
+ "1358 Raja asterias 27648166_46560546 "
803
+ ]
804
+ },
805
+ "execution_count": 18,
806
+ "metadata": {},
807
+ "output_type": "execute_result"
808
+ }
809
+ ],
810
+ "source": [
811
+ "big_mismatch.loc[big_mismatch[\"eol_page_id_rs\"] == 46560546].sample(5)"
812
+ ]
813
+ },
814
+ {
815
+ "cell_type": "markdown",
816
+ "metadata": {},
817
+ "source": [
818
+ "Meanwhile, these are giving me 404's: 27648160, 27648159, 27648164, 27648161, 27648166"
819
+ ]
820
+ },
821
+ {
822
+ "cell_type": "code",
823
+ "execution_count": 19,
824
+ "metadata": {},
825
+ "outputs": [
826
+ {
827
+ "data": {
828
+ "text/html": [
829
+ "<div>\n",
830
+ "<style scoped>\n",
831
+ " .dataframe tbody tr th:only-of-type {\n",
832
+ " vertical-align: middle;\n",
833
+ " }\n",
834
+ "\n",
835
+ " .dataframe tbody tr th {\n",
836
+ " vertical-align: top;\n",
837
+ " }\n",
838
+ "\n",
839
+ " .dataframe thead th {\n",
840
+ " text-align: right;\n",
841
+ " }\n",
842
+ "</style>\n",
843
+ "<table border=\"1\" class=\"dataframe\">\n",
844
+ " <thead>\n",
845
+ " <tr style=\"text-align: right;\">\n",
846
+ " <th></th>\n",
847
+ " <th>eol_content_id</th>\n",
848
+ " <th>eol_page_id</th>\n",
849
+ " <th>medium_source_url</th>\n",
850
+ " <th>eol_full_size_copy_url</th>\n",
851
+ " <th>license_name</th>\n",
852
+ " <th>copyright_owner</th>\n",
853
+ " <th>expected_image_filename</th>\n",
854
+ " <th>source_0706</th>\n",
855
+ " <th>source_0726</th>\n",
856
+ " <th>source_1206</th>\n",
857
+ " <th>combined_id_manifest</th>\n",
858
+ " <th>md5</th>\n",
859
+ " <th>combined_id_manifest_checksums</th>\n",
860
+ " <th>eol_content_id_cargo</th>\n",
861
+ " <th>eol_page_id_cargo</th>\n",
862
+ " <th>combined_id_cargo</th>\n",
863
+ " </tr>\n",
864
+ " </thead>\n",
865
+ " <tbody>\n",
866
+ " </tbody>\n",
867
+ "</table>\n",
868
+ "</div>"
869
+ ],
870
+ "text/plain": [
871
+ "Empty DataFrame\n",
872
+ "Columns: [eol_content_id, eol_page_id, medium_source_url, eol_full_size_copy_url, license_name, copyright_owner, expected_image_filename, source_0706, source_0726, source_1206, combined_id_manifest, md5, combined_id_manifest_checksums, eol_content_id_cargo, eol_page_id_cargo, combined_id_cargo]\n",
873
+ "Index: []"
874
+ ]
875
+ },
876
+ "execution_count": 19,
877
+ "metadata": {},
878
+ "output_type": "execute_result"
879
+ }
880
+ ],
881
+ "source": [
882
+ "# check if content IDs get recycled, content ID: 27648165, now online as: 30223317\n",
883
+ "links_manifest_cargo.loc[links_manifest_cargo[\"eol_content_id_cargo\"] == 30223317]"
884
+ ]
885
+ },
886
+ {
887
+ "cell_type": "code",
888
+ "execution_count": 20,
889
+ "metadata": {},
890
+ "outputs": [
891
+ {
892
+ "data": {
893
+ "text/html": [
894
+ "<div>\n",
895
+ "<style scoped>\n",
896
+ " .dataframe tbody tr th:only-of-type {\n",
897
+ " vertical-align: middle;\n",
898
+ " }\n",
899
+ "\n",
900
+ " .dataframe tbody tr th {\n",
901
+ " vertical-align: top;\n",
902
+ " }\n",
903
+ "\n",
904
+ " .dataframe thead th {\n",
905
+ " text-align: right;\n",
906
+ " }\n",
907
+ "</style>\n",
908
+ "<table border=\"1\" class=\"dataframe\">\n",
909
+ " <thead>\n",
910
+ " <tr style=\"text-align: right;\">\n",
911
+ " <th></th>\n",
912
+ " <th>eol_content_id</th>\n",
913
+ " <th>eol_page_id</th>\n",
914
+ " <th>medium_source_url</th>\n",
915
+ " <th>eol_full_size_copy_url</th>\n",
916
+ " <th>license_name</th>\n",
917
+ " <th>copyright_owner</th>\n",
918
+ " <th>expected_image_filename</th>\n",
919
+ " <th>source_0706</th>\n",
920
+ " <th>source_0726</th>\n",
921
+ " <th>source_1206</th>\n",
922
+ " <th>combined_id_manifest</th>\n",
923
+ " <th>md5</th>\n",
924
+ " <th>combined_id_manifest_checksums</th>\n",
925
+ " <th>eol_content_id_cargo</th>\n",
926
+ " <th>eol_page_id_cargo</th>\n",
927
+ " <th>combined_id_cargo</th>\n",
928
+ " </tr>\n",
929
+ " </thead>\n",
930
+ " <tbody>\n",
931
+ " </tbody>\n",
932
+ "</table>\n",
933
+ "</div>"
934
+ ],
935
+ "text/plain": [
936
+ "Empty DataFrame\n",
937
+ "Columns: [eol_content_id, eol_page_id, medium_source_url, eol_full_size_copy_url, license_name, copyright_owner, expected_image_filename, source_0706, source_0726, source_1206, combined_id_manifest, md5, combined_id_manifest_checksums, eol_content_id_cargo, eol_page_id_cargo, combined_id_cargo]\n",
938
+ "Index: []"
939
+ ]
940
+ },
941
+ "execution_count": 20,
942
+ "metadata": {},
943
+ "output_type": "execute_result"
944
+ }
945
+ ],
946
+ "source": [
947
+ "# Is it in manifest?\n",
948
+ "links_manifest_cargo.loc[links_manifest_cargo[\"eol_content_id\"] == 30223317]"
949
+ ]
950
+ },
951
+ {
952
+ "cell_type": "markdown",
953
+ "metadata": {},
954
+ "source": [
955
+ "This tracks with all eol content IDs being unique across manifest versions...would there be some other intermediate stage where it changed IDs _again_?!"
956
+ ]
957
+ },
958
+ {
959
+ "cell_type": "code",
960
+ "execution_count": 27,
961
+ "metadata": {},
962
+ "outputs": [],
963
+ "source": [
964
+ "# Save CSV of mismatched, they should be salvageable.\n",
965
+ "# We saw these images both online and in our cargo, just with different IDs\n",
966
+ "\n",
967
+ "mismatched_rs.to_csv(\"../data/mismatched_rarespecies.csv\", index=False)"
968
+ ]
969
+ },
970
+ {
971
+ "cell_type": "markdown",
972
+ "metadata": {},
973
+ "source": [
974
+ "Most of our images for some of these species are missing their metadata. For the vast majority of the species, it's just 1 or 2 images."
975
+ ]
976
+ },
977
+ {
978
+ "cell_type": "markdown",
979
+ "metadata": {},
980
+ "source": [
981
+ "## Investigate Duplication\n",
982
+ "\n",
983
+ "Now I want some more info on those duplicated MD5's."
984
+ ]
985
+ },
986
+ {
987
+ "cell_type": "code",
988
+ "execution_count": 21,
989
+ "metadata": {},
990
+ "outputs": [],
991
+ "source": [
992
+ "rs_links[\"md5_dupes\"] = rs_links.duplicated(subset = \"md5\", keep = \"first\")\n",
993
+ "rs_links[\"rs_id_dupes\"] = rs_links.duplicated(subset = \"rarespecies_id\", keep = \"first\")"
994
+ ]
995
+ },
996
+ {
997
+ "cell_type": "code",
998
+ "execution_count": 22,
999
+ "metadata": {},
1000
+ "outputs": [
1001
+ {
1002
+ "data": {
1003
+ "text/plain": [
1004
+ "md5_dupes\n",
1005
+ "True 726\n",
1006
+ "Name: count, dtype: int64"
1007
+ ]
1008
+ },
1009
+ "execution_count": 22,
1010
+ "metadata": {},
1011
+ "output_type": "execute_result"
1012
+ }
1013
+ ],
1014
+ "source": [
1015
+ "rs_links.loc[rs_links[\"rs_id_dupes\"], \"md5_dupes\"].value_counts()"
1016
+ ]
1017
+ },
1018
+ {
1019
+ "cell_type": "code",
1020
+ "execution_count": 23,
1021
+ "metadata": {},
1022
+ "outputs": [
1023
+ {
1024
+ "data": {
1025
+ "text/plain": [
1026
+ "md5_dupes\n",
1027
+ "False 11663\n",
1028
+ "True 163\n",
1029
+ "Name: count, dtype: int64"
1030
+ ]
1031
+ },
1032
+ "execution_count": 23,
1033
+ "metadata": {},
1034
+ "output_type": "execute_result"
1035
+ }
1036
+ ],
1037
+ "source": [
1038
+ "rs_links.loc[~rs_links[\"rs_id_dupes\"], \"md5_dupes\"].value_counts()"
1039
+ ]
1040
+ },
1041
+ {
1042
+ "cell_type": "markdown",
1043
+ "metadata": {},
1044
+ "source": [
1045
+ "Looks like we have 163 duplicated images in Rare Species..."
1046
+ ]
1047
+ },
1048
+ {
1049
+ "cell_type": "code",
1050
+ "execution_count": 24,
1051
+ "metadata": {},
1052
+ "outputs": [
1053
+ {
1054
+ "data": {
1055
+ "text/plain": [
1056
+ "rarespecies_id 163\n",
1057
+ "eol_content_id_rs 163\n",
1058
+ "eol_page_id_rs 80\n",
1059
+ "kingdom 1\n",
1060
+ "phylum 4\n",
1061
+ "class 9\n",
1062
+ "order 37\n",
1063
+ "family 56\n",
1064
+ "genus 73\n",
1065
+ "species 80\n",
1066
+ "sciName 80\n",
1067
+ "combined_id_rs 163\n",
1068
+ "eol_content_id 163\n",
1069
+ "eol_page_id 80\n",
1070
+ "medium_source_url 163\n",
1071
+ "eol_full_size_copy_url 163\n",
1072
+ "license_name 10\n",
1073
+ "copyright_owner 48\n",
1074
+ "expected_image_filename 163\n",
1075
+ "source_0706 2\n",
1076
+ "source_0726 1\n",
1077
+ "source_1206 2\n",
1078
+ "combined_id_manifest 163\n",
1079
+ "md5 163\n",
1080
+ "combined_id_manifest_checksums 163\n",
1081
+ "eol_content_id_cargo 163\n",
1082
+ "eol_page_id_cargo 80\n",
1083
+ "combined_id_cargo 163\n",
1084
+ "md5_dupes 1\n",
1085
+ "rs_id_dupes 1\n",
1086
+ "dtype: int64"
1087
+ ]
1088
+ },
1089
+ "execution_count": 24,
1090
+ "metadata": {},
1091
+ "output_type": "execute_result"
1092
+ }
1093
+ ],
1094
+ "source": [
1095
+ "rs = rs_links.loc[~rs_links[\"rs_id_dupes\"]]\n",
1096
+ "rs_dupes = rs.loc[rs[\"md5_dupes\"]]\n",
1097
+ "rs_dupes.nunique()"
1098
+ ]
1099
+ },
1100
+ {
1101
+ "cell_type": "code",
1102
+ "execution_count": 25,
1103
+ "metadata": {},
1104
+ "outputs": [
1105
+ {
1106
+ "data": {
1107
+ "text/plain": [
1108
+ "sciName\n",
1109
+ "Calumma ambreense 7\n",
1110
+ "Acanthochelys macrocephala 7\n",
1111
+ "Polyergus nigerrimus 7\n",
1112
+ "Pheidole elecebra 6\n",
1113
+ "Nothomyrmecia macrops 6\n",
1114
+ "Callorhinchus callorynchus 5\n",
1115
+ "Atelopus flavescens 5\n",
1116
+ "Adetomyrma venatrix 5\n",
1117
+ "Pleurodeles waltl 4\n",
1118
+ "Orcaella brevirostris 4\n",
1119
+ "Name: count, dtype: int64"
1120
+ ]
1121
+ },
1122
+ "execution_count": 25,
1123
+ "metadata": {},
1124
+ "output_type": "execute_result"
1125
+ }
1126
+ ],
1127
+ "source": [
1128
+ "rs_dupes.sciName.value_counts()[:10]"
1129
+ ]
1130
+ },
1131
+ {
1132
+ "cell_type": "markdown",
1133
+ "metadata": {},
1134
+ "source": [
1135
+ "We have 30 images per species, so we have about a fourth duplicated for some. Note that the counts here are the number of duplicate images, so the total number of times these particular images appear is N + 1."
1136
+ ]
1137
+ },
1138
+ {
1139
+ "cell_type": "markdown",
1140
+ "metadata": {},
1141
+ "source": [
1142
+ "Let's see how many images we have for each of these duplicated images."
1143
+ ]
1144
+ },
1145
+ {
1146
+ "cell_type": "code",
1147
+ "execution_count": 26,
1148
+ "metadata": {},
1149
+ "outputs": [
1150
+ {
1151
+ "data": {
1152
+ "text/plain": [
1153
+ "[4453333, 460289, 45277122, 46561158, 1286909, 45510188, 45510548, 791049]"
1154
+ ]
1155
+ },
1156
+ "execution_count": 26,
1157
+ "metadata": {},
1158
+ "output_type": "execute_result"
1159
+ }
1160
+ ],
1161
+ "source": [
1162
+ "rs_sci_dupe_pgs = list(rs_dupes.eol_page_id.unique())\n",
1163
+ "rs_sci_dupe_pgs[:8]"
1164
+ ]
1165
+ },
1166
+ {
1167
+ "cell_type": "code",
1168
+ "execution_count": 27,
1169
+ "metadata": {
1170
+ "lines_to_next_cell": 2
1171
+ },
1172
+ "outputs": [],
1173
+ "source": [
1174
+ "num_images_by_pg = {}\n",
1175
+ "#list with unique by md5\n",
1176
+ "num_unique_imgs_by_pg = {}\n",
1177
+ "for pg_id in rs_sci_dupe_pgs:\n",
1178
+ " num_images = links_manifest_cargo.loc[links_manifest_cargo[\"eol_page_id\"] == pg_id].shape[0]\n",
1179
+ " num_images_by_pg[pg_id] = num_images\n",
1180
+ " num_unique_images = links_manifest_cargo.loc[links_manifest_cargo[\"eol_page_id\"] == pg_id, \"md5\"].nunique()\n",
1181
+ " num_unique_imgs_by_pg[pg_id] = num_unique_images"
1182
+ ]
1183
+ },
1184
+ {
1185
+ "cell_type": "code",
1186
+ "execution_count": 28,
1187
+ "metadata": {},
1188
+ "outputs": [
1189
+ {
1190
+ "data": {
1191
+ "text/plain": [
1192
+ "80"
1193
+ ]
1194
+ },
1195
+ "execution_count": 28,
1196
+ "metadata": {},
1197
+ "output_type": "execute_result"
1198
+ }
1199
+ ],
1200
+ "source": [
1201
+ "len(num_images_by_pg)"
1202
+ ]
1203
+ },
1204
+ {
1205
+ "cell_type": "code",
1206
+ "execution_count": 29,
1207
+ "metadata": {},
1208
+ "outputs": [
1209
+ {
1210
+ "name": "stdout",
1211
+ "output_type": "stream",
1212
+ "text": [
1213
+ "page ID 1286909 has less than 30 unique images; it has 27 unique images\n",
1214
+ "page ID 791049 has less than 30 unique images; it has 27 unique images\n",
1215
+ "page ID 485420 has less than 30 unique images; it has 24 unique images\n",
1216
+ "page ID 914531 has less than 30 unique images; it has 29 unique images\n",
1217
+ "page ID 205714 has less than 30 unique images; it has 29 unique images\n"
1218
+ ]
1219
+ }
1220
+ ],
1221
+ "source": [
1222
+ "for pg_id in num_unique_imgs_by_pg.keys():\n",
1223
+ " if num_unique_imgs_by_pg[pg_id] < 30:\n",
1224
+ " print(f\"page ID {pg_id} has less than 30 unique images; it has {num_unique_imgs_by_pg[pg_id]} unique images\")"
1225
+ ]
1226
+ },
1227
+ {
1228
+ "cell_type": "markdown",
1229
+ "metadata": {},
1230
+ "source": [
1231
+ "https://eol.org/pages/485420/media has only 21 true images, since 3 are post-its."
1232
+ ]
1233
+ },
1234
+ {
1235
+ "cell_type": "code",
1236
+ "execution_count": 32,
1237
+ "metadata": {},
1238
+ "outputs": [
1239
+ {
1240
+ "data": {
1241
+ "text/html": [
1242
+ "<div>\n",
1243
+ "<style scoped>\n",
1244
+ " .dataframe tbody tr th:only-of-type {\n",
1245
+ " vertical-align: middle;\n",
1246
+ " }\n",
1247
+ "\n",
1248
+ " .dataframe tbody tr th {\n",
1249
+ " vertical-align: top;\n",
1250
+ " }\n",
1251
+ "\n",
1252
+ " .dataframe thead th {\n",
1253
+ " text-align: right;\n",
1254
+ " }\n",
1255
+ "</style>\n",
1256
+ "<table border=\"1\" class=\"dataframe\">\n",
1257
+ " <thead>\n",
1258
+ " <tr style=\"text-align: right;\">\n",
1259
+ " <th></th>\n",
1260
+ " <th>rarespecies_id</th>\n",
1261
+ " <th>eol_content_id_rs</th>\n",
1262
+ " <th>eol_page_id_rs</th>\n",
1263
+ " <th>kingdom</th>\n",
1264
+ " <th>phylum</th>\n",
1265
+ " <th>class</th>\n",
1266
+ " <th>order</th>\n",
1267
+ " <th>family</th>\n",
1268
+ " <th>genus</th>\n",
1269
+ " <th>species</th>\n",
1270
+ " <th>sciName</th>\n",
1271
+ " <th>combined_id_rs</th>\n",
1272
+ " </tr>\n",
1273
+ " </thead>\n",
1274
+ " <tbody>\n",
1275
+ " <tr>\n",
1276
+ " <th>0</th>\n",
1277
+ " <td>8e649092-3e9a-470d-8fe2-1a679e8dbfa9</td>\n",
1278
+ " <td>22519448</td>\n",
1279
+ " <td>914532</td>\n",
1280
+ " <td>Animalia</td>\n",
1281
+ " <td>Chordata</td>\n",
1282
+ " <td>Aves</td>\n",
1283
+ " <td>Anseriformes</td>\n",
1284
+ " <td>Anatidae</td>\n",
1285
+ " <td>Anser</td>\n",
1286
+ " <td>canagicus</td>\n",
1287
+ " <td>Anser canagicus</td>\n",
1288
+ " <td>22519448_914532</td>\n",
1289
+ " </tr>\n",
1290
+ " <tr>\n",
1291
+ " <th>1</th>\n",
1292
+ " <td>9ceb3c09-a43a-4f43-9462-a61cea102f0a</td>\n",
1293
+ " <td>28677580</td>\n",
1294
+ " <td>1057176</td>\n",
1295
+ " <td>Animalia</td>\n",
1296
+ " <td>Chordata</td>\n",
1297
+ " <td>Reptilia</td>\n",
1298
+ " <td>Squamata</td>\n",
1299
+ " <td>Dactyloidae</td>\n",
1300
+ " <td>Anolis</td>\n",
1301
+ " <td>koopmani</td>\n",
1302
+ " <td>Anolis koopmani</td>\n",
1303
+ " <td>28677580_1057176</td>\n",
1304
+ " </tr>\n",
1305
+ " <tr>\n",
1306
+ " <th>2</th>\n",
1307
+ " <td>d0a34ead-c4f2-4a5b-bf57-00e2a9f9f4af</td>\n",
1308
+ " <td>20714475</td>\n",
1309
+ " <td>47047909</td>\n",
1310
+ " <td>Animalia</td>\n",
1311
+ " <td>Chordata</td>\n",
1312
+ " <td>Reptilia</td>\n",
1313
+ " <td>Squamata</td>\n",
1314
+ " <td>Scincidae</td>\n",
1315
+ " <td>Oligosoma</td>\n",
1316
+ " <td>macgregori</td>\n",
1317
+ " <td>Oligosoma macgregori</td>\n",
1318
+ " <td>20714475_47047909</td>\n",
1319
+ " </tr>\n",
1320
+ " <tr>\n",
1321
+ " <th>3</th>\n",
1322
+ " <td>4ef2a6eb-9910-488b-8fd1-b68ae49ce4da</td>\n",
1323
+ " <td>29975068</td>\n",
1324
+ " <td>45509269</td>\n",
1325
+ " <td>Animalia</td>\n",
1326
+ " <td>Chordata</td>\n",
1327
+ " <td>Aves</td>\n",
1328
+ " <td>Charadriiformes</td>\n",
1329
+ " <td>Laridae</td>\n",
1330
+ " <td>Pagophila</td>\n",
1331
+ " <td>eburnea</td>\n",
1332
+ " <td>Pagophila eburnea</td>\n",
1333
+ " <td>29975068_45509269</td>\n",
1334
+ " </tr>\n",
1335
+ " <tr>\n",
1336
+ " <th>4</th>\n",
1337
+ " <td>095c3a37-6921-401c-b55c-67c5e80096c3</td>\n",
1338
+ " <td>29462184</td>\n",
1339
+ " <td>331080</td>\n",
1340
+ " <td>Animalia</td>\n",
1341
+ " <td>Chordata</td>\n",
1342
+ " <td>Mammalia</td>\n",
1343
+ " <td>Artiodactyla</td>\n",
1344
+ " <td>Bovidae</td>\n",
1345
+ " <td>Oryx</td>\n",
1346
+ " <td>leucoryx</td>\n",
1347
+ " <td>Oryx leucoryx</td>\n",
1348
+ " <td>29462184_331080</td>\n",
1349
+ " </tr>\n",
1350
+ " </tbody>\n",
1351
+ "</table>\n",
1352
+ "</div>"
1353
+ ],
1354
+ "text/plain": [
1355
+ " rarespecies_id eol_content_id_rs eol_page_id_rs \\\n",
1356
+ "0 8e649092-3e9a-470d-8fe2-1a679e8dbfa9 22519448 914532 \n",
1357
+ "1 9ceb3c09-a43a-4f43-9462-a61cea102f0a 28677580 1057176 \n",
1358
+ "2 d0a34ead-c4f2-4a5b-bf57-00e2a9f9f4af 20714475 47047909 \n",
1359
+ "3 4ef2a6eb-9910-488b-8fd1-b68ae49ce4da 29975068 45509269 \n",
1360
+ "4 095c3a37-6921-401c-b55c-67c5e80096c3 29462184 331080 \n",
1361
+ "\n",
1362
+ " kingdom phylum class order family genus \\\n",
1363
+ "0 Animalia Chordata Aves Anseriformes Anatidae Anser \n",
1364
+ "1 Animalia Chordata Reptilia Squamata Dactyloidae Anolis \n",
1365
+ "2 Animalia Chordata Reptilia Squamata Scincidae Oligosoma \n",
1366
+ "3 Animalia Chordata Aves Charadriiformes Laridae Pagophila \n",
1367
+ "4 Animalia Chordata Mammalia Artiodactyla Bovidae Oryx \n",
1368
+ "\n",
1369
+ " species sciName combined_id_rs \n",
1370
+ "0 canagicus Anser canagicus 22519448_914532 \n",
1371
+ "1 koopmani Anolis koopmani 28677580_1057176 \n",
1372
+ "2 macgregori Oligosoma macgregori 20714475_47047909 \n",
1373
+ "3 eburnea Pagophila eburnea 29975068_45509269 \n",
1374
+ "4 leucoryx Oryx leucoryx 29462184_331080 "
1375
+ ]
1376
+ },
1377
+ "execution_count": 32,
1378
+ "metadata": {},
1379
+ "output_type": "execute_result"
1380
+ }
1381
+ ],
1382
+ "source": [
1383
+ "rs_catalog.head()"
1384
+ ]
1385
+ },
1386
+ {
1387
+ "cell_type": "code",
1388
+ "execution_count": 33,
1389
+ "metadata": {},
1390
+ "outputs": [
1391
+ {
1392
+ "data": {
1393
+ "text/plain": [
1394
+ "856 28675441_453303_eol-full-size-copy.jpg\n",
1395
+ "3628 22574040_456490_eol-full-size-copy.jpg\n",
1396
+ "11038 22222313_45511297_eol-full-size-copy.jpg\n",
1397
+ "1526 20963513_45511277_eol-full-size-copy.jpg\n",
1398
+ "3703 20080370_46579618_eol-full-size-copy.jpg\n",
1399
+ "1991 21744553_1039032_eol-full-size-copy.jpg\n",
1400
+ "9552 20997172_46561158_eol-full-size-copy.jpg\n",
1401
+ "Name: file_name, dtype: object"
1402
+ ]
1403
+ },
1404
+ "execution_count": 33,
1405
+ "metadata": {},
1406
+ "output_type": "execute_result"
1407
+ }
1408
+ ],
1409
+ "source": [
1410
+ "rs_catalog[\"file_name\"] = rs_catalog[\"combined_id_rs\"].astype(str) + \"_eol-full-size-copy.jpg\"\n",
1411
+ "rs_catalog[\"file_name\"].sample(7)"
1412
+ ]
1413
+ },
1414
+ {
1415
+ "cell_type": "code",
1416
+ "execution_count": 4,
1417
+ "metadata": {},
1418
+ "outputs": [],
1419
+ "source": [
1420
+ "# save filelist for easier fetching\n",
1421
+ "rs_catalog[\"file_name\"].to_csv(\"../data/rs_file_list.txt\", index = False)"
1422
+ ]
1423
+ },
1424
+ {
1425
+ "cell_type": "markdown",
1426
+ "metadata": {},
1427
+ "source": [
1428
+ "### Check for number of _unique_ images per species\n",
1429
+ "\n",
1430
+ "We want to see if we can replace the species that don't have at least 30 unique images per species in our rare species dataset. We need the full list of options from IUCN...We did hold out all 400?\n",
1431
+ "\n",
1432
+ "Would require going back and checking for species in predicted catalog that aren't in catalog, then comparing that to `links_manifest_cargo_on_md5`."
1433
+ ]
1434
+ },
1435
+ {
1436
+ "cell_type": "code",
1437
+ "execution_count": 34,
1438
+ "metadata": {},
1439
+ "outputs": [],
1440
+ "source": [
1441
+ "pred_cat = pd.read_csv(\"../../data/predicted-catalog.csv\", low_memory=False)\n",
1442
+ "catalog = pd.read_csv(\"../../data/data/catalog.csv\", low_memory=False)"
1443
+ ]
1444
+ },
1445
+ {
1446
+ "cell_type": "code",
1447
+ "execution_count": 35,
1448
+ "metadata": {},
1449
+ "outputs": [],
1450
+ "source": [
1451
+ "# process catalog\n",
1452
+ "catalog = catalog.loc[catalog.split != \"train_small\"]\n",
1453
+ "eol_catalog = catalog.loc[catalog.eol_content_id.notna()]\n",
1454
+ "eol_catalog = eol_catalog.astype({\"eol_content_id\": \"int64\", \"eol_page_id\": \"int64\"})\n",
1455
+ "\n",
1456
+ "# process pred-cat\n",
1457
+ "eol_pred_cat = pred_cat.loc[pred_cat.eol_content_id.notna()]\n",
1458
+ "eol_pred_cat = eol_pred_cat.astype({\"eol_content_id\": \"int64\", \"eol_page_id\": \"int64\"})"
1459
+ ]
1460
+ },
1461
+ {
1462
+ "cell_type": "code",
1463
+ "execution_count": 39,
1464
+ "metadata": {},
1465
+ "outputs": [
1466
+ {
1467
+ "name": "stdout",
1468
+ "output_type": "stream",
1469
+ "text": [
1470
+ "<class 'pandas.core.frame.DataFrame'>\n",
1471
+ "RangeIndex: 6277374 entries, 0 to 6277373\n",
1472
+ "Data columns (total 18 columns):\n",
1473
+ " # Column Non-Null Count Dtype \n",
1474
+ "--- ------ -------------- ----- \n",
1475
+ " 0 split 6277374 non-null object \n",
1476
+ " 1 treeoflife_id 6277374 non-null object \n",
1477
+ " 2 eol_content_id_pred 6277374 non-null int64 \n",
1478
+ " 3 eol_page_id 6277374 non-null int64 \n",
1479
+ " 4 bioscan_part 0 non-null float64\n",
1480
+ " 5 bioscan_filename 0 non-null object \n",
1481
+ " 6 inat21_filename 0 non-null object \n",
1482
+ " 7 inat21_cls_name 0 non-null object \n",
1483
+ " 8 inat21_cls_num 0 non-null float64\n",
1484
+ " 9 kingdom 6016565 non-null object \n",
1485
+ " 10 phylum 6018161 non-null object \n",
1486
+ " 11 class 5998392 non-null object \n",
1487
+ " 12 order 5992253 non-null object \n",
1488
+ " 13 family 5975682 non-null object \n",
1489
+ " 14 genus 5967267 non-null object \n",
1490
+ " 15 species 5978567 non-null object \n",
1491
+ " 16 common 6277374 non-null object \n",
1492
+ " 17 eol_content_id_cat 6250420 non-null float64\n",
1493
+ "dtypes: float64(3), int64(2), object(13)\n",
1494
+ "memory usage: 862.1+ MB\n"
1495
+ ]
1496
+ }
1497
+ ],
1498
+ "source": [
1499
+ "full_pred_cat = pd.merge(eol_pred_cat, eol_catalog[[\"treeoflife_id\", \"eol_content_id\"]], on = \"treeoflife_id\", how = \"left\", suffixes = (\"_pred\", \"_cat\"))\n",
1500
+ "full_pred_cat.info(show_counts = True)"
1501
+ ]
1502
+ },
1503
+ {
1504
+ "cell_type": "code",
1505
+ "execution_count": 41,
1506
+ "metadata": {},
1507
+ "outputs": [
1508
+ {
1509
+ "data": {
1510
+ "text/plain": [
1511
+ "26954"
1512
+ ]
1513
+ },
1514
+ "execution_count": 41,
1515
+ "metadata": {},
1516
+ "output_type": "execute_result"
1517
+ }
1518
+ ],
1519
+ "source": [
1520
+ "non_cat_ids = list(full_pred_cat.loc[full_pred_cat[\"eol_content_id_cat\"].isna(), \"treeoflife_id\"])\n",
1521
+ "len(non_cat_ids)"
1522
+ ]
1523
+ },
1524
+ {
1525
+ "cell_type": "code",
1526
+ "execution_count": 54,
1527
+ "metadata": {},
1528
+ "outputs": [
1529
+ {
1530
+ "name": "stderr",
1531
+ "output_type": "stream",
1532
+ "text": [
1533
+ "/var/folders/nv/f0fq1p1n1_3b11x579py_0q80000gq/T/ipykernel_2421/666684240.py:2: SettingWithCopyWarning: \n",
1534
+ "A value is trying to be set on a copy of a slice from a DataFrame.\n",
1535
+ "Try using .loc[row_indexer,col_indexer] = value instead\n",
1536
+ "\n",
1537
+ "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
1538
+ " pot_imgs[\"sciName\"] = pot_imgs[\"genus\"] + \" \" + pot_imgs[\"species\"]\n"
1539
+ ]
1540
+ },
1541
+ {
1542
+ "data": {
1543
+ "text/plain": [
1544
+ "split 2\n",
1545
+ "treeoflife_id 26954\n",
1546
+ "eol_content_id 26954\n",
1547
+ "eol_page_id 831\n",
1548
+ "bioscan_part 0\n",
1549
+ "bioscan_filename 0\n",
1550
+ "inat21_filename 0\n",
1551
+ "inat21_cls_name 0\n",
1552
+ "inat21_cls_num 0\n",
1553
+ "kingdom 2\n",
1554
+ "phylum 6\n",
1555
+ "class 18\n",
1556
+ "order 106\n",
1557
+ "family 285\n",
1558
+ "genus 566\n",
1559
+ "species 749\n",
1560
+ "common 796\n",
1561
+ "sciName 802\n",
1562
+ "dtype: int64"
1563
+ ]
1564
+ },
1565
+ "execution_count": 54,
1566
+ "metadata": {},
1567
+ "output_type": "execute_result"
1568
+ }
1569
+ ],
1570
+ "source": [
1571
+ "pot_imgs = eol_pred_cat.loc[eol_pred_cat.treeoflife_id.isin(non_cat_ids)]\n",
1572
+ "pot_imgs[\"sciName\"] = pot_imgs[\"genus\"] + \" \" + pot_imgs[\"species\"]\n",
1573
+ "pot_imgs.nunique()"
1574
+ ]
1575
+ },
1576
+ {
1577
+ "cell_type": "markdown",
1578
+ "metadata": {},
1579
+ "source": [
1580
+ "Interesting, we have 831 unique EOL page IDs, but only 802 unique scientific names. Wonder how that matches up with 7-tuples."
1581
+ ]
1582
+ },
1583
+ {
1584
+ "cell_type": "code",
1585
+ "execution_count": 55,
1586
+ "metadata": {},
1587
+ "outputs": [
1588
+ {
1589
+ "name": "stderr",
1590
+ "output_type": "stream",
1591
+ "text": [
1592
+ "/var/folders/nv/f0fq1p1n1_3b11x579py_0q80000gq/T/ipykernel_2421/3965230711.py:2: SettingWithCopyWarning: \n",
1593
+ "A value is trying to be set on a copy of a slice from a DataFrame.\n",
1594
+ "Try using .loc[row_indexer,col_indexer] = value instead\n",
1595
+ "\n",
1596
+ "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
1597
+ " pot_imgs[\"duplicate\"] = pot_imgs.duplicated(subset = taxa, keep = \"first\")\n"
1598
+ ]
1599
+ },
1600
+ {
1601
+ "data": {
1602
+ "text/plain": [
1603
+ "duplicate\n",
1604
+ "True 26152\n",
1605
+ "False 802\n",
1606
+ "Name: count, dtype: int64"
1607
+ ]
1608
+ },
1609
+ "execution_count": 55,
1610
+ "metadata": {},
1611
+ "output_type": "execute_result"
1612
+ }
1613
+ ],
1614
+ "source": [
1615
+ "taxa = list(pot_imgs.columns)[9:-2]\n",
1616
+ "pot_imgs[\"duplicate\"] = pot_imgs.duplicated(subset = taxa, keep = \"first\")\n",
1617
+ "\n",
1618
+ "# our species count this way is num true in duplicate\n",
1619
+ "pot_imgs.duplicate.value_counts()"
1620
+ ]
1621
+ },
1622
+ {
1623
+ "cell_type": "markdown",
1624
+ "metadata": {},
1625
+ "source": [
1626
+ "Okay, so this matches up with our `sciName` count."
1627
+ ]
1628
+ },
1629
+ {
1630
+ "cell_type": "code",
1631
+ "execution_count": 56,
1632
+ "metadata": {},
1633
+ "outputs": [
1634
+ {
1635
+ "data": {
1636
+ "text/plain": [
1637
+ "(279370, 24)"
1638
+ ]
1639
+ },
1640
+ "execution_count": 56,
1641
+ "metadata": {},
1642
+ "output_type": "execute_result"
1643
+ }
1644
+ ],
1645
+ "source": [
1646
+ "eol_cols = list(pot_imgs.columns)[1:4] + list(pot_imgs.columns)[9:]\n",
1647
+ "\n",
1648
+ "pot_imgs = pot_imgs[eol_cols]\n",
1649
+ "\n",
1650
+ "#compare to catalog sciNames\n",
1651
+ "eol_catalog[\"sciName\"] = eol_catalog[\"genus\"] + \" \" + eol_catalog[\"species\"]\n",
1652
+ "\n",
1653
+ "overlap_sciNames = pd.merge(pot_imgs, eol_catalog[eol_cols[:-1]], on = \"sciName\", how = \"inner\")\n",
1654
+ "overlap_sciNames.shape"
1655
+ ]
1656
+ },
1657
+ {
1658
+ "cell_type": "code",
1659
+ "execution_count": 58,
1660
+ "metadata": {},
1661
+ "outputs": [
1662
+ {
1663
+ "data": {
1664
+ "text/plain": [
1665
+ "treeoflife_id_x 3994\n",
1666
+ "eol_content_id_x 3994\n",
1667
+ "eol_page_id_x 402\n",
1668
+ "kingdom_x 2\n",
1669
+ "phylum_x 6\n",
1670
+ "class_x 15\n",
1671
+ "order_x 81\n",
1672
+ "family_x 192\n",
1673
+ "genus_x 320\n",
1674
+ "species_x 390\n",
1675
+ "common_x 402\n",
1676
+ "sciName 402\n",
1677
+ "duplicate 2\n",
1678
+ "treeoflife_id_y 28738\n",
1679
+ "eol_content_id_y 28738\n",
1680
+ "eol_page_id_y 444\n",
1681
+ "kingdom_y 2\n",
1682
+ "phylum_y 6\n",
1683
+ "class_y 15\n",
1684
+ "order_y 81\n",
1685
+ "family_y 192\n",
1686
+ "genus_y 320\n",
1687
+ "species_y 390\n",
1688
+ "common_y 402\n",
1689
+ "dtype: int64"
1690
+ ]
1691
+ },
1692
+ "execution_count": 58,
1693
+ "metadata": {},
1694
+ "output_type": "execute_result"
1695
+ }
1696
+ ],
1697
+ "source": [
1698
+ "overlap_sciNames.nunique()"
1699
+ ]
1700
+ },
1701
+ {
1702
+ "cell_type": "markdown",
1703
+ "metadata": {},
1704
+ "source": [
1705
+ "Here are our other 402 species, so we didn't hold out anything but the 400 chosen.\n",
1706
+ "\n",
1707
+ "We're stuck with less images for some of them unless we source images from elsewhere."
1708
+ ]
1709
+ },
1710
+ {
1711
+ "cell_type": "code",
1712
+ "execution_count": null,
1713
+ "metadata": {},
1714
+ "outputs": [],
1715
+ "source": []
1716
+ }
1717
+ ],
1718
+ "metadata": {
1719
+ "jupytext": {
1720
+ "formats": "ipynb,py:percent"
1721
+ },
1722
+ "kernelspec": {
1723
+ "display_name": "tol",
1724
+ "language": "python",
1725
+ "name": "python3"
1726
+ },
1727
+ "language_info": {
1728
+ "codemirror_mode": {
1729
+ "name": "ipython",
1730
+ "version": 3
1731
+ },
1732
+ "file_extension": ".py",
1733
+ "mimetype": "text/x-python",
1734
+ "name": "python",
1735
+ "nbconvert_exporter": "python",
1736
+ "pygments_lexer": "ipython3",
1737
+ "version": "3.11.6"
1738
+ }
1739
+ },
1740
+ "nbformat": 4,
1741
+ "nbformat_minor": 2
1742
+ }
eol_realign/notebooks/links_rs_duplicates.py ADDED
@@ -0,0 +1,268 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: tol
12
+ # language: python
13
+ # name: python3
14
+ # ---
15
+
16
+ # %%
17
+ import pandas as pd
18
+
19
+ # %% [markdown]
20
+ # ### Read in Links CSV file
21
+
22
+ # %%
23
+ links_manifest_cargo = pd.read_csv("../data/links_manifest_cargo_on_md5.csv", low_memory=False)
24
+
25
+ # %%
26
+ links_manifest_cargo.info(show_counts=True)
27
+
28
+ # %% [markdown]
29
+ # ## Check on Rare Species Catalog
30
+
31
+ # %%
32
+ rs_catalog = pd.read_csv("../../rare_species/data/rarespecies-catalog.csv",
33
+ low_memory=False,
34
+ dtype = {"eol_content_id": "int64", "eol_page_id": "int64"})
35
+ rs_catalog.info(show_counts = True)
36
+
37
+ # %%
38
+ rs_catalog["combined_id_rs"] = rs_catalog["eol_content_id"].astype(str) + "_" + rs_catalog["eol_page_id"].astype(str)
39
+ rs_catalog.rename(columns={'eol_content_id': 'eol_content_id_rs', 'eol_page_id': 'eol_page_id_rs'}, inplace=True)
40
+
41
+ # %%
42
+ rs_links = pd.merge(rs_catalog,
43
+ links_manifest_cargo,
44
+ left_on = "combined_id_rs",
45
+ right_on = "combined_id_cargo",
46
+ how = "inner")
47
+ rs_links.info(show_counts = True)
48
+
49
+ # %%
50
+ rs_links.nunique()
51
+
52
+ # %% [markdown]
53
+ # Let's check the mismatched cargo/manifest entries for those last 174...
54
+
55
+ # %%
56
+ matched_rs_ids = list(rs_links.combined_id_rs.unique())
57
+ len(matched_rs_ids)
58
+
59
+ # %%
60
+ matched_rs_ids[:4]
61
+
62
+ # %%
63
+ rs_catalog["combined_id_rs"].sample(4)
64
+
65
+ # %%
66
+ mismatched_rs = rs_catalog.loc[~rs_catalog["combined_id_rs"].isin(matched_rs_ids)]
67
+ mismatched_rs.info(show_counts = True)
68
+
69
+ # %%
70
+ mismatched_rs.nunique()
71
+
72
+ # %%
73
+ mismatched_rs.sciName.value_counts()
74
+
75
+ # %%
76
+ big_sciNames_missing = ["Aonyx capensis",
77
+ "Zoogoneticus tequila",
78
+ "Sousa plumbea",
79
+ "Sylvilagus transitionalis",
80
+ "Scaphirhynchus albus",
81
+ "Raja asterias"]
82
+
83
+ # %%
84
+ pg_ids = []
85
+ for sciName in big_sciNames_missing:
86
+ pg_ids.append(rs_links.loc[rs_links["sciName"] == sciName, "eol_page_id"].unique())
87
+ pg_ids
88
+
89
+ # %%
90
+ num_images_by_pg = []
91
+ for pg_id in pg_ids:
92
+ num_images = links_manifest_cargo.loc[links_manifest_cargo["eol_page_id"] == pg_id[0]].shape[0]
93
+ num_images_by_pg.append((pg_id[0], num_images))
94
+
95
+ num_images_by_pg
96
+
97
+ # %% [markdown]
98
+ # The media for both of these last two is online: https://eol.org/pages/46560546/media, https://eol.org/pages/205909/media
99
+
100
+ # %%
101
+ big_mismatch = mismatched_rs.loc[mismatched_rs["sciName"].isin(big_sciNames_missing)]
102
+ big_mismatch.loc[big_mismatch["eol_page_id_rs"] == 205909].sample(5)
103
+
104
+ # %% [markdown]
105
+ # sampling some, they're "not in any collections": https://eol.org/media/30098484
106
+
107
+ # %%
108
+ big_mismatch.loc[big_mismatch["eol_page_id_rs"] == 46560546].sample(5)
109
+
110
+ # %% [markdown]
111
+ # Meanwhile, these are giving me 404's: 27648160, 27648159, 27648164, 27648161, 27648166
112
+
113
+ # %%
114
+ # check if content IDs get recycled, content ID: 27648165, now online as: 30223317
115
+ links_manifest_cargo.loc[links_manifest_cargo["eol_content_id_cargo"] == 30223317]
116
+
117
+ # %%
118
+ # Is it in manifest?
119
+ links_manifest_cargo.loc[links_manifest_cargo["eol_content_id"] == 30223317]
120
+
121
+ # %% [markdown]
122
+ # This tracks with all eol content IDs being unique across manifest versions...would there be some other intermediate stage where it changed IDs _again_?!
123
+
124
+ # %%
125
+ # Save CSV of mismatched, they should be salvageable.
126
+ # We saw these images both online and in our cargo, just with different IDs
127
+
128
+ mismatched_rs.to_csv("../data/mismatched_rarespecies.csv", index=False)
129
+
130
+ # %% [markdown]
131
+ # Most of our images for some of these species are missing their metadata. For the vast majority of the species, it's just 1 or 2 images.
132
+
133
+ # %% [markdown]
134
+ # ## Investigate Duplication
135
+ #
136
+ # Now I want some more info on those duplicated MD5's.
137
+
138
+ # %%
139
+ rs_links["md5_dupes"] = rs_links.duplicated(subset = "md5", keep = "first")
140
+ rs_links["rs_id_dupes"] = rs_links.duplicated(subset = "rarespecies_id", keep = "first")
141
+
142
+ # %%
143
+ rs_links.loc[rs_links["rs_id_dupes"], "md5_dupes"].value_counts()
144
+
145
+ # %%
146
+ rs_links.loc[~rs_links["rs_id_dupes"], "md5_dupes"].value_counts()
147
+
148
+ # %% [markdown]
149
+ # Looks like we have 163 duplicated images in Rare Species...
150
+
151
+ # %%
152
+ rs = rs_links.loc[~rs_links["rs_id_dupes"]]
153
+ rs_dupes = rs.loc[rs["md5_dupes"]]
154
+ rs_dupes.nunique()
155
+
156
+ # %%
157
+ rs_dupes.sciName.value_counts()[:10]
158
+
159
+ # %% [markdown]
160
+ # We have 30 images per species, so we have about a fourth duplicated for some. Note that the counts here are the number of duplicate images, so the total number of times these particular images appear is N + 1.
161
+
162
+ # %% [markdown]
163
+ # Let's see how many images we have for each of these duplicated images.
164
+
165
+ # %%
166
+ rs_sci_dupe_pgs = list(rs_dupes.eol_page_id.unique())
167
+ rs_sci_dupe_pgs[:8]
168
+
169
+ # %%
170
+ num_images_by_pg = {}
171
+ #list with unique by md5
172
+ num_unique_imgs_by_pg = {}
173
+ for pg_id in rs_sci_dupe_pgs:
174
+ num_images = links_manifest_cargo.loc[links_manifest_cargo["eol_page_id"] == pg_id].shape[0]
175
+ num_images_by_pg[pg_id] = num_images
176
+ num_unique_images = links_manifest_cargo.loc[links_manifest_cargo["eol_page_id"] == pg_id, "md5"].nunique()
177
+ num_unique_imgs_by_pg[pg_id] = num_unique_images
178
+
179
+
180
+ # %%
181
+ len(num_images_by_pg)
182
+
183
+ # %%
184
+ for pg_id in num_unique_imgs_by_pg.keys():
185
+ if num_unique_imgs_by_pg[pg_id] < 30:
186
+ print(f"page ID {pg_id} has less than 30 unique images; it has {num_unique_imgs_by_pg[pg_id]} unique images")
187
+
188
+ # %% [markdown]
189
+ # https://eol.org/pages/485420/media has only 21 true images, since 3 are post-its.
190
+
191
+ # %%
192
+ rs_catalog.head()
193
+
194
+ # %%
195
+ rs_catalog["file_name"] = rs_catalog["combined_id_rs"].astype(str) + "_eol-full-size-copy.jpg"
196
+ rs_catalog["file_name"].sample(7)
197
+
198
+ # %%
199
+ # save filelist for easier fetching
200
+ rs_catalog["file_name"].to_csv("../data/rs_file_list.txt", index = False)
201
+
202
+ # %% [markdown]
203
+ # ### Check for number of _unique_ images per species
204
+ #
205
+ # We want to see if we can replace the species that don't have at least 30 unique images per species in our rare species dataset. We need the full list of options from IUCN...We did hold out all 400?
206
+ #
207
+ # Would require going back and checking for species in predicted catalog that aren't in catalog, then comparing that to `links_manifest_cargo_on_md5`.
208
+
209
+ # %%
210
+ pred_cat = pd.read_csv("../../data/predicted-catalog.csv", low_memory=False)
211
+ catalog = pd.read_csv("../../data/data/catalog.csv", low_memory=False)
212
+
213
+ # %%
214
+ # process catalog
215
+ catalog = catalog.loc[catalog.split != "train_small"]
216
+ eol_catalog = catalog.loc[catalog.eol_content_id.notna()]
217
+ eol_catalog = eol_catalog.astype({"eol_content_id": "int64", "eol_page_id": "int64"})
218
+
219
+ # process pred-cat
220
+ eol_pred_cat = pred_cat.loc[pred_cat.eol_content_id.notna()]
221
+ eol_pred_cat = eol_pred_cat.astype({"eol_content_id": "int64", "eol_page_id": "int64"})
222
+
223
+ # %%
224
+ full_pred_cat = pd.merge(eol_pred_cat, eol_catalog[["treeoflife_id", "eol_content_id"]], on = "treeoflife_id", how = "left", suffixes = ("_pred", "_cat"))
225
+ full_pred_cat.info(show_counts = True)
226
+
227
+ # %%
228
+ non_cat_ids = list(full_pred_cat.loc[full_pred_cat["eol_content_id_cat"].isna(), "treeoflife_id"])
229
+ len(non_cat_ids)
230
+
231
+ # %%
232
+ pot_imgs = eol_pred_cat.loc[eol_pred_cat.treeoflife_id.isin(non_cat_ids)]
233
+ pot_imgs["sciName"] = pot_imgs["genus"] + " " + pot_imgs["species"]
234
+ pot_imgs.nunique()
235
+
236
+ # %% [markdown]
237
+ # Interesting, we have 831 unique EOL page IDs, but only 802 unique scientific names. Wonder how that matches up with 7-tuples.
238
+
239
+ # %%
240
+ taxa = list(pot_imgs.columns)[9:-2]
241
+ pot_imgs["duplicate"] = pot_imgs.duplicated(subset = taxa, keep = "first")
242
+
243
+ # our species count this way is num true in duplicate
244
+ pot_imgs.duplicate.value_counts()
245
+
246
+ # %% [markdown]
247
+ # Okay, so this matches up with our `sciName` count.
248
+
249
+ # %%
250
+ eol_cols = list(pot_imgs.columns)[1:4] + list(pot_imgs.columns)[9:]
251
+
252
+ pot_imgs = pot_imgs[eol_cols]
253
+
254
+ #compare to catalog sciNames
255
+ eol_catalog["sciName"] = eol_catalog["genus"] + " " + eol_catalog["species"]
256
+
257
+ overlap_sciNames = pd.merge(pot_imgs, eol_catalog[eol_cols[:-1]], on = "sciName", how = "inner")
258
+ overlap_sciNames.shape
259
+
260
+ # %%
261
+ overlap_sciNames.nunique()
262
+
263
+ # %% [markdown]
264
+ # Here are our other 402 species, so we didn't hold out anything but the 400 chosen.
265
+ #
266
+ # We're stuck with less images for some of them unless we source images from elsewhere.
267
+
268
+ # %%