{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "RS_FILEPATH = \"../../rare_species/data/\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Read in Links CSV file\n", "\n", "Full cargo archive has some more content than 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)." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "links_manifest_cargo = pd.read_csv(\"../data/eol-cargo-archive_combined-manifest-checksums_links.csv\", low_memory=False)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 7514001 entries, 0 to 7514000\n", "Data columns (total 17 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 filename_archive 7514001 non-null object\n", " 1 md5_archive 7514001 non-null object\n", " 2 combined_id_archive 7514001 non-null object\n", " 3 filename_manifest 7514001 non-null object\n", " 4 md5_combined_manifest 7514001 non-null object\n", " 5 combined_id_manifest_redownload 7514001 non-null object\n", " 6 eol_content_id 7514001 non-null int64 \n", " 7 eol_page_id 7514001 non-null int64 \n", " 8 medium_source_url 7514001 non-null object\n", " 9 eol_full_size_copy_url 7514001 non-null object\n", " 10 license_name 7514001 non-null object\n", " 11 copyright_owner 6860825 non-null object\n", " 12 expected_image_filename 7514001 non-null object\n", " 13 source_0706 7514001 non-null bool \n", " 14 source_0726 7514001 non-null bool \n", " 15 source_1206 7514001 non-null bool \n", " 16 combined_id_full_manifest 7514001 non-null object\n", "dtypes: bool(3), int64(2), object(12)\n", "memory usage: 824.1+ MB\n" ] } ], "source": [ "links_manifest_cargo.info(show_counts=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Check on Rare Species Catalog" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 12000 entries, 0 to 11999\n", "Data columns (total 11 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 rarespecies_id 12000 non-null object\n", " 1 eol_content_id 12000 non-null int64 \n", " 2 eol_page_id 12000 non-null int64 \n", " 3 kingdom 12000 non-null object\n", " 4 phylum 12000 non-null object\n", " 5 class 12000 non-null object\n", " 6 order 12000 non-null object\n", " 7 family 12000 non-null object\n", " 8 genus 12000 non-null object\n", " 9 species 12000 non-null object\n", " 10 sciName 12000 non-null object\n", "dtypes: int64(2), object(9)\n", "memory usage: 1.0+ MB\n" ] } ], "source": [ "rs_catalog = pd.read_csv(RS_FILEPATH + \"rarespecies-catalog.csv\",\n", " low_memory=False,\n", " dtype = {\"eol_content_id\": \"int64\", \"eol_page_id\": \"int64\"})\n", "rs_catalog.info(show_counts = True)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "rs_catalog[\"combined_id_rs\"] = rs_catalog[\"eol_content_id\"].astype(str) + \"_\" + rs_catalog[\"eol_page_id\"].astype(str)\n", "rs_catalog.rename(columns={'eol_content_id': 'eol_content_id_rs', 'eol_page_id': 'eol_page_id_rs'}, inplace=True)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 12552 entries, 0 to 12551\n", "Data columns (total 29 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 rarespecies_id 12552 non-null object\n", " 1 eol_content_id_rs 12552 non-null int64 \n", " 2 eol_page_id_rs 12552 non-null int64 \n", " 3 kingdom 12552 non-null object\n", " 4 phylum 12552 non-null object\n", " 5 class 12552 non-null object\n", " 6 order 12552 non-null object\n", " 7 family 12552 non-null object\n", " 8 genus 12552 non-null object\n", " 9 species 12552 non-null object\n", " 10 sciName 12552 non-null object\n", " 11 combined_id_rs 12552 non-null object\n", " 12 filename_archive 12552 non-null object\n", " 13 md5_archive 12552 non-null object\n", " 14 combined_id_archive 12552 non-null object\n", " 15 filename_manifest 12552 non-null object\n", " 16 md5_combined_manifest 12552 non-null object\n", " 17 combined_id_manifest_redownload 12552 non-null object\n", " 18 eol_content_id 12552 non-null int64 \n", " 19 eol_page_id 12552 non-null int64 \n", " 20 medium_source_url 12552 non-null object\n", " 21 eol_full_size_copy_url 12552 non-null object\n", " 22 license_name 12552 non-null object\n", " 23 copyright_owner 11171 non-null object\n", " 24 expected_image_filename 12552 non-null object\n", " 25 source_0706 12552 non-null bool \n", " 26 source_0726 12552 non-null bool \n", " 27 source_1206 12552 non-null bool \n", " 28 combined_id_full_manifest 12552 non-null object\n", "dtypes: bool(3), int64(4), object(22)\n", "memory usage: 2.5+ MB\n" ] } ], "source": [ "rs_links = pd.merge(rs_catalog,\n", " links_manifest_cargo,\n", " left_on = \"combined_id_rs\",\n", " right_on = \"combined_id_archive\", # merge on archive (replaced cargo)\n", " how = \"inner\")\n", "rs_links.info(show_counts = True)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "rarespecies_id 11826\n", "eol_content_id_rs 11826\n", "eol_page_id_rs 400\n", "kingdom 1\n", "phylum 5\n", "class 15\n", "order 85\n", "family 202\n", "genus 316\n", "species 385\n", "sciName 400\n", "combined_id_rs 11826\n", "filename_archive 11826\n", "md5_archive 11663\n", "combined_id_archive 11826\n", "filename_manifest 12221\n", "md5_combined_manifest 11663\n", "combined_id_manifest_redownload 12221\n", "eol_content_id 12221\n", "eol_page_id 447\n", "medium_source_url 12056\n", "eol_full_size_copy_url 12119\n", "license_name 15\n", "copyright_owner 3724\n", "expected_image_filename 12221\n", "source_0706 2\n", "source_0726 2\n", "source_1206 2\n", "combined_id_full_manifest 12221\n", "dtype: int64" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rs_links.nunique()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "All these numbers match our check with the cargo file." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's check the mismatched cargo/manifest entries for those last 174..." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "matched_rs_ids = list(rs_links.combined_id_rs.unique())\n", "len(matched_rs_ids)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['22519448_914532',\n", " '28677580_1057176',\n", " '20714475_47047909',\n", " '29975068_45509269']" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "matched_rs_ids[:4]" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "5890 20469929_326451\n", "11023 28478387_46559744\n", "409 22582812_51263523\n", "5166 22180215_2984557\n", "Name: combined_id_rs, dtype: object" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rs_catalog[\"combined_id_rs\"].sample(4)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Index: 174 entries, 163 to 11990\n", "Data columns (total 12 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 rarespecies_id 174 non-null object\n", " 1 eol_content_id_rs 174 non-null int64 \n", " 2 eol_page_id_rs 174 non-null int64 \n", " 3 kingdom 174 non-null object\n", " 4 phylum 174 non-null object\n", " 5 class 174 non-null object\n", " 6 order 174 non-null object\n", " 7 family 174 non-null object\n", " 8 genus 174 non-null object\n", " 9 species 174 non-null object\n", " 10 sciName 174 non-null object\n", " 11 combined_id_rs 174 non-null object\n", "dtypes: int64(2), object(10)\n", "memory usage: 17.7+ KB\n" ] } ], "source": [ "mismatched_rs = rs_catalog.loc[~rs_catalog[\"combined_id_rs\"].isin(matched_rs_ids)]\n", "mismatched_rs.info(show_counts = True)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "rarespecies_id 174\n", "eol_content_id_rs 174\n", "eol_page_id_rs 34\n", "kingdom 1\n", "phylum 2\n", "class 7\n", "order 22\n", "family 28\n", "genus 31\n", "species 33\n", "sciName 34\n", "combined_id_rs 174\n", "dtype: int64" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mismatched_rs.nunique()" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "sciName\n", "Aonyx capensis 27\n", "Zoogoneticus tequila 27\n", "Sousa plumbea 17\n", "Sylvilagus transitionalis 16\n", "Scaphirhynchus albus 16\n", "Raja asterias 9\n", "Tursiops aduncus 6\n", "Dalatias licha 6\n", "Alopias vulpinus 5\n", "Hexanchus griseus 5\n", "Myliobatis aquila 5\n", "Bathytoshia centroura 4\n", "Rostroraja alba 3\n", "Sylvilagus brasiliensis 3\n", "Microcebus rufus 2\n", "Glyptemys muhlenbergii 2\n", "Crocodylus rhombifer 2\n", "Cercopithecus mona 2\n", "Harpia harpyja 2\n", "Certhidea olivacea 1\n", "Lachnolaimus maximus 1\n", "Carcharhinus amblyrhynchos 1\n", "Mantella aurantiaca 1\n", "Piliocolobus tephrosceles 1\n", "Raja undulata 1\n", "Luehdorfia japonica 1\n", "Trogon bairdii 1\n", "Phoebastria albatrus 1\n", "Carcharhinus melanopterus 1\n", "Cetorhinus maximus 1\n", "Desmognathus imitator 1\n", "Phyllobates vittatus 1\n", "Centrochelys sulcata 1\n", "Eulemur fulvus 1\n", "Name: count, dtype: int64" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mismatched_rs.sciName.value_counts()" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "big_sciNames_missing = [\"Aonyx capensis\",\n", " \"Zoogoneticus tequila\",\n", " \"Sousa plumbea\",\n", " \"Sylvilagus transitionalis\",\n", " \"Scaphirhynchus albus\",\n", " \"Raja asterias\"]" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[array([46559139]),\n", " array([208913]),\n", " array([46559307]),\n", " array([1011315]),\n", " array([205909]),\n", " array([46560546])]" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pg_ids = []\n", "for sciName in big_sciNames_missing:\n", " pg_ids.append(rs_links.loc[rs_links[\"sciName\"] == sciName, \"eol_page_id\"].unique())\n", "pg_ids" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[(46559139, 16),\n", " (208913, 4),\n", " (46559307, 22),\n", " (1011315, 22),\n", " (205909, 28),\n", " (46560546, 24)]" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "num_images_by_pg = []\n", "for pg_id in pg_ids:\n", " num_images = links_manifest_cargo.loc[links_manifest_cargo[\"eol_page_id\"] == pg_id[0]].shape[0]\n", " num_images_by_pg.append((pg_id[0], num_images))\n", "\n", "num_images_by_pg" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The media for both of these last two is online: https://eol.org/pages/46560546/media, https://eol.org/pages/205909/media" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
rarespecies_ideol_content_id_rseol_page_id_rskingdomphylumclassorderfamilygenusspeciessciNamecombined_id_rs
1413d239159f-cb15-4c30-8aeb-d8177f8cf34a30098492205909AnimaliaChordataActinopterygiiAcipenseriformesAcipenseridaeScaphirhynchusalbusScaphirhynchus albus30098492_205909
76194d7436d1-82de-416b-8a51-6452efd45f4430098515205909AnimaliaChordataActinopterygiiAcipenseriformesAcipenseridaeScaphirhynchusalbusScaphirhynchus albus30098515_205909
79162d342a7c-7e0c-4981-9630-019bb90183be30098499205909AnimaliaChordataActinopterygiiAcipenseriformesAcipenseridaeScaphirhynchusalbusScaphirhynchus albus30098499_205909
11026a9560f41-403d-46a0-a92a-9694cceffe9630098523205909AnimaliaChordataActinopterygiiAcipenseriformesAcipenseridaeScaphirhynchusalbusScaphirhynchus albus30098523_205909
193ba2857c7-f02d-44f9-a116-8a450dc53e1430098516205909AnimaliaChordataActinopterygiiAcipenseriformesAcipenseridaeScaphirhynchusalbusScaphirhynchus albus30098516_205909
\n", "
" ], "text/plain": [ " rarespecies_id eol_content_id_rs \\\n", "1413 d239159f-cb15-4c30-8aeb-d8177f8cf34a 30098492 \n", "7619 4d7436d1-82de-416b-8a51-6452efd45f44 30098515 \n", "7916 2d342a7c-7e0c-4981-9630-019bb90183be 30098499 \n", "11026 a9560f41-403d-46a0-a92a-9694cceffe96 30098523 \n", "193 ba2857c7-f02d-44f9-a116-8a450dc53e14 30098516 \n", "\n", " eol_page_id_rs kingdom phylum class order \\\n", "1413 205909 Animalia Chordata Actinopterygii Acipenseriformes \n", "7619 205909 Animalia Chordata Actinopterygii Acipenseriformes \n", "7916 205909 Animalia Chordata Actinopterygii Acipenseriformes \n", "11026 205909 Animalia Chordata Actinopterygii Acipenseriformes \n", "193 205909 Animalia Chordata Actinopterygii Acipenseriformes \n", "\n", " family genus species sciName \\\n", "1413 Acipenseridae Scaphirhynchus albus Scaphirhynchus albus \n", "7619 Acipenseridae Scaphirhynchus albus Scaphirhynchus albus \n", "7916 Acipenseridae Scaphirhynchus albus Scaphirhynchus albus \n", "11026 Acipenseridae Scaphirhynchus albus Scaphirhynchus albus \n", "193 Acipenseridae Scaphirhynchus albus Scaphirhynchus albus \n", "\n", " combined_id_rs \n", "1413 30098492_205909 \n", "7619 30098515_205909 \n", "7916 30098499_205909 \n", "11026 30098523_205909 \n", "193 30098516_205909 " ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "big_mismatch = mismatched_rs.loc[mismatched_rs[\"sciName\"].isin(big_sciNames_missing)]\n", "big_mismatch.loc[big_mismatch[\"eol_page_id_rs\"] == 205909].sample(5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "sampling some, they're \"not in any collections\": https://eol.org/media/30098484" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
rarespecies_ideol_content_id_rseol_page_id_rskingdomphylumclassorderfamilygenusspeciessciNamecombined_id_rs
970292da8fa4-fb94-42b3-9483-86d2672d66442764816546560546AnimaliaChordataChondrichthyesRajiformesRajidaeRajaasteriasRaja asterias27648165_46560546
365512633820-3a3a-4c77-bd38-7221bd18b7472764815746560546AnimaliaChordataChondrichthyesRajiformesRajidaeRajaasteriasRaja asterias27648157_46560546
20256cb50905-48ee-4770-9605-91a95e3d027c2764815946560546AnimaliaChordataChondrichthyesRajiformesRajidaeRajaasteriasRaja asterias27648159_46560546
1358d436ec20-202d-44ec-9081-ca59afef356f2764816646560546AnimaliaChordataChondrichthyesRajiformesRajidaeRajaasteriasRaja asterias27648166_46560546
6574a7c43306-6a3a-4d94-b7f0-147ad9f20a732764816046560546AnimaliaChordataChondrichthyesRajiformesRajidaeRajaasteriasRaja asterias27648160_46560546
\n", "
" ], "text/plain": [ " rarespecies_id eol_content_id_rs eol_page_id_rs \\\n", "9702 92da8fa4-fb94-42b3-9483-86d2672d6644 27648165 46560546 \n", "3655 12633820-3a3a-4c77-bd38-7221bd18b747 27648157 46560546 \n", "2025 6cb50905-48ee-4770-9605-91a95e3d027c 27648159 46560546 \n", "1358 d436ec20-202d-44ec-9081-ca59afef356f 27648166 46560546 \n", "6574 a7c43306-6a3a-4d94-b7f0-147ad9f20a73 27648160 46560546 \n", "\n", " kingdom phylum class order family genus species \\\n", "9702 Animalia Chordata Chondrichthyes Rajiformes Rajidae Raja asterias \n", "3655 Animalia Chordata Chondrichthyes Rajiformes Rajidae Raja asterias \n", "2025 Animalia Chordata Chondrichthyes Rajiformes Rajidae Raja asterias \n", "1358 Animalia Chordata Chondrichthyes Rajiformes Rajidae Raja asterias \n", "6574 Animalia Chordata Chondrichthyes Rajiformes Rajidae Raja asterias \n", "\n", " sciName combined_id_rs \n", "9702 Raja asterias 27648165_46560546 \n", "3655 Raja asterias 27648157_46560546 \n", "2025 Raja asterias 27648159_46560546 \n", "1358 Raja asterias 27648166_46560546 \n", "6574 Raja asterias 27648160_46560546 " ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "big_mismatch.loc[big_mismatch[\"eol_page_id_rs\"] == 46560546].sample(5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Meanwhile, these are giving me 404's: 27648160, 27648159, 27648164, 27648161, 27648166" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def get_archive_content(combined_id):\n", " return combined_id.split(\"_\")[0]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "links_manifest_cargo[\"eol_content_id_archive\"] = links_manifest_cargo[\"combined_id_archive\"].apply(get_archive_content)" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
filename_archivemd5_archivecombined_id_archivefilename_manifestmd5_combined_manifestcombined_id_manifest_redownloadeol_content_ideol_page_idmedium_source_urleol_full_size_copy_urllicense_namecopyright_ownerexpected_image_filenamesource_0706source_0726source_1206combined_id_full_manifesteol_content_id_archive
\n", "
" ], "text/plain": [ "Empty DataFrame\n", "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, eol_content_id_archive]\n", "Index: []" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# check if content IDs get recycled, content ID: 27648165, now online as: 30223317\n", "# is eol_content_id the archive content ID?\n", "links_manifest_cargo.loc[links_manifest_cargo[\"eol_content_id_archive\"] == 30223317]" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
filename_archivemd5_archivecombined_id_archivefilename_manifestmd5_combined_manifestcombined_id_manifest_redownloadeol_content_ideol_page_idmedium_source_urleol_full_size_copy_urllicense_namecopyright_ownerexpected_image_filenamesource_0706source_0726source_1206combined_id_full_manifesteol_content_id_archive
\n", "
" ], "text/plain": [ "Empty DataFrame\n", "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, eol_content_id_archive]\n", "Index: []" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Is it in manifest?\n", "links_manifest_cargo.loc[links_manifest_cargo[\"eol_content_id\"] == 30223317]" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
filename_archivemd5_archivecombined_id_archivefilename_manifestmd5_combined_manifestcombined_id_manifest_redownloadeol_content_ideol_page_idmedium_source_urleol_full_size_copy_urllicense_namecopyright_ownerexpected_image_filenamesource_0706source_0726source_1206combined_id_full_manifesteol_content_id_archiveeol_content_id_manifest
\n", "
" ], "text/plain": [ "Empty DataFrame\n", "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, eol_content_id_archive, eol_content_id_manifest]\n", "Index: []" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# to be sure we check manifest\n", "links_manifest_cargo[\"eol_content_id_manifest\"] = links_manifest_cargo[\"combined_id_full_manifest\"].apply(get_archive_content)\n", "\n", "links_manifest_cargo.loc[links_manifest_cargo[\"eol_content_id_manifest\"] == 30223317]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This tracks with all eol content IDs being unique across manifest versions...would there be some other intermediate stage where it changed IDs _again_?!" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [], "source": [ "# Save CSV of mismatched, they should be salvageable.\n", "# We saw these images both online and in our cargo, just with different IDs\n", "\n", "mismatched_rs.to_csv(\"../data/archive_mismatched_rarespecies.csv\", index=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Investigate Duplication\n", "\n", "Now I want some more info on those duplicated MD5's." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "rs_links[\"md5_dupes\"] = rs_links.duplicated(subset = \"md5_archive\", keep = \"first\")\n", "rs_links[\"rs_id_dupes\"] = rs_links.duplicated(subset = \"rarespecies_id\", keep = \"first\")" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "md5_dupes\n", "True 726\n", "Name: count, dtype: int64" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rs_links.loc[rs_links[\"rs_id_dupes\"], \"md5_dupes\"].value_counts()" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "md5_dupes\n", "False 11663\n", "True 163\n", "Name: count, dtype: int64" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rs_links.loc[~rs_links[\"rs_id_dupes\"], \"md5_dupes\"].value_counts()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Looks like we have 163 duplicated images in Rare Species..." ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "rarespecies_id 163\n", "eol_content_id_rs 163\n", "eol_page_id_rs 80\n", "kingdom 1\n", "phylum 4\n", "class 9\n", "order 37\n", "family 56\n", "genus 73\n", "species 80\n", "sciName 80\n", "combined_id_rs 163\n", "filename_archive 163\n", "md5_archive 163\n", "combined_id_archive 163\n", "filename_manifest 163\n", "md5_combined_manifest 163\n", "combined_id_manifest_redownload 163\n", "eol_content_id 163\n", "eol_page_id 80\n", "medium_source_url 163\n", "eol_full_size_copy_url 163\n", "license_name 10\n", "copyright_owner 54\n", "expected_image_filename 163\n", "source_0706 2\n", "source_0726 2\n", "source_1206 2\n", "combined_id_full_manifest 163\n", "md5_dupes 1\n", "rs_id_dupes 1\n", "dtype: int64" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rs = rs_links.loc[~rs_links[\"rs_id_dupes\"]]\n", "rs_dupes = rs.loc[rs[\"md5_dupes\"]]\n", "rs_dupes.nunique()" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "sciName\n", "Calumma ambreense 7\n", "Acanthochelys macrocephala 7\n", "Polyergus nigerrimus 7\n", "Pheidole elecebra 6\n", "Nothomyrmecia macrops 6\n", "Callorhinchus callorynchus 5\n", "Atelopus flavescens 5\n", "Adetomyrma venatrix 5\n", "Pleurodeles waltl 4\n", "Orcaella brevirostris 4\n", "Name: count, dtype: int64" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rs_dupes.sciName.value_counts()[:10]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's see how many images we have for each of these duplicated images." ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[4453333, 460289, 45277122, 46561158, 1286909, 45510188, 45510548, 791049]" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rs_sci_dupe_pgs = list(rs_dupes.eol_page_id.unique())\n", "rs_sci_dupe_pgs[:8]" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "lines_to_next_cell": 2 }, "outputs": [], "source": [ "num_images_by_pg = {}\n", "#list with unique by md5\n", "num_unique_imgs_by_pg = {}\n", "for pg_id in rs_sci_dupe_pgs:\n", " num_images = links_manifest_cargo.loc[links_manifest_cargo[\"eol_page_id\"] == pg_id].shape[0]\n", " num_images_by_pg[pg_id] = num_images\n", " num_unique_images = links_manifest_cargo.loc[links_manifest_cargo[\"eol_page_id\"] == pg_id, \"md5_archive\"].nunique()\n", " num_unique_imgs_by_pg[pg_id] = num_unique_images" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "80" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(num_images_by_pg)" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "page ID 1286909 has less than 30 unique images; it has 27 unique images\n", "page ID 791049 has less than 30 unique images; it has 27 unique images\n", "page ID 485420 has less than 30 unique images; it has 24 unique images\n", "page ID 914531 has less than 30 unique images; it has 29 unique images\n", "page ID 205714 has less than 30 unique images; it has 29 unique images\n" ] } ], "source": [ "for pg_id in num_unique_imgs_by_pg.keys():\n", " if num_unique_imgs_by_pg[pg_id] < 30:\n", " print(f\"page ID {pg_id} has less than 30 unique images; it has {num_unique_imgs_by_pg[pg_id]} unique images\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "https://eol.org/pages/485420/media has only 21 true images, since 3 are post-its." ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
rarespecies_ideol_content_id_rseol_page_id_rskingdomphylumclassorderfamilygenusspeciessciNamecombined_id_rs
08e649092-3e9a-470d-8fe2-1a679e8dbfa922519448914532AnimaliaChordataAvesAnseriformesAnatidaeAnsercanagicusAnser canagicus22519448_914532
19ceb3c09-a43a-4f43-9462-a61cea102f0a286775801057176AnimaliaChordataReptiliaSquamataDactyloidaeAnoliskoopmaniAnolis koopmani28677580_1057176
2d0a34ead-c4f2-4a5b-bf57-00e2a9f9f4af2071447547047909AnimaliaChordataReptiliaSquamataScincidaeOligosomamacgregoriOligosoma macgregori20714475_47047909
34ef2a6eb-9910-488b-8fd1-b68ae49ce4da2997506845509269AnimaliaChordataAvesCharadriiformesLaridaePagophilaeburneaPagophila eburnea29975068_45509269
4095c3a37-6921-401c-b55c-67c5e80096c329462184331080AnimaliaChordataMammaliaArtiodactylaBovidaeOryxleucoryxOryx leucoryx29462184_331080
\n", "
" ], "text/plain": [ " rarespecies_id eol_content_id_rs eol_page_id_rs \\\n", "0 8e649092-3e9a-470d-8fe2-1a679e8dbfa9 22519448 914532 \n", "1 9ceb3c09-a43a-4f43-9462-a61cea102f0a 28677580 1057176 \n", "2 d0a34ead-c4f2-4a5b-bf57-00e2a9f9f4af 20714475 47047909 \n", "3 4ef2a6eb-9910-488b-8fd1-b68ae49ce4da 29975068 45509269 \n", "4 095c3a37-6921-401c-b55c-67c5e80096c3 29462184 331080 \n", "\n", " kingdom phylum class order family genus \\\n", "0 Animalia Chordata Aves Anseriformes Anatidae Anser \n", "1 Animalia Chordata Reptilia Squamata Dactyloidae Anolis \n", "2 Animalia Chordata Reptilia Squamata Scincidae Oligosoma \n", "3 Animalia Chordata Aves Charadriiformes Laridae Pagophila \n", "4 Animalia Chordata Mammalia Artiodactyla Bovidae Oryx \n", "\n", " species sciName combined_id_rs \n", "0 canagicus Anser canagicus 22519448_914532 \n", "1 koopmani Anolis koopmani 28677580_1057176 \n", "2 macgregori Oligosoma macgregori 20714475_47047909 \n", "3 eburnea Pagophila eburnea 29975068_45509269 \n", "4 leucoryx Oryx leucoryx 29462184_331080 " ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rs_catalog.head()" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "7228 30077892_46559947_eol-full-size-copy.jpg\n", "10774 29485438_46559780_eol-full-size-copy.jpg\n", "60 28672110_795859_eol-full-size-copy.jpg\n", "1640 12835827_46454284_eol-full-size-copy.jpg\n", "536 22066842_45511093_eol-full-size-copy.jpg\n", "5669 20495364_205910_eol-full-size-copy.jpg\n", "3543 13992854_45518912_eol-full-size-copy.jpg\n", "Name: file_name, dtype: object" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rs_catalog[\"file_name\"] = rs_catalog[\"combined_id_rs\"].astype(str) + \"_eol-full-size-copy.jpg\"\n", "rs_catalog[\"file_name\"].sample(7)" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [], "source": [ "# save filelist for easier fetching\n", "#rs_catalog[\"file_name\"].to_csv(\"../data/rs_file_list.txt\", index = False)\n", "# Not needed now" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Save `rs_links` to file for adjusting Rare Species images for uniqueness." ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [], "source": [ "rs_links.to_csv(\"../data/rs_links.csv\", index = False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Get MD5s of Images on Misalgined Pages\n", "\n", "Relevant background from Matt (with some notes for context here):\n", "- I have a CSV called `rarespecies_catalog_missing_manifest___archive.csv` with 174 entries (I double-checked that the entries in the \"sciName\" column all look good ... there are duplicates there, but all are valid Genus species binomials)\n", " - This file is from `archive_mismatched_rarespecies.csv` created above.\n", "- Filtered that for all the unique page IDs.\n", "- Downloaded a media manifest current as of today (March 11)\n", "- There are 1,929 entries in today's media manifest with page IDs from the filtered list mentioned above\n", "- Downloaded them to `eol_data_cleanup/data/rare_species_pageids/` (on OSC)\n", "- Logged downloads with errors (there were 2), so we have 1,927 JPGs\n", "- Took MD5s as well, which are in `eol_data_cleanup/data/rare_species_pageids/md5s.csv` (on OSC. Here this file is `rarespecies_missing_pages_md5s.csv`).\n", " - Has \"filename\" and \"md5\" columns, and filenames are `__eol-full-size-copy.jpg`." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 1927 entries, 0 to 1926\n", "Data columns (total 2 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 filename 1927 non-null object\n", " 1 md5 1927 non-null object\n", "dtypes: object(2)\n", "memory usage: 30.2+ KB\n" ] } ], "source": [ "rs_mp = pd.read_csv(\"../data/rarespecies_missing_pages_md5s.csv\", low_memory=False)\n", "rs_mp.info(show_counts = True)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "filename 1927\n", "md5 1899\n", "dtype: int64" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rs_mp.nunique()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "So, how many of these are in the archive?" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 1835 entries, 0 to 1834\n", "Data columns (total 5 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 filename 1835 non-null object\n", " 1 md5 1835 non-null object\n", " 2 filename_archive 1835 non-null object\n", " 3 md5_archive 1835 non-null object\n", " 4 filename_manifest 1835 non-null object\n", "dtypes: object(5)\n", "memory usage: 71.8+ KB\n" ] } ], "source": [ "rs_mp_archive = pd.merge(rs_mp,\n", " links_manifest_cargo[[\"filename_archive\", \"md5_archive\", \"filename_manifest\"]],\n", " left_on = \"md5\",\n", " right_on = \"md5_archive\",\n", " how = \"inner\")\n", "rs_mp_archive.info(show_counts = True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Interesting, most of these are actually in the archive." ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "filename 1595\n", "md5 1568\n", "filename_archive 1616\n", "md5_archive 1568\n", "filename_manifest 1631\n", "dtype: int64" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rs_mp_archive.nunique()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Though it's mostly duplicates, so that makes sense with our earlier numbers." ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
filenamemd5filename_archivemd5_archivefilename_manifest
014192835_1010637_eol-full-size-copy.jpgbcf9f23cfbd8f872e94a022789995c5614192835_1010637_eol-full-size-copy.jpgbcf9f23cfbd8f872e94a022789995c5614192835_1010637_eol-full-size-copy.jpg
122662179_45511624_eol-full-size-copy.jpg9e4dddfc2afc130953f8fbc0d61b52fb22662179_45511624_eol-full-size-copy.jpg9e4dddfc2afc130953f8fbc0d61b52fb22662179_45511624_eol-full-size-copy.jpg
\n", "
" ], "text/plain": [ " filename md5 \\\n", "0 14192835_1010637_eol-full-size-copy.jpg bcf9f23cfbd8f872e94a022789995c56 \n", "1 22662179_45511624_eol-full-size-copy.jpg 9e4dddfc2afc130953f8fbc0d61b52fb \n", "\n", " filename_archive md5_archive \\\n", "0 14192835_1010637_eol-full-size-copy.jpg bcf9f23cfbd8f872e94a022789995c56 \n", "1 22662179_45511624_eol-full-size-copy.jpg 9e4dddfc2afc130953f8fbc0d61b52fb \n", "\n", " filename_manifest \n", "0 14192835_1010637_eol-full-size-copy.jpg \n", "1 22662179_45511624_eol-full-size-copy.jpg " ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rs_mp_archive.head(2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Ensure uniqueness across available images\n", "\n", "Let's reduce the archive DataFrame down to just EOL page IDs from the Rare Species Catalog. We'll match on the archive page ID's (pulled from `filename_archive`). Then we need to merge `rs_mp` with `eol_media_manifest_2024-03-11.csv` to get the source info and concatenate the two DataFrames." ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
EOL content IDEOL page IDMedium Source URLEOL Full-Size Copy URLLicense NameCopyright Owner
05470022500901http://entnemdept.ufl.edu/walker/buzz/487dmj.gifhttps://content.eol.org/data/media/54/67/bb/80...cc-by-nc-sa-3.0Susan A. Wineriter/Singing Insects of North Am...
15470023858799http://entnemdept.ufl.edu/walker/buzz/291pm.jpghttps://content.eol.org/data/media/54/67/6a/80...cc-by-nc-sa-3.0Thomas J. Walker/Singing Insects of North America
\n", "
" ], "text/plain": [ " EOL content ID EOL page ID \\\n", "0 5470022 500901 \n", "1 5470023 858799 \n", "\n", " Medium Source URL \\\n", "0 http://entnemdept.ufl.edu/walker/buzz/487dmj.gif \n", "1 http://entnemdept.ufl.edu/walker/buzz/291pm.jpg \n", "\n", " EOL Full-Size Copy URL License Name \\\n", "0 https://content.eol.org/data/media/54/67/bb/80... cc-by-nc-sa-3.0 \n", "1 https://content.eol.org/data/media/54/67/6a/80... cc-by-nc-sa-3.0 \n", "\n", " Copyright Owner \n", "0 Susan A. Wineriter/Singing Insects of North Am... \n", "1 Thomas J. Walker/Singing Insects of North America " ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mp_manifest = pd.read_csv(\"../data/eol_media_manifest_2024-03-11.csv\",\n", " low_memory=False,\n", " dtype = {\"EOL content ID\": \"int64\", \"EOL page ID\": \"int64\"})\n", "mp_manifest.head(2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Rename columns to match the archive file." ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "mp_manifest.rename(columns={\"EOL content ID\": \"eol_content_id\",\n", " \"EOL page ID\": \"eol_page_id\",\n", " \"Medium Source URL\": \"medium_source_url\",\n", " \"EOL Full-Size Copy URL\": \"eol_full_size_copy_url\",\n", " \"License Name\": \"license_name\",\n", " \"Copyright Owner\": \"copyright_owner\"},\n", " inplace = True)\n", "mp_manifest[\"filename\"] = mp_manifest[\"eol_content_id\"].astype(str) + \"_\" + mp_manifest[\"eol_page_id\"].astype(str) + \"_eol-full-size-copy.jpg\"" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "filename 1927\n", "md5 1899\n", "eol_content_id 1927\n", "eol_page_id 34\n", "medium_source_url 1927\n", "eol_full_size_copy_url 1927\n", "license_name 14\n", "copyright_owner 618\n", "dtype: int64" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rs_mp_manifest = pd.merge(rs_mp,\n", " mp_manifest,\n", " on = \"filename\",\n", " how = \"inner\")\n", "rs_mp_manifest.nunique()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Good, everything merged as expected. Let's cut down the `links_manifest_cargo` DataFrame to just Rare Species pages, then we can concatenate these." ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "400" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rs_pages = list(rs_catalog.eol_page_id_rs.unique())\n", "len(rs_pages) # should be 400" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "def get_page_id(combined_id):\n", " # want to use the archive combined ID to ensure match\n", " # combined ID is eolContentID_eolPageID\n", " return int(combined_id.split(\"_\")[1])\n", "\n", "links_manifest_cargo[\"eol_page_id_archive\"] = links_manifest_cargo[\"combined_id_archive\"].apply(get_page_id)" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "filename_archive 22231\n", "md5_archive 21815\n", "combined_id_archive 22231\n", "filename_manifest 22747\n", "md5_combined_manifest 21815\n", "combined_id_manifest_redownload 22747\n", "eol_content_id 22747\n", "eol_page_id 467\n", "medium_source_url 22369\n", "eol_full_size_copy_url 22560\n", "license_name 15\n", "copyright_owner 5286\n", "expected_image_filename 22747\n", "source_0706 2\n", "source_0726 2\n", "source_1206 2\n", "combined_id_full_manifest 22747\n", "eol_page_id_archive 400\n", "dtype: int64" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rs_links_cargo = links_manifest_cargo.loc[links_manifest_cargo[\"eol_page_id_archive\"].isin(rs_pages)]\n", "rs_links_cargo.nunique()" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/var/folders/nv/f0fq1p1n1_3b11x579py_0q80000gq/T/ipykernel_11036/4189562674.py:6: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " rs_links_cargo[\"eol_content_id_archive\"] = rs_links_cargo[\"combined_id_archive\"].apply(get_content_id)\n" ] }, { "data": { "text/plain": [ "filename_archive 22231\n", "md5_archive 21815\n", "combined_id_archive 22231\n", "filename_manifest 22747\n", "md5_combined_manifest 21815\n", "combined_id_manifest_redownload 22747\n", "eol_content_id 22747\n", "eol_page_id 467\n", "medium_source_url 22369\n", "eol_full_size_copy_url 22560\n", "license_name 15\n", "copyright_owner 5286\n", "expected_image_filename 22747\n", "source_0706 2\n", "source_0726 2\n", "source_1206 2\n", "combined_id_full_manifest 22747\n", "eol_page_id_archive 400\n", "eol_content_id_archive 22231\n", "dtype: int64" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def get_content_id(combined_id):\n", " # want to use the archive combined ID to ensure match\n", " # combined ID is eolContentID_eolPageID\n", " return int(combined_id.split(\"_\")[0])\n", "\n", "rs_links_cargo[\"eol_content_id_archive\"] = rs_links_cargo[\"combined_id_archive\"].apply(get_content_id)\n", "rs_links_cargo.nunique()" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['filename_archive',\n", " 'md5_archive',\n", " 'combined_id_archive',\n", " 'eol_content_id_archive',\n", " 'eol_page_id_archive',\n", " 'medium_source_url',\n", " 'eol_full_size_copy_url',\n", " 'license_name',\n", " 'copyright_owner']" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cols_to_match = list(rs_links_cargo.columns)[:3] + [\"eol_content_id_archive\", \"eol_page_id_archive\"] + list(rs_mp_manifest.columns)[4:]\n", "cols_to_match" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['filename', 'md5', 'combined_id', 'eol_content_id', 'eol_page_id',\n", " 'medium_source_url', 'eol_full_size_copy_url', 'license_name',\n", " 'copyright_owner'],\n", " dtype='object')" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rs_links_cargo = rs_links_cargo[cols_to_match]\n", "rs_links_cargo.rename(columns={\"filename_archive\": \"filename\",\n", " \"md5_archive\": \"md5\",\n", " \"combined_id_archive\": \"combined_id\",\n", " \"eol_content_id_archive\": \"eol_content_id\",\n", " \"eol_page_id_archive\": \"eol_page_id\"},\n", " inplace = True)\n", "rs_links_cargo.columns" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we just need to add `combined_id` to `rs_mp_manifest` and we'll be able to concatenate them." ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
filenamemd5eol_content_ideol_page_idmedium_source_urleol_full_size_copy_urllicense_namecopyright_ownercombined_id
014192835_1010637_eol-full-size-copy.jpgbcf9f23cfbd8f872e94a022789995c56141928351010637https://farm5.staticflickr.com/4036/4450466800...https://content.eol.org/data/media/d7/1c/ce/54...cc-by-nc-saMark Stevens14192835_1010637
122662179_45511624_eol-full-size-copy.jpg9e4dddfc2afc130953f8fbc0d61b52fb2266217945511624https://inaturalist-open-data.s3.amazonaws.com...https://content.eol.org/data/media/55/a1/bf/18...cc-by-nc-4.0oscarcubero22662179_45511624
228915133_1010637_eol-full-size-copy.jpge3d3c433af26fd4dfef43e32459d1d81289151331010637https://upload.wikimedia.org/wikipedia/commons...https://content.eol.org/data/media/3a/46/66/50...cc-by-sa-3.0Profgkay28915133_1010637
322310543_46559744_eol-full-size-copy.jpgb2919b9a5273d9091cd7b5b5e682b53c2231054346559744https://inaturalist-open-data.s3.amazonaws.com...https://content.eol.org/data/media/58/f8/88/18...cc-by-nc-4.0Amy Jaecker-Jones22310543_46559744
430025399_333429_eol-full-size-copy.jpg1a1be33aeb1b694b26838416e2dedb8030025399333429https://upload.wikimedia.org/wikipedia/commons...https://content.eol.org/data/media/59/10/02/50...cc-by-sa-3.0User:Winnerhominid30025399_333429
\n", "
" ], "text/plain": [ " filename md5 \\\n", "0 14192835_1010637_eol-full-size-copy.jpg bcf9f23cfbd8f872e94a022789995c56 \n", "1 22662179_45511624_eol-full-size-copy.jpg 9e4dddfc2afc130953f8fbc0d61b52fb \n", "2 28915133_1010637_eol-full-size-copy.jpg e3d3c433af26fd4dfef43e32459d1d81 \n", "3 22310543_46559744_eol-full-size-copy.jpg b2919b9a5273d9091cd7b5b5e682b53c \n", "4 30025399_333429_eol-full-size-copy.jpg 1a1be33aeb1b694b26838416e2dedb80 \n", "\n", " eol_content_id eol_page_id \\\n", "0 14192835 1010637 \n", "1 22662179 45511624 \n", "2 28915133 1010637 \n", "3 22310543 46559744 \n", "4 30025399 333429 \n", "\n", " medium_source_url \\\n", "0 https://farm5.staticflickr.com/4036/4450466800... \n", "1 https://inaturalist-open-data.s3.amazonaws.com... \n", "2 https://upload.wikimedia.org/wikipedia/commons... \n", "3 https://inaturalist-open-data.s3.amazonaws.com... \n", "4 https://upload.wikimedia.org/wikipedia/commons... \n", "\n", " eol_full_size_copy_url license_name \\\n", "0 https://content.eol.org/data/media/d7/1c/ce/54... cc-by-nc-sa \n", "1 https://content.eol.org/data/media/55/a1/bf/18... cc-by-nc-4.0 \n", "2 https://content.eol.org/data/media/3a/46/66/50... cc-by-sa-3.0 \n", "3 https://content.eol.org/data/media/58/f8/88/18... cc-by-nc-4.0 \n", "4 https://content.eol.org/data/media/59/10/02/50... cc-by-sa-3.0 \n", "\n", " copyright_owner combined_id \n", "0 Mark Stevens 14192835_1010637 \n", "1 oscarcubero 22662179_45511624 \n", "2 Profgkay 28915133_1010637 \n", "3 Amy Jaecker-Jones 22310543_46559744 \n", "4 User:Winnerhominid 30025399_333429 " ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rs_mp_manifest[\"combined_id\"] = rs_mp_manifest[\"eol_content_id\"].astype(str) + \"_\" + rs_mp_manifest[\"eol_page_id\"].astype(str)\n", "rs_mp_manifest.head()" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "filename 22570\n", "md5 22146\n", "combined_id 22570\n", "eol_content_id 22570\n", "eol_page_id 400\n", "medium_source_url 22701\n", "eol_full_size_copy_url 22892\n", "license_name 15\n", "copyright_owner 5326\n", "dtype: int64" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rs_full_manifest = pd.concat([rs_links_cargo, rs_mp_manifest], ignore_index=True)\n", "rs_full_manifest.nunique()" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(25515, 9)" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rs_full_manifest.shape" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "25515" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# does that match?\n", "rs_links_cargo.shape[0] + rs_mp_manifest.shape[0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's reduce this down to just unique MD5s. I think we'll have to regenerate rarespecies IDs, since we can't necessarily match all the ones we had before." ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Index: 22146 entries, 0 to 25513\n", "Data columns (total 10 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 filename 22146 non-null object\n", " 1 md5 22146 non-null object\n", " 2 combined_id 22146 non-null object\n", " 3 eol_content_id 22146 non-null int64 \n", " 4 eol_page_id 22146 non-null int64 \n", " 5 medium_source_url 22146 non-null object\n", " 6 eol_full_size_copy_url 22146 non-null object\n", " 7 license_name 22146 non-null object\n", " 8 copyright_owner 18958 non-null object\n", " 9 duplicate_img 22146 non-null bool \n", "dtypes: bool(1), int64(2), object(7)\n", "memory usage: 1.7+ MB\n" ] } ], "source": [ "rs_full_manifest[\"duplicate_img\"] = rs_full_manifest.duplicated(subset = \"md5\", keep = \"first\")\n", "rs_full_manifest_unique = rs_full_manifest.loc[~rs_full_manifest[\"duplicate_img\"]]\n", "rs_full_manifest_unique.info(show_counts = True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now I need to reduce to just 30 images per page. Let's save this as a CSV first actually and then generate that in a new notebook. I 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...\n", "\n", "### Run Owner match script on this before saving\n", "\n", "Let's match any missing owners where possible to make sure this is a full-info DataFrame before saving it to a CSV." ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [], "source": [ "from tqdm import tqdm" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [], "source": [ "def get_owners_titles(manifest, owners):\n", " \"\"\"\n", " Function to attach owner names and image titles to manifest entries in combined manifest.\n", " Fills empty \"copyright_owner\" and \"title\" values with \"not provided\".\n", " Parameters:\n", " -----------\n", " manifest - rs_full_manifest_unique\n", " owners - DataFrame of July 26, 2023 media manifest entries that had missing owners, updated with their information.\n", " Returns:\n", " --------\n", " manifest - Rare Species media manifest DataFrame with missing owners resolved to extent possible.\n", " \"\"\"\n", " missing_owners = [\n", " comb_id\n", " for comb_id in list(\n", " manifest.loc[manifest[\"copyright_owner\"].isna(), \"combined_id\"]\n", " )\n", " ]\n", "\n", " for comb_id in tqdm(missing_owners):\n", " temp = owners.loc[owners.combined_id_owner == comb_id]\n", " copyright_owner = str(temp[\"Copyright Owner\"].values)\n", " title = str(temp.title.values)\n", " manifest.loc[manifest[\"combined_id\"] == comb_id, \"copyright_owner\"] = copyright_owner\n", " manifest.loc[manifest[\"combined_id\"] == comb_id, \"title\"] = title\n", "\n", " # Print counts of licenses for which owner info was not resolved\n", " print(\n", " \"Licenses still missing Copyright Owners: \\n\",\n", " manifest.loc[\n", " manifest[\"copyright_owner\"].isna(), \"license_name\"\n", " ].value_counts(),\n", " )\n", "\n", " # Fill null \"copyright_owner\" and \"Title\" values with \"not provided\"\n", " manifest[\"copyright_owner\"].fillna(\"not provided\", inplace=True)\n", " manifest[\"title\"].fillna(\"not provided\", inplace=True)\n", "\n", " return manifest\n", "\n", "\n", "def update_owners(manifest, owners):\n", " \"\"\"\n", " Function to fetch and attach the missing owner and title information to EOL catalog entries and save catalog-media file.\n", " Parameters:\n", " -----------\n", " manifest - rs_full_manifest_unique.\n", " owners - DataFrame of July 26, 2023 media manifest entries that had missing owners, updated with their information.\n", " \"\"\"\n", " # Need combined IDs for the owner match file\n", " # EOL content & page IDs read in as int64\n", " owners[\"combined_id_owner\"] = owners[\"EOL content ID\"].astype(str) + \"_\" + owners[\"EOL page ID\"].astype(str)\n", "\n", " updated_manifest = get_owners_titles(manifest, owners)\n", "\n", " return updated_manifest" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [], "source": [ "owner_df = pd.read_csv(\"../data/media_manifest_missing_licenses_jul26_owners.csv\",\n", " low_memory = False,\n", " dtype={\"EOL content ID\": \"int64\", \"EOL page ID\": \"int64\"},)\n" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ " 0%| | 0/3188 [00:00\n", "Index: 22146 entries, 0 to 25513\n", "Data columns (total 11 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 filename 22146 non-null object\n", " 1 md5 22146 non-null object\n", " 2 combined_id 22146 non-null object\n", " 3 eol_content_id 22146 non-null int64 \n", " 4 eol_page_id 22146 non-null int64 \n", " 5 medium_source_url 22146 non-null object\n", " 6 eol_full_size_copy_url 22146 non-null object\n", " 7 license_name 22146 non-null object\n", " 8 copyright_owner 22146 non-null object\n", " 9 duplicate_img 22146 non-null bool \n", " 10 title 22146 non-null object\n", "dtypes: bool(1), int64(2), object(8)\n", "memory usage: 1.9+ MB\n" ] } ], "source": [ "complete_rs_manifest = update_owners(rs_full_manifest_unique, owner_df)\n", "complete_rs_manifest.info(show_counts = True)" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(0, 11)" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "complete_rs_manifest.loc[complete_rs_manifest[\"copyright_owner\"] == \"not provided\"].shape" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
filenamemd5combined_ideol_content_ideol_page_idmedium_source_urleol_full_size_copy_urllicense_namecopyright_ownerduplicate_imgtitle
137130052484_308387_eol-full-size-copy.jpg39bea196c9335a93a937327f04e5872930052484_30838730052484308387https://upload.wikimedia.org/wikipedia/commons...https://content.eol.org/data/media/64/58/c6/50...cc-by-sa-3.0['BotMultichillT']False['Okapia johnstoni5.jpg']
252429389820_1179513_eol-full-size-copy.jpgad70ce70b54302f80a78035e52c5552c29389820_1179513293898201179513https://upload.wikimedia.org/wikipedia/commons...https://content.eol.org/data/media/67/ce/e1/50...cc-by-sa-3.0Vera BuhlFalsenot provided
432728221214_45276460_eol-full-size-copy.jpgd0188bee1b8e37f0e590221e37aeb8bf28221214_452764602822121445276460http://n2t.net/ark:/65665/m3ae98ac6e-dd63-48bf...https://content.eol.org/data/media/15/8b/b0/53...cc-0-1.0['Smithsonian Institution, NMNH, Invertebrate ...False['IZ COE 86556 whole colony top view']
1468714681519_403723_eol-full-size-copy.jpgd1851dd3f010c509f719e044b8826dc914681519_40372314681519403723https://www.antweb.org/images/casent0901314/ca...https://content.eol.org/data/media/bf/35/96/16...cc-by-nc-sa-4.0California Academy of SciencesFalsenot provided
531929844429_45511531_eol-full-size-copy.jpg0ea23bac2d7369f18bf14a78abf3e3e729844429_455115312984442945511531https://upload.wikimedia.org/wikipedia/commons...https://content.eol.org/data/media/5f/35/51/50...cc-by-sa-3.0Alastair RaeFalsenot provided
1077628913280_330971_eol-full-size-copy.jpgf585a0ebce3aec60d30fb545ceedfe4628913280_33097128913280330971https://upload.wikimedia.org/wikipedia/commons...https://content.eol.org/data/media/5f/ad/6c/50...cc-by-sa-3.0Stéphanie BretFalsenot provided
2284514053938_336170_eol-full-size-copy.jpg2a652f57ca3b7dd4e7ad73ab6aef57fd14053938_33617014053938336170https://live.staticflickr.com/6045/6274545363_...https://content.eol.org/data/media/d8/8f/86/54...cc-byBrian GratwickeFalsenot provided
\n", "
" ], "text/plain": [ " filename \\\n", "1371 30052484_308387_eol-full-size-copy.jpg \n", "2524 29389820_1179513_eol-full-size-copy.jpg \n", "4327 28221214_45276460_eol-full-size-copy.jpg \n", "14687 14681519_403723_eol-full-size-copy.jpg \n", "5319 29844429_45511531_eol-full-size-copy.jpg \n", "10776 28913280_330971_eol-full-size-copy.jpg \n", "22845 14053938_336170_eol-full-size-copy.jpg \n", "\n", " md5 combined_id eol_content_id \\\n", "1371 39bea196c9335a93a937327f04e58729 30052484_308387 30052484 \n", "2524 ad70ce70b54302f80a78035e52c5552c 29389820_1179513 29389820 \n", "4327 d0188bee1b8e37f0e590221e37aeb8bf 28221214_45276460 28221214 \n", "14687 d1851dd3f010c509f719e044b8826dc9 14681519_403723 14681519 \n", "5319 0ea23bac2d7369f18bf14a78abf3e3e7 29844429_45511531 29844429 \n", "10776 f585a0ebce3aec60d30fb545ceedfe46 28913280_330971 28913280 \n", "22845 2a652f57ca3b7dd4e7ad73ab6aef57fd 14053938_336170 14053938 \n", "\n", " eol_page_id medium_source_url \\\n", "1371 308387 https://upload.wikimedia.org/wikipedia/commons... \n", "2524 1179513 https://upload.wikimedia.org/wikipedia/commons... \n", "4327 45276460 http://n2t.net/ark:/65665/m3ae98ac6e-dd63-48bf... \n", "14687 403723 https://www.antweb.org/images/casent0901314/ca... \n", "5319 45511531 https://upload.wikimedia.org/wikipedia/commons... \n", "10776 330971 https://upload.wikimedia.org/wikipedia/commons... \n", "22845 336170 https://live.staticflickr.com/6045/6274545363_... \n", "\n", " eol_full_size_copy_url license_name \\\n", "1371 https://content.eol.org/data/media/64/58/c6/50... cc-by-sa-3.0 \n", "2524 https://content.eol.org/data/media/67/ce/e1/50... cc-by-sa-3.0 \n", "4327 https://content.eol.org/data/media/15/8b/b0/53... cc-0-1.0 \n", "14687 https://content.eol.org/data/media/bf/35/96/16... cc-by-nc-sa-4.0 \n", "5319 https://content.eol.org/data/media/5f/35/51/50... cc-by-sa-3.0 \n", "10776 https://content.eol.org/data/media/5f/ad/6c/50... cc-by-sa-3.0 \n", "22845 https://content.eol.org/data/media/d8/8f/86/54... cc-by \n", "\n", " copyright_owner duplicate_img \\\n", "1371 ['BotMultichillT'] False \n", "2524 Vera Buhl False \n", "4327 ['Smithsonian Institution, NMNH, Invertebrate ... False \n", "14687 California Academy of Sciences False \n", "5319 Alastair Rae False \n", "10776 Stéphanie Bret False \n", "22845 Brian Gratwicke False \n", "\n", " title \n", "1371 ['Okapia johnstoni5.jpg'] \n", "2524 not provided \n", "4327 ['IZ COE 86556 whole colony top view'] \n", "14687 not provided \n", "5319 not provided \n", "10776 not provided \n", "22845 not provided " ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "complete_rs_manifest.sample(7)" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(18958, 11)" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "complete_rs_manifest.loc[complete_rs_manifest[\"title\"] == \"not provided\"].shape" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Most don't have title, but they all have the copyright owner filled in. That's good!" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
filenamemd5combined_ideol_content_ideol_page_idmedium_source_urleol_full_size_copy_urllicense_namecopyright_ownertitle
028493296_995017_eol-full-size-copy.jpge83ab9a6630f01099fee7effbd7b68a728493296_99501728493296995017http://mczbase.mcz.harvard.edu/specimen_images...https://content.eol.org/data/media/c7/b7/04/26...cc-by-nc-sa-3.0Museum of Comparative Zoology, Harvard Universitynot provided
121548284_1049155_eol-full-size-copy.jpg90545b27c992f2fbcb0edb81fbf8c04221548284_1049155215482841049155https://inaturalist-open-data.s3.amazonaws.com...https://content.eol.org/data/media/58/f9/6d/18...cc-by-nc-4.0hickeldypickleldynot provided
\n", "
" ], "text/plain": [ " filename md5 \\\n", "0 28493296_995017_eol-full-size-copy.jpg e83ab9a6630f01099fee7effbd7b68a7 \n", "1 21548284_1049155_eol-full-size-copy.jpg 90545b27c992f2fbcb0edb81fbf8c042 \n", "\n", " combined_id eol_content_id eol_page_id \\\n", "0 28493296_995017 28493296 995017 \n", "1 21548284_1049155 21548284 1049155 \n", "\n", " medium_source_url \\\n", "0 http://mczbase.mcz.harvard.edu/specimen_images... \n", "1 https://inaturalist-open-data.s3.amazonaws.com... \n", "\n", " eol_full_size_copy_url license_name \\\n", "0 https://content.eol.org/data/media/c7/b7/04/26... cc-by-nc-sa-3.0 \n", "1 https://content.eol.org/data/media/58/f9/6d/18... cc-by-nc-4.0 \n", "\n", " copyright_owner title \n", "0 Museum of Comparative Zoology, Harvard University not provided \n", "1 hickeldypickleldy not provided " ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cols = [col for col in list(complete_rs_manifest.columns) if col != \"duplicate_img\"]\n", "complete_rs_manifest = complete_rs_manifest[cols]\n", "complete_rs_manifest.head(2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Add License URL Column for Completeness" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [], "source": [ "CC_URL = \"https://creativecommons.org/\"\n", "\n", "\n", "def get_license_url(license_version):\n", " \"\"\"\n", " Function to generate the appropriate Creative Commons URL for a given license.\n", " All licenses in the media manifest are \"cc-XX\", a variation on \"publicdomain\", or \"No known copyright restrictions\".\n", "\n", " Parameters:\n", " -----------\n", " license_version - String. License (eg., \"cc-by-nc 3.0\").\n", "\n", " Returns:\n", " --------\n", " license_url - String. Creative Commons URL associated with the license_version.\n", "\n", " \"\"\"\n", " # First check for version number and isolate it\n", " if \".\" in license_version:\n", " version = license_version.split(sep=\"-\")[-1]\n", " license_name = license_version.split(sep=\"-\" + version)[0]\n", " else:\n", " # No version specified, so default to latest version (4.0)\n", " license_name = license_version\n", " version = \"4.0\"\n", " # Check which type of license\n", " if license_name[:5] == \"cc-by\":\n", " by_x = license_name.split(sep=\"cc-\")[1]\n", " license_url = CC_URL + \"licenses/\" + by_x + \"/\" + version\n", " elif (license_name[:4] == \"cc-0\") or (\"public\" in license_name):\n", " license_url = CC_URL + \"publicdomain/zero/1.0\"\n", " else:\n", " # \"No known copyright restrictions\"\n", " license_url = None\n", " return license_url\n" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [], "source": [ "license_col = \"license_name\"\n", "complete_rs_manifest[\"license_link\"] = complete_rs_manifest[license_col].apply(get_license_url)" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Index: 22146 entries, 0 to 25513\n", "Data columns (total 11 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 filename 22146 non-null object\n", " 1 md5 22146 non-null object\n", " 2 combined_id 22146 non-null object\n", " 3 eol_content_id 22146 non-null int64 \n", " 4 eol_page_id 22146 non-null int64 \n", " 5 medium_source_url 22146 non-null object\n", " 6 eol_full_size_copy_url 22146 non-null object\n", " 7 license_name 22146 non-null object\n", " 8 copyright_owner 22146 non-null object\n", " 9 title 22146 non-null object\n", " 10 license_link 22103 non-null object\n", "dtypes: int64(2), object(9)\n", "memory usage: 2.0+ MB\n" ] } ], "source": [ "complete_rs_manifest.info(show_counts=True)" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Licenses with no URL: \n", " license_name\n", "No known copyright restrictions 43\n", "Name: count, dtype: int64\n" ] } ], "source": [ "print(\n", " \"Licenses with no URL: \\n\",\n", " complete_rs_manifest.loc[complete_rs_manifest[\"license_link\"].isna(), license_col].value_counts(),\n", " )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As expected, we're good to save this full Rare Species manifest now." ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [], "source": [ "complete_rs_manifest.to_csv(\"../data/rarespecies_full_manifest.csv\", index = False)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "jupytext": { "formats": "ipynb,py:percent" }, "kernelspec": { "display_name": "tol", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.3" } }, "nbformat": 4, "nbformat_minor": 2 }