"
+ ],
+ "text/plain": [
+ " data_source kingdom phylum class order family \\\n",
+ "5553984 BIOSCAN Animalia Arthropoda Insecta Diptera Phoridae \n",
+ "5115679 BIOSCAN Animalia Arthropoda Insecta Lepidoptera Oecophoridae \n",
+ "7746318 BIOSCAN Animalia Arthropoda Insecta Diptera Phoridae \n",
+ "5034837 BIOSCAN Animalia Arthropoda Insecta Diptera Chironomidae \n",
+ "6157434 BIOSCAN Animalia Arthropoda Insecta Diptera Phoridae \n",
+ "7720398 BIOSCAN Animalia Arthropoda Insecta Diptera Psychodidae \n",
+ "6191559 BIOSCAN Animalia Arthropoda Insecta Diptera Phoridae \n",
+ "\n",
+ " genus species \\\n",
+ "5553984 Megaselia NaN \n",
+ "5115679 Idioglossa idioglossa malaise5743 \n",
+ "7746318 Megaselia NaN \n",
+ "5034837 Chaetocladius chaetocladius perennis \n",
+ "6157434 Apocephalus NaN \n",
+ "7720398 Psychoda psychoda phalaenoides \n",
+ "6191559 Metopina_group NaN \n",
+ "\n",
+ " common \n",
+ "5553984 Megaselia \n",
+ "5115679 Idioglossa idioglossa malaise5743 \n",
+ "7746318 Megaselia \n",
+ "5034837 Chaetocladius chaetocladius perennis \n",
+ "6157434 Ant-decapitating Flies \n",
+ "7720398 Psychoda psychoda phalaenoides \n",
+ "6191559 Metopina_group "
+ ]
+ },
+ "execution_count": 29,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "bioscan_df.loc[bioscan_df['genus'].notna()].sample(7)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Observe that we do have instances where `common` is labeled as `Genus genus species`."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 30,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "
data_source
\n",
+ "
kingdom
\n",
+ "
phylum
\n",
+ "
class
\n",
+ "
order
\n",
+ "
family
\n",
+ "
genus
\n",
+ "
species
\n",
+ "
common
\n",
+ "
\n",
+ " \n",
+ " \n",
+ "
\n",
+ "
6710632
\n",
+ "
BIOSCAN
\n",
+ "
Animalia
\n",
+ "
Arthropoda
\n",
+ "
Insecta
\n",
+ "
Coleoptera
\n",
+ "
Scirtidae
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
Animalia Arthropoda Insecta Coleoptera Scirtidae
\n",
+ "
\n",
+ "
\n",
+ "
4530081
\n",
+ "
BIOSCAN
\n",
+ "
Animalia
\n",
+ "
Arthropoda
\n",
+ "
Insecta
\n",
+ "
Hymenoptera
\n",
+ "
Mymaridae
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
Animalia Arthropoda Insecta Hymenoptera Mymaridae
\n",
+ "
\n",
+ "
\n",
+ "
4368575
\n",
+ "
BIOSCAN
\n",
+ "
Animalia
\n",
+ "
Arthropoda
\n",
+ "
Insecta
\n",
+ "
Diptera
\n",
+ "
Cecidomyiidae
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
Animalia Arthropoda Insecta Diptera Cecidomyiidae
\n",
+ "
\n",
+ "
\n",
+ "
7790658
\n",
+ "
BIOSCAN
\n",
+ "
Animalia
\n",
+ "
Arthropoda
\n",
+ "
Insecta
\n",
+ "
Diptera
\n",
+ "
Cecidomyiidae
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
Animalia Arthropoda Insecta Diptera Cecidomyiidae
\n",
+ "
\n",
+ "
\n",
+ "
5208630
\n",
+ "
BIOSCAN
\n",
+ "
Animalia
\n",
+ "
Arthropoda
\n",
+ "
Insecta
\n",
+ "
Diptera
\n",
+ "
Chironomidae
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
Animalia Arthropoda Insecta Diptera Chironomidae
\n",
+ "
\n",
+ "
\n",
+ "
6199863
\n",
+ "
BIOSCAN
\n",
+ "
Animalia
\n",
+ "
Arthropoda
\n",
+ "
Insecta
\n",
+ "
Hymenoptera
\n",
+ "
Platygastridae
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
Animalia Arthropoda Insecta Hymenoptera Platyg...
\n",
+ "
\n",
+ "
\n",
+ "
4882465
\n",
+ "
BIOSCAN
\n",
+ "
Animalia
\n",
+ "
Arthropoda
\n",
+ "
Insecta
\n",
+ "
Diptera
\n",
+ "
Psychodidae
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
Animalia Arthropoda Insecta Diptera Psychodidae
\n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " data_source kingdom phylum class order \\\n",
+ "6710632 BIOSCAN Animalia Arthropoda Insecta Coleoptera \n",
+ "4530081 BIOSCAN Animalia Arthropoda Insecta Hymenoptera \n",
+ "4368575 BIOSCAN Animalia Arthropoda Insecta Diptera \n",
+ "7790658 BIOSCAN Animalia Arthropoda Insecta Diptera \n",
+ "5208630 BIOSCAN Animalia Arthropoda Insecta Diptera \n",
+ "6199863 BIOSCAN Animalia Arthropoda Insecta Hymenoptera \n",
+ "4882465 BIOSCAN Animalia Arthropoda Insecta Diptera \n",
+ "\n",
+ " family genus species \\\n",
+ "6710632 Scirtidae NaN NaN \n",
+ "4530081 Mymaridae NaN NaN \n",
+ "4368575 Cecidomyiidae NaN NaN \n",
+ "7790658 Cecidomyiidae NaN NaN \n",
+ "5208630 Chironomidae NaN NaN \n",
+ "6199863 Platygastridae NaN NaN \n",
+ "4882465 Psychodidae NaN NaN \n",
+ "\n",
+ " common \n",
+ "6710632 Animalia Arthropoda Insecta Coleoptera Scirtidae \n",
+ "4530081 Animalia Arthropoda Insecta Hymenoptera Mymaridae \n",
+ "4368575 Animalia Arthropoda Insecta Diptera Cecidomyiidae \n",
+ "7790658 Animalia Arthropoda Insecta Diptera Cecidomyiidae \n",
+ "5208630 Animalia Arthropoda Insecta Diptera Chironomidae \n",
+ "6199863 Animalia Arthropoda Insecta Hymenoptera Platyg... \n",
+ "4882465 Animalia Arthropoda Insecta Diptera Psychodidae "
+ ]
+ },
+ "execution_count": 30,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "bioscan_df.loc[bioscan_df['genus'].isna()].sample(7)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Observe that when the `genus` is null, we get `common` of all higher order taxa available.\n",
+ "\n",
+ "This `common` assignment is something to fix. It could be part of the reason our first iteration did better with bugs (they got full taxa much more frequently)."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 31,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "/tmp/ipykernel_414099/2375049309.py:2: 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",
+ " bioscan_df['duplicate'] = bioscan_df.duplicated(subset = taxa, keep = 'first')\n"
+ ]
+ }
+ ],
+ "source": [
+ "#number of unique 7-tuples in BIOSCAN\n",
+ "bioscan_df['duplicate'] = bioscan_df.duplicated(subset = taxa, keep = 'first')\n",
+ "bioscan_df_unique_taxa = bioscan_df.loc[~bioscan_df['duplicate']]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 32,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ "Index: 10635 entries, 4319650 to 8403725\n",
+ "Data columns (total 10 columns):\n",
+ " # Column Non-Null Count Dtype \n",
+ "--- ------ -------------- ----- \n",
+ " 0 data_source 10635 non-null object\n",
+ " 1 kingdom 10635 non-null object\n",
+ " 2 phylum 10635 non-null object\n",
+ " 3 class 10635 non-null object\n",
+ " 4 order 10635 non-null object\n",
+ " 5 family 10621 non-null object\n",
+ " 6 genus 10203 non-null object\n",
+ " 7 species 8316 non-null object\n",
+ " 8 common 10635 non-null object\n",
+ " 9 duplicate 10635 non-null bool \n",
+ "dtypes: bool(1), object(9)\n",
+ "memory usage: 841.2+ KB\n"
+ ]
+ }
+ ],
+ "source": [
+ "bioscan_df_unique_taxa.info(show_counts = True)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Our number of unique 7-tuple taxa corresponds with the number of unique values for `common`, interesting, yet not surpising considering the way that `common` seems to have been generated. The actual common names that are in that column likley aren't repeated across species.\n",
+ "\n",
+ "We should be able to fill all in for all values of `species` that also have `genus` indicated. Is `genus` labeled for all entries with `species` labeled? "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 33,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ "Index: 84450 entries, 4401381 to 8403808\n",
+ "Data columns (total 10 columns):\n",
+ " # Column Non-Null Count Dtype \n",
+ "--- ------ -------------- ----- \n",
+ " 0 data_source 84450 non-null object\n",
+ " 1 kingdom 84450 non-null object\n",
+ " 2 phylum 84450 non-null object\n",
+ " 3 class 84450 non-null object\n",
+ " 4 order 84450 non-null object\n",
+ " 5 family 84450 non-null object\n",
+ " 6 genus 84441 non-null object\n",
+ " 7 species 84450 non-null object\n",
+ " 8 common 84450 non-null object\n",
+ " 9 duplicate 84450 non-null bool \n",
+ "dtypes: bool(1), object(9)\n",
+ "memory usage: 6.5+ MB\n"
+ ]
+ }
+ ],
+ "source": [
+ "bioscan_df.loc[bioscan_df.species.notna()].info(show_counts = True)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "There are only 9 images where the `species` is labeled, but the `genus` isn't."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 34,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "
data_source
\n",
+ "
kingdom
\n",
+ "
phylum
\n",
+ "
class
\n",
+ "
order
\n",
+ "
family
\n",
+ "
genus
\n",
+ "
species
\n",
+ "
common
\n",
+ "
duplicate
\n",
+ "
\n",
+ " \n",
+ " \n",
+ "
\n",
+ "
4406083
\n",
+ "
BIOSCAN
\n",
+ "
Animalia
\n",
+ "
Arthropoda
\n",
+ "
Insecta
\n",
+ "
Hymenoptera
\n",
+ "
Eulophidae
\n",
+ "
NaN
\n",
+ "
tetramalaise01 malaise6997
\n",
+ "
tetramalaise01 malaise6997
\n",
+ "
False
\n",
+ "
\n",
+ "
\n",
+ "
4426320
\n",
+ "
BIOSCAN
\n",
+ "
Animalia
\n",
+ "
Arthropoda
\n",
+ "
Insecta
\n",
+ "
Hymenoptera
\n",
+ "
Eulophidae
\n",
+ "
NaN
\n",
+ "
tetramalaise01 malaise7245
\n",
+ "
tetramalaise01 malaise7245
\n",
+ "
False
\n",
+ "
\n",
+ "
\n",
+ "
4438796
\n",
+ "
BIOSCAN
\n",
+ "
Animalia
\n",
+ "
Arthropoda
\n",
+ "
Insecta
\n",
+ "
Hymenoptera
\n",
+ "
Eulophidae
\n",
+ "
NaN
\n",
+ "
tetramalaise01 malaise7245
\n",
+ "
tetramalaise01 malaise7245
\n",
+ "
True
\n",
+ "
\n",
+ "
\n",
+ "
4450980
\n",
+ "
BIOSCAN
\n",
+ "
Animalia
\n",
+ "
Arthropoda
\n",
+ "
Insecta
\n",
+ "
Hymenoptera
\n",
+ "
Eulophidae
\n",
+ "
NaN
\n",
+ "
tetramalaise01 malaise4739
\n",
+ "
tetramalaise01 malaise4739
\n",
+ "
False
\n",
+ "
\n",
+ "
\n",
+ "
4459021
\n",
+ "
BIOSCAN
\n",
+ "
Animalia
\n",
+ "
Arthropoda
\n",
+ "
Insecta
\n",
+ "
Hymenoptera
\n",
+ "
Eulophidae
\n",
+ "
NaN
\n",
+ "
tetramalaise01 malaise7245
\n",
+ "
tetramalaise01 malaise7245
\n",
+ "
True
\n",
+ "
\n",
+ "
\n",
+ "
6196384
\n",
+ "
BIOSCAN
\n",
+ "
Animalia
\n",
+ "
Arthropoda
\n",
+ "
Insecta
\n",
+ "
Hymenoptera
\n",
+ "
Eulophidae
\n",
+ "
NaN
\n",
+ "
tetramalaise01 malaise7544
\n",
+ "
tetramalaise01 malaise7544
\n",
+ "
False
\n",
+ "
\n",
+ "
\n",
+ "
7322471
\n",
+ "
BIOSCAN
\n",
+ "
Animalia
\n",
+ "
Arthropoda
\n",
+ "
Insecta
\n",
+ "
Hymenoptera
\n",
+ "
Eulophidae
\n",
+ "
NaN
\n",
+ "
tetramalaise01 malaise4749
\n",
+ "
tetramalaise01 malaise4749
\n",
+ "
False
\n",
+ "
\n",
+ "
\n",
+ "
7766002
\n",
+ "
BIOSCAN
\n",
+ "
Animalia
\n",
+ "
Arthropoda
\n",
+ "
Insecta
\n",
+ "
Hymenoptera
\n",
+ "
Eulophidae
\n",
+ "
NaN
\n",
+ "
tetramalaise01 malaise4739
\n",
+ "
tetramalaise01 malaise4739
\n",
+ "
True
\n",
+ "
\n",
+ "
\n",
+ "
8292691
\n",
+ "
BIOSCAN
\n",
+ "
Animalia
\n",
+ "
Arthropoda
\n",
+ "
Insecta
\n",
+ "
Hymenoptera
\n",
+ "
Eulophidae
\n",
+ "
NaN
\n",
+ "
tetramalaise01 malaise4739
\n",
+ "
tetramalaise01 malaise4739
\n",
+ "
True
\n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " data_source kingdom phylum class order family \\\n",
+ "4406083 BIOSCAN Animalia Arthropoda Insecta Hymenoptera Eulophidae \n",
+ "4426320 BIOSCAN Animalia Arthropoda Insecta Hymenoptera Eulophidae \n",
+ "4438796 BIOSCAN Animalia Arthropoda Insecta Hymenoptera Eulophidae \n",
+ "4450980 BIOSCAN Animalia Arthropoda Insecta Hymenoptera Eulophidae \n",
+ "4459021 BIOSCAN Animalia Arthropoda Insecta Hymenoptera Eulophidae \n",
+ "6196384 BIOSCAN Animalia Arthropoda Insecta Hymenoptera Eulophidae \n",
+ "7322471 BIOSCAN Animalia Arthropoda Insecta Hymenoptera Eulophidae \n",
+ "7766002 BIOSCAN Animalia Arthropoda Insecta Hymenoptera Eulophidae \n",
+ "8292691 BIOSCAN Animalia Arthropoda Insecta Hymenoptera Eulophidae \n",
+ "\n",
+ " genus species common \\\n",
+ "4406083 NaN tetramalaise01 malaise6997 tetramalaise01 malaise6997 \n",
+ "4426320 NaN tetramalaise01 malaise7245 tetramalaise01 malaise7245 \n",
+ "4438796 NaN tetramalaise01 malaise7245 tetramalaise01 malaise7245 \n",
+ "4450980 NaN tetramalaise01 malaise4739 tetramalaise01 malaise4739 \n",
+ "4459021 NaN tetramalaise01 malaise7245 tetramalaise01 malaise7245 \n",
+ "6196384 NaN tetramalaise01 malaise7544 tetramalaise01 malaise7544 \n",
+ "7322471 NaN tetramalaise01 malaise4749 tetramalaise01 malaise4749 \n",
+ "7766002 NaN tetramalaise01 malaise4739 tetramalaise01 malaise4739 \n",
+ "8292691 NaN tetramalaise01 malaise4739 tetramalaise01 malaise4739 \n",
+ "\n",
+ " duplicate \n",
+ "4406083 False \n",
+ "4426320 False \n",
+ "4438796 True \n",
+ "4450980 False \n",
+ "4459021 True \n",
+ "6196384 False \n",
+ "7322471 False \n",
+ "7766002 True \n",
+ "8292691 True "
+ ]
+ },
+ "execution_count": 34,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "bioscan_df.loc[(bioscan_df.species.notna()) & (bioscan_df.genus.isna())]"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "It seems the `genus` is `tetramalaise01` ([genus page for tetraMalaise01](https://v3.boldsystems.org/index.php/Taxbrowser_Taxonpage?taxid=1074204))."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "In general, when the species is listed in BIOSCAN it is listed as `genus-species`. This is certainly true here and would work to fill the 9 missing genera."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### EOL"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 35,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ "Index: 6621365 entries, 0 to 10436520\n",
+ "Data columns (total 9 columns):\n",
+ " # Column Non-Null Count Dtype \n",
+ "--- ------ -------------- ----- \n",
+ " 0 data_source 6621365 non-null object\n",
+ " 1 kingdom 3919403 non-null object\n",
+ " 2 phylum 3917533 non-null object\n",
+ " 3 class 2842328 non-null object\n",
+ " 4 order 3875193 non-null object\n",
+ " 5 family 3906994 non-null object\n",
+ " 6 genus 5119837 non-null object\n",
+ " 7 species 4408570 non-null object\n",
+ " 8 common 6621365 non-null object\n",
+ "dtypes: object(9)\n",
+ "memory usage: 505.2+ MB\n"
+ ]
+ }
+ ],
+ "source": [
+ "eol_df.info(show_counts = True)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 36,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "data_source 1\n",
+ "kingdom 3\n",
+ "phylum 49\n",
+ "class 119\n",
+ "order 679\n",
+ "family 5446\n",
+ "genus 89115\n",
+ "species 180738\n",
+ "common 518118\n",
+ "dtype: int64"
+ ]
+ },
+ "execution_count": 36,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "eol_df.nunique()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 45,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "data_source 1\n",
+ "kingdom 3\n",
+ "phylum 31\n",
+ "class 66\n",
+ "order 284\n",
+ "family 1480\n",
+ "genus 48126\n",
+ "species 0\n",
+ "common 148959\n",
+ "duplicate 2\n",
+ "dtype: int64"
+ ]
+ },
+ "execution_count": 45,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "eol_df.loc[eol_df.species.isna()].nunique()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "There are 570,515 unique page IDs from EOL, which clearly represent varying levels of taxa.\n",
+ "\n",
+ "Unique species + unique common where species is null does not reach this number."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 37,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "kingdom\n",
+ "Metazoa 2207522\n",
+ "Archaeplastida 1481804\n",
+ "Fungi 230077\n",
+ "Name: count, dtype: int64"
+ ]
+ },
+ "execution_count": 37,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "eol_df['kingdom'].value_counts()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "EOL uses `Metazoa` and `Archaeplastida` in place of `Animalia` and `Plantae`, respectively. These designations will need to be merged.\n",
+ "\n",
+ "We have already observed that not all ranks are filled in at the higher levels, sometimes having just one gap. It seems this is particularly common for `class` (it has the least non-null values of any taxa by far)."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 38,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "/tmp/ipykernel_414099/52183210.py:2: 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",
+ " eol_df['duplicate'] = eol_df.duplicated(subset = taxa, keep = 'first')\n"
+ ]
+ }
+ ],
+ "source": [
+ "#number of unique 7-tuples in EOL\n",
+ "eol_df['duplicate'] = eol_df.duplicated(subset = taxa, keep = 'first')\n",
+ "eol_df_unique_taxa = eol_df.loc[~eol_df['duplicate']]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 39,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ "Index: 422190 entries, 0 to 10436512\n",
+ "Data columns (total 10 columns):\n",
+ " # Column Non-Null Count Dtype \n",
+ "--- ------ -------------- ----- \n",
+ " 0 data_source 422190 non-null object\n",
+ " 1 kingdom 256471 non-null object\n",
+ " 2 phylum 256242 non-null object\n",
+ " 3 class 192666 non-null object\n",
+ " 4 order 253217 non-null object\n",
+ " 5 family 255792 non-null object\n",
+ " 6 genus 421118 non-null object\n",
+ " 7 species 372306 non-null object\n",
+ " 8 common 422190 non-null object\n",
+ " 9 duplicate 422190 non-null bool \n",
+ "dtypes: bool(1), object(9)\n",
+ "memory usage: 32.6+ MB\n"
+ ]
+ }
+ ],
+ "source": [
+ "eol_df_unique_taxa.info(show_counts = True)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "The actual number of distinct creatures is likely higher, as evidenced below where we have unique common names listed in `common` but all taxa are null.\n",
+ "\n",
+ "We should be able to fill all in for all values of `species` that also have `genus` indicated. Is `genus` labeled for all entries with `species` labeled? "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 40,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ "Index: 4408570 entries, 1 to 10436520\n",
+ "Data columns (total 10 columns):\n",
+ " # Column Non-Null Count Dtype \n",
+ "--- ------ -------------- ----- \n",
+ " 0 data_source 4408570 non-null object\n",
+ " 1 kingdom 3562320 non-null object\n",
+ " 2 phylum 3560488 non-null object\n",
+ " 3 class 2496336 non-null object\n",
+ " 4 order 3526489 non-null object\n",
+ " 5 family 3555902 non-null object\n",
+ " 6 genus 4408326 non-null object\n",
+ " 7 species 4408570 non-null object\n",
+ " 8 common 4408570 non-null object\n",
+ " 9 duplicate 4408570 non-null bool \n",
+ "dtypes: bool(1), object(9)\n",
+ "memory usage: 340.6+ MB\n"
+ ]
+ }
+ ],
+ "source": [
+ "eol_df.loc[eol_df.species.notna()].info(show_counts = True)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "It looks like we do have just under 250 images for which there's a `species` label, but no `genus` label. This is a sufficiently low number that we could go in to manually check them and hopefully match the the proper higher taxonomic ranks (considering some species names get reused across different genera)."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Let's get a quick sample of the `common` column for images both with and without `species` labels. "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 41,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "
data_source
\n",
+ "
kingdom
\n",
+ "
phylum
\n",
+ "
class
\n",
+ "
order
\n",
+ "
family
\n",
+ "
genus
\n",
+ "
species
\n",
+ "
common
\n",
+ "
duplicate
\n",
+ "
\n",
+ " \n",
+ " \n",
+ "
\n",
+ "
7109927
\n",
+ "
EOL
\n",
+ "
Archaeplastida
\n",
+ "
Tracheophyta
\n",
+ "
NaN
\n",
+ "
Fabales
\n",
+ "
Polygalaceae
\n",
+ "
Polygala
\n",
+ "
leendertziae
\n",
+ "
Polygala leendertziae
\n",
+ "
True
\n",
+ "
\n",
+ "
\n",
+ "
1169608
\n",
+ "
EOL
\n",
+ "
Fungi
\n",
+ "
Ascomycota
\n",
+ "
Eurotiomycetes
\n",
+ "
Pyrenulales
\n",
+ "
Pyrenulaceae
\n",
+ "
Pyrenula
\n",
+ "
dermatodes
\n",
+ "
Pyrenula dermatodes
\n",
+ "
True
\n",
+ "
\n",
+ "
\n",
+ "
2955438
\n",
+ "
EOL
\n",
+ "
Archaeplastida
\n",
+ "
Tracheophyta
\n",
+ "
NaN
\n",
+ "
Magnoliales
\n",
+ "
Annonaceae
\n",
+ "
Asimina
\n",
+ "
obovata
\n",
+ "
bigflower pawpaw
\n",
+ "
True
\n",
+ "
\n",
+ "
\n",
+ "
1551580
\n",
+ "
EOL
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
Numenius
\n",
+ "
hudsonicus
\n",
+ "
Numenius hudsonicus
\n",
+ "
True
\n",
+ "
\n",
+ "
\n",
+ "
3845702
\n",
+ "
EOL
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
Urtica
\n",
+ "
gracilis holosericea
\n",
+ "
stinging nettle
\n",
+ "
True
\n",
+ "
\n",
+ "
\n",
+ "
3499959
\n",
+ "
EOL
\n",
+ "
Metazoa
\n",
+ "
Chordata
\n",
+ "
Gnathostomata
\n",
+ "
Gymnophiona
\n",
+ "
Ichthyophiidae
\n",
+ "
Ichthyophis
\n",
+ "
bombayensis
\n",
+ "
Bombay Caecilian
\n",
+ "
True
\n",
+ "
\n",
+ "
\n",
+ "
4155103
\n",
+ "
EOL
\n",
+ "
Fungi
\n",
+ "
Basidiomycota
\n",
+ "
Agaricomycetes
\n",
+ "
Boletales
\n",
+ "
Suillaceae
\n",
+ "
Suillus
\n",
+ "
placidus
\n",
+ "
Slippery white bolete
\n",
+ "
True
\n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " data_source kingdom phylum class \\\n",
+ "7109927 EOL Archaeplastida Tracheophyta NaN \n",
+ "1169608 EOL Fungi Ascomycota Eurotiomycetes \n",
+ "2955438 EOL Archaeplastida Tracheophyta NaN \n",
+ "1551580 EOL NaN NaN NaN \n",
+ "3845702 EOL NaN NaN NaN \n",
+ "3499959 EOL Metazoa Chordata Gnathostomata \n",
+ "4155103 EOL Fungi Basidiomycota Agaricomycetes \n",
+ "\n",
+ " order family genus species \\\n",
+ "7109927 Fabales Polygalaceae Polygala leendertziae \n",
+ "1169608 Pyrenulales Pyrenulaceae Pyrenula dermatodes \n",
+ "2955438 Magnoliales Annonaceae Asimina obovata \n",
+ "1551580 NaN NaN Numenius hudsonicus \n",
+ "3845702 NaN NaN Urtica gracilis holosericea \n",
+ "3499959 Gymnophiona Ichthyophiidae Ichthyophis bombayensis \n",
+ "4155103 Boletales Suillaceae Suillus placidus \n",
+ "\n",
+ " common duplicate \n",
+ "7109927 Polygala leendertziae True \n",
+ "1169608 Pyrenula dermatodes True \n",
+ "2955438 bigflower pawpaw True \n",
+ "1551580 Numenius hudsonicus True \n",
+ "3845702 stinging nettle True \n",
+ "3499959 Bombay Caecilian True \n",
+ "4155103 Slippery white bolete True "
+ ]
+ },
+ "execution_count": 41,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# existing species label\n",
+ "eol_df.loc[eol_df.species.notna()].sample(7)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Good, some of these do have common names. We could check numbers of `common` where it doesn't match the `genus-species` form for a better count, but our random sample is promising."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 42,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "
data_source
\n",
+ "
kingdom
\n",
+ "
phylum
\n",
+ "
class
\n",
+ "
order
\n",
+ "
family
\n",
+ "
genus
\n",
+ "
species
\n",
+ "
common
\n",
+ "
duplicate
\n",
+ "
\n",
+ " \n",
+ " \n",
+ "
\n",
+ "
2635269
\n",
+ "
EOL
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
tāranga
\n",
+ "
True
\n",
+ "
\n",
+ "
\n",
+ "
4404459
\n",
+ "
EOL
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
Trans-Pecos thimblehead
\n",
+ "
True
\n",
+ "
\n",
+ "
\n",
+ "
575560
\n",
+ "
EOL
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
Cremastobaeus
\n",
+ "
True
\n",
+ "
\n",
+ "
\n",
+ "
456164
\n",
+ "
EOL
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
American red raspberry
\n",
+ "
True
\n",
+ "
\n",
+ "
\n",
+ "
10332391
\n",
+ "
EOL
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
Straight-lined Vaxi Moth
\n",
+ "
True
\n",
+ "
\n",
+ "
\n",
+ "
6082438
\n",
+ "
EOL
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
Rock ptarmigan
\n",
+ "
True
\n",
+ "
\n",
+ "
\n",
+ "
3443067
\n",
+ "
EOL
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
NaN
\n",
+ "
Catapion meieri
\n",
+ "
True
\n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " data_source kingdom phylum class order family genus species \\\n",
+ "2635269 EOL NaN NaN NaN NaN NaN NaN NaN \n",
+ "4404459 EOL NaN NaN NaN NaN NaN NaN NaN \n",
+ "575560 EOL NaN NaN NaN NaN NaN NaN NaN \n",
+ "456164 EOL NaN NaN NaN NaN NaN NaN NaN \n",
+ "10332391 EOL NaN NaN NaN NaN NaN NaN NaN \n",
+ "6082438 EOL NaN NaN NaN NaN NaN NaN NaN \n",
+ "3443067 EOL NaN NaN NaN NaN NaN NaN NaN \n",
+ "\n",
+ " common duplicate \n",
+ "2635269 tāranga True \n",
+ "4404459 Trans-Pecos thimblehead True \n",
+ "575560 Cremastobaeus True \n",
+ "456164 American red raspberry True \n",
+ "10332391 Straight-lined Vaxi Moth True \n",
+ "6082438 Rock ptarmigan True \n",
+ "3443067 Catapion meieri True "
+ ]
+ },
+ "execution_count": 42,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# No species label\n",
+ "eol_df.loc[eol_df.species.isna()].sample(7)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "All `common` values are filled in with predominently common names. It seems we could map these back to some level of taxa with the taxon-common matching? Though why would these EOL images have common without any other designation?\n",
+ "\n",
+ "Good example of strange inconsistency: the `American red raspberry` is `Rubus strigosus`, and a quick Google search easily provides the entire taxonomy.\n",
+ "\n",
+ "`Cremastobaeus` seems to be a genus of wasp."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Checking for overlap between the three data sources will not give accurate results until these labels are standardized.\n",
+ "\n",
+ "In general, when the species is listed in BIOSCAN it is listed as `genus-species`, so we could generate a new column with just the species designation to try to get a more accurate count across species. \n",
+ "\n",
+ "For now, let's just take a quick look at genera across the datasets since they are more standardized (and listed more often in BIOSCAN)."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 46,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "there are 89115 genera in EOL\n",
+ "there are 4884 genera in inat21\n",
+ "there are 3444 genera in bioscan\n"
+ ]
+ }
+ ],
+ "source": [
+ "eol_genera = list(eol_df.loc[eol_df['genus'].notna(), 'genus'].unique())\n",
+ "inat21_genera = list(inat21_df.loc[inat21_df['genus'].notna(), 'genus'].unique())\n",
+ "bioscan_genera = list(bioscan_df.loc[bioscan_df['genus'].notna(), 'genus'].unique())\n",
+ "\n",
+ "print(f\"there are {len(eol_genera)} genera in EOL\")\n",
+ "print(f\"there are {len(inat21_genera)} genera in inat21\")\n",
+ "print(f\"there are {len(bioscan_genera)} genera in bioscan\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 48,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "There are 4809 genera shared between EOL and iNat21.\n",
+ "There are 2720 genera shared between EOL and BIOSCAN.\n",
+ "There are 212 genera shared between iNat21 and BIOSCAN.\n",
+ "There are 212 genera shared between all three data sources.\n"
+ ]
+ }
+ ],
+ "source": [
+ "gen_overlap = list(set(eol_genera) & set(inat21_genera))\n",
+ "print(f\"There are {len(gen_overlap)} genera shared between EOL and iNat21.\")\n",
+ "print(f\"There are {len(list(set(eol_genera) & set(bioscan_genera)))} genera shared between EOL and BIOSCAN.\")\n",
+ "print(f\"There are {len(list(set(inat21_genera) & set(bioscan_genera)))} genera shared between iNat21 and BIOSCAN.\")\n",
+ "print(f\"There are {len(list(set(gen_overlap) & set(bioscan_genera)))} genera shared between all three data sources.\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "BIOSCAN and iNat21's overlap of genera is completely contained in EOL."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Overall Stats\n",
+ "\n",
+ "Keep in mind, this is without standardizing `kingdom` or fixing any other inconsistencies observed above."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 49,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import numpy as np"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 50,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "avgs_all_images = []\n",
+ "std_all_images = []\n",
+ "avgs_labeled_images = []\n",
+ "std_labeled_images = []\n",
+ "for taxon in taxa_com[1:]: #taxa + common\n",
+ " num_taxon = df[taxon].nunique()\n",
+ " num_img_taxon = len(df.loc[df[taxon].notna()])\n",
+ " avg_all = 10436521/num_taxon\n",
+ " std_all = np.sqrt(10436521/num_taxon)\n",
+ " avg_labeled = num_img_taxon/num_taxon\n",
+ " std_labeled = np.sqrt(num_img_taxon/num_taxon)\n",
+ " avgs_all_images.append(avg_all)\n",
+ " std_all_images.append(std_all)\n",
+ " avgs_labeled_images.append(avg_labeled)\n",
+ " std_labeled_images.append(std_labeled)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 51,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "