{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 5683 entries, 0 to 5682\n", "Data columns (total 4 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 coreid 5683 non-null object \n", " 1 type 0 non-null float64\n", " 2 identifier 5683 non-null object \n", " 3 license 0 non-null float64\n", "dtypes: float64(2), object(2)\n", "memory usage: 177.7+ KB\n" ] } ], "source": [ "multimedia = pd.read_csv(\"../metadata/deduplication/Zenodo_meta_files/multimedia__(rec_3477891).csv\", low_memory=False)\n", "multimedia.info(show_counts=True)" ] }, { "cell_type": "code", "execution_count": 3, "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", "
coreidtypeidentifierlicense
0275ad2e7-bc7e-4e74-832e-869825f5bf0bNaNhttps://zenodo.org/record/2684906/files/CAM008...NaN
1cf02ac3a-6204-417c-b342-6f84eab48931NaNhttps://zenodo.org/record/2714333/files/CAM041...NaN
27be80267-dbe9-4f4b-8f73-c7355447d5e1NaNhttps://zenodo.org/record/2686762/files/CAM008...NaN
3b97011cb-c4fd-4ea9-8828-dc920c7b900aNaNhttps://zenodo.org/record/2684906/files/CAM008...NaN
46375bf74-3333-4cb6-a0dc-f95c3794edaeNaNhttps://zenodo.org/record/2714333/files/CAM040...NaN
\n", "
" ], "text/plain": [ " coreid type \\\n", "0 275ad2e7-bc7e-4e74-832e-869825f5bf0b NaN \n", "1 cf02ac3a-6204-417c-b342-6f84eab48931 NaN \n", "2 7be80267-dbe9-4f4b-8f73-c7355447d5e1 NaN \n", "3 b97011cb-c4fd-4ea9-8828-dc920c7b900a NaN \n", "4 6375bf74-3333-4cb6-a0dc-f95c3794edae NaN \n", "\n", " identifier license \n", "0 https://zenodo.org/record/2684906/files/CAM008... NaN \n", "1 https://zenodo.org/record/2714333/files/CAM041... NaN \n", "2 https://zenodo.org/record/2686762/files/CAM008... NaN \n", "3 https://zenodo.org/record/2684906/files/CAM008... NaN \n", "4 https://zenodo.org/record/2714333/files/CAM040... NaN " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "multimedia.head()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'https://zenodo.org/record/2684906/files/CAM008538_d.JPG'" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "multimedia.identifier[0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's get a filename and record number recorded. Would like to add a `zenodo_link` column to see how that matches up to the master file as well. David said these were mostly resolution for records from [3477891](https://zenodo.org/records/3477891) (where these files are from) at download.\n", "\n", "`identifier` is non-null for all entries, but there is one non-Zenodo link." ] }, { "cell_type": "code", "execution_count": 5, "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", "
coreidtypeidentifierlicensezenodo_linkImage_namerecord_number
0275ad2e7-bc7e-4e74-832e-869825f5bf0bNaNhttps://zenodo.org/record/2684906/files/CAM008...NaNhttps://zenodo.org/record/2684906CAM008538_d.JPG2684906
1cf02ac3a-6204-417c-b342-6f84eab48931NaNhttps://zenodo.org/record/2714333/files/CAM041...NaNhttps://zenodo.org/record/2714333CAM041048_v.JPG2714333
27be80267-dbe9-4f4b-8f73-c7355447d5e1NaNhttps://zenodo.org/record/2686762/files/CAM008...NaNhttps://zenodo.org/record/2686762CAM008842_d.JPG2686762
3b97011cb-c4fd-4ea9-8828-dc920c7b900aNaNhttps://zenodo.org/record/2684906/files/CAM008...NaNhttps://zenodo.org/record/2684906CAM008539_v.JPG2684906
46375bf74-3333-4cb6-a0dc-f95c3794edaeNaNhttps://zenodo.org/record/2714333/files/CAM040...NaNhttps://zenodo.org/record/2714333CAM040771_v.JPG2714333
\n", "
" ], "text/plain": [ " coreid type \\\n", "0 275ad2e7-bc7e-4e74-832e-869825f5bf0b NaN \n", "1 cf02ac3a-6204-417c-b342-6f84eab48931 NaN \n", "2 7be80267-dbe9-4f4b-8f73-c7355447d5e1 NaN \n", "3 b97011cb-c4fd-4ea9-8828-dc920c7b900a NaN \n", "4 6375bf74-3333-4cb6-a0dc-f95c3794edae NaN \n", "\n", " identifier license \\\n", "0 https://zenodo.org/record/2684906/files/CAM008... NaN \n", "1 https://zenodo.org/record/2714333/files/CAM041... NaN \n", "2 https://zenodo.org/record/2686762/files/CAM008... NaN \n", "3 https://zenodo.org/record/2684906/files/CAM008... NaN \n", "4 https://zenodo.org/record/2714333/files/CAM040... NaN \n", "\n", " zenodo_link Image_name record_number \n", "0 https://zenodo.org/record/2684906 CAM008538_d.JPG 2684906 \n", "1 https://zenodo.org/record/2714333 CAM041048_v.JPG 2714333 \n", "2 https://zenodo.org/record/2686762 CAM008842_d.JPG 2686762 \n", "3 https://zenodo.org/record/2684906 CAM008539_v.JPG 2684906 \n", "4 https://zenodo.org/record/2714333 CAM040771_v.JPG 2714333 " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def get_link_filename(identifier):\n", " if \"zenodo\" not in identifier:\n", " link_list = identifier.split(\"com/\")\n", " link_list[0] = np.nan\n", " else:\n", " link_list = identifier.split(\"/files/\")\n", " # link is first part, filename at end\n", " return pd.Series(link_list)\n", "\n", "def get_record_number(zenodo_link):\n", " if type(zenodo_link) != float:\n", " link = zenodo_link.split(\"record/\")\n", " return link[1]\n", "\n", "multimedia[[\"zenodo_link\", \"Image_name\"]] = multimedia[\"identifier\"].apply(get_link_filename)\n", "multimedia[\"record_number\"] = multimedia[\"zenodo_link\"].apply(get_record_number)\n", "multimedia.head()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "http://earthcape-heliconius.s3-eu-west-1.amazonaws.com/F1FD2804C9E643798A7C1B0D9FBDE4AB.JPG\n" ] } ], "source": [ "for link in list(multimedia.identifier):\n", " if \"zenodo\" not in link:\n", " print(link)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "So there is one image that does not have a Zenodo link." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 5683 entries, 0 to 5682\n", "Data columns (total 7 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 coreid 5683 non-null object \n", " 1 type 0 non-null float64\n", " 2 identifier 5683 non-null object \n", " 3 license 0 non-null float64\n", " 4 zenodo_link 5682 non-null object \n", " 5 Image_name 5683 non-null object \n", " 6 record_number 5682 non-null object \n", "dtypes: float64(2), object(5)\n", "memory usage: 310.9+ KB\n" ] } ], "source": [ "multimedia.info()" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "coreid 2794\n", "type 0\n", "identifier 5683\n", "license 0\n", "zenodo_link 12\n", "Image_name 5683\n", "record_number 12\n", "dtype: int64" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "multimedia.nunique()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `coreid` is repeated, but the `Image_name` is unique across entries, so this could (hopefully) connect us to the source images." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "record_number\n", "2707828 1276\n", "2714333 1113\n", "2686762 986\n", "2684906 863\n", "2677821 703\n", "2702457 276\n", "2682458 158\n", "2682669 124\n", "2552371 91\n", "2550097 50\n", "2553977 22\n", "2813153 20\n", "Name: count, dtype: int64" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "multimedia.record_number.value_counts()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Interesting, it would seem that record 3477891 is a collection of these 12 other records. It matches with this [GBIF Collection](https://www.gbif.org/dataset/34f8683a-dfc0-46b8-acf6-390fe5ca6b92) that is the \"collection records from the research group of Chris Jiggins at the University of Cambridge derived from almost 20 years of field studies. Many records include images as well as locality data.\" released in October 2019." ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 4372 entries, 0 to 4371\n", "Data columns (total 29 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 id 4372 non-null object \n", " 1 occurrenceID 4372 non-null object \n", " 2 catalogNumber 4372 non-null object \n", " 3 datasetName 4372 non-null object \n", " 4 recordNumber 0 non-null float64\n", " 5 otherCatalogNumbers 33 non-null object \n", " 6 basisOfRecord 4372 non-null object \n", " 7 eventDate 3806 non-null object \n", " 8 locality 4372 non-null object \n", " 9 country 4372 non-null object \n", " 10 decimalLatitude 4372 non-null float64\n", " 11 decimalLongitude 4372 non-null float64\n", " 12 geodeticDatum 4372 non-null int64 \n", " 13 year 3806 non-null float64\n", " 14 sex 3882 non-null object \n", " 15 lifeStage 39 non-null object \n", " 16 recordedBy 0 non-null float64\n", " 17 individualCount 4372 non-null int64 \n", " 18 taxonId 1105 non-null float64\n", " 19 scientificName 4360 non-null object \n", " 20 scientificNameAuthorship 0 non-null float64\n", " 21 taxonRank 4358 non-null object \n", " 22 genus 4358 non-null object \n", " 23 family 4086 non-null object \n", " 24 order 4086 non-null object \n", " 25 class 4086 non-null object \n", " 26 kingdom 4086 non-null object \n", " 27 coordinateUncertaintyInMeters 0 non-null float64\n", " 28 dynamicProperties 4372 non-null object \n", "dtypes: float64(8), int64(2), object(19)\n", "memory usage: 990.7+ KB\n" ] } ], "source": [ "occurrence = pd.read_csv(\"../metadata/deduplication/Zenodo_meta_files/occurrences__(rec_3477891).csv\",low_memory=False)\n", "occurrence.info(show_counts=True)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "id 4372\n", "occurrenceID 4372\n", "catalogNumber 4372\n", "datasetName 1\n", "dtype: int64" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "occurrence[(occurrence.columns)[:4]].nunique()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Are `id` and `occurrenceID` all equal?" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(4372, 29)" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "occurrence.loc[occurrence[\"id\"] == occurrence[\"occurrenceID\"]].shape" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This has a record number column, but there are no non-null values, so we'll try to fill that in. Except there is nothing to use to fill it in...we have to connect on `catalogNumber` to the `id` to the `coreid`, but `catalogNumber` is just the CAMID and we have more unique IDs than there are in the multimedia file..." ] }, { "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idoccurrenceIDcatalogNumberdatasetNamerecordNumberotherCatalogNumbersbasisOfRecordeventDatelocalitycountry...scientificNamescientificNameAuthorshiptaxonRankgenusfamilyorderclasskingdomcoordinateUncertaintyInMetersdynamicProperties
000075b7f-3920-4987-a3e4-e98568a3855800075b7f-3920-4987-a3e4-e98568a38558CAM040599Heliconiine Butterfly Collection Records from ...NaNNaNPreservedSpecimen2017-03-07Mashpi to Pachijal 2Ecuador...Heliconius cydno ssp. alitheaNaNSubspeciesHeliconiusNymphalidaeLepidopteraInsectaAnimaliaNaN{}
1000dc8ca-5d60-4aff-9823-33d20d52c7cd000dc8ca-5d60-4aff-9823-33d20d52c7cdCAM040277Heliconiine Butterfly Collection Records from ...NaNNaNPreservedSpecimen2017-01-30Km 119 Baeza - Lago AgrioEcuador...Actinote sp.NaNSpeciesActinoteNymphalidaeLepidopteraInsectaAnimaliaNaN{}
2001b4619-bfe3-4a89-9709-45a70c1fa380001b4619-bfe3-4a89-9709-45a70c1fa380CAM120368Heliconiine Butterfly Collection Records from ...NaNNaNPreservedSpecimen2005-11-15Anangu Boca del Rio ECD OREcuador...Pseudoscada timna ssp. utillaNaNSubspeciesPseudoscadaNymphalidaeLepidopteraInsectaAnimaliaNaN{}
30021e86f-64b3-4ce8-b872-f783f00f5f6a0021e86f-64b3-4ce8-b872-f783f00f5f6aCAM014638Heliconiine Butterfly Collection Records from ...NaNNaNPreservedSpecimen2009-11-23Puerta LaraPanamá...Heliconius melpomene ssp. melpomeneNaNSubspeciesHeliconiusNymphalidaeLepidopteraInsectaAnimaliaNaN{}
40034a857-9ed6-45be-b437-8e20eef541bb0034a857-9ed6-45be-b437-8e20eef541bbCAM008071Heliconiine Butterfly Collection Records from ...NaNNaNPreservedSpecimen2000-12-17Gamboa #183Panamá...Anthanassa drusillaNaNSpeciesAnthanassaNymphalidaeLepidopteraInsectaAnimaliaNaN{}
\n", "

5 rows × 29 columns

\n", "
" ], "text/plain": [ " id occurrenceID \\\n", "0 00075b7f-3920-4987-a3e4-e98568a38558 00075b7f-3920-4987-a3e4-e98568a38558 \n", "1 000dc8ca-5d60-4aff-9823-33d20d52c7cd 000dc8ca-5d60-4aff-9823-33d20d52c7cd \n", "2 001b4619-bfe3-4a89-9709-45a70c1fa380 001b4619-bfe3-4a89-9709-45a70c1fa380 \n", "3 0021e86f-64b3-4ce8-b872-f783f00f5f6a 0021e86f-64b3-4ce8-b872-f783f00f5f6a \n", "4 0034a857-9ed6-45be-b437-8e20eef541bb 0034a857-9ed6-45be-b437-8e20eef541bb \n", "\n", " catalogNumber datasetName \\\n", "0 CAM040599 Heliconiine Butterfly Collection Records from ... \n", "1 CAM040277 Heliconiine Butterfly Collection Records from ... \n", "2 CAM120368 Heliconiine Butterfly Collection Records from ... \n", "3 CAM014638 Heliconiine Butterfly Collection Records from ... \n", "4 CAM008071 Heliconiine Butterfly Collection Records from ... \n", "\n", " recordNumber otherCatalogNumbers basisOfRecord eventDate \\\n", "0 NaN NaN PreservedSpecimen 2017-03-07 \n", "1 NaN NaN PreservedSpecimen 2017-01-30 \n", "2 NaN NaN PreservedSpecimen 2005-11-15 \n", "3 NaN NaN PreservedSpecimen 2009-11-23 \n", "4 NaN NaN PreservedSpecimen 2000-12-17 \n", "\n", " locality country ... \\\n", "0 Mashpi to Pachijal 2 Ecuador ... \n", "1 Km 119 Baeza - Lago Agrio Ecuador ... \n", "2 Anangu Boca del Rio ECD OR Ecuador ... \n", "3 Puerta Lara Panamá ... \n", "4 Gamboa #183 Panamá ... \n", "\n", " scientificName scientificNameAuthorship taxonRank \\\n", "0 Heliconius cydno ssp. alithea NaN Subspecies \n", "1 Actinote sp. NaN Species \n", "2 Pseudoscada timna ssp. utilla NaN Subspecies \n", "3 Heliconius melpomene ssp. melpomene NaN Subspecies \n", "4 Anthanassa drusilla NaN Species \n", "\n", " genus family order class kingdom \\\n", "0 Heliconius Nymphalidae Lepidoptera Insecta Animalia \n", "1 Actinote Nymphalidae Lepidoptera Insecta Animalia \n", "2 Pseudoscada Nymphalidae Lepidoptera Insecta Animalia \n", "3 Heliconius Nymphalidae Lepidoptera Insecta Animalia \n", "4 Anthanassa Nymphalidae Lepidoptera Insecta Animalia \n", "\n", " coordinateUncertaintyInMeters dynamicProperties \n", "0 NaN {} \n", "1 NaN {} \n", "2 NaN {} \n", "3 NaN {} \n", "4 NaN {} \n", "\n", "[5 rows x 29 columns]" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "occurrence.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "How many unique CAMIDs do we have in `multimedia`?" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2802" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def get_camid(image_name):\n", " if \"_\" in image_name:\n", " return image_name.split(\"_\")[0]\n", " else:\n", " # We have at least one record with image name that doesn't have CAMID (the non-zenodo record)\n", " return np.nan\n", "\n", "multimedia[\"CAMID\"] = multimedia[\"Image_name\"].apply(get_camid)\n", "multimedia[\"CAMID\"].nunique()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Okay, so there are more unique `CAMID`s than there are unique `coreid`s, but less than there are unique CAMIDs (`catalogNumber`) in `occurrence`...\n", "\n", "What do I get if I merge these on `CAMID` and `coreid`?" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 5407 entries, 0 to 5406\n", "Data columns (total 37 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 coreid 5407 non-null object \n", " 1 type 0 non-null float64\n", " 2 identifier 5407 non-null object \n", " 3 license 0 non-null float64\n", " 4 zenodo_link 5407 non-null object \n", " 5 Image_name 5407 non-null object \n", " 6 record_number 5407 non-null object \n", " 7 CAMID 5407 non-null object \n", " 8 id 5407 non-null object \n", " 9 occurrenceID 5407 non-null object \n", " 10 catalogNumber 5407 non-null object \n", " 11 datasetName 5407 non-null object \n", " 12 recordNumber 0 non-null float64\n", " 13 otherCatalogNumbers 0 non-null object \n", " 14 basisOfRecord 5407 non-null object \n", " 15 eventDate 4937 non-null object \n", " 16 locality 5407 non-null object \n", " 17 country 5407 non-null object \n", " 18 decimalLatitude 5407 non-null float64\n", " 19 decimalLongitude 5407 non-null float64\n", " 20 geodeticDatum 5407 non-null int64 \n", " 21 year 4937 non-null float64\n", " 22 sex 5307 non-null object \n", " 23 lifeStage 0 non-null object \n", " 24 recordedBy 0 non-null float64\n", " 25 individualCount 5407 non-null int64 \n", " 26 taxonId 1473 non-null float64\n", " 27 scientificName 5389 non-null object \n", " 28 scientificNameAuthorship 0 non-null float64\n", " 29 taxonRank 5387 non-null object \n", " 30 genus 5387 non-null object \n", " 31 family 5211 non-null object \n", " 32 order 5211 non-null object \n", " 33 class 5211 non-null object \n", " 34 kingdom 5211 non-null object \n", " 35 coordinateUncertaintyInMeters 0 non-null float64\n", " 36 dynamicProperties 5407 non-null object \n", "dtypes: float64(10), int64(2), object(25)\n", "memory usage: 1.5+ MB\n" ] } ], "source": [ "test_merge = pd.merge(multimedia,\n", " occurrence,\n", " left_on = [\"coreid\", \"CAMID\"],\n", " right_on = [\"id\", \"catalogNumber\"],\n", " how = \"inner\")\n", "test_merge.info(show_counts=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "So there are about 270 images listed in `multimedia` that are unaccounted for in `occurences`." ] }, { "cell_type": "code", "execution_count": 16, "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", "
coreidtypeidentifierlicensezenodo_linkImage_namerecord_numberCAMIDidoccurrenceIDcatalogNumberdatasetName
0275ad2e7-bc7e-4e74-832e-869825f5bf0bNaNhttps://zenodo.org/record/2684906/files/CAM008...NaNhttps://zenodo.org/record/2684906CAM008538_d.JPG2684906CAM008538275ad2e7-bc7e-4e74-832e-869825f5bf0b275ad2e7-bc7e-4e74-832e-869825f5bf0bCAM008538Heliconiine Butterfly Collection Records from ...
1275ad2e7-bc7e-4e74-832e-869825f5bf0bNaNhttps://zenodo.org/record/2684906/files/CAM008...NaNhttps://zenodo.org/record/2684906CAM008538_v.JPG2684906CAM008538275ad2e7-bc7e-4e74-832e-869825f5bf0b275ad2e7-bc7e-4e74-832e-869825f5bf0bCAM008538Heliconiine Butterfly Collection Records from ...
2cf02ac3a-6204-417c-b342-6f84eab48931NaNhttps://zenodo.org/record/2714333/files/CAM041...NaNhttps://zenodo.org/record/2714333CAM041048_v.JPG2714333CAM041048cf02ac3a-6204-417c-b342-6f84eab48931cf02ac3a-6204-417c-b342-6f84eab48931CAM041048Heliconiine Butterfly Collection Records from ...
3cf02ac3a-6204-417c-b342-6f84eab48931NaNhttps://zenodo.org/record/2714333/files/CAM041...NaNhttps://zenodo.org/record/2714333CAM041048_d.JPG2714333CAM041048cf02ac3a-6204-417c-b342-6f84eab48931cf02ac3a-6204-417c-b342-6f84eab48931CAM041048Heliconiine Butterfly Collection Records from ...
47be80267-dbe9-4f4b-8f73-c7355447d5e1NaNhttps://zenodo.org/record/2686762/files/CAM008...NaNhttps://zenodo.org/record/2686762CAM008842_d.JPG2686762CAM0088427be80267-dbe9-4f4b-8f73-c7355447d5e17be80267-dbe9-4f4b-8f73-c7355447d5e1CAM008842Heliconiine Butterfly Collection Records from ...
\n", "
" ], "text/plain": [ " coreid type \\\n", "0 275ad2e7-bc7e-4e74-832e-869825f5bf0b NaN \n", "1 275ad2e7-bc7e-4e74-832e-869825f5bf0b NaN \n", "2 cf02ac3a-6204-417c-b342-6f84eab48931 NaN \n", "3 cf02ac3a-6204-417c-b342-6f84eab48931 NaN \n", "4 7be80267-dbe9-4f4b-8f73-c7355447d5e1 NaN \n", "\n", " identifier license \\\n", "0 https://zenodo.org/record/2684906/files/CAM008... NaN \n", "1 https://zenodo.org/record/2684906/files/CAM008... NaN \n", "2 https://zenodo.org/record/2714333/files/CAM041... NaN \n", "3 https://zenodo.org/record/2714333/files/CAM041... NaN \n", "4 https://zenodo.org/record/2686762/files/CAM008... NaN \n", "\n", " zenodo_link Image_name record_number \\\n", "0 https://zenodo.org/record/2684906 CAM008538_d.JPG 2684906 \n", "1 https://zenodo.org/record/2684906 CAM008538_v.JPG 2684906 \n", "2 https://zenodo.org/record/2714333 CAM041048_v.JPG 2714333 \n", "3 https://zenodo.org/record/2714333 CAM041048_d.JPG 2714333 \n", "4 https://zenodo.org/record/2686762 CAM008842_d.JPG 2686762 \n", "\n", " CAMID id \\\n", "0 CAM008538 275ad2e7-bc7e-4e74-832e-869825f5bf0b \n", "1 CAM008538 275ad2e7-bc7e-4e74-832e-869825f5bf0b \n", "2 CAM041048 cf02ac3a-6204-417c-b342-6f84eab48931 \n", "3 CAM041048 cf02ac3a-6204-417c-b342-6f84eab48931 \n", "4 CAM008842 7be80267-dbe9-4f4b-8f73-c7355447d5e1 \n", "\n", " occurrenceID catalogNumber \\\n", "0 275ad2e7-bc7e-4e74-832e-869825f5bf0b CAM008538 \n", "1 275ad2e7-bc7e-4e74-832e-869825f5bf0b CAM008538 \n", "2 cf02ac3a-6204-417c-b342-6f84eab48931 CAM041048 \n", "3 cf02ac3a-6204-417c-b342-6f84eab48931 CAM041048 \n", "4 7be80267-dbe9-4f4b-8f73-c7355447d5e1 CAM008842 \n", "\n", " datasetName \n", "0 Heliconiine Butterfly Collection Records from ... \n", "1 Heliconiine Butterfly Collection Records from ... \n", "2 Heliconiine Butterfly Collection Records from ... \n", "3 Heliconiine Butterfly Collection Records from ... \n", "4 Heliconiine Butterfly Collection Records from ... " ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "test_merge[list(test_merge.columns)[:12]].head()" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "coreid 2713\n", "CAMID 2713\n", "identifier 5407\n", "record_number 10\n", "dtype: int64" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "test_merge[[\"coreid\", \"CAMID\", \"identifier\", \"record_number\"]].nunique()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Uniqueness counts from `multimedia`:\n", "```\n", "CAMID 2802\n", "coreid 2794\n", "identifier 5683\n", "Image_name 5683\n", "record_number 12\n", "```\n", "It seems there are 2 records that don't match on IDs, which is a loss of 81 unique listings in `multimedia`.\n", "\n", "How will this compare to the entries from record 3477891 in our master file? Also, are these other records in there?" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Index: 5501 entries, 3235 to 42852\n", "Data columns (total 28 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 CAMID 5501 non-null object\n", " 1 X 5501 non-null int64 \n", " 2 Image_name 5501 non-null object\n", " 3 View 5501 non-null object\n", " 4 zenodo_name 5501 non-null object\n", " 5 zenodo_link 5501 non-null object\n", " 6 Sequence 5501 non-null object\n", " 7 Taxonomic_Name 5501 non-null object\n", " 8 Locality 5501 non-null object\n", " 9 Sample_accession 925 non-null object\n", " 10 Collected_by 0 non-null object\n", " 11 Other_ID 12 non-null object\n", " 12 Date 5025 non-null object\n", " 13 Dataset 5501 non-null object\n", " 14 Store 5421 non-null object\n", " 15 Brood 4 non-null object\n", " 16 Death_Date 0 non-null object\n", " 17 Cross_Type 0 non-null object\n", " 18 Stage 0 non-null object\n", " 19 Sex 5435 non-null object\n", " 20 Unit_Type 5501 non-null object\n", " 21 file_type 5501 non-null object\n", " 22 record_number 5501 non-null int64 \n", " 23 species 5501 non-null object\n", " 24 subspecies 3673 non-null object\n", " 25 genus 5501 non-null object\n", " 26 file_url 5501 non-null object\n", " 27 hybrid_stat 3705 non-null object\n", "dtypes: int64(2), object(26)\n", "memory usage: 1.2+ MB\n" ] } ], "source": [ "df = pd.read_csv(\"../Jiggins_Zenodo_Img_Master.csv\", low_memory = False)\n", "\n", "odd_record = df.loc[df[\"record_number\"] == 3477891]\n", "odd_record.info()" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [], "source": [ "id_cols = [\"CAMID\", \"X\", \"Image_name\", \"zenodo_name\", \"zenodo_link\", \"file_url\", \"Dataset\"]" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "CAMID 2704\n", "X 5501\n", "Image_name 5497\n", "zenodo_name 1\n", "zenodo_link 1\n", "file_url 5497\n", "Dataset 1\n", "dtype: int64" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "odd_record[id_cols].nunique()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This falls somewhere between the `multimedia` & `occurrence` merge, and the `multimedia` file. Let's see a sample of these images then try aligning it with `multimedia` on `Image_name`." ] }, { "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
CAMIDXImage_namezenodo_namezenodo_linkfile_urlDataset
3235CAM00000144387CAM000001_v.JPGoccurences_and_multimedia.csvhttps://zenodo.org/record/3477891https://zenodo.org/record/3477891/files/CAM000...Heliconiine Butterfly Collection Records from ...
3236CAM00000144386CAM000001_d.JPGoccurences_and_multimedia.csvhttps://zenodo.org/record/3477891https://zenodo.org/record/3477891/files/CAM000...Heliconiine Butterfly Collection Records from ...
3237CAM00000344388CAM000003_d.JPGoccurences_and_multimedia.csvhttps://zenodo.org/record/3477891https://zenodo.org/record/3477891/files/CAM000...Heliconiine Butterfly Collection Records from ...
3240CAM00000344389CAM000003_v.JPGoccurences_and_multimedia.csvhttps://zenodo.org/record/3477891https://zenodo.org/record/3477891/files/CAM000...Heliconiine Butterfly Collection Records from ...
3242CAM00000444390CAM000004_d.JPGoccurences_and_multimedia.csvhttps://zenodo.org/record/3477891https://zenodo.org/record/3477891/files/CAM000...Heliconiine Butterfly Collection Records from ...
\n", "
" ], "text/plain": [ " CAMID X Image_name zenodo_name \\\n", "3235 CAM000001 44387 CAM000001_v.JPG occurences_and_multimedia.csv \n", "3236 CAM000001 44386 CAM000001_d.JPG occurences_and_multimedia.csv \n", "3237 CAM000003 44388 CAM000003_d.JPG occurences_and_multimedia.csv \n", "3240 CAM000003 44389 CAM000003_v.JPG occurences_and_multimedia.csv \n", "3242 CAM000004 44390 CAM000004_d.JPG occurences_and_multimedia.csv \n", "\n", " zenodo_link \\\n", "3235 https://zenodo.org/record/3477891 \n", "3236 https://zenodo.org/record/3477891 \n", "3237 https://zenodo.org/record/3477891 \n", "3240 https://zenodo.org/record/3477891 \n", "3242 https://zenodo.org/record/3477891 \n", "\n", " file_url \\\n", "3235 https://zenodo.org/record/3477891/files/CAM000... \n", "3236 https://zenodo.org/record/3477891/files/CAM000... \n", "3237 https://zenodo.org/record/3477891/files/CAM000... \n", "3240 https://zenodo.org/record/3477891/files/CAM000... \n", "3242 https://zenodo.org/record/3477891/files/CAM000... \n", "\n", " Dataset \n", "3235 Heliconiine Butterfly Collection Records from ... \n", "3236 Heliconiine Butterfly Collection Records from ... \n", "3237 Heliconiine Butterfly Collection Records from ... \n", "3240 Heliconiine Butterfly Collection Records from ... \n", "3242 Heliconiine Butterfly Collection Records from ... " ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "odd_record[id_cols].head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "They are all labeled as that dataset with the `zenodo_name` \"occurrences_and_multimedia.csv\" because it was a combo of these used by Christopher to populate the CSV." ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 5501 entries, 0 to 5500\n", "Data columns (total 14 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 CAMID_master 5501 non-null object \n", " 1 X 5501 non-null int64 \n", " 2 Image_name 5501 non-null object \n", " 3 zenodo_name 5501 non-null object \n", " 4 zenodo_link_master 5501 non-null object \n", " 5 file_url 5501 non-null object \n", " 6 Dataset 5501 non-null object \n", " 7 coreid 5501 non-null object \n", " 8 type 0 non-null float64\n", " 9 identifier 5501 non-null object \n", " 10 license 0 non-null float64\n", " 11 zenodo_link_media 5501 non-null object \n", " 12 record_number 5501 non-null object \n", " 13 CAMID_media 5409 non-null object \n", "dtypes: float64(2), int64(1), object(11)\n", "memory usage: 601.8+ KB\n" ] } ], "source": [ "odd_multimedia = pd.merge(odd_record[id_cols],\n", " multimedia,\n", " on = \"Image_name\",\n", " how = \"inner\",\n", " suffixes = (\"_master\", \"_media\"))\n", "odd_multimedia.info()" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "CAMID_master 2704\n", "X 5501\n", "Image_name 5497\n", "zenodo_name 1\n", "zenodo_link_master 1\n", "file_url 5497\n", "Dataset 1\n", "coreid 2704\n", "type 0\n", "identifier 5497\n", "license 0\n", "zenodo_link_media 12\n", "record_number 12\n", "CAMID_media 2712\n", "dtype: int64" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "odd_multimedia.nunique()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Looks like all the images were captured (there are more entries than unique `Image_name` & URL), so we should be able to replace the URLs in the master file with the multimedia image URLs directly.\n", "\n", "We do want to compare record numbers to the master file first." ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "media_records = list(multimedia.record_number.unique())\n", "media_imgs = list(multimedia.Image_name.unique())\n", "master_records = list(df.record_number.unique())\n", "\n", "overlap_records = [record for record in media_records if record in master_records]\n", "len(overlap_records)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Ahhh no duplication then. Interesting (and good!)" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(5501, 55)" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "non_odd_df = df.loc[df[\"record_number\"] != 3477891]\n", "\n", "test_odd_merge = pd.merge(odd_record,\n", " non_odd_df,\n", " on = \"Image_name\",\n", " how = \"inner\")\n", "test_odd_merge.shape" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'https://zenodo.org/record/2677821/files/CAM000003_v.JPG'" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "multimedia.loc[multimedia[\"Image_name\"] == \"CAM000003_v.JPG\", \"identifier\"].values[0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Duplication in `Image_name`, though that's not necessarily unexpected." ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "CAMID 2704\n", "X 5501\n", "Image_name 5497\n", "View 2\n", "zenodo_name 1\n", "zenodo_link 1\n", "Sequence 2704\n", "Taxonomic_Name 195\n", "Locality 205\n", "Sample_accession 446\n", "Collected_by 0\n", "Other_ID 5\n", "Date 200\n", "Dataset 1\n", "Store 55\n", "Brood 2\n", "Death_Date 0\n", "Cross_Type 0\n", "Stage 0\n", "Sex 3\n", "Unit_Type 2\n", "file_type 1\n", "record_number 1\n", "species 121\n", "subspecies 93\n", "genus 38\n", "file_url 5497\n", "hybrid_stat 2\n", "dtype: int64" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "for image_name in list(odd_record.Image_name.unique()):\n", " url = multimedia.loc[multimedia[\"Image_name\"] == image_name, \"identifier\"].values[0]\n", " df.loc[(df[\"record_number\"] == 3477891) & (df[\"Image_name\"] == image_name), \"file_url\"] = url\n", "\n", "df.loc[df[\"record_number\"] == 3477891].nunique()" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "CAMID 11991\n", "X 44809\n", "Image_name 36281\n", "zenodo_name 33\n", "zenodo_link 30\n", "file_url 39297\n", "Dataset 8\n", "dtype: int64" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df[id_cols].nunique()" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Dataset\n", "Heliconiine Butterfly Collection Records from University of Cambridge 25211\n", "Patricio Salazar 7519\n", "Nadeau Sheffield 3233\n", "Bogota Collection (Camilo Salazar) 982\n", "Cambridge Collection 47\n", "Mallet 22\n", "Merril_Gamboa 6\n", "STRI Collection (Owen) 4\n", "Name: count, dtype: int64" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.Dataset.value_counts()" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "CAMID 6538\n", "X 25211\n", "Image_name 17362\n", "View 7\n", "zenodo_name 17\n", "zenodo_link 17\n", "Sequence 6538\n", "Taxonomic_Name 287\n", "Locality 372\n", "Sample_accession 485\n", "Collected_by 0\n", "Other_ID 1123\n", "Date 282\n", "Dataset 1\n", "Store 102\n", "Brood 102\n", "Death_Date 0\n", "Cross_Type 0\n", "Stage 0\n", "Sex 3\n", "Unit_Type 2\n", "file_type 2\n", "record_number 17\n", "species 207\n", "subspecies 99\n", "genus 82\n", "file_url 19710\n", "hybrid_stat 2\n", "dtype: int64" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "HBCRUC = \"Heliconiine Butterfly Collection Records from University of Cambridge\"\n", "df.loc[df.Dataset == HBCRUC].nunique()" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [], "source": [ "df.to_csv(\"../metadata/Jiggins_Zenodo_Img_Master_3477891Patch.csv\", index = False)" ] } ], "metadata": { "kernelspec": { "display_name": "std", "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 }