egrace479 commited on
Commit
3b215bc
·
verified ·
1 Parent(s): 3b50e8b

Add notebook generating the updated rare species catalog, lisences, and manifest files

Browse files
eol_realign/notebooks/re-gen_rs_catalog.ipynb ADDED
@@ -0,0 +1,712 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": "code",
14
+ "execution_count": 2,
15
+ "metadata": {},
16
+ "outputs": [],
17
+ "source": [
18
+ "RS_FILEPATH = \"../../rare_species/data/\""
19
+ ]
20
+ },
21
+ {
22
+ "cell_type": "markdown",
23
+ "metadata": {},
24
+ "source": [
25
+ "### Read in Complete Rare Species Manifest"
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: 22146 entries, 0 to 22145\n",
39
+ "Data columns (total 11 columns):\n",
40
+ " # Column Non-Null Count Dtype \n",
41
+ "--- ------ -------------- ----- \n",
42
+ " 0 filename 22146 non-null object\n",
43
+ " 1 md5 22146 non-null object\n",
44
+ " 2 combined_id 22146 non-null object\n",
45
+ " 3 eol_content_id 22146 non-null int64 \n",
46
+ " 4 eol_page_id 22146 non-null int64 \n",
47
+ " 5 medium_source_url 22146 non-null object\n",
48
+ " 6 eol_full_size_copy_url 22146 non-null object\n",
49
+ " 7 license_name 22146 non-null object\n",
50
+ " 8 copyright_owner 22146 non-null object\n",
51
+ " 9 title 22146 non-null object\n",
52
+ " 10 license_link 22103 non-null object\n",
53
+ "dtypes: int64(2), object(9)\n",
54
+ "memory usage: 1.9+ MB\n"
55
+ ]
56
+ }
57
+ ],
58
+ "source": [
59
+ "rs_manifest = pd.read_csv(\"../data/rarespecies_full_manifest.csv\",\n",
60
+ " low_memory=False,\n",
61
+ " dtype = {\"eol_content_id\": \"int64\", \"eol_page_id\": \"int64\"})\n",
62
+ "rs_manifest.info(show_counts = True)"
63
+ ]
64
+ },
65
+ {
66
+ "cell_type": "markdown",
67
+ "metadata": {},
68
+ "source": [
69
+ "## Read in Rare Species Catalog"
70
+ ]
71
+ },
72
+ {
73
+ "cell_type": "markdown",
74
+ "metadata": {},
75
+ "source": [
76
+ "Note that the original [`rarespecies-catalog`](https://huggingface.co/datasets/imageomics/ToL-EDA/blob/5db838a9db980f4cf96027b326b06e0f42df0c65/rare_species/data/rarespecies-catalog.csv) generation was done in [`rare_species_make_catalog.ipynb`](https://huggingface.co/datasets/imageomics/ToL-EDA/blob/5db838a9db980f4cf96027b326b06e0f42df0c65/rare_species/notebooks/rare_species_make_catalog.ipynb). It used [`predicted-catalog.csv`](https://huggingface.co/datasets/imageomics/ToL-EDA/blob/5db838a9db980f4cf96027b326b06e0f42df0c65/data/predicted-catalog.csv) to get the taxonomic information and align the [rare species cargo](https://huggingface.co/datasets/imageomics/ToL-EDA/blob/5db838a9db980f4cf96027b326b06e0f42df0c65/rare_species/data/rarespecies.csv) appropriately. There were also checks that the unseen subset was indeed excluded from the [catalog](https://huggingface.co/datasets/imageomics/ToL-EDA/blob/5db838a9db980f4cf96027b326b06e0f42df0c65/data/catalog.csv).\n",
77
+ "\n",
78
+ "We will use the [`rarespecies-catalog.csv`](https://huggingface.co/datasets/imageomics/ToL-EDA/blob/5db838a9db980f4cf96027b326b06e0f42df0c65/rare_species/data/rarespecies-catalog.csv) generated in that notebook to align taxonomic information with the full rare species manifest (renamed locally to `rarespecies-catalog-orig.csv`)."
79
+ ]
80
+ },
81
+ {
82
+ "cell_type": "code",
83
+ "execution_count": 4,
84
+ "metadata": {},
85
+ "outputs": [
86
+ {
87
+ "name": "stdout",
88
+ "output_type": "stream",
89
+ "text": [
90
+ "<class 'pandas.core.frame.DataFrame'>\n",
91
+ "RangeIndex: 12000 entries, 0 to 11999\n",
92
+ "Data columns (total 11 columns):\n",
93
+ " # Column Non-Null Count Dtype \n",
94
+ "--- ------ -------------- ----- \n",
95
+ " 0 rarespecies_id 12000 non-null object\n",
96
+ " 1 eol_content_id 12000 non-null int64 \n",
97
+ " 2 eol_page_id 12000 non-null int64 \n",
98
+ " 3 kingdom 12000 non-null object\n",
99
+ " 4 phylum 12000 non-null object\n",
100
+ " 5 class 12000 non-null object\n",
101
+ " 6 order 12000 non-null object\n",
102
+ " 7 family 12000 non-null object\n",
103
+ " 8 genus 12000 non-null object\n",
104
+ " 9 species 12000 non-null object\n",
105
+ " 10 sciName 12000 non-null object\n",
106
+ "dtypes: int64(2), object(9)\n",
107
+ "memory usage: 1.0+ MB\n"
108
+ ]
109
+ }
110
+ ],
111
+ "source": [
112
+ "rs_catalog = pd.read_csv(RS_FILEPATH + \"rarespecies-catalog-orig.csv\",\n",
113
+ " low_memory=False,\n",
114
+ " dtype = {\"eol_content_id\": \"int64\", \"eol_page_id\": \"int64\"})\n",
115
+ "rs_catalog.info(show_counts = True)"
116
+ ]
117
+ },
118
+ {
119
+ "cell_type": "markdown",
120
+ "metadata": {},
121
+ "source": [
122
+ "## Check Number of Images per Page"
123
+ ]
124
+ },
125
+ {
126
+ "cell_type": "code",
127
+ "execution_count": 5,
128
+ "metadata": {},
129
+ "outputs": [
130
+ {
131
+ "data": {
132
+ "text/plain": [
133
+ "22146"
134
+ ]
135
+ },
136
+ "execution_count": 5,
137
+ "metadata": {},
138
+ "output_type": "execute_result"
139
+ }
140
+ ],
141
+ "source": [
142
+ "rs_manifest[\"md5\"].nunique()"
143
+ ]
144
+ },
145
+ {
146
+ "cell_type": "markdown",
147
+ "metadata": {},
148
+ "source": [
149
+ "We should have at least 30 images per species, except for 5. Let's check the number of images for each species (all now included are unique, as demonstrated above)."
150
+ ]
151
+ },
152
+ {
153
+ "cell_type": "code",
154
+ "execution_count": 6,
155
+ "metadata": {
156
+ "lines_to_next_cell": 2
157
+ },
158
+ "outputs": [],
159
+ "source": [
160
+ "num_images_by_pg = {}\n",
161
+ "\n",
162
+ "for pg_id in list(rs_manifest.eol_page_id.unique()):\n",
163
+ " num_images = rs_manifest.loc[rs_manifest[\"eol_page_id\"] == pg_id].shape[0]\n",
164
+ " num_images_by_pg[pg_id] = num_images\n",
165
+ " rs_manifest.loc[rs_manifest[\"eol_page_id\"] == pg_id, \"num_images\"] = num_images\n"
166
+ ]
167
+ },
168
+ {
169
+ "cell_type": "code",
170
+ "execution_count": 7,
171
+ "metadata": {},
172
+ "outputs": [
173
+ {
174
+ "data": {
175
+ "text/plain": [
176
+ "93"
177
+ ]
178
+ },
179
+ "execution_count": 7,
180
+ "metadata": {},
181
+ "output_type": "execute_result"
182
+ }
183
+ ],
184
+ "source": [
185
+ "rs_manifest.num_images.nunique()"
186
+ ]
187
+ },
188
+ {
189
+ "cell_type": "markdown",
190
+ "metadata": {},
191
+ "source": [
192
+ "There's a lot of variety in the number of images per page. We'll check again on the (expected 5) pages that have less than 30 images."
193
+ ]
194
+ },
195
+ {
196
+ "cell_type": "code",
197
+ "execution_count": 8,
198
+ "metadata": {},
199
+ "outputs": [
200
+ {
201
+ "name": "stdout",
202
+ "output_type": "stream",
203
+ "text": [
204
+ "page ID 485420 has less than 30 unique images; it has 24 unique images\n",
205
+ "page ID 914531 has less than 30 unique images; it has 29 unique images\n",
206
+ "page ID 791049 has less than 30 unique images; it has 27 unique images\n",
207
+ "page ID 205714 has less than 30 unique images; it has 29 unique images\n",
208
+ "page ID 1286909 has less than 30 unique images; it has 27 unique images\n"
209
+ ]
210
+ }
211
+ ],
212
+ "source": [
213
+ "for pg_id in num_images_by_pg.keys():\n",
214
+ " if num_images_by_pg[pg_id] < 30:\n",
215
+ " print(f\"page ID {pg_id} has less than 30 unique images; it has {num_images_by_pg[pg_id]} unique images\")"
216
+ ]
217
+ },
218
+ {
219
+ "cell_type": "markdown",
220
+ "metadata": {},
221
+ "source": [
222
+ "https://eol.org/pages/485420/media has only 21 true images, since 3 are post-its. These will need to be manually noted and removed."
223
+ ]
224
+ },
225
+ {
226
+ "cell_type": "markdown",
227
+ "metadata": {},
228
+ "source": [
229
+ "### Reduce to 30 Images per Page"
230
+ ]
231
+ },
232
+ {
233
+ "cell_type": "markdown",
234
+ "metadata": {},
235
+ "source": [
236
+ "Now we need to reduce to just 30 images per page. We can realign the labels based on the page IDs from the `rarespecies_catalog`, but I won't be able to properly rematch the `rarespecies_id`, so that will need to be regenerated..."
237
+ ]
238
+ },
239
+ {
240
+ "cell_type": "code",
241
+ "execution_count": 9,
242
+ "metadata": {},
243
+ "outputs": [
244
+ {
245
+ "data": {
246
+ "text/plain": [
247
+ "22146"
248
+ ]
249
+ },
250
+ "execution_count": 9,
251
+ "metadata": {},
252
+ "output_type": "execute_result"
253
+ }
254
+ ],
255
+ "source": [
256
+ "# Is filename unique? --yes, 22146 is number of images in the full rarespecies manifest\n",
257
+ "rs_manifest.filename.nunique()"
258
+ ]
259
+ },
260
+ {
261
+ "cell_type": "code",
262
+ "execution_count": 15,
263
+ "metadata": {},
264
+ "outputs": [
265
+ {
266
+ "data": {
267
+ "text/plain": [
268
+ "keep\n",
269
+ "yes 11986\n",
270
+ "Name: count, dtype: int64"
271
+ ]
272
+ },
273
+ "execution_count": 15,
274
+ "metadata": {},
275
+ "output_type": "execute_result"
276
+ }
277
+ ],
278
+ "source": [
279
+ "img_list_by_page = {}\n",
280
+ "\n",
281
+ "for page_id in list(rs_manifest.eol_page_id.unique()):\n",
282
+ " temp = rs_manifest.loc[rs_manifest.eol_page_id == page_id]\n",
283
+ " if temp.num_images.values[0] > 30:\n",
284
+ " imgs_to_keep = list(temp.filename.sample(30, random_state = 614)) #seed for reproducibility\n",
285
+ " else:\n",
286
+ " imgs_to_keep = list(temp.filename)\n",
287
+ "\n",
288
+ " rs_manifest.loc[rs_manifest[\"filename\"].isin(imgs_to_keep), \"keep\"] = \"yes\"\n",
289
+ " img_list_by_page[page_id] = imgs_to_keep\n",
290
+ "\n",
291
+ "rs_manifest[\"keep\"].value_counts()"
292
+ ]
293
+ },
294
+ {
295
+ "cell_type": "markdown",
296
+ "metadata": {},
297
+ "source": [
298
+ "That's 14 less than 12000 images, which matches with the number of images we'd be reduced by due to the 5 pages that have less than 30 images."
299
+ ]
300
+ },
301
+ {
302
+ "cell_type": "code",
303
+ "execution_count": 16,
304
+ "metadata": {},
305
+ "outputs": [
306
+ {
307
+ "data": {
308
+ "text/plain": [
309
+ "filename 11986\n",
310
+ "md5 11986\n",
311
+ "combined_id 11986\n",
312
+ "eol_content_id 11986\n",
313
+ "eol_page_id 400\n",
314
+ "medium_source_url 11986\n",
315
+ "eol_full_size_copy_url 11986\n",
316
+ "license_name 15\n",
317
+ "copyright_owner 4164\n",
318
+ "title 1290\n",
319
+ "license_link 10\n",
320
+ "num_images 93\n",
321
+ "keep 1\n",
322
+ "dtype: int64"
323
+ ]
324
+ },
325
+ "execution_count": 16,
326
+ "metadata": {},
327
+ "output_type": "execute_result"
328
+ }
329
+ ],
330
+ "source": [
331
+ "reduced_rs_manifest = rs_manifest.loc[rs_manifest[\"keep\"] == \"yes\"]\n",
332
+ "\n",
333
+ "reduced_rs_manifest.nunique()"
334
+ ]
335
+ },
336
+ {
337
+ "cell_type": "code",
338
+ "execution_count": 17,
339
+ "metadata": {},
340
+ "outputs": [
341
+ {
342
+ "data": {
343
+ "text/plain": [
344
+ "num_images\n",
345
+ "30.0 11850\n",
346
+ "29.0 58\n",
347
+ "27.0 54\n",
348
+ "24.0 24\n",
349
+ "Name: count, dtype: int64"
350
+ ]
351
+ },
352
+ "execution_count": 17,
353
+ "metadata": {},
354
+ "output_type": "execute_result"
355
+ }
356
+ ],
357
+ "source": [
358
+ "for pg_id in list(reduced_rs_manifest.eol_page_id.unique()):\n",
359
+ " num_images = reduced_rs_manifest.loc[reduced_rs_manifest[\"eol_page_id\"] == pg_id].shape[0]\n",
360
+ " reduced_rs_manifest.loc[reduced_rs_manifest[\"eol_page_id\"] == pg_id, \"num_images\"] = num_images\n",
361
+ "\n",
362
+ "reduced_rs_manifest[\"num_images\"].value_counts()"
363
+ ]
364
+ },
365
+ {
366
+ "cell_type": "markdown",
367
+ "metadata": {},
368
+ "source": [
369
+ "One page has only 24, two have 27 & 29, the remaining 395 pages have 30.\n",
370
+ "\n",
371
+ "Let's track down those 3 post-it images on page 485420."
372
+ ]
373
+ },
374
+ {
375
+ "cell_type": "code",
376
+ "execution_count": 19,
377
+ "metadata": {},
378
+ "outputs": [
379
+ {
380
+ "name": "stdout",
381
+ "output_type": "stream",
382
+ "text": [
383
+ "https://eol.org/media/29856158\n",
384
+ "https://eol.org/media/28605134\n",
385
+ "https://eol.org/media/14677205\n",
386
+ "https://eol.org/media/28605135\n",
387
+ "https://eol.org/media/29856162\n",
388
+ "https://eol.org/media/29856156\n",
389
+ "https://eol.org/media/29856167\n",
390
+ "https://eol.org/media/29856165\n",
391
+ "https://eol.org/media/29856163\n",
392
+ "https://eol.org/media/29856157\n",
393
+ "https://eol.org/media/14677203\n",
394
+ "https://eol.org/media/29856159\n",
395
+ "https://eol.org/media/28605131\n",
396
+ "https://eol.org/media/29856155\n",
397
+ "https://eol.org/media/29856151\n",
398
+ "https://eol.org/media/29856161\n",
399
+ "https://eol.org/media/14677207\n",
400
+ "https://eol.org/media/29856150\n",
401
+ "https://eol.org/media/29856164\n",
402
+ "https://eol.org/media/14677204\n",
403
+ "https://eol.org/media/28605132\n",
404
+ "https://eol.org/media/28605133\n",
405
+ "https://eol.org/media/28605130\n",
406
+ "https://eol.org/media/29856166\n"
407
+ ]
408
+ }
409
+ ],
410
+ "source": [
411
+ "for content_id in list(reduced_rs_manifest.loc[reduced_rs_manifest[\"eol_page_id\"] == 485420, \"eol_content_id\"]):\n",
412
+ " print(f\"https://eol.org/media/{content_id}\")\n"
413
+ ]
414
+ },
415
+ {
416
+ "cell_type": "markdown",
417
+ "metadata": {},
418
+ "source": [
419
+ "Post-it image EOL Content IDs (unique in this DataFrame):\n",
420
+ "- [28605134](https://eol.org/media/28605134)\n",
421
+ "- [29856159](https://eol.org/media/29856159)\n",
422
+ "- [29856164](https://eol.org/media/29856164)"
423
+ ]
424
+ },
425
+ {
426
+ "cell_type": "code",
427
+ "execution_count": 21,
428
+ "metadata": {},
429
+ "outputs": [
430
+ {
431
+ "data": {
432
+ "text/plain": [
433
+ "filename 11983\n",
434
+ "md5 11983\n",
435
+ "combined_id 11983\n",
436
+ "eol_content_id 11983\n",
437
+ "eol_page_id 400\n",
438
+ "medium_source_url 11983\n",
439
+ "eol_full_size_copy_url 11983\n",
440
+ "license_name 15\n",
441
+ "copyright_owner 4164\n",
442
+ "title 1290\n",
443
+ "license_link 10\n",
444
+ "num_images 4\n",
445
+ "keep 1\n",
446
+ "dtype: int64"
447
+ ]
448
+ },
449
+ "execution_count": 21,
450
+ "metadata": {},
451
+ "output_type": "execute_result"
452
+ }
453
+ ],
454
+ "source": [
455
+ "post_its = [28605134, 29856159, 29856164]\n",
456
+ "\n",
457
+ "rarespecies_manifest = reduced_rs_manifest.loc[~reduced_rs_manifest[\"eol_content_id\"].isin(post_its)]\n",
458
+ "rarespecies_manifest.nunique()"
459
+ ]
460
+ },
461
+ {
462
+ "cell_type": "markdown",
463
+ "metadata": {},
464
+ "source": [
465
+ "Remove extra columns"
466
+ ]
467
+ },
468
+ {
469
+ "cell_type": "code",
470
+ "execution_count": 22,
471
+ "metadata": {},
472
+ "outputs": [
473
+ {
474
+ "data": {
475
+ "text/plain": [
476
+ "Index(['filename', 'md5', 'combined_id', 'eol_content_id', 'eol_page_id',\n",
477
+ " 'medium_source_url', 'eol_full_size_copy_url', 'license_name',\n",
478
+ " 'copyright_owner', 'title', 'license_link'],\n",
479
+ " dtype='object')"
480
+ ]
481
+ },
482
+ "execution_count": 22,
483
+ "metadata": {},
484
+ "output_type": "execute_result"
485
+ }
486
+ ],
487
+ "source": [
488
+ "rarespecies_manifest = rarespecies_manifest[list(rarespecies_manifest.columns)[:-2]]\n",
489
+ "rarespecies_manifest.columns"
490
+ ]
491
+ },
492
+ {
493
+ "cell_type": "markdown",
494
+ "metadata": {},
495
+ "source": [
496
+ "### Add `uuid` (new `rarespecies_id`)"
497
+ ]
498
+ },
499
+ {
500
+ "cell_type": "code",
501
+ "execution_count": 25,
502
+ "metadata": {},
503
+ "outputs": [],
504
+ "source": [
505
+ "import uuid"
506
+ ]
507
+ },
508
+ {
509
+ "cell_type": "code",
510
+ "execution_count": 26,
511
+ "metadata": {},
512
+ "outputs": [
513
+ {
514
+ "data": {
515
+ "text/plain": [
516
+ "11983"
517
+ ]
518
+ },
519
+ "execution_count": 26,
520
+ "metadata": {},
521
+ "output_type": "execute_result"
522
+ }
523
+ ],
524
+ "source": [
525
+ "rarespecies_manifest[\"rarespecies_id\"] = [uuid.uuid4() for i in range(rarespecies_manifest.shape[0])]\n",
526
+ "rarespecies_manifest.rarespecies_id.nunique()"
527
+ ]
528
+ },
529
+ {
530
+ "cell_type": "markdown",
531
+ "metadata": {},
532
+ "source": [
533
+ "### Save Manifest with `uuid`s"
534
+ ]
535
+ },
536
+ {
537
+ "cell_type": "code",
538
+ "execution_count": 27,
539
+ "metadata": {},
540
+ "outputs": [],
541
+ "source": [
542
+ "rarespecies_manifest.to_csv(RS_FILEPATH + \"rarespecies_manifest.csv\", index = False)"
543
+ ]
544
+ },
545
+ {
546
+ "cell_type": "markdown",
547
+ "metadata": {},
548
+ "source": [
549
+ "### Make and Save License File"
550
+ ]
551
+ },
552
+ {
553
+ "cell_type": "code",
554
+ "execution_count": 28,
555
+ "metadata": {},
556
+ "outputs": [],
557
+ "source": [
558
+ "licesne_cols = [\"rarespecies_id\",\n",
559
+ " \"eol_content_id\",\n",
560
+ " \"eol_page_id\",\n",
561
+ " \"md5\",\n",
562
+ " \"medium_source_url\",\n",
563
+ " \"eol_full_size_copy_url\",\n",
564
+ " \"license_name\",\n",
565
+ " \"copyright_owner\",\n",
566
+ " \"license_link\",\n",
567
+ " \"title\"]\n",
568
+ "\n",
569
+ "licenses = rarespecies_manifest[licesne_cols]"
570
+ ]
571
+ },
572
+ {
573
+ "cell_type": "code",
574
+ "execution_count": 29,
575
+ "metadata": {},
576
+ "outputs": [],
577
+ "source": [
578
+ "licenses.to_csv(RS_FILEPATH + \"licenses.csv\", index = False)"
579
+ ]
580
+ },
581
+ {
582
+ "cell_type": "markdown",
583
+ "metadata": {},
584
+ "source": [
585
+ "## Make Rare Species Catalog\n",
586
+ "\n",
587
+ "Align taxonomic information to the IDs in the manifest."
588
+ ]
589
+ },
590
+ {
591
+ "cell_type": "code",
592
+ "execution_count": 30,
593
+ "metadata": {},
594
+ "outputs": [],
595
+ "source": [
596
+ "id_cols = [\"rarespecies_id\", \"eol_content_id\", \"eol_page_id\"]"
597
+ ]
598
+ },
599
+ {
600
+ "cell_type": "code",
601
+ "execution_count": 31,
602
+ "metadata": {},
603
+ "outputs": [
604
+ {
605
+ "data": {
606
+ "text/plain": [
607
+ "['eol_page_id',\n",
608
+ " 'kingdom',\n",
609
+ " 'phylum',\n",
610
+ " 'class',\n",
611
+ " 'order',\n",
612
+ " 'family',\n",
613
+ " 'genus',\n",
614
+ " 'species',\n",
615
+ " 'sciName']"
616
+ ]
617
+ },
618
+ "execution_count": 31,
619
+ "metadata": {},
620
+ "output_type": "execute_result"
621
+ }
622
+ ],
623
+ "source": [
624
+ "cat_cols = list(rs_catalog.columns)[2:]\n",
625
+ "cat_cols"
626
+ ]
627
+ },
628
+ {
629
+ "cell_type": "code",
630
+ "execution_count": 32,
631
+ "metadata": {},
632
+ "outputs": [
633
+ {
634
+ "data": {
635
+ "text/plain": [
636
+ "rarespecies_id 11983\n",
637
+ "eol_content_id 11983\n",
638
+ "eol_page_id 400\n",
639
+ "kingdom 1\n",
640
+ "phylum 5\n",
641
+ "class 15\n",
642
+ "order 85\n",
643
+ "family 202\n",
644
+ "genus 316\n",
645
+ "species 385\n",
646
+ "sciName 400\n",
647
+ "dtype: int64"
648
+ ]
649
+ },
650
+ "execution_count": 32,
651
+ "metadata": {},
652
+ "output_type": "execute_result"
653
+ }
654
+ ],
655
+ "source": [
656
+ "updated_catalog = pd.merge(rarespecies_manifest[id_cols],\n",
657
+ " rs_catalog[cat_cols],\n",
658
+ " on = \"eol_page_id\",\n",
659
+ " how = \"left\")\n",
660
+ "\n",
661
+ "updated_catalog.nunique()"
662
+ ]
663
+ },
664
+ {
665
+ "cell_type": "markdown",
666
+ "metadata": {},
667
+ "source": [
668
+ "Looks good, precisely as expected. Let's save this to a CSV now."
669
+ ]
670
+ },
671
+ {
672
+ "cell_type": "code",
673
+ "execution_count": 33,
674
+ "metadata": {},
675
+ "outputs": [],
676
+ "source": [
677
+ "updated_catalog.to_csv(RS_FILEPATH + \"rarespecies-catalog.csv\", index = False)"
678
+ ]
679
+ },
680
+ {
681
+ "cell_type": "code",
682
+ "execution_count": null,
683
+ "metadata": {},
684
+ "outputs": [],
685
+ "source": []
686
+ }
687
+ ],
688
+ "metadata": {
689
+ "jupytext": {
690
+ "formats": "ipynb,py:percent"
691
+ },
692
+ "kernelspec": {
693
+ "display_name": "tol",
694
+ "language": "python",
695
+ "name": "python3"
696
+ },
697
+ "language_info": {
698
+ "codemirror_mode": {
699
+ "name": "ipython",
700
+ "version": 3
701
+ },
702
+ "file_extension": ".py",
703
+ "mimetype": "text/x-python",
704
+ "name": "python",
705
+ "nbconvert_exporter": "python",
706
+ "pygments_lexer": "ipython3",
707
+ "version": "3.11.3"
708
+ }
709
+ },
710
+ "nbformat": 4,
711
+ "nbformat_minor": 2
712
+ }