egrace479 commited on
Commit
85b0ebf
·
verified ·
1 Parent(s): 8c437d6

Upload archive analysis and data for catalog realign

Browse files

We gained an additional 630 matches over previous attempt. None of the images with mismatched archive-manifest IDs matched.
Total number of images missing metadata is 30,746.
3,734 of these are in the train_small subset.

.gitattributes CHANGED
@@ -67,3 +67,4 @@ eol_realign/data/links_inner.csv filter=lfs diff=lfs merge=lfs -text
67
  eol_realign/data/links_manifest_cargo_on_md5.csv filter=lfs diff=lfs merge=lfs -text
68
  eol_realign/data/links_cargo_manifest_IDmismatch.csv filter=lfs diff=lfs merge=lfs -text
69
  eol_realign/data/eol-cargo-archive_combined-manifest-checksums_links.csv filter=lfs diff=lfs merge=lfs -text
 
 
67
  eol_realign/data/links_manifest_cargo_on_md5.csv filter=lfs diff=lfs merge=lfs -text
68
  eol_realign/data/links_cargo_manifest_IDmismatch.csv filter=lfs diff=lfs merge=lfs -text
69
  eol_realign/data/eol-cargo-archive_combined-manifest-checksums_links.csv filter=lfs diff=lfs merge=lfs -text
70
+ eol_realign/data/eol-cargo-archive_catalog_combined-manifest-checksums_links.csv filter=lfs diff=lfs merge=lfs -text
eol_realign/data/eol-cargo-archive_catalog_combined-manifest-checksums_links.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fc0cc8d4555ed4cf3e5bba2f0c88339bc605ca30982e427d7288e1eb0e74071e
3
+ size 3921517771
eol_realign/notebooks/links_align_reduced.ipynb CHANGED
@@ -2,18 +2,45 @@
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
  {
@@ -22,8 +49,8 @@
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
  {
@@ -36,46 +63,42 @@
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
  ],
@@ -93,28 +116,29 @@
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
  ],
@@ -122,90 +146,174 @@
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": [
@@ -216,7 +324,7 @@
216
  },
217
  {
218
  "cell_type": "code",
219
- "execution_count": 48,
220
  "metadata": {},
221
  "outputs": [
222
  {
@@ -229,7 +337,7 @@
229
  "dtype: int64"
230
  ]
231
  },
232
- "execution_count": 48,
233
  "metadata": {},
234
  "output_type": "execute_result"
235
  }
@@ -240,7 +348,7 @@
240
  },
241
  {
242
  "cell_type": "code",
243
- "execution_count": 49,
244
  "metadata": {},
245
  "outputs": [],
246
  "source": [
@@ -249,7 +357,7 @@
249
  },
250
  {
251
  "cell_type": "code",
252
- "execution_count": 50,
253
  "metadata": {},
254
  "outputs": [
255
  {
@@ -292,7 +400,7 @@
292
  },
293
  {
294
  "cell_type": "code",
295
- "execution_count": 51,
296
  "metadata": {},
297
  "outputs": [
298
  {
@@ -320,7 +428,7 @@
320
  },
321
  {
322
  "cell_type": "code",
323
- "execution_count": 52,
324
  "metadata": {
325
  "lines_to_next_cell": 2
326
  },
@@ -333,16 +441,16 @@
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
  }
@@ -352,22 +460,29 @@
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
  }
@@ -380,26 +495,26 @@
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
  }
@@ -410,7 +525,7 @@
410
  },
411
  {
412
  "cell_type": "code",
413
- "execution_count": 56,
414
  "metadata": {},
415
  "outputs": [
416
  {
@@ -418,25 +533,25 @@
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
  ],
@@ -447,29 +562,29 @@
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
  }
@@ -482,14 +597,21 @@
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
  {
@@ -497,72 +619,81 @@
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
  }
@@ -578,6 +709,187 @@
578
  "These pages are reasonably full too: [5660435](https://eol.org/pages/5660435)."
579
  ]
580
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
581
  {
582
  "cell_type": "markdown",
583
  "metadata": {},
@@ -587,7 +899,7 @@
587
  },
588
  {
589
  "cell_type": "code",
590
- "execution_count": 60,
591
  "metadata": {},
592
  "outputs": [
593
  {
@@ -624,7 +936,7 @@
624
  },
625
  {
626
  "cell_type": "code",
627
- "execution_count": 61,
628
  "metadata": {},
629
  "outputs": [],
630
  "source": [
@@ -634,7 +946,7 @@
634
  },
635
  {
636
  "cell_type": "code",
637
- "execution_count": 62,
638
  "metadata": {},
639
  "outputs": [
640
  {
@@ -643,39 +955,40 @@
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
  ],
@@ -683,51 +996,52 @@
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
  }
@@ -745,7 +1059,7 @@
745
  },
746
  {
747
  "cell_type": "code",
748
- "execution_count": 64,
749
  "metadata": {},
750
  "outputs": [
751
  {
@@ -754,7 +1068,7 @@
754
  "11826"
755
  ]
756
  },
757
- "execution_count": 64,
758
  "metadata": {},
759
  "output_type": "execute_result"
760
  }
@@ -766,7 +1080,7 @@
766
  },
767
  {
768
  "cell_type": "code",
769
- "execution_count": 65,
770
  "metadata": {},
771
  "outputs": [
772
  {
@@ -778,7 +1092,7 @@
778
  " '29975068_45509269']"
779
  ]
780
  },
781
- "execution_count": 65,
782
  "metadata": {},
783
  "output_type": "execute_result"
784
  }
@@ -789,20 +1103,20 @@
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
  }
@@ -813,7 +1127,7 @@
813
  },
814
  {
815
  "cell_type": "code",
816
- "execution_count": 67,
817
  "metadata": {},
818
  "outputs": [
819
  {
@@ -849,7 +1163,7 @@
849
  },
850
  {
851
  "cell_type": "code",
852
- "execution_count": 68,
853
  "metadata": {},
854
  "outputs": [
855
  {
@@ -858,38 +1172,39 @@
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
  }
@@ -898,7 +1213,7 @@
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
  ]
 
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": "code",
14
+ "execution_count": 2,
15
+ "metadata": {},
16
+ "outputs": [],
17
+ "source": [
18
+ "TOL_FILEPATH = \"../../data/\""
19
+ ]
20
+ },
21
  {
22
  "cell_type": "markdown",
23
  "metadata": {},
24
  "source": [
25
+ "### Read in Links CSV files\n",
26
+ "\n",
27
+ "Full cargo archives have some more content than the [original `links_inner` file](https://huggingface.co/datasets/imageomics/ToL-EDA/blob/fa08e0f6692a013e4e4f5ca30dd0e8883c0021d8/eol_realign/data/links_inner.csv) and the [original `links_manifest_cargo_on_md5.csv`](https://huggingface.co/datasets/imageomics/ToL-EDA/blob/fa08e0f6692a013e4e4f5ca30dd0e8883c0021d8/eol_realign/data/links_manifest_cargo_on_md5.csv).\n",
28
+ "\n",
29
+ "From Matt:\n",
30
+ "> It represents a series of inner merges:\n",
31
+ "> 1. The list of images in the EOL cargo archive (used to create the webdatasets) with the EOL portion of `catalog.csv`\n",
32
+ "> - Merged on a combined identifier of `eol_content_id` and `eol_page_id`.\n",
33
+ "> Result from 1) with the list of images redownloaded from all 3 media manifests we touched around the original download time (identified [here](https://huggingface.co/datasets/imageomics/ToL-EDA/discussions/5#6584808d92eba5ad69b8379f)).\n",
34
+ "> - Merged on MD5\n",
35
+ ">\n",
36
+ "> The result has 6,219,674 unique `treeoflife_id` entries and 6,146,917 unique `md5` entries. It has the combined `eol_content_id` and `eol_page_id` identifiers used at each stage:\n",
37
+ "- `combined_id_catalog`: represents what's in the original catalog \n",
38
+ "- `combined_id_manifest_full_manifest`: represents what's in the combined manifest from all 3 dates \n",
39
+ "> It also has an indicator of which of the three media manifest files each entry was present in (one or more) in columns representing retreival date (eg., `source_0706`: indicates if it was present in the manifest retrieved on July 6, 2023). It also has the copyright owner and license information as contained in the media manifest files.\n",
40
+ ">\n",
41
+ "> Still needs to be run through the owner name finding code. ([owner_match](https://huggingface.co/datasets/imageomics/ToL-EDA/blob/71ad5b49226a3a49634931005eeb340b3c96db13/scripts/match_owners.py) --note: this version uses inner merges, so will remove entries without media info. Probably should adjust this.)\n",
42
+ "\n",
43
+ "For reference on the numbers, there are 6,250,420 EOL images in TreeOfLife-10M (the catalog). Comparing with `links_inner` previously (from [`links_inner.csv`](https://huggingface.co/datasets/imageomics/ToL-EDA/blob/fa08e0f6692a013e4e4f5ca30dd0e8883c0021d8/eol_realign/data/links_inner.csv)) we were missing 31,376 images, 29 of which were identified in [`links_manifest_cargo_on_md5.csv`](https://huggingface.co/datasets/imageomics/ToL-EDA/blob/fa08e0f6692a013e4e4f5ca30dd0e8883c0021d8/eol_realign/data/links_manifest_cargo_on_md5.csv)."
44
  ]
45
  },
46
  {
 
49
  "metadata": {},
50
  "outputs": [],
51
  "source": [
52
+ "links_inner = pd.read_csv(\"../data/eol-cargo-archive_catalog_combined-manifest-checksums_links.csv\", low_memory=False)\n",
53
+ "links_manifest_cargo = pd.read_csv(\"../data/eol-cargo-archive_combined-manifest-checksums_links.csv\", low_memory=False)"
54
  ]
55
  },
56
  {
 
63
  "output_type": "stream",
64
  "text": [
65
  "<class 'pandas.core.frame.DataFrame'>\n",
66
+ "RangeIndex: 6841202 entries, 0 to 6841201\n",
67
+ "Data columns (total 30 columns):\n",
68
+ " # Column Non-Null Count Dtype \n",
69
+ "--- ------ -------------- ----- \n",
70
+ " 0 filename_archive 6841202 non-null object \n",
71
+ " 1 md5 6841202 non-null object \n",
72
+ " 2 combined_id_archive 6841202 non-null object \n",
73
+ " 3 split 6841202 non-null object \n",
74
+ " 4 treeoflife_id 6841202 non-null object \n",
75
+ " 5 bioscan_part 0 non-null float64\n",
76
+ " 6 bioscan_filename 0 non-null float64\n",
77
+ " 7 inat21_filename 0 non-null float64\n",
78
+ " 8 inat21_cls_name 0 non-null float64\n",
79
+ " 9 inat21_cls_num 0 non-null float64\n",
80
+ " 10 kingdom 6551473 non-null object \n",
81
+ " 11 phylum 6553206 non-null object \n",
82
+ " 12 class 6532009 non-null object \n",
83
+ " 13 order 6525621 non-null object \n",
84
+ " 14 family 6506076 non-null object \n",
85
+ " 15 genus 6486130 non-null object \n",
86
+ " 16 species 6406307 non-null object \n",
87
+ " 17 common 6841202 non-null object \n",
88
+ " 18 combined_id_catalog 6841202 non-null object \n",
89
+ " 19 filename_manifest 6841202 non-null object \n",
90
+ " 20 combined_id_manifest_redownload 6841202 non-null object \n",
91
+ " 21 medium_source_url 6841202 non-null object \n",
92
+ " 22 eol_full_size_copy_url 6841202 non-null object \n",
93
+ " 23 license_name 6841202 non-null object \n",
94
+ " 24 copyright_owner 6208498 non-null object \n",
95
+ " 25 expected_image_filename 6841202 non-null object \n",
96
+ " 26 source_0706 6841202 non-null bool \n",
97
+ " 27 source_0726 6841202 non-null bool \n",
98
+ " 28 source_1206 6841202 non-null bool \n",
99
+ " 29 combined_id_full_manifest 6841202 non-null object \n",
100
+ "dtypes: bool(3), float64(5), object(22)\n",
101
+ "memory usage: 1.4+ GB\n"
 
 
 
 
102
  ]
103
  }
104
  ],
 
116
  "output_type": "stream",
117
  "text": [
118
  "<class 'pandas.core.frame.DataFrame'>\n",
119
+ "RangeIndex: 7514001 entries, 0 to 7514000\n",
120
+ "Data columns (total 17 columns):\n",
121
+ " # Column Non-Null Count Dtype \n",
122
+ "--- ------ -------------- ----- \n",
123
+ " 0 filename_archive 7514001 non-null object\n",
124
+ " 1 md5_archive 7514001 non-null object\n",
125
+ " 2 combined_id_archive 7514001 non-null object\n",
126
+ " 3 filename_manifest 7514001 non-null object\n",
127
+ " 4 md5_combined_manifest 7514001 non-null object\n",
128
+ " 5 combined_id_manifest_redownload 7514001 non-null object\n",
129
+ " 6 eol_content_id 7514001 non-null int64 \n",
130
+ " 7 eol_page_id 7514001 non-null int64 \n",
131
+ " 8 medium_source_url 7514001 non-null object\n",
132
+ " 9 eol_full_size_copy_url 7514001 non-null object\n",
133
+ " 10 license_name 7514001 non-null object\n",
134
+ " 11 copyright_owner 6860825 non-null object\n",
135
+ " 12 expected_image_filename 7514001 non-null object\n",
136
+ " 13 source_0706 7514001 non-null bool \n",
137
+ " 14 source_0726 7514001 non-null bool \n",
138
+ " 15 source_1206 7514001 non-null bool \n",
139
+ " 16 combined_id_full_manifest 7514001 non-null object\n",
140
+ "dtypes: bool(3), int64(2), object(12)\n",
141
+ "memory usage: 824.1+ MB\n"
142
  ]
143
  }
144
  ],
 
146
  "links_manifest_cargo.info(show_counts=True)"
147
  ]
148
  },
149
+ {
150
+ "cell_type": "markdown",
151
+ "metadata": {},
152
+ "source": [
153
+ "These both have about 600-700 more entries than the earlier files."
154
+ ]
155
+ },
156
  {
157
  "cell_type": "code",
158
  "execution_count": 6,
159
  "metadata": {},
160
+ "outputs": [
161
+ {
162
+ "data": {
163
+ "text/html": [
164
+ "<div>\n",
165
+ "<style scoped>\n",
166
+ " .dataframe tbody tr th:only-of-type {\n",
167
+ " vertical-align: middle;\n",
168
+ " }\n",
169
+ "\n",
170
+ " .dataframe tbody tr th {\n",
171
+ " vertical-align: top;\n",
172
+ " }\n",
173
+ "\n",
174
+ " .dataframe thead th {\n",
175
+ " text-align: right;\n",
176
+ " }\n",
177
+ "</style>\n",
178
+ "<table border=\"1\" class=\"dataframe\">\n",
179
+ " <thead>\n",
180
+ " <tr style=\"text-align: right;\">\n",
181
+ " <th></th>\n",
182
+ " <th>filename_archive</th>\n",
183
+ " <th>md5_archive</th>\n",
184
+ " <th>combined_id_archive</th>\n",
185
+ " <th>filename_manifest</th>\n",
186
+ " <th>md5_combined_manifest</th>\n",
187
+ " <th>combined_id_manifest_redownload</th>\n",
188
+ " <th>eol_content_id</th>\n",
189
+ " <th>eol_page_id</th>\n",
190
+ " <th>medium_source_url</th>\n",
191
+ " <th>eol_full_size_copy_url</th>\n",
192
+ " <th>license_name</th>\n",
193
+ " <th>copyright_owner</th>\n",
194
+ " <th>expected_image_filename</th>\n",
195
+ " <th>source_0706</th>\n",
196
+ " <th>source_0726</th>\n",
197
+ " <th>source_1206</th>\n",
198
+ " <th>combined_id_full_manifest</th>\n",
199
+ " </tr>\n",
200
+ " </thead>\n",
201
+ " <tbody>\n",
202
+ " </tbody>\n",
203
+ "</table>\n",
204
+ "</div>"
205
+ ],
206
+ "text/plain": [
207
+ "Empty DataFrame\n",
208
+ "Columns: [filename_archive, md5_archive, combined_id_archive, filename_manifest, md5_combined_manifest, combined_id_manifest_redownload, 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_full_manifest]\n",
209
+ "Index: []"
210
+ ]
211
+ },
212
+ "execution_count": 6,
213
+ "metadata": {},
214
+ "output_type": "execute_result"
215
+ }
216
+ ],
217
+ "source": [
218
+ "# These should be the same\n",
219
+ "links_manifest_cargo.loc[links_manifest_cargo[\"combined_id_manifest_redownload\"] != links_manifest_cargo[\"combined_id_full_manifest\"]]"
220
+ ]
221
+ },
222
+ {
223
+ "cell_type": "code",
224
+ "execution_count": 7,
225
+ "metadata": {},
226
  "outputs": [
227
  {
228
  "name": "stdout",
229
  "output_type": "stream",
230
  "text": [
231
  "<class 'pandas.core.frame.DataFrame'>\n",
232
+ "Index: 822558 entries, 2 to 7513999\n",
233
+ "Data columns (total 17 columns):\n",
234
+ " # Column Non-Null Count Dtype \n",
235
+ "--- ------ -------------- ----- \n",
236
+ " 0 filename_archive 822558 non-null object\n",
237
+ " 1 md5_archive 822558 non-null object\n",
238
+ " 2 combined_id_archive 822558 non-null object\n",
239
+ " 3 filename_manifest 822558 non-null object\n",
240
+ " 4 md5_combined_manifest 822558 non-null object\n",
241
+ " 5 combined_id_manifest_redownload 822558 non-null object\n",
242
+ " 6 eol_content_id 822558 non-null int64 \n",
243
+ " 7 eol_page_id 822558 non-null int64 \n",
244
+ " 8 medium_source_url 822558 non-null object\n",
245
+ " 9 eol_full_size_copy_url 822558 non-null object\n",
246
+ " 10 license_name 822558 non-null object\n",
247
+ " 11 copyright_owner 797147 non-null object\n",
248
+ " 12 expected_image_filename 822558 non-null object\n",
249
+ " 13 source_0706 822558 non-null bool \n",
250
+ " 14 source_0726 822558 non-null bool \n",
251
+ " 15 source_1206 822558 non-null bool \n",
252
+ " 16 combined_id_full_manifest 822558 non-null object\n",
253
+ "dtypes: bool(3), int64(2), object(12)\n",
254
+ "memory usage: 96.5+ MB\n"
255
  ]
256
  }
257
  ],
258
  "source": [
259
+ "# archive has replaced cargo\n",
260
+ "# full manifest or manifest redownload to replace manifest checksums -- they are equal\n",
261
+ "links_mismatch = links_manifest_cargo.loc[links_manifest_cargo[\"combined_id_archive\"] != links_manifest_cargo[\"combined_id_full_manifest\"]]\n",
262
  "links_mismatch.info(show_counts = True)"
263
  ]
264
  },
265
+ {
266
+ "cell_type": "markdown",
267
+ "metadata": {},
268
+ "source": [
269
+ "There are 42 more mismatched entries. Only 13 additional unique images (MD5s)."
270
+ ]
271
+ },
272
  {
273
  "cell_type": "code",
274
+ "execution_count": 9,
275
  "metadata": {},
276
  "outputs": [
277
  {
278
  "data": {
279
  "text/plain": [
280
+ "md5_archive 624574\n",
281
+ "combined_id_full_manifest 712540\n",
282
+ "combined_id_archive 703446\n",
283
  "dtype: int64"
284
  ]
285
  },
286
+ "execution_count": 9,
287
  "metadata": {},
288
  "output_type": "execute_result"
289
  }
290
  ],
291
  "source": [
292
+ "links_mismatch[[\"md5_archive\", \"combined_id_full_manifest\", \"combined_id_archive\"]].nunique()"
293
  ]
294
  },
295
  {
296
  "cell_type": "code",
297
+ "execution_count": 10,
298
  "metadata": {},
299
  "outputs": [],
300
  "source": [
301
+ "# This is archive manifest mismatch\n",
302
+ "links_mismatch.to_csv(\"../data/links_archive_manifest_IDmismatch.csv\", index = False)"
303
  ]
304
  },
305
  {
306
  "cell_type": "code",
307
+ "execution_count": 11,
308
  "metadata": {},
309
  "outputs": [],
310
  "source": [
311
+ "catalog = pd.read_csv(TOL_FILEPATH + \"catalog.csv\", low_memory=False)"
312
  ]
313
  },
314
  {
315
  "cell_type": "code",
316
+ "execution_count": 12,
317
  "metadata": {},
318
  "outputs": [],
319
  "source": [
 
324
  },
325
  {
326
  "cell_type": "code",
327
+ "execution_count": 13,
328
  "metadata": {},
329
  "outputs": [
330
  {
 
337
  "dtype: int64"
338
  ]
339
  },
340
+ "execution_count": 13,
341
  "metadata": {},
342
  "output_type": "execute_result"
343
  }
 
348
  },
349
  {
350
  "cell_type": "code",
351
+ "execution_count": 14,
352
  "metadata": {},
353
  "outputs": [],
354
  "source": [
 
357
  },
358
  {
359
  "cell_type": "code",
360
+ "execution_count": 15,
361
  "metadata": {},
362
  "outputs": [
363
  {
 
400
  },
401
  {
402
  "cell_type": "code",
403
+ "execution_count": 16,
404
  "metadata": {},
405
  "outputs": [
406
  {
 
428
  },
429
  {
430
  "cell_type": "code",
431
+ "execution_count": 17,
432
  "metadata": {
433
  "lines_to_next_cell": 2
434
  },
 
441
  },
442
  {
443
  "cell_type": "code",
444
+ "execution_count": 18,
445
  "metadata": {},
446
  "outputs": [
447
  {
448
  "data": {
449
  "text/plain": [
450
+ "6219674"
451
  ]
452
  },
453
+ "execution_count": 18,
454
  "metadata": {},
455
  "output_type": "execute_result"
456
  }
 
460
  "len(matched_catalog_ids)"
461
  ]
462
  },
463
+ {
464
+ "cell_type": "markdown",
465
+ "metadata": {},
466
+ "source": [
467
+ "Here we go, we got an additional 630 matched IDs!"
468
+ ]
469
+ },
470
  {
471
  "cell_type": "code",
472
+ "execution_count": 19,
473
  "metadata": {},
474
  "outputs": [
475
  {
476
  "data": {
477
  "text/plain": [
478
+ "['29538374_65414274',\n",
479
+ " '27793900_888015',\n",
480
+ " '29121641_5618956',\n",
481
+ " '27596176_607817',\n",
482
+ " '20300703_267922']"
483
  ]
484
  },
485
+ "execution_count": 19,
486
  "metadata": {},
487
  "output_type": "execute_result"
488
  }
 
495
  "cell_type": "markdown",
496
  "metadata": {},
497
  "source": [
498
+ "We still have about 30K unmatched (as shown below, it's down to 30,746 from 31,376), let's find those in the catalog and then we'll try to merge with our mismatched cargo & manifest."
499
  ]
500
  },
501
  {
502
  "cell_type": "code",
503
+ "execution_count": 20,
504
  "metadata": {},
505
  "outputs": [
506
  {
507
  "data": {
508
  "text/plain": [
509
+ "5842839 28875844_579175\n",
510
+ "7715090 21712402_702458\n",
511
+ "10112940 27938371_3091824\n",
512
+ "8606944 27597441_49820955\n",
513
+ "1247592 14852900_2896866\n",
514
  "Name: combined_id_catalog, dtype: object"
515
  ]
516
  },
517
+ "execution_count": 20,
518
  "metadata": {},
519
  "output_type": "execute_result"
520
  }
 
525
  },
526
  {
527
  "cell_type": "code",
528
+ "execution_count": 21,
529
  "metadata": {},
530
  "outputs": [
531
  {
 
533
  "output_type": "stream",
534
  "text": [
535
  "<class 'pandas.core.frame.DataFrame'>\n",
536
+ "Index: 30746 entries, 956874 to 10996978\n",
537
  "Data columns (total 13 columns):\n",
538
  " # Column Non-Null Count Dtype \n",
539
  "--- ------ -------------- ----- \n",
540
+ " 0 split 30746 non-null object\n",
541
+ " 1 treeoflife_id 30746 non-null object\n",
542
+ " 2 eol_content_id_catalog 30746 non-null int64 \n",
543
+ " 3 eol_page_id_catalog 30746 non-null int64 \n",
544
+ " 4 kingdom 30573 non-null object\n",
545
+ " 5 phylum 30578 non-null object\n",
546
+ " 6 class 30153 non-null object\n",
547
+ " 7 order 30528 non-null object\n",
548
+ " 8 family 30294 non-null object\n",
549
+ " 9 genus 30192 non-null object\n",
550
+ " 10 species 29399 non-null object\n",
551
+ " 11 common 30746 non-null object\n",
552
+ " 12 combined_id_catalog 30746 non-null object\n",
553
  "dtypes: int64(2), object(11)\n",
554
+ "memory usage: 3.3+ MB\n"
555
  ]
556
  }
557
  ],
 
562
  },
563
  {
564
  "cell_type": "code",
565
+ "execution_count": 22,
566
  "metadata": {},
567
  "outputs": [
568
  {
569
  "data": {
570
  "text/plain": [
571
  "split 2\n",
572
+ "treeoflife_id 30746\n",
573
+ "eol_content_id_catalog 30746\n",
574
+ "eol_page_id_catalog 7042\n",
575
  "kingdom 7\n",
576
  "phylum 33\n",
577
+ "class 87\n",
578
+ "order 355\n",
579
+ "family 1165\n",
580
+ "genus 3503\n",
581
+ "species 5174\n",
582
+ "common 6884\n",
583
+ "combined_id_catalog 30746\n",
584
  "dtype: int64"
585
  ]
586
  },
587
+ "execution_count": 22,
588
  "metadata": {},
589
  "output_type": "execute_result"
590
  }
 
597
  "cell_type": "markdown",
598
  "metadata": {},
599
  "source": [
600
+ "Seems one class got resolved (equals more orders and down)."
601
+ ]
602
+ },
603
+ {
604
+ "cell_type": "markdown",
605
+ "metadata": {},
606
+ "source": [
607
+ "## Merge with Mismatched CargoArchive-Manifest\n",
608
  "\n",
609
+ "let's merge with `links_mismatch` to see if the mismatched archive and manifest combined IDs can be linked up."
610
  ]
611
  },
612
  {
613
  "cell_type": "code",
614
+ "execution_count": 23,
615
  "metadata": {},
616
  "outputs": [
617
  {
 
619
  "output_type": "stream",
620
  "text": [
621
  "<class 'pandas.core.frame.DataFrame'>\n",
622
+ "RangeIndex: 0 entries\n",
623
+ "Data columns (total 30 columns):\n",
624
+ " # Column Non-Null Count Dtype \n",
625
+ "--- ------ -------------- ----- \n",
626
+ " 0 split 0 non-null object\n",
627
+ " 1 treeoflife_id 0 non-null object\n",
628
+ " 2 eol_content_id_catalog 0 non-null int64 \n",
629
+ " 3 eol_page_id_catalog 0 non-null int64 \n",
630
+ " 4 kingdom 0 non-null object\n",
631
+ " 5 phylum 0 non-null object\n",
632
+ " 6 class 0 non-null object\n",
633
+ " 7 order 0 non-null object\n",
634
+ " 8 family 0 non-null object\n",
635
+ " 9 genus 0 non-null object\n",
636
+ " 10 species 0 non-null object\n",
637
+ " 11 common 0 non-null object\n",
638
+ " 12 combined_id_catalog 0 non-null object\n",
639
+ " 13 filename_archive 0 non-null object\n",
640
+ " 14 md5_archive 0 non-null object\n",
641
+ " 15 combined_id_archive 0 non-null object\n",
642
+ " 16 filename_manifest 0 non-null object\n",
643
+ " 17 md5_combined_manifest 0 non-null object\n",
644
+ " 18 combined_id_manifest_redownload 0 non-null object\n",
645
+ " 19 eol_content_id 0 non-null int64 \n",
646
+ " 20 eol_page_id 0 non-null int64 \n",
647
+ " 21 medium_source_url 0 non-null object\n",
648
+ " 22 eol_full_size_copy_url 0 non-null object\n",
649
+ " 23 license_name 0 non-null object\n",
650
+ " 24 copyright_owner 0 non-null object\n",
651
+ " 25 expected_image_filename 0 non-null object\n",
652
+ " 26 source_0706 0 non-null bool \n",
653
+ " 27 source_0726 0 non-null bool \n",
654
+ " 28 source_1206 0 non-null bool \n",
655
+ " 29 combined_id_full_manifest 0 non-null object\n",
656
+ "dtypes: bool(3), int64(4), object(23)\n",
657
+ "memory usage: 132.0+ bytes\n"
658
  ]
659
  }
660
  ],
661
  "source": [
662
+ "# replace manifest checksums with full manifest as above\n",
663
  "links_catalog_mismatch = pd.merge(mismatched_catalog,\n",
664
  " links_mismatch,\n",
665
  " left_on = \"combined_id_catalog\",\n",
666
+ " right_on = \"combined_id_full_manifest\",\n",
667
  " how = \"inner\")\n",
668
  "links_catalog_mismatch.info(show_counts = True)"
669
  ]
670
  },
671
+ {
672
+ "cell_type": "markdown",
673
+ "metadata": {},
674
+ "source": [
675
+ "Now there's no gain from the mismatch file, but that was only 29 images, so we've captured them from the archive (plus more!)."
676
+ ]
677
+ },
678
  {
679
  "cell_type": "code",
680
+ "execution_count": 24,
681
  "metadata": {},
682
  "outputs": [
683
  {
684
  "data": {
685
  "text/plain": [
686
+ "2003559 15270321_240065\n",
687
+ "8751466 29485627_17806\n",
688
+ "4818957 27965287_35726\n",
689
+ "8697796 9483753_328724\n",
690
+ "1049389 9446784_5019858\n",
691
+ "8364678 9467133_2925218\n",
692
+ "5119903 28880812_10305215\n",
693
  "Name: combined_id_catalog, dtype: object"
694
  ]
695
  },
696
+ "execution_count": 24,
697
  "metadata": {},
698
  "output_type": "execute_result"
699
  }
 
709
  "These pages are reasonably full too: [5660435](https://eol.org/pages/5660435)."
710
  ]
711
  },
712
+ {
713
+ "cell_type": "markdown",
714
+ "metadata": {},
715
+ "source": [
716
+ "### Final Catalog\n",
717
+ "\n",
718
+ "Our final EOL catalog is thus going to be the `treeoflife_id`s in `links_inner`.\n",
719
+ "\n",
720
+ "Finall question is just how does this look for our `train_small`?"
721
+ ]
722
+ },
723
+ {
724
+ "cell_type": "code",
725
+ "execution_count": 34,
726
+ "metadata": {},
727
+ "outputs": [
728
+ {
729
+ "name": "stdout",
730
+ "output_type": "stream",
731
+ "text": [
732
+ "<class 'pandas.core.frame.DataFrame'>\n",
733
+ "Index: 593764 entries, 0 to 918500\n",
734
+ "Data columns (total 12 columns):\n",
735
+ " # Column Non-Null Count Dtype \n",
736
+ "--- ------ -------------- ----- \n",
737
+ " 0 split 593764 non-null object \n",
738
+ " 1 treeoflife_id 593764 non-null object \n",
739
+ " 2 eol_content_id 593764 non-null float64\n",
740
+ " 3 eol_page_id 593764 non-null float64\n",
741
+ " 4 kingdom 569128 non-null object \n",
742
+ " 5 phylum 569285 non-null object \n",
743
+ " 6 class 567356 non-null object \n",
744
+ " 7 order 566839 non-null object \n",
745
+ " 8 family 565269 non-null object \n",
746
+ " 9 genus 564605 non-null object \n",
747
+ " 10 species 565399 non-null object \n",
748
+ " 11 common 593764 non-null object \n",
749
+ "dtypes: float64(2), object(10)\n",
750
+ "memory usage: 58.9+ MB\n"
751
+ ]
752
+ }
753
+ ],
754
+ "source": [
755
+ "cat_2 = pd.read_csv(TOL_FILEPATH + \"catalog.csv\", low_memory=False)\n",
756
+ "\n",
757
+ "# reduce to just train_small and all non-EOL entries\n",
758
+ "cat_2 = cat_2.loc[cat_2.split == \"train_small\"]\n",
759
+ "eol_cat_2 = cat_2.loc[cat_2.eol_content_id.notna()]\n",
760
+ "\n",
761
+ "eol_cat_2 = eol_cat_2[eol_cols]\n",
762
+ "eol_cat_2.info(show_counts=True)"
763
+ ]
764
+ },
765
+ {
766
+ "cell_type": "markdown",
767
+ "metadata": {},
768
+ "source": [
769
+ "So `train_small` has 593,764 images from EOL. \n",
770
+ "\n",
771
+ "Let's recast IDs as ints to match up with `links_inner` and check we have info for all of them."
772
+ ]
773
+ },
774
+ {
775
+ "cell_type": "code",
776
+ "execution_count": 35,
777
+ "metadata": {},
778
+ "outputs": [
779
+ {
780
+ "name": "stdout",
781
+ "output_type": "stream",
782
+ "text": [
783
+ "<class 'pandas.core.frame.DataFrame'>\n",
784
+ "Index: 593764 entries, 0 to 918500\n",
785
+ "Data columns (total 4 columns):\n",
786
+ " # Column Non-Null Count Dtype \n",
787
+ "--- ------ -------------- ----- \n",
788
+ " 0 split 593764 non-null object\n",
789
+ " 1 treeoflife_id 593764 non-null object\n",
790
+ " 2 eol_content_id 593764 non-null int64 \n",
791
+ " 3 eol_page_id 593764 non-null int64 \n",
792
+ "dtypes: int64(2), object(2)\n",
793
+ "memory usage: 22.7+ MB\n"
794
+ ]
795
+ }
796
+ ],
797
+ "source": [
798
+ "eol_cat_2 = eol_cat_2.astype({\"eol_content_id\": \"int64\", \"eol_page_id\": \"int64\"})\n",
799
+ "eol_cat_2[eol_cols[:4]].info()"
800
+ ]
801
+ },
802
+ {
803
+ "cell_type": "code",
804
+ "execution_count": 36,
805
+ "metadata": {},
806
+ "outputs": [],
807
+ "source": [
808
+ "# make combined ID for catalog and add suffix to eol content and page IDs\n",
809
+ "eol_cat_2['combined_id_catalog'] = eol_cat_2['eol_content_id'].astype(str) + '_' + eol_cat_2['eol_page_id'].astype(str)\n",
810
+ "eol_cat_2.rename(columns={'eol_content_id': 'eol_content_id_catalog', 'eol_page_id': 'eol_page_id_catalog'}, inplace=True)"
811
+ ]
812
+ },
813
+ {
814
+ "cell_type": "code",
815
+ "execution_count": 40,
816
+ "metadata": {},
817
+ "outputs": [
818
+ {
819
+ "name": "stdout",
820
+ "output_type": "stream",
821
+ "text": [
822
+ "<class 'pandas.core.frame.DataFrame'>\n",
823
+ "RangeIndex: 612614 entries, 0 to 612613\n",
824
+ "Data columns (total 25 columns):\n",
825
+ " # Column Non-Null Count Dtype \n",
826
+ "--- ------ -------------- ----- \n",
827
+ " 0 split 612614 non-null object\n",
828
+ " 1 treeoflife_id 612614 non-null object\n",
829
+ " 2 eol_content_id_catalog 612614 non-null int64 \n",
830
+ " 3 eol_page_id_catalog 612614 non-null int64 \n",
831
+ " 4 kingdom 584979 non-null object\n",
832
+ " 5 phylum 585140 non-null object\n",
833
+ " 6 class 583235 non-null object\n",
834
+ " 7 order 582668 non-null object\n",
835
+ " 8 family 581082 non-null object\n",
836
+ " 9 genus 580464 non-null object\n",
837
+ " 10 species 579943 non-null object\n",
838
+ " 11 common 612614 non-null object\n",
839
+ " 12 combined_id_catalog_x 612614 non-null object\n",
840
+ " 13 combined_id_catalog_y 612614 non-null object\n",
841
+ " 14 filename_manifest 612614 non-null object\n",
842
+ " 15 combined_id_manifest_redownload 612614 non-null object\n",
843
+ " 16 medium_source_url 612614 non-null object\n",
844
+ " 17 eol_full_size_copy_url 612614 non-null object\n",
845
+ " 18 license_name 612614 non-null object\n",
846
+ " 19 copyright_owner 554029 non-null object\n",
847
+ " 20 expected_image_filename 612614 non-null object\n",
848
+ " 21 source_0706 612614 non-null bool \n",
849
+ " 22 source_0726 612614 non-null bool \n",
850
+ " 23 source_1206 612614 non-null bool \n",
851
+ " 24 combined_id_full_manifest 612614 non-null object\n",
852
+ "dtypes: bool(3), int64(2), object(20)\n",
853
+ "memory usage: 104.6+ MB\n"
854
+ ]
855
+ }
856
+ ],
857
+ "source": [
858
+ "eol_ts_links = pd.merge(eol_cat_2,\n",
859
+ " links_inner[list(links_inner.columns)[18:]],\n",
860
+ " left_on = \"combined_id_catalog\",\n",
861
+ " right_on = \"combined_id_full_manifest\",\n",
862
+ " how = \"inner\")\n",
863
+ "eol_ts_links.info(show_counts = True)"
864
+ ]
865
+ },
866
+ {
867
+ "cell_type": "code",
868
+ "execution_count": 41,
869
+ "metadata": {},
870
+ "outputs": [
871
+ {
872
+ "data": {
873
+ "text/plain": [
874
+ "590730"
875
+ ]
876
+ },
877
+ "execution_count": 41,
878
+ "metadata": {},
879
+ "output_type": "execute_result"
880
+ }
881
+ ],
882
+ "source": [
883
+ "eol_ts_links.treeoflife_id.nunique()"
884
+ ]
885
+ },
886
+ {
887
+ "cell_type": "markdown",
888
+ "metadata": {},
889
+ "source": [
890
+ "So we are missing the metadata for 3,734 of these images."
891
+ ]
892
+ },
893
  {
894
  "cell_type": "markdown",
895
  "metadata": {},
 
899
  },
900
  {
901
  "cell_type": "code",
902
+ "execution_count": 25,
903
  "metadata": {},
904
  "outputs": [
905
  {
 
936
  },
937
  {
938
  "cell_type": "code",
939
+ "execution_count": 26,
940
  "metadata": {},
941
  "outputs": [],
942
  "source": [
 
946
  },
947
  {
948
  "cell_type": "code",
949
+ "execution_count": 27,
950
  "metadata": {},
951
  "outputs": [
952
  {
 
955
  "text": [
956
  "<class 'pandas.core.frame.DataFrame'>\n",
957
  "RangeIndex: 12552 entries, 0 to 12551\n",
958
+ "Data columns (total 29 columns):\n",
959
+ " # Column Non-Null Count Dtype \n",
960
+ "--- ------ -------------- ----- \n",
961
+ " 0 rarespecies_id 12552 non-null object\n",
962
+ " 1 eol_content_id_rs 12552 non-null int64 \n",
963
+ " 2 eol_page_id_rs 12552 non-null int64 \n",
964
+ " 3 kingdom 12552 non-null object\n",
965
+ " 4 phylum 12552 non-null object\n",
966
+ " 5 class 12552 non-null object\n",
967
+ " 6 order 12552 non-null object\n",
968
+ " 7 family 12552 non-null object\n",
969
+ " 8 genus 12552 non-null object\n",
970
+ " 9 species 12552 non-null object\n",
971
+ " 10 sciName 12552 non-null object\n",
972
+ " 11 combined_id_rs 12552 non-null object\n",
973
+ " 12 filename_archive 12552 non-null object\n",
974
+ " 13 md5_archive 12552 non-null object\n",
975
+ " 14 combined_id_archive 12552 non-null object\n",
976
+ " 15 filename_manifest 12552 non-null object\n",
977
+ " 16 md5_combined_manifest 12552 non-null object\n",
978
+ " 17 combined_id_manifest_redownload 12552 non-null object\n",
979
+ " 18 eol_content_id 12552 non-null int64 \n",
980
+ " 19 eol_page_id 12552 non-null int64 \n",
981
+ " 20 medium_source_url 12552 non-null object\n",
982
+ " 21 eol_full_size_copy_url 12552 non-null object\n",
983
+ " 22 license_name 12552 non-null object\n",
984
+ " 23 copyright_owner 11171 non-null object\n",
985
+ " 24 expected_image_filename 12552 non-null object\n",
986
+ " 25 source_0706 12552 non-null bool \n",
987
+ " 26 source_0726 12552 non-null bool \n",
988
+ " 27 source_1206 12552 non-null bool \n",
989
+ " 28 combined_id_full_manifest 12552 non-null object\n",
990
+ "dtypes: bool(3), int64(4), object(22)\n",
991
+ "memory usage: 2.5+ MB\n"
992
  ]
993
  }
994
  ],
 
996
  "rs_links = pd.merge(rs_catalog,\n",
997
  " links_manifest_cargo,\n",
998
  " left_on = \"combined_id_rs\",\n",
999
+ " right_on = \"combined_id_archive\", # looking at archive\n",
1000
  " how = \"inner\")\n",
1001
  "rs_links.info(show_counts = True)"
1002
  ]
1003
  },
1004
  {
1005
  "cell_type": "code",
1006
+ "execution_count": 28,
1007
  "metadata": {},
1008
  "outputs": [
1009
  {
1010
  "data": {
1011
  "text/plain": [
1012
+ "rarespecies_id 11826\n",
1013
+ "eol_content_id_rs 11826\n",
1014
+ "eol_page_id_rs 400\n",
1015
+ "kingdom 1\n",
1016
+ "phylum 5\n",
1017
+ "class 15\n",
1018
+ "order 85\n",
1019
+ "family 202\n",
1020
+ "genus 316\n",
1021
+ "species 385\n",
1022
+ "sciName 400\n",
1023
+ "combined_id_rs 11826\n",
1024
+ "filename_archive 11826\n",
1025
+ "md5_archive 11663\n",
1026
+ "combined_id_archive 11826\n",
1027
+ "filename_manifest 12221\n",
1028
+ "md5_combined_manifest 11663\n",
1029
+ "combined_id_manifest_redownload 12221\n",
1030
+ "eol_content_id 12221\n",
1031
+ "eol_page_id 447\n",
1032
+ "medium_source_url 12056\n",
1033
+ "eol_full_size_copy_url 12119\n",
1034
+ "license_name 15\n",
1035
+ "copyright_owner 3724\n",
1036
+ "expected_image_filename 12221\n",
1037
+ "source_0706 2\n",
1038
+ "source_0726 2\n",
1039
+ "source_1206 2\n",
1040
+ "combined_id_full_manifest 12221\n",
1041
  "dtype: int64"
1042
  ]
1043
  },
1044
+ "execution_count": 28,
1045
  "metadata": {},
1046
  "output_type": "execute_result"
1047
  }
 
1059
  },
1060
  {
1061
  "cell_type": "code",
1062
+ "execution_count": 29,
1063
  "metadata": {},
1064
  "outputs": [
1065
  {
 
1068
  "11826"
1069
  ]
1070
  },
1071
+ "execution_count": 29,
1072
  "metadata": {},
1073
  "output_type": "execute_result"
1074
  }
 
1080
  },
1081
  {
1082
  "cell_type": "code",
1083
+ "execution_count": 30,
1084
  "metadata": {},
1085
  "outputs": [
1086
  {
 
1092
  " '29975068_45509269']"
1093
  ]
1094
  },
1095
+ "execution_count": 30,
1096
  "metadata": {},
1097
  "output_type": "execute_result"
1098
  }
 
1103
  },
1104
  {
1105
  "cell_type": "code",
1106
+ "execution_count": 31,
1107
  "metadata": {},
1108
  "outputs": [
1109
  {
1110
  "data": {
1111
  "text/plain": [
1112
+ "1473 29538601_46580048\n",
1113
+ "11127 29447084_1019571\n",
1114
+ "6578 20398296_328017\n",
1115
+ "11583 29772112_1049135\n",
1116
  "Name: combined_id_rs, dtype: object"
1117
  ]
1118
  },
1119
+ "execution_count": 31,
1120
  "metadata": {},
1121
  "output_type": "execute_result"
1122
  }
 
1127
  },
1128
  {
1129
  "cell_type": "code",
1130
+ "execution_count": 32,
1131
  "metadata": {},
1132
  "outputs": [
1133
  {
 
1163
  },
1164
  {
1165
  "cell_type": "code",
1166
+ "execution_count": 33,
1167
  "metadata": {},
1168
  "outputs": [
1169
  {
 
1172
  "text": [
1173
  "<class 'pandas.core.frame.DataFrame'>\n",
1174
  "RangeIndex: 0 entries\n",
1175
+ "Data columns (total 29 columns):\n",
1176
+ " # Column Non-Null Count Dtype \n",
1177
+ "--- ------ -------------- ----- \n",
1178
+ " 0 rarespecies_id 0 non-null object\n",
1179
+ " 1 eol_content_id_rs 0 non-null int64 \n",
1180
+ " 2 eol_page_id_rs 0 non-null int64 \n",
1181
+ " 3 kingdom 0 non-null object\n",
1182
+ " 4 phylum 0 non-null object\n",
1183
+ " 5 class 0 non-null object\n",
1184
+ " 6 order 0 non-null object\n",
1185
+ " 7 family 0 non-null object\n",
1186
+ " 8 genus 0 non-null object\n",
1187
+ " 9 species 0 non-null object\n",
1188
+ " 10 sciName 0 non-null object\n",
1189
+ " 11 combined_id_rs 0 non-null object\n",
1190
+ " 12 filename_archive 0 non-null object\n",
1191
+ " 13 md5_archive 0 non-null object\n",
1192
+ " 14 combined_id_archive 0 non-null object\n",
1193
+ " 15 filename_manifest 0 non-null object\n",
1194
+ " 16 md5_combined_manifest 0 non-null object\n",
1195
+ " 17 combined_id_manifest_redownload 0 non-null object\n",
1196
+ " 18 eol_content_id 0 non-null int64 \n",
1197
+ " 19 eol_page_id 0 non-null int64 \n",
1198
+ " 20 medium_source_url 0 non-null object\n",
1199
+ " 21 eol_full_size_copy_url 0 non-null object\n",
1200
+ " 22 license_name 0 non-null object\n",
1201
+ " 23 copyright_owner 0 non-null object\n",
1202
+ " 24 expected_image_filename 0 non-null object\n",
1203
+ " 25 source_0706 0 non-null bool \n",
1204
+ " 26 source_0726 0 non-null bool \n",
1205
+ " 27 source_1206 0 non-null bool \n",
1206
+ " 28 combined_id_full_manifest 0 non-null object\n",
1207
+ "dtypes: bool(3), int64(4), object(22)\n",
1208
  "memory usage: 132.0+ bytes\n"
1209
  ]
1210
  }
 
1213
  "links_rs_mismatch = pd.merge(mismatched_rs,\n",
1214
  " links_mismatch,\n",
1215
  " left_on = \"combined_id_rs\",\n",
1216
+ " right_on = \"combined_id_full_manifest\",\n",
1217
  " how = \"inner\")\n",
1218
  "links_rs_mismatch.info(show_counts = True)"
1219
  ]
eol_realign/notebooks/links_align_reduced.py CHANGED
@@ -16,12 +16,33 @@
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)
@@ -29,18 +50,31 @@ links_inner.info(show_counts=True)
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
@@ -74,11 +108,14 @@ eol_catalog.rename(columns={'eol_content_id': 'eol_content_id_catalog', 'eol_pag
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)
@@ -91,24 +128,76 @@ mismatched_catalog.info(show_counts = True)
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
 
@@ -126,7 +215,7 @@ rs_catalog.rename(columns={'eol_content_id': 'eol_content_id_rs', 'eol_page_id':
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
 
@@ -154,7 +243,7 @@ mismatched_rs.info(show_counts = True)
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
 
 
16
  # %%
17
  import pandas as pd
18
 
19
+ # %%
20
+ TOL_FILEPATH = "../../data/"
21
+
22
  # %% [markdown]
23
  # ### Read in Links CSV files
24
+ #
25
+ # Full cargo archives have some more content than the [original `links_inner` file](https://huggingface.co/datasets/imageomics/ToL-EDA/blob/fa08e0f6692a013e4e4f5ca30dd0e8883c0021d8/eol_realign/data/links_inner.csv) and the [original `links_manifest_cargo_on_md5.csv`](https://huggingface.co/datasets/imageomics/ToL-EDA/blob/fa08e0f6692a013e4e4f5ca30dd0e8883c0021d8/eol_realign/data/links_manifest_cargo_on_md5.csv).
26
+ #
27
+ # From Matt:
28
+ # > It represents a series of inner merges:
29
+ # > 1. The list of images in the EOL cargo archive (used to create the webdatasets) with the EOL portion of `catalog.csv`
30
+ # > - Merged on a combined identifier of `eol_content_id` and `eol_page_id`.
31
+ # > Result from 1) with the list of images redownloaded from all 3 media manifests we touched around the original download time (identified [here](https://huggingface.co/datasets/imageomics/ToL-EDA/discussions/5#6584808d92eba5ad69b8379f)).
32
+ # > - Merged on MD5
33
+ # >
34
+ # > The result has 6,219,674 unique `treeoflife_id` entries and 6,146,917 unique `md5` entries. It has the combined `eol_content_id` and `eol_page_id` identifiers used at each stage:
35
+ # - `combined_id_catalog`: represents what's in the original catalog
36
+ # - `combined_id_manifest_full_manifest`: represents what's in the combined manifest from all 3 dates
37
+ # > It also has an indicator of which of the three media manifest files each entry was present in (one or more) in columns representing retreival date (eg., `source_0706`: indicates if it was present in the manifest retrieved on July 6, 2023). It also has the copyright owner and license information as contained in the media manifest files.
38
+ # >
39
+ # > Still needs to be run through the owner name finding code. ([owner_match](https://huggingface.co/datasets/imageomics/ToL-EDA/blob/71ad5b49226a3a49634931005eeb340b3c96db13/scripts/match_owners.py) --note: this version uses inner merges, so will remove entries without media info. Probably should adjust this.)
40
+ #
41
+ # For reference on the numbers, there are 6,250,420 EOL images in TreeOfLife-10M (the catalog). Comparing with `links_inner` previously (from [`links_inner.csv`](https://huggingface.co/datasets/imageomics/ToL-EDA/blob/fa08e0f6692a013e4e4f5ca30dd0e8883c0021d8/eol_realign/data/links_inner.csv)) we were missing 31,376 images, 29 of which were identified in [`links_manifest_cargo_on_md5.csv`](https://huggingface.co/datasets/imageomics/ToL-EDA/blob/fa08e0f6692a013e4e4f5ca30dd0e8883c0021d8/eol_realign/data/links_manifest_cargo_on_md5.csv).
42
 
43
  # %%
44
+ links_inner = pd.read_csv("../data/eol-cargo-archive_catalog_combined-manifest-checksums_links.csv", low_memory=False)
45
+ links_manifest_cargo = pd.read_csv("../data/eol-cargo-archive_combined-manifest-checksums_links.csv", low_memory=False)
46
 
47
  # %%
48
  links_inner.info(show_counts=True)
 
50
  # %%
51
  links_manifest_cargo.info(show_counts=True)
52
 
53
+ # %% [markdown]
54
+ # These both have about 600-700 more entries than the earlier files.
55
+
56
  # %%
57
+ # These should be the same
58
+ links_manifest_cargo.loc[links_manifest_cargo["combined_id_manifest_redownload"] != links_manifest_cargo["combined_id_full_manifest"]]
59
+
60
+ # %%
61
+ # archive has replaced cargo
62
+ # full manifest or manifest redownload to replace manifest checksums -- they are equal
63
+ links_mismatch = links_manifest_cargo.loc[links_manifest_cargo["combined_id_archive"] != links_manifest_cargo["combined_id_full_manifest"]]
64
  links_mismatch.info(show_counts = True)
65
 
66
+ # %% [markdown]
67
+ # There are 42 more mismatched entries. Only 13 additional unique images (MD5s).
68
+
69
  # %%
70
+ links_mismatch[["md5_archive", "combined_id_full_manifest", "combined_id_archive"]].nunique()
71
 
72
  # %%
73
+ # This is archive manifest mismatch
74
+ links_mismatch.to_csv("../data/links_archive_manifest_IDmismatch.csv", index = False)
75
 
76
  # %%
77
+ catalog = pd.read_csv(TOL_FILEPATH + "catalog.csv", low_memory=False)
78
 
79
  # %%
80
  # remove train_small and all non-EOL entries
 
108
  matched_catalog_ids = list(links_inner.combined_id_catalog.unique())
109
  len(matched_catalog_ids)
110
 
111
+ # %% [markdown]
112
+ # Here we go, we got an additional 630 matched IDs!
113
+
114
  # %%
115
  matched_catalog_ids[:5]
116
 
117
  # %% [markdown]
118
+ # We still have about 30K unmatched (as shown below, it's down to 30,746 from 31,376), let's find those in the catalog and then we'll try to merge with our mismatched cargo & manifest.
119
 
120
  # %%
121
  eol_catalog['combined_id_catalog'].sample(5)
 
128
  mismatched_catalog.nunique()
129
 
130
  # %% [markdown]
131
+ # Seems one class got resolved (equals more orders and down).
132
+
133
+ # %% [markdown]
134
+ # ## Merge with Mismatched CargoArchive-Manifest
135
  #
136
+ # let's merge with `links_mismatch` to see if the mismatched archive and manifest combined IDs can be linked up.
137
 
138
  # %%
139
+ # replace manifest checksums with full manifest as above
140
  links_catalog_mismatch = pd.merge(mismatched_catalog,
141
  links_mismatch,
142
  left_on = "combined_id_catalog",
143
+ right_on = "combined_id_full_manifest",
144
  how = "inner")
145
  links_catalog_mismatch.info(show_counts = True)
146
 
147
+ # %% [markdown]
148
+ # Now there's no gain from the mismatch file, but that was only 29 images, so we've captured them from the archive (plus more!).
149
+
150
  # %%
151
  mismatched_catalog.combined_id_catalog.sample(7)
152
 
153
  # %% [markdown]
154
  # These pages are reasonably full too: [5660435](https://eol.org/pages/5660435).
155
 
156
+ # %% [markdown]
157
+ # ### Final Catalog
158
+ #
159
+ # Our final EOL catalog is thus going to be the `treeoflife_id`s in `links_inner`.
160
+ #
161
+ # Finall question is just how does this look for our `train_small`?
162
+
163
+ # %%
164
+ cat_2 = pd.read_csv(TOL_FILEPATH + "catalog.csv", low_memory=False)
165
+
166
+ # reduce to just train_small and all non-EOL entries
167
+ cat_2 = cat_2.loc[cat_2.split == "train_small"]
168
+ eol_cat_2 = cat_2.loc[cat_2.eol_content_id.notna()]
169
+
170
+ eol_cat_2 = eol_cat_2[eol_cols]
171
+ eol_cat_2.info(show_counts=True)
172
+
173
+ # %% [markdown]
174
+ # So `train_small` has 593,764 images from EOL.
175
+ #
176
+ # Let's recast IDs as ints to match up with `links_inner` and check we have info for all of them.
177
+
178
+ # %%
179
+ eol_cat_2 = eol_cat_2.astype({"eol_content_id": "int64", "eol_page_id": "int64"})
180
+ eol_cat_2[eol_cols[:4]].info()
181
+
182
+ # %%
183
+ # make combined ID for catalog and add suffix to eol content and page IDs
184
+ eol_cat_2['combined_id_catalog'] = eol_cat_2['eol_content_id'].astype(str) + '_' + eol_cat_2['eol_page_id'].astype(str)
185
+ eol_cat_2.rename(columns={'eol_content_id': 'eol_content_id_catalog', 'eol_page_id': 'eol_page_id_catalog'}, inplace=True)
186
+
187
+ # %%
188
+ eol_ts_links = pd.merge(eol_cat_2,
189
+ links_inner[list(links_inner.columns)[18:]],
190
+ left_on = "combined_id_catalog",
191
+ right_on = "combined_id_full_manifest",
192
+ how = "inner")
193
+ eol_ts_links.info(show_counts = True)
194
+
195
+ # %%
196
+ eol_ts_links.treeoflife_id.nunique()
197
+
198
+ # %% [markdown]
199
+ # So we are missing the metadata for 3,734 of these images.
200
+
201
  # %% [markdown]
202
  # ## Check on Rare Species Catalog
203
 
 
215
  rs_links = pd.merge(rs_catalog,
216
  links_manifest_cargo,
217
  left_on = "combined_id_rs",
218
+ right_on = "combined_id_archive", # looking at archive
219
  how = "inner")
220
  rs_links.info(show_counts = True)
221
 
 
243
  links_rs_mismatch = pd.merge(mismatched_rs,
244
  links_mismatch,
245
  left_on = "combined_id_rs",
246
+ right_on = "combined_id_full_manifest",
247
  how = "inner")
248
  links_rs_mismatch.info(show_counts = True)
249