{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "TOL_FILEPATH = \"../../data/\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Read in Links CSV files\n", "\n", "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", "\n", "From Matt:\n", "> It represents a series of inner merges:\n", "> 1. The list of images in the EOL cargo archive (used to create the webdatasets) with the EOL portion of `catalog.csv`\n", "> - Merged on a combined identifier of `eol_content_id` and `eol_page_id`.\n", "> 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", "> - Merged on MD5\n", ">\n", "> 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", "- `combined_id_catalog`: represents what's in the original catalog \n", "- `combined_id_manifest_full_manifest`: represents what's in the combined manifest from all 3 dates \n", "> 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", ">\n", "> 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", "\n", "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)." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "links_inner = pd.read_csv(\"../data/eol-cargo-archive_catalog_combined-manifest-checksums_links.csv\", low_memory=False)\n", "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: 6841202 entries, 0 to 6841201\n", "Data columns (total 30 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 filename_archive 6841202 non-null object \n", " 1 md5 6841202 non-null object \n", " 2 combined_id_archive 6841202 non-null object \n", " 3 split 6841202 non-null object \n", " 4 treeoflife_id 6841202 non-null object \n", " 5 bioscan_part 0 non-null float64\n", " 6 bioscan_filename 0 non-null float64\n", " 7 inat21_filename 0 non-null float64\n", " 8 inat21_cls_name 0 non-null float64\n", " 9 inat21_cls_num 0 non-null float64\n", " 10 kingdom 6551473 non-null object \n", " 11 phylum 6553206 non-null object \n", " 12 class 6532009 non-null object \n", " 13 order 6525621 non-null object \n", " 14 family 6506076 non-null object \n", " 15 genus 6486130 non-null object \n", " 16 species 6406307 non-null object \n", " 17 common 6841202 non-null object \n", " 18 combined_id_catalog 6841202 non-null object \n", " 19 filename_manifest 6841202 non-null object \n", " 20 combined_id_manifest_redownload 6841202 non-null object \n", " 21 medium_source_url 6841202 non-null object \n", " 22 eol_full_size_copy_url 6841202 non-null object \n", " 23 license_name 6841202 non-null object \n", " 24 copyright_owner 6208498 non-null object \n", " 25 expected_image_filename 6841202 non-null object \n", " 26 source_0706 6841202 non-null bool \n", " 27 source_0726 6841202 non-null bool \n", " 28 source_1206 6841202 non-null bool \n", " 29 combined_id_full_manifest 6841202 non-null object \n", "dtypes: bool(3), float64(5), object(22)\n", "memory usage: 1.4+ GB\n" ] } ], "source": [ "links_inner.info(show_counts=True)" ] }, { "cell_type": "code", "execution_count": 5, "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": [ "These both have about 600-700 more entries than the earlier files." ] }, { "cell_type": "code", "execution_count": 6, "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", "
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_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]\n", "Index: []" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# These should be the same\n", "links_manifest_cargo.loc[links_manifest_cargo[\"combined_id_manifest_redownload\"] != links_manifest_cargo[\"combined_id_full_manifest\"]]" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Index: 822558 entries, 2 to 7513999\n", "Data columns (total 17 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 filename_archive 822558 non-null object\n", " 1 md5_archive 822558 non-null object\n", " 2 combined_id_archive 822558 non-null object\n", " 3 filename_manifest 822558 non-null object\n", " 4 md5_combined_manifest 822558 non-null object\n", " 5 combined_id_manifest_redownload 822558 non-null object\n", " 6 eol_content_id 822558 non-null int64 \n", " 7 eol_page_id 822558 non-null int64 \n", " 8 medium_source_url 822558 non-null object\n", " 9 eol_full_size_copy_url 822558 non-null object\n", " 10 license_name 822558 non-null object\n", " 11 copyright_owner 797147 non-null object\n", " 12 expected_image_filename 822558 non-null object\n", " 13 source_0706 822558 non-null bool \n", " 14 source_0726 822558 non-null bool \n", " 15 source_1206 822558 non-null bool \n", " 16 combined_id_full_manifest 822558 non-null object\n", "dtypes: bool(3), int64(2), object(12)\n", "memory usage: 96.5+ MB\n" ] } ], "source": [ "# archive has replaced cargo\n", "# full manifest or manifest redownload to replace manifest checksums -- they are equal\n", "links_mismatch = links_manifest_cargo.loc[links_manifest_cargo[\"combined_id_archive\"] != links_manifest_cargo[\"combined_id_full_manifest\"]]\n", "links_mismatch.info(show_counts = True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There are 42 more mismatched entries. Only 13 additional unique images (MD5s)." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "md5_archive 624574\n", "combined_id_full_manifest 712540\n", "combined_id_archive 703446\n", "dtype: int64" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "links_mismatch[[\"md5_archive\", \"combined_id_full_manifest\", \"combined_id_archive\"]].nunique()" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "# This is archive manifest mismatch\n", "links_mismatch.to_csv(\"../data/links_archive_manifest_IDmismatch.csv\", index = False)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "catalog = pd.read_csv(TOL_FILEPATH + \"catalog.csv\", low_memory=False)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "# remove train_small and all non-EOL entries\n", "catalog = catalog.loc[catalog.split != \"train_small\"]\n", "eol_catalog = catalog.loc[catalog.eol_content_id.notna()]" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "split 2\n", "treeoflife_id 6250420\n", "eol_content_id 6250420\n", "eol_page_id 503589\n", "dtype: int64" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "eol_catalog[list(eol_catalog.columns)[:4]].nunique()" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "eol_cols = [col for col in list(eol_catalog.columns) if \"bioscan\" not in col and \"inat\" not in col]" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Index: 6250420 entries, 956715 to 11000930\n", "Data columns (total 12 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 split 6250420 non-null object \n", " 1 treeoflife_id 6250420 non-null object \n", " 2 eol_content_id 6250420 non-null float64\n", " 3 eol_page_id 6250420 non-null float64\n", " 4 kingdom 5989611 non-null object \n", " 5 phylum 5991207 non-null object \n", " 6 class 5971438 non-null object \n", " 7 order 5965299 non-null object \n", " 8 family 5948728 non-null object \n", " 9 genus 5940313 non-null object \n", " 10 species 5951613 non-null object \n", " 11 common 6250420 non-null object \n", "dtypes: float64(2), object(10)\n", "memory usage: 619.9+ MB\n" ] } ], "source": [ "eol_catalog = eol_catalog[eol_cols]\n", "eol_catalog.info(show_counts=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Must recast IDs as `int64`" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Index: 6250420 entries, 956715 to 11000930\n", "Data columns (total 4 columns):\n", " # Column Dtype \n", "--- ------ ----- \n", " 0 split object\n", " 1 treeoflife_id object\n", " 2 eol_content_id int64 \n", " 3 eol_page_id int64 \n", "dtypes: int64(2), object(2)\n", "memory usage: 238.4+ MB\n" ] } ], "source": [ "eol_catalog = eol_catalog.astype({\"eol_content_id\": \"int64\", \"eol_page_id\": \"int64\"})\n", "eol_catalog[eol_cols[:4]].info()" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "lines_to_next_cell": 2 }, "outputs": [], "source": [ "# make combined ID for catalog and add suffix to eol content and page IDs\n", "eol_catalog['combined_id_catalog'] = eol_catalog['eol_content_id'].astype(str) + '_' + eol_catalog['eol_page_id'].astype(str)\n", "eol_catalog.rename(columns={'eol_content_id': 'eol_content_id_catalog', 'eol_page_id': 'eol_page_id_catalog'}, inplace=True)" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "6219674" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "matched_catalog_ids = list(links_inner.combined_id_catalog.unique())\n", "len(matched_catalog_ids)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here we go, we got an additional 630 matched IDs!" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['29538374_65414274',\n", " '27793900_888015',\n", " '29121641_5618956',\n", " '27596176_607817',\n", " '20300703_267922']" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "matched_catalog_ids[:5]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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." ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "5842839 28875844_579175\n", "7715090 21712402_702458\n", "10112940 27938371_3091824\n", "8606944 27597441_49820955\n", "1247592 14852900_2896866\n", "Name: combined_id_catalog, dtype: object" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "eol_catalog['combined_id_catalog'].sample(5)" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Index: 30746 entries, 956874 to 10996978\n", "Data columns (total 13 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 split 30746 non-null object\n", " 1 treeoflife_id 30746 non-null object\n", " 2 eol_content_id_catalog 30746 non-null int64 \n", " 3 eol_page_id_catalog 30746 non-null int64 \n", " 4 kingdom 30573 non-null object\n", " 5 phylum 30578 non-null object\n", " 6 class 30153 non-null object\n", " 7 order 30528 non-null object\n", " 8 family 30294 non-null object\n", " 9 genus 30192 non-null object\n", " 10 species 29399 non-null object\n", " 11 common 30746 non-null object\n", " 12 combined_id_catalog 30746 non-null object\n", "dtypes: int64(2), object(11)\n", "memory usage: 3.3+ MB\n" ] } ], "source": [ "mismatched_catalog = eol_catalog.loc[~eol_catalog[\"combined_id_catalog\"].isin(matched_catalog_ids)]\n", "mismatched_catalog.info(show_counts = True)" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "split 2\n", "treeoflife_id 30746\n", "eol_content_id_catalog 30746\n", "eol_page_id_catalog 7042\n", "kingdom 7\n", "phylum 33\n", "class 87\n", "order 355\n", "family 1165\n", "genus 3503\n", "species 5174\n", "common 6884\n", "combined_id_catalog 30746\n", "dtype: int64" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mismatched_catalog.nunique()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Seems one class got resolved (equals more orders and down)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Merge with Mismatched CargoArchive-Manifest\n", "\n", "let's merge with `links_mismatch` to see if the mismatched archive and manifest combined IDs can be linked up." ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 0 entries\n", "Data columns (total 30 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 split 0 non-null object\n", " 1 treeoflife_id 0 non-null object\n", " 2 eol_content_id_catalog 0 non-null int64 \n", " 3 eol_page_id_catalog 0 non-null int64 \n", " 4 kingdom 0 non-null object\n", " 5 phylum 0 non-null object\n", " 6 class 0 non-null object\n", " 7 order 0 non-null object\n", " 8 family 0 non-null object\n", " 9 genus 0 non-null object\n", " 10 species 0 non-null object\n", " 11 common 0 non-null object\n", " 12 combined_id_catalog 0 non-null object\n", " 13 filename_archive 0 non-null object\n", " 14 md5_archive 0 non-null object\n", " 15 combined_id_archive 0 non-null object\n", " 16 filename_manifest 0 non-null object\n", " 17 md5_combined_manifest 0 non-null object\n", " 18 combined_id_manifest_redownload 0 non-null object\n", " 19 eol_content_id 0 non-null int64 \n", " 20 eol_page_id 0 non-null int64 \n", " 21 medium_source_url 0 non-null object\n", " 22 eol_full_size_copy_url 0 non-null object\n", " 23 license_name 0 non-null object\n", " 24 copyright_owner 0 non-null object\n", " 25 expected_image_filename 0 non-null object\n", " 26 source_0706 0 non-null bool \n", " 27 source_0726 0 non-null bool \n", " 28 source_1206 0 non-null bool \n", " 29 combined_id_full_manifest 0 non-null object\n", "dtypes: bool(3), int64(4), object(23)\n", "memory usage: 132.0+ bytes\n" ] } ], "source": [ "# replace manifest checksums with full manifest as above\n", "links_catalog_mismatch = pd.merge(mismatched_catalog,\n", " links_mismatch,\n", " left_on = \"combined_id_catalog\",\n", " right_on = \"combined_id_full_manifest\",\n", " how = \"inner\")\n", "links_catalog_mismatch.info(show_counts = True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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!)." ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2003559 15270321_240065\n", "8751466 29485627_17806\n", "4818957 27965287_35726\n", "8697796 9483753_328724\n", "1049389 9446784_5019858\n", "8364678 9467133_2925218\n", "5119903 28880812_10305215\n", "Name: combined_id_catalog, dtype: object" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mismatched_catalog.combined_id_catalog.sample(7)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "These pages are reasonably full too: [5660435](https://eol.org/pages/5660435)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Final Catalog\n", "\n", "Our final EOL catalog is thus going to be the `treeoflife_id`s in `links_inner`.\n", "\n", "Finall question is just how does this look for our `train_small`?" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Index: 593764 entries, 0 to 918500\n", "Data columns (total 12 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 split 593764 non-null object \n", " 1 treeoflife_id 593764 non-null object \n", " 2 eol_content_id 593764 non-null float64\n", " 3 eol_page_id 593764 non-null float64\n", " 4 kingdom 569128 non-null object \n", " 5 phylum 569285 non-null object \n", " 6 class 567356 non-null object \n", " 7 order 566839 non-null object \n", " 8 family 565269 non-null object \n", " 9 genus 564605 non-null object \n", " 10 species 565399 non-null object \n", " 11 common 593764 non-null object \n", "dtypes: float64(2), object(10)\n", "memory usage: 58.9+ MB\n" ] } ], "source": [ "cat_2 = pd.read_csv(TOL_FILEPATH + \"catalog.csv\", low_memory=False)\n", "\n", "# reduce to just train_small and all non-EOL entries\n", "cat_2 = cat_2.loc[cat_2.split == \"train_small\"]\n", "eol_cat_2 = cat_2.loc[cat_2.eol_content_id.notna()]\n", "\n", "eol_cat_2 = eol_cat_2[eol_cols]\n", "eol_cat_2.info(show_counts=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "So `train_small` has 593,764 images from EOL. \n", "\n", "Let's recast IDs as ints to match up with `links_inner` and check we have info for all of them." ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Index: 593764 entries, 0 to 918500\n", "Data columns (total 4 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 split 593764 non-null object\n", " 1 treeoflife_id 593764 non-null object\n", " 2 eol_content_id 593764 non-null int64 \n", " 3 eol_page_id 593764 non-null int64 \n", "dtypes: int64(2), object(2)\n", "memory usage: 22.7+ MB\n" ] } ], "source": [ "eol_cat_2 = eol_cat_2.astype({\"eol_content_id\": \"int64\", \"eol_page_id\": \"int64\"})\n", "eol_cat_2[eol_cols[:4]].info()" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [], "source": [ "# make combined ID for catalog and add suffix to eol content and page IDs\n", "eol_cat_2['combined_id_catalog'] = eol_cat_2['eol_content_id'].astype(str) + '_' + eol_cat_2['eol_page_id'].astype(str)\n", "eol_cat_2.rename(columns={'eol_content_id': 'eol_content_id_catalog', 'eol_page_id': 'eol_page_id_catalog'}, inplace=True)" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 612614 entries, 0 to 612613\n", "Data columns (total 25 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 split 612614 non-null object\n", " 1 treeoflife_id 612614 non-null object\n", " 2 eol_content_id_catalog 612614 non-null int64 \n", " 3 eol_page_id_catalog 612614 non-null int64 \n", " 4 kingdom 584979 non-null object\n", " 5 phylum 585140 non-null object\n", " 6 class 583235 non-null object\n", " 7 order 582668 non-null object\n", " 8 family 581082 non-null object\n", " 9 genus 580464 non-null object\n", " 10 species 579943 non-null object\n", " 11 common 612614 non-null object\n", " 12 combined_id_catalog_x 612614 non-null object\n", " 13 combined_id_catalog_y 612614 non-null object\n", " 14 filename_manifest 612614 non-null object\n", " 15 combined_id_manifest_redownload 612614 non-null object\n", " 16 medium_source_url 612614 non-null object\n", " 17 eol_full_size_copy_url 612614 non-null object\n", " 18 license_name 612614 non-null object\n", " 19 copyright_owner 554029 non-null object\n", " 20 expected_image_filename 612614 non-null object\n", " 21 source_0706 612614 non-null bool \n", " 22 source_0726 612614 non-null bool \n", " 23 source_1206 612614 non-null bool \n", " 24 combined_id_full_manifest 612614 non-null object\n", "dtypes: bool(3), int64(2), object(20)\n", "memory usage: 104.6+ MB\n" ] } ], "source": [ "eol_ts_links = pd.merge(eol_cat_2,\n", " links_inner[list(links_inner.columns)[18:]],\n", " left_on = \"combined_id_catalog\",\n", " right_on = \"combined_id_full_manifest\",\n", " how = \"inner\")\n", "eol_ts_links.info(show_counts = True)" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "590730" ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "eol_ts_links.treeoflife_id.nunique()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "So we are missing the metadata for 3,734 of these images." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Check on Rare Species Catalog" ] }, { "cell_type": "code", "execution_count": 25, "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(\"../../rare_species/data/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": 26, "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": 27, "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\", # looking at archive\n", " how = \"inner\")\n", "rs_links.info(show_counts = True)" ] }, { "cell_type": "code", "execution_count": 28, "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": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rs_links.nunique()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's check the mismatched cargo/manifest entries for those last 174..." ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "11826" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "matched_rs_ids = list(rs_links.combined_id_rs.unique())\n", "len(matched_rs_ids)" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['22519448_914532',\n", " '28677580_1057176',\n", " '20714475_47047909',\n", " '29975068_45509269']" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "matched_rs_ids[:4]" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1473 29538601_46580048\n", "11127 29447084_1019571\n", "6578 20398296_328017\n", "11583 29772112_1049135\n", "Name: combined_id_rs, dtype: object" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rs_catalog[\"combined_id_rs\"].sample(4)" ] }, { "cell_type": "code", "execution_count": 32, "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": 33, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 0 entries\n", "Data columns (total 29 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 rarespecies_id 0 non-null object\n", " 1 eol_content_id_rs 0 non-null int64 \n", " 2 eol_page_id_rs 0 non-null int64 \n", " 3 kingdom 0 non-null object\n", " 4 phylum 0 non-null object\n", " 5 class 0 non-null object\n", " 6 order 0 non-null object\n", " 7 family 0 non-null object\n", " 8 genus 0 non-null object\n", " 9 species 0 non-null object\n", " 10 sciName 0 non-null object\n", " 11 combined_id_rs 0 non-null object\n", " 12 filename_archive 0 non-null object\n", " 13 md5_archive 0 non-null object\n", " 14 combined_id_archive 0 non-null object\n", " 15 filename_manifest 0 non-null object\n", " 16 md5_combined_manifest 0 non-null object\n", " 17 combined_id_manifest_redownload 0 non-null object\n", " 18 eol_content_id 0 non-null int64 \n", " 19 eol_page_id 0 non-null int64 \n", " 20 medium_source_url 0 non-null object\n", " 21 eol_full_size_copy_url 0 non-null object\n", " 22 license_name 0 non-null object\n", " 23 copyright_owner 0 non-null object\n", " 24 expected_image_filename 0 non-null object\n", " 25 source_0706 0 non-null bool \n", " 26 source_0726 0 non-null bool \n", " 27 source_1206 0 non-null bool \n", " 28 combined_id_full_manifest 0 non-null object\n", "dtypes: bool(3), int64(4), object(22)\n", "memory usage: 132.0+ bytes\n" ] } ], "source": [ "links_rs_mismatch = pd.merge(mismatched_rs,\n", " links_mismatch,\n", " left_on = \"combined_id_rs\",\n", " right_on = \"combined_id_full_manifest\",\n", " how = \"inner\")\n", "links_rs_mismatch.info(show_counts = True)" ] }, { "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 }