{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Summary\n", "\n", "We explored our downloaded images in `EDA-DL-0-3.ipynb`, and established the following causes of duplication along with remedies:\n", "1. The \"patch\" record (record 3477891) which required alignment in `Data-gen-1-1.ipynb`, resulting in `../metadata/Jiggins_Zenodo_Img_Master_3477891Patch.csv` used for download, is a duplication of all listed records. Additionally, it introduced extra copies of 4 images with incorrect labels for their views (i.e., dorsal vs ventral).\n", " - Solution: This record will be removed.\n", "2. The remaining duplication (430 images x2) comes from 5 records: [4291095](https://zenodo.org/records/4291095), [2813153](https://zenodo.org/records/2813153), [5526257](https://zenodo.org/records/5526257), [2553977](https://zenodo.org/records/2553977), and [2552371](https://zenodo.org/records/2552371).\n", " - Though there is nothing in their descriptions on Zenodo to indicate this overlap occurred, record 4291095 duplicated 415 images from record 2813153. 104 of these images had their view/side labels (dorsal vs ventral) updated to reflect an earlier mislabeling in record 2813153; these were all RAW copies of the images. All other metadata was consistent across records.\n", " - Solution: Copies of these images and their metadata will be retained from the newer record, record 4291095.\n", " - Record 5526257 has 10 images that were added twice. All their metadata is consistent, so we will just keep the first instance of each image.\n", " - Records 2553977 and 2552371 are both \"Miscellaneous Heliconius wing photographs (2001-2019)\" Parts 3 & 1, respectively. Record 2553977 has duplicated images with matching metadata, though 3 of the 4 images have different filenames (`Image_name`). It seems to have resulted from typos or not indicating `cut`, as they are all close-up crops of a single wing. From this perspective, the view labels (dorsal) don't seem appropriate when we have more fine-grained indicators such as \"forewing dorsal\".\n", " - Suggestion that the entries in this record with `cut` in the filename not be used for general classification unless this variety is desired. These also appear to be all the `tif` images, which are often ignored.\n", " - Record 2552371 has one image duplicated with two different `CAMID`s assigned (different views as well). These will both be removed as the image has no indicator of the specimen ID in it. Note that these also were labeled `Heliconius sp.`.\n", "3. Looking at images that were not duplicates, there are clearly still multiple images of the same specimen from the same perspective (eg., two dorsal images) that are also of the same file type (eg., both jpgs). Duplication was checked at the pixel level, so there is no guarantee that they are truly different images, but due to the scope of this collection (over 20 years), it does not seem unlikely that multiple images could have been taken of the same specimen. \n", " - Suggestion/Solution: When determining splits using this data, follow these steps:\n", " 1. Ensure you are looking at only **_one_** view (eg., dorsal or ventral).\n", " 2. Ensure you are only looking one file type (`raw`, `jpg`, or `tif`).\n", " 3. Reduce to only unique `CAMID`s.\n", " 4. Generate splits as desired.\n", " 5. Add images to splits based on matched `CAMID`s if multiple views are desired (i.e., if a `CAMID` is present in the dorsal training, add the matching ventral image to the training set).\n", " 6. Be sure to check only desired categories are included, such as excluding hybrids or cross types, or specimens not labeled to the level of classification.\n", "\n", "\n", "## Generate \"Clean\" Master Metadata File\n", "\n", "We'll now generate a cleaned master metadata file from `../metadata/deduplication/Jiggins_Zenodo_Img_Master_3477891Patch_downloaded.csv` (generated in `EDA-DL-0-3.ipynb` from our download master file and checksums of successful downloads) following the solutions outlined above. " ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "STATS_COLS = [\"X\",\n", " \"CAMID\",\n", " \"Image_name\",\n", " \"md5\",\n", " \"record_number\",\n", " \"Taxonomic_Name\",\n", " \"species\",\n", " \"subspecies\",\n", " \"genus\",\n", " \"Cross_Type\",\n", " \"View\",\n", " \"Locality\",\n", " \"Sex\",\n", " \"Dataset\",\n", " \"file_type\"]" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 42143 entries, 0 to 42142\n", "Data columns (total 15 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 X 42143 non-null int64 \n", " 1 CAMID 42143 non-null object\n", " 2 Image_name 42143 non-null object\n", " 3 md5 42143 non-null object\n", " 4 record_number 42143 non-null int64 \n", " 5 Taxonomic_Name 42143 non-null object\n", " 6 species 42143 non-null object\n", " 7 subspecies 24502 non-null object\n", " 8 genus 42143 non-null object\n", " 9 Cross_Type 4447 non-null object\n", " 10 View 41364 non-null object\n", " 11 Locality 29047 non-null object\n", " 12 Sex 33254 non-null object\n", " 13 Dataset 34924 non-null object\n", " 14 file_type 42143 non-null object\n", "dtypes: int64(2), object(13)\n", "memory usage: 4.8+ MB\n" ] } ], "source": [ "df = pd.read_csv(\"../metadata/deduplication/Jiggins_Zenodo_Img_Master_3477891Patch_downloaded.csv\", low_memory = False)\n", "df[STATS_COLS].info()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "X 42143\n", "CAMID 11968\n", "Image_name 36216\n", "md5 36212\n", "record_number 30\n", "Taxonomic_Name 366\n", "species 246\n", "subspecies 155\n", "genus 94\n", "Cross_Type 30\n", "View 7\n", "Locality 644\n", "Sex 3\n", "Dataset 7\n", "file_type 3\n", "dtype: int64" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df[STATS_COLS].nunique()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Observations:\n", "- Half of the Zenodo records wind up with duplicated images. \n", "- `Image_name` uniqueness is close to `md5`, but there are 4 more unique image names than unique images. I believe this was from the duplication in reocrd 2553977. We can check when cleaning it. \n", "- None of the cross types are duplicated.\n", "- We do have multiple unique images for a single `CAMID`, more than just dorsal vs ventral since there are 11968 unique CAMIDs and 36212 unique `md5` values (36212 = **3**x11968 + 308)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Remove Record 3477891\n", "\n", "This is just a duplication of images and we already have from earlier records, along with some extra duplication that gets mislabeled." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "X 36642\n", "CAMID 11968\n", "Image_name 36216\n", "md5 36212\n", "record_number 29\n", "Taxonomic_Name 366\n", "species 246\n", "subspecies 155\n", "genus 94\n", "Cross_Type 30\n", "View 7\n", "Locality 644\n", "Sex 3\n", "Dataset 7\n", "file_type 3\n", "dtype: int64" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_reduced = df.loc[df[\"record_number\"] != 3477891].copy()\n", "df_reduced[STATS_COLS].nunique()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The only change is in `X` (our total entry count) and in `record_number` (expected since we removed one)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Address Remaining Duplicates\n", "\n", "The remaining duplicates are across 5 records and will require a bit more care to reslove (following the plan outlined at the top of the notebook and in the README).\n", "\n", "### Record 4291095 & 2813153 Duplicates\n", "\n", "There are 415 duplicates across these two records, with `View` corrections in record 4291095, so we will remove the duplicates from record 2813153." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['CAMID', 'X', 'Image_name', 'View', 'zenodo_name', 'zenodo_link',\n", " 'Sequence', 'Taxonomic_Name', 'Locality', 'Sample_accession',\n", " 'Collected_by', 'Other_ID', 'Date', 'Dataset', 'Store', 'Brood',\n", " 'Death_Date', 'Cross_Type', 'Stage', 'Sex', 'Unit_Type', 'file_type',\n", " 'record_number', 'species', 'subspecies', 'genus', 'file_url',\n", " 'hybrid_stat', 'filename', 'filepath', 'md5'],\n", " dtype='object')" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_reduced.columns" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We start by marking all duplicate images since the decision of which to keep is dependent on comparisons between them." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "md5_duplicated\n", "False 35782\n", "True 860\n", "Name: count, dtype: int64" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_reduced[\"md5_duplicated\"] = df_reduced.duplicated(\"md5\", keep = False)\n", "df_reduced[\"md5_duplicated\"].value_counts()" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "415" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "duplicates = df_reduced[df_reduced[\"md5_duplicated\"]]\n", "dupes_2813153 = duplicates.loc[duplicates[\"record_number\"] == 2813153]\n", "#print(duplicates.loc[duplicates[\"record_number\"] == 4291095])\n", "dupes_2813153.shape[0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We will record the `X` value from these 415 entries to remove them from the overall dataset in favor of the updated entries from record 4291095." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "X_dupes_2813153 = list(dupes_2813153.X)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "X 36227\n", "CAMID 11968\n", "Image_name 36216\n", "md5 36212\n", "record_number 29\n", "Taxonomic_Name 366\n", "species 246\n", "subspecies 155\n", "genus 94\n", "Cross_Type 30\n", "View 7\n", "Locality 644\n", "Sex 3\n", "Dataset 7\n", "file_type 3\n", "dtype: int64" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_reduced_2 = df_reduced.loc[~df_reduced[\"X\"].isin(X_dupes_2813153)]\n", "df_reduced_2[STATS_COLS].nunique()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As expected, our numbers are holding steady with a reduction in `X` values of 415." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Record 5526257 Duplicates\n", "\n", "For record 5526257, the 10 duplicated entries are all the same, so we will just check `.duplicated` and keep the first instance of each." ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "dupe_entries\n", "False 10\n", "True 10\n", "Name: count, dtype: int64\n" ] }, { "data": { "text/plain": [ "10" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dupes_5526257 = duplicates.loc[duplicates[\"record_number\"] == 5526257].copy()\n", "dupes_5526257[\"dupe_entries\"] = dupes_5526257.duplicated([\"CAMID\", \"Image_name\", \"View\", \"Taxonomic_Name\", \"Locality\", \"md5\"], keep = \"first\")\n", "print(dupes_5526257[\"dupe_entries\"].value_counts())\n", "\n", "X_dupes_5526257 = list(dupes_5526257.loc[dupes_5526257[\"dupe_entries\"], \"X\"])\n", "len(X_dupes_5526257)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "X 36217\n", "CAMID 11968\n", "Image_name 36216\n", "md5 36212\n", "record_number 29\n", "Taxonomic_Name 366\n", "species 246\n", "subspecies 155\n", "genus 94\n", "Cross_Type 30\n", "View 7\n", "Locality 644\n", "Sex 3\n", "Dataset 7\n", "file_type 3\n", "dtype: int64" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_reduced_3 = df_reduced_2.loc[~df_reduced_2[\"X\"].isin(X_dupes_5526257)]\n", "df_reduced_3[STATS_COLS].nunique()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Reduction in `X` by 10, consistency in all other numbers.\n", "\n", "### Record 2552371 Duplicates\n", "\n", "We are removing both duplicates from this record as their metadata is contradictory and cannot be verified. (Two different CAMIDs, different filenames, different views, etc.)" ] }, { "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", "
CAMIDXImage_nameViewzenodo_namezenodo_linkSequenceTaxonomic_NameLocalitySample_accession...record_numberspeciessubspeciesgenusfile_urlhybrid_statfilenamefilepathmd5md5_duplicated
11978CAM0103542347110354d.jpgdorsalHeliconius_wing_old_photos_2001_2019_part1.csvhttps://zenodo.org/record/255237110,354Heliconius sp.NaNNaN...2552371Heliconius sp.NaNHeliconiushttps://zenodo.org/record/2552371/files/10354d...NaN23471_10354d.jpgimages/Heliconius sp./23471_10354d.jpg84d4ac6527458786cdb33166cd80e0a8True
12010CAM0103622348410362v.jpgventralHeliconius_wing_old_photos_2001_2019_part1.csvhttps://zenodo.org/record/255237110,362Heliconius sp.NaNNaN...2552371Heliconius sp.NaNHeliconiushttps://zenodo.org/record/2552371/files/10362v...NaN23484_10362v.jpgimages/Heliconius sp./23484_10362v.jpg84d4ac6527458786cdb33166cd80e0a8True
\n", "

2 rows × 32 columns

\n", "
" ], "text/plain": [ " CAMID X Image_name View \\\n", "11978 CAM010354 23471 10354d.jpg dorsal \n", "12010 CAM010362 23484 10362v.jpg ventral \n", "\n", " zenodo_name \\\n", "11978 Heliconius_wing_old_photos_2001_2019_part1.csv \n", "12010 Heliconius_wing_old_photos_2001_2019_part1.csv \n", "\n", " zenodo_link Sequence Taxonomic_Name Locality \\\n", "11978 https://zenodo.org/record/2552371 10,354 Heliconius sp. NaN \n", "12010 https://zenodo.org/record/2552371 10,362 Heliconius sp. NaN \n", "\n", " Sample_accession ... record_number species subspecies \\\n", "11978 NaN ... 2552371 Heliconius sp. NaN \n", "12010 NaN ... 2552371 Heliconius sp. NaN \n", "\n", " genus file_url \\\n", "11978 Heliconius https://zenodo.org/record/2552371/files/10354d... \n", "12010 Heliconius https://zenodo.org/record/2552371/files/10362v... \n", "\n", " hybrid_stat filename filepath \\\n", "11978 NaN 23471_10354d.jpg images/Heliconius sp./23471_10354d.jpg \n", "12010 NaN 23484_10362v.jpg images/Heliconius sp./23484_10362v.jpg \n", "\n", " md5 md5_duplicated \n", "11978 84d4ac6527458786cdb33166cd80e0a8 True \n", "12010 84d4ac6527458786cdb33166cd80e0a8 True \n", "\n", "[2 rows x 32 columns]" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dupes_2552371 = duplicates.loc[duplicates[\"record_number\"] == 2552371]\n", "X_dupes_2552371 = list(dupes_2552371[\"X\"])\n", "dupes_2552371" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "X 36215\n", "CAMID 11968\n", "Image_name 36214\n", "md5 36211\n", "record_number 29\n", "Taxonomic_Name 366\n", "species 246\n", "subspecies 155\n", "genus 94\n", "Cross_Type 30\n", "View 7\n", "Locality 644\n", "Sex 3\n", "Dataset 7\n", "file_type 3\n", "dtype: int64" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_reduced_4 = df_reduced_3.loc[~df_reduced_3[\"X\"].isin(X_dupes_2552371)]\n", "df_reduced_4[STATS_COLS].nunique()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Removing these two has reduced our `X` count by 2, as well as our number of unique `Image_name`s, and it reduced our unique image count (`md5`) by 1. Observe that our unique `CAMID` count has remained constant, so both specimens indicated by these duplicate images are still represented in the dataset." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Record 2553977 Duplicates\n", "\n", "The duplicated entries for record 2553977 are the most complicated in that their metadata is nearly exact, though a few have different filenames (`Image_name`) and we would like to preserve the version that has `_cut` in the name." ] }, { "cell_type": "code", "execution_count": 15, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
XCAMIDImage_namemd5record_numberTaxonomic_NamespeciessubspeciesgenusCross_TypeViewLocalitySexDatasetfile_type
4014126197CAM050147CAM050147_DS1_HW_IMG_8537_cut_3.tif21e726df7076f5c13fe1441126bac4d52553977Heliconius sara ssp. saraHeliconius sarasaraHeliconiusNaNdorsalMadingleyNaNNaNtif
4014426196CAM050147CAM050147_DS1_HW_IMG_8537_cut_3.tif21e726df7076f5c13fe1441126bac4d52553977Heliconius sara ssp. saraHeliconius sarasaraHeliconiusNaNdorsalMadingleyNaNNaNtif
4011226102CAM050036CAM050036_S1_9_FW_IMG_8547_wb_2.tif34adbd5596f977834fb2c6876d2f44932553977Heliconius sara ssp. saraHeliconius sarasaraHeliconiusNaNdorsalGamboa_insectariesNaNNaNtif
4011626115CAM050036CAM050036_S1_9_FW_IMG_8547_cut_2.tif34adbd5596f977834fb2c6876d2f44932553977Heliconius sara ssp. saraHeliconius sarasaraHeliconiusNaNdorsalGamboa_insectariesNaNNaNtif
4013826112CAM050147CAM050147_DS1_IMG_8513_4.tif464801449aa127933d9619cb4e6f0a012553977Heliconius sara ssp. saraHeliconius sarasaraHeliconiusNaNdorsalMadingleyNaNNaNtif
4014526117CAM050147CAM050147_DS1_FW_IMG_8513_cut_4.tif464801449aa127933d9619cb4e6f0a012553977Heliconius sara ssp. saraHeliconius sarasaraHeliconiusNaNdorsalMadingleyNaNNaNtif
4011326105CAM050036CAM050036_S1_9_HW_wt_IMG_8541_cut3.tif6d63d659fbc02369010938bbc229ad4d2553977Heliconius sara ssp. saraHeliconius sarasaraHeliconiusNaNdorsalGamboa_insectariesNaNNaNtif
4012026116CAM050036CAM050036_S1_9_HW_wt_IMG_8541_cut_3.tif6d63d659fbc02369010938bbc229ad4d2553977Heliconius sara ssp. saraHeliconius sarasaraHeliconiusNaNdorsalGamboa_insectariesNaNNaNtif
\n", "
" ], "text/plain": [ " X CAMID Image_name \\\n", "40141 26197 CAM050147 CAM050147_DS1_HW_IMG_8537_cut_3.tif \n", "40144 26196 CAM050147 CAM050147_DS1_HW_IMG_8537_cut_3.tif \n", "40112 26102 CAM050036 CAM050036_S1_9_FW_IMG_8547_wb_2.tif \n", "40116 26115 CAM050036 CAM050036_S1_9_FW_IMG_8547_cut_2.tif \n", "40138 26112 CAM050147 CAM050147_DS1_IMG_8513_4.tif \n", "40145 26117 CAM050147 CAM050147_DS1_FW_IMG_8513_cut_4.tif \n", "40113 26105 CAM050036 CAM050036_S1_9_HW_wt_IMG_8541_cut3.tif \n", "40120 26116 CAM050036 CAM050036_S1_9_HW_wt_IMG_8541_cut_3.tif \n", "\n", " md5 record_number \\\n", "40141 21e726df7076f5c13fe1441126bac4d5 2553977 \n", "40144 21e726df7076f5c13fe1441126bac4d5 2553977 \n", "40112 34adbd5596f977834fb2c6876d2f4493 2553977 \n", "40116 34adbd5596f977834fb2c6876d2f4493 2553977 \n", "40138 464801449aa127933d9619cb4e6f0a01 2553977 \n", "40145 464801449aa127933d9619cb4e6f0a01 2553977 \n", "40113 6d63d659fbc02369010938bbc229ad4d 2553977 \n", "40120 6d63d659fbc02369010938bbc229ad4d 2553977 \n", "\n", " Taxonomic_Name species subspecies genus \\\n", "40141 Heliconius sara ssp. sara Heliconius sara sara Heliconius \n", "40144 Heliconius sara ssp. sara Heliconius sara sara Heliconius \n", "40112 Heliconius sara ssp. sara Heliconius sara sara Heliconius \n", "40116 Heliconius sara ssp. sara Heliconius sara sara Heliconius \n", "40138 Heliconius sara ssp. sara Heliconius sara sara Heliconius \n", "40145 Heliconius sara ssp. sara Heliconius sara sara Heliconius \n", "40113 Heliconius sara ssp. sara Heliconius sara sara Heliconius \n", "40120 Heliconius sara ssp. sara Heliconius sara sara Heliconius \n", "\n", " Cross_Type View Locality Sex Dataset file_type \n", "40141 NaN dorsal Madingley NaN NaN tif \n", "40144 NaN dorsal Madingley NaN NaN tif \n", "40112 NaN dorsal Gamboa_insectaries NaN NaN tif \n", "40116 NaN dorsal Gamboa_insectaries NaN NaN tif \n", "40138 NaN dorsal Madingley NaN NaN tif \n", "40145 NaN dorsal Madingley NaN NaN tif \n", "40113 NaN dorsal Gamboa_insectaries NaN NaN tif \n", "40120 NaN dorsal Gamboa_insectaries NaN NaN tif " ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dupes_2553977 = duplicates.loc[duplicates[\"record_number\"] == 2553977]\n", "dupes_2553977[STATS_COLS].sort_values(\"md5\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For each of these, we want the one with `_cut_` in the `Image_name`." ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[26102, 26105, 26112]" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "X_dupes_2553977 = [x for x in list(dupes_2553977[\"X\"]) if \"_cut_\" not in dupes_2553977.loc[dupes_2553977[\"X\"] == x, \"Image_name\"].values[0]]\n", "\n", "# Check we got the ones expected\n", "X_dupes_2553977" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "# Add 26196, since both those entries (26196 and 26197) are the same\n", "X_dupes_2553977.append(26196)\n" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "X 36211\n", "CAMID 11968\n", "Image_name 36211\n", "md5 36211\n", "record_number 29\n", "Taxonomic_Name 366\n", "species 246\n", "subspecies 155\n", "genus 94\n", "Cross_Type 30\n", "View 7\n", "Locality 644\n", "Sex 3\n", "Dataset 7\n", "file_type 3\n", "dtype: int64" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_reduced_5 = df_reduced_4.loc[~df_reduced_4[\"X\"].isin(X_dupes_2553977)]\n", "df_reduced_5[STATS_COLS].nunique()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "4 entries were removed, reducing our number of unique `Image_name`s by 3 (one of the duplicated images had all its metadata duplicated), and everything else has remained consistent. Now the number of unique image names and entries matches the number of unique images. We have a total of 36,211 images, and we will save this reduced CSV as our new master file." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Save Reduced Master File of Unique Images\n", "\n", "Don't include last column indicating duplicate MD5s." ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [], "source": [ "df_reduced_5[list(df_reduced_5.columns)[:-1]].to_csv(\"../Jiggins_Zenodo_Img_Master.csv\", index = False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Generate New Master Heliconius and Dorsal Subsets\n", "\n", "## Read in New Master File\n", "\n", "First check on our stats noted in the README." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 36211 entries, 0 to 36210\n", "Data columns (total 31 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 CAMID 36211 non-null object\n", " 1 X 36211 non-null int64 \n", " 2 Image_name 36211 non-null object\n", " 3 View 35432 non-null object\n", " 4 zenodo_name 36211 non-null object\n", " 5 zenodo_link 36211 non-null object\n", " 6 Sequence 35279 non-null object\n", " 7 Taxonomic_Name 36211 non-null object\n", " 8 Locality 23127 non-null object\n", " 9 Sample_accession 3647 non-null object\n", " 10 Collected_by 3043 non-null object\n", " 11 Other_ID 11329 non-null object\n", " 12 Date 23040 non-null object\n", " 13 Dataset 29114 non-null object\n", " 14 Store 27813 non-null object\n", " 15 Brood 13847 non-null object\n", " 16 Death_Date 269 non-null object\n", " 17 Cross_Type 4447 non-null object\n", " 18 Stage 6 non-null object\n", " 19 Sex 27514 non-null object\n", " 20 Unit_Type 25060 non-null object\n", " 21 file_type 36211 non-null object\n", " 22 record_number 36211 non-null int64 \n", " 23 species 36211 non-null object\n", " 24 subspecies 20400 non-null object\n", " 25 genus 36211 non-null object\n", " 26 file_url 36211 non-null object\n", " 27 hybrid_stat 20948 non-null object\n", " 28 filename 36211 non-null object\n", " 29 filepath 36211 non-null object\n", " 30 md5 36211 non-null object\n", "dtypes: int64(2), object(29)\n", "memory usage: 8.6+ MB\n" ] } ], "source": [ "master = pd.read_csv(\"../Jiggins_Zenodo_Img_Master.csv\", low_memory = False)\n", "master.info()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Taxonomic Labeling Check\n", "\n", "As noted above, there are instances of ` sp.` in the `Taxonomic_Name` column. These get reproduced in the `species` column as well. We also have at least one instance of just `Heliconius`, and an instance of `Unknown` was observed outside this process. To ensure the taxonomic information is indeed clear, we will print and check all 246 unique species listed in the dataset." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "pd.Series(master.species.unique()).to_csv(\"../metadata/Unique_species_labels.txt\", index = False)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "We have 24 'species' designations really labeled only to genus, 5 species designations that may not be labeled at the species level, and 1 with 'hybrid' in the name.\n" ] } ], "source": [ "species_list = list(master.species.unique())\n", "\n", "sp_list = []\n", "one_word_list = []\n", "hybrid_label = []\n", "for species in species_list:\n", " if \"sp.\" in species:\n", " sp_list.append(species)\n", " if len(species.split(\" \")) == 1:\n", " one_word_list.append(species)\n", " if \"hybrid\" in species.lower():\n", " hybrid_label.append(species)\n", "\n", "print(f\"We have {len(sp_list)} 'species' designations really labeled only to genus, {len(one_word_list)} species designations that may not be labeled at the species level, and {len(hybrid_label)} with 'hybrid' in the name.\")" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['Pteronymia', 'Unknown', 'Ithomiinae', 'Stratiomyidae', 'Heliconius']" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "one_word_list" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['Heliconius hybrid']" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hybrid_label" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This matches my manual check:\n", "\n", "Non-standard labels found:\n", "\n", "- 'Heliconius hybrid'\n", "- \"sp.\":\n", " >'Heliconius sp.', 'Melinaea sp.', 'Oleria sp.', 'Ithomia sp.', 'Godyris sp.', 'Hypothyris sp.', 'Pteronymia sp.', 'Greta sp.', 'Dircenna sp.', 'Actinote sp.', 'Eresia sp.', 'Eueides sp.', 'Pteronymia sp.nov.', 'Patricia sp.', 'Hyalyris sp.', 'Olyras sp.', 'Mechanitis sp.', 'Euides sp.', 'Taygetis sp.', 'Euselasia sp.', 'Eunica sp.', 'Ascia sp.', 'Euptychia sp.', 'Megaleas sp.'\n", "- One name: 'Heliconius', 'Stratiomyidae', 'Ithomiinae', 'Pteronymia', + 'Unknown'. \n", " - This is becuase `species` was just a split at `ssp.` and take the first element of that list, hence the duplication of single names.\n", "\n", "### Taxonomic Labeling Fix:\n", "- We'll adjust the genera to be ` sp.` to be consistent. Then to avoid any labeled only to the genus level, one must simply exclude those with `sp.` in the species name. \n", "- The `Heliconius hybrid` should be labeled as a hybrid, but have null `subspecies` value, so that should be avoidable or useable as well. \n", "- We will remove the `Unknown` values as their CAMIDs don't appear elsewhere so the taxonomic information is non-reconcilable. \n", "- Christopher confirmed that `Ithomiinae` and `Pteronymia` are genera in the family `nymphalidae`, like `Heliconius`, but `Stratiomyidae` is a \"Soldier Fly\" (Google, Christopher did not recognize it as a butterfly), clearly not a butterfly from the images. This label is present in [record 5561246](https://zenodo.org/records/5561246), attached to `CAMID: CAM036326`, which does not appear elsewhere in our dataset (see check below). Looking at the record, it is labeled as `BSF blue wings` in the CSV, and the images are clearly of a butterfly's wings. We have concluded it is a mislabeling and will drop it for now." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "There are 18 entries with the taxonomic label 'Unknown', and 18 entries of that/those CAMID(s).\n" ] }, { "data": { "text/plain": [ "zenodo_link\n", "https://zenodo.org/record/5561246 12\n", "https://zenodo.org/record/4291095 4\n", "https://zenodo.org/record/2702457 2\n", "Name: count, dtype: int64" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cams_unknown = list(master.loc[master[\"species\"] == \"Unknown\", \"CAMID\"])\n", "print(f\"There are {len(cams_unknown)} entries with the taxonomic label 'Unknown', and {master.loc[master['CAMID'].isin(cams_unknown)].shape[0]} entries of that/those CAMID(s).\")\n", "master.loc[master[\"CAMID\"].isin(cams_unknown), \"zenodo_link\"].value_counts()" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "There are 4 entries with the taxonomic label 'Stratiomyidae', and 4 entries of that/those CAMID(s).\n" ] }, { "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", "
CAMIDXImage_nameViewzenodo_namezenodo_linkSequenceTaxonomic_NameLocalitySample_accession...file_typerecord_numberspeciessubspeciesgenusfile_urlhybrid_statfilenamefilepathmd5
21877CAM03632641866CAM036326_d.CR2dorsalFilelist.csvhttps://zenodo.org/record/556124636,326StratiomyidaeReserva Serra Bonita - BSF02NaN...raw5561246StratiomyidaeNaNStratiomyidaehttps://zenodo.org/record/5561246/files/CAM036...NaN41866_CAM036326_d.CR2images/Stratiomyidae/41866_CAM036326_d.CR24d823bf9308f967d8c1b2ea9325dac1d
21878CAM03632641867CAM036326_d.JPGdorsalFilelist.csvhttps://zenodo.org/record/556124636,326StratiomyidaeReserva Serra Bonita - BSF02NaN...jpg5561246StratiomyidaeNaNStratiomyidaehttps://zenodo.org/record/5561246/files/CAM036...NaN41867_CAM036326_d.JPGimages/Stratiomyidae/41867_CAM036326_d.JPG23d2d33583c31c83b3e36563418204b8
21879CAM03632641868CAM036326_v.CR2ventralFilelist.csvhttps://zenodo.org/record/556124636,326StratiomyidaeReserva Serra Bonita - BSF02NaN...raw5561246StratiomyidaeNaNStratiomyidaehttps://zenodo.org/record/5561246/files/CAM036...NaN41868_CAM036326_v.CR2images/Stratiomyidae/41868_CAM036326_v.CR2d4a628aa306aa7deafa93d2b913ba4de
21880CAM03632641869CAM036326_v.JPGventralFilelist.csvhttps://zenodo.org/record/556124636,326StratiomyidaeReserva Serra Bonita - BSF02NaN...jpg5561246StratiomyidaeNaNStratiomyidaehttps://zenodo.org/record/5561246/files/CAM036...NaN41869_CAM036326_v.JPGimages/Stratiomyidae/41869_CAM036326_v.JPG0a8ed38b8ad9755831bb796febaa624e
\n", "

4 rows × 31 columns

\n", "
" ], "text/plain": [ " CAMID X Image_name View zenodo_name \\\n", "21877 CAM036326 41866 CAM036326_d.CR2 dorsal Filelist.csv \n", "21878 CAM036326 41867 CAM036326_d.JPG dorsal Filelist.csv \n", "21879 CAM036326 41868 CAM036326_v.CR2 ventral Filelist.csv \n", "21880 CAM036326 41869 CAM036326_v.JPG ventral Filelist.csv \n", "\n", " zenodo_link Sequence Taxonomic_Name \\\n", "21877 https://zenodo.org/record/5561246 36,326 Stratiomyidae \n", "21878 https://zenodo.org/record/5561246 36,326 Stratiomyidae \n", "21879 https://zenodo.org/record/5561246 36,326 Stratiomyidae \n", "21880 https://zenodo.org/record/5561246 36,326 Stratiomyidae \n", "\n", " Locality Sample_accession ... file_type \\\n", "21877 Reserva Serra Bonita - BSF02 NaN ... raw \n", "21878 Reserva Serra Bonita - BSF02 NaN ... jpg \n", "21879 Reserva Serra Bonita - BSF02 NaN ... raw \n", "21880 Reserva Serra Bonita - BSF02 NaN ... jpg \n", "\n", " record_number species subspecies genus \\\n", "21877 5561246 Stratiomyidae NaN Stratiomyidae \n", "21878 5561246 Stratiomyidae NaN Stratiomyidae \n", "21879 5561246 Stratiomyidae NaN Stratiomyidae \n", "21880 5561246 Stratiomyidae NaN Stratiomyidae \n", "\n", " file_url hybrid_stat \\\n", "21877 https://zenodo.org/record/5561246/files/CAM036... NaN \n", "21878 https://zenodo.org/record/5561246/files/CAM036... NaN \n", "21879 https://zenodo.org/record/5561246/files/CAM036... NaN \n", "21880 https://zenodo.org/record/5561246/files/CAM036... NaN \n", "\n", " filename filepath \\\n", "21877 41866_CAM036326_d.CR2 images/Stratiomyidae/41866_CAM036326_d.CR2 \n", "21878 41867_CAM036326_d.JPG images/Stratiomyidae/41867_CAM036326_d.JPG \n", "21879 41868_CAM036326_v.CR2 images/Stratiomyidae/41868_CAM036326_v.CR2 \n", "21880 41869_CAM036326_v.JPG images/Stratiomyidae/41869_CAM036326_v.JPG \n", "\n", " md5 \n", "21877 4d823bf9308f967d8c1b2ea9325dac1d \n", "21878 23d2d33583c31c83b3e36563418204b8 \n", "21879 d4a628aa306aa7deafa93d2b913ba4de \n", "21880 0a8ed38b8ad9755831bb796febaa624e \n", "\n", "[4 rows x 31 columns]" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cams_stratiomyidae = list(master.loc[master[\"species\"] == \"Stratiomyidae\", \"CAMID\"])\n", "print(f\"There are {len(cams_stratiomyidae)} entries with the taxonomic label 'Stratiomyidae', and {master.loc[master['CAMID'].isin(cams_stratiomyidae)].shape[0]} entries of that/those CAMID(s).\")\n", "master.loc[master[\"species\"] == \"Stratiomyidae\"]" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "missing_label_cams = cams_unknown + cams_stratiomyidae\n", "master.loc[master[\"CAMID\"].isin(missing_label_cams)].to_csv(\"../metadata/Missing_taxa_download.csv\")" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "36193" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Drop Unknown\n", "master = master.loc[master[\"species\"] != \"Unknown\"]\n", "master.shape[0] # should now be 36,193" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "36189" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Drop Stratiomyidae\n", "master = master.loc[master[\"species\"] != \"Stratiomyidae\"]\n", "master.shape[0] # should now be 36,189" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "# Rename 'Pteronymia', 'Ithomiinae', and 'Heliconius' as ' sp.' for consistency\n", "rename_sp = ['Pteronymia', 'Ithomiinae', 'Heliconius']\n", "\n", "for species in rename_sp:\n", " master.loc[master[\"species\"] == species, \"Taxonomic_Name\"] = species + \" sp.\"\n", " master.loc[master[\"species\"] == species, \"species\"] = species + \" sp.\"" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "We have 25 'species' designations really labeled only to genus, 0 species designations that may not be labeled at the species level.\n" ] } ], "source": [ "# Check, sp_list should now be 25, as Heliconius sp. and 'Pteronymia sp.' were already on there, and our one_word_list should now be zero\n", "species_list = list(master.species.unique())\n", "\n", "sp_list = []\n", "one_word_list = []\n", "for species in species_list:\n", " if \"sp.\" in species:\n", " sp_list.append(species)\n", " if len(species.split(\" \")) == 1:\n", " one_word_list.append(species)\n", "\n", "print(f\"We have {len(sp_list)} 'species' designations really labeled only to genus, {len(one_word_list)} species designations that may not be labeled at the species level.\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Stats Checks & Save\n", "\n", "We'll now save our updated master file, then check all our stats to update the Dataset Card appropriately before regenerating our other subsets." ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "master.to_csv(\"../Jiggins_Zenodo_Img_Master.csv\", index = False)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Index: 36189 entries, 0 to 36210\n", "Data columns (total 31 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 CAMID 36189 non-null object\n", " 1 X 36189 non-null int64 \n", " 2 Image_name 36189 non-null object\n", " 3 View 35410 non-null object\n", " 4 zenodo_name 36189 non-null object\n", " 5 zenodo_link 36189 non-null object\n", " 6 Sequence 35257 non-null object\n", " 7 Taxonomic_Name 36189 non-null object\n", " 8 Locality 23105 non-null object\n", " 9 Sample_accession 3647 non-null object\n", " 10 Collected_by 3043 non-null object\n", " 11 Other_ID 11325 non-null object\n", " 12 Date 23022 non-null object\n", " 13 Dataset 29112 non-null object\n", " 14 Store 27807 non-null object\n", " 15 Brood 13847 non-null object\n", " 16 Death_Date 269 non-null object\n", " 17 Cross_Type 4447 non-null object\n", " 18 Stage 6 non-null object\n", " 19 Sex 27510 non-null object\n", " 20 Unit_Type 25058 non-null object\n", " 21 file_type 36189 non-null object\n", " 22 record_number 36189 non-null int64 \n", " 23 species 36189 non-null object\n", " 24 subspecies 20400 non-null object\n", " 25 genus 36189 non-null object\n", " 26 file_url 36189 non-null object\n", " 27 hybrid_stat 20948 non-null object\n", " 28 filename 36189 non-null object\n", " 29 filepath 36189 non-null object\n", " 30 md5 36189 non-null object\n", "dtypes: int64(2), object(29)\n", "memory usage: 8.8+ MB\n" ] } ], "source": [ "master.info()" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "CAMID 11962\n", "X 36189\n", "Image_name 36189\n", "View 7\n", "zenodo_name 31\n", "zenodo_link 29\n", "Sequence 10876\n", "Taxonomic_Name 362\n", "Locality 643\n", "Sample_accession 1559\n", "Collected_by 12\n", "Other_ID 3080\n", "Date 804\n", "Dataset 7\n", "Store 137\n", "Brood 224\n", "Death_Date 79\n", "Cross_Type 30\n", "Stage 1\n", "Sex 3\n", "Unit_Type 4\n", "file_type 3\n", "record_number 29\n", "species 242\n", "subspecies 155\n", "genus 92\n", "file_url 36189\n", "hybrid_stat 2\n", "filename 36189\n", "filepath 36189\n", "md5 36189\n", "dtype: int64" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "master.nunique()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that a total of 4 \"unique\" Taxonomic Names and species were removed above: \"Unknown\", \"Heliconius\", \"Pteronymia\", \"Ithomiinae\", and \"Stratiomyidae\" were removed and \"Ithomiinae sp.\" was added. This process also resulted in the removal of 2 \"unique\" genera (\"Unknown\" and \"Stratiomyidae\").\n", "\n", "No records were removed." ] }, { "cell_type": "code", "execution_count": 17, "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", " \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_nameViewzenodo_namezenodo_linkSequenceTaxonomic_NameLocalitySample_accession...file_typerecord_numberspeciessubspeciesgenusfile_urlhybrid_statfilenamefilepathmd5
13300CAM0135662604013566_H_m_thelxiopeia_V.JPG.jpgventralHeliconius_wing_old_photos_2001_2019_part3.csvhttps://zenodo.org/record/255397713,566Heliconius melpomene ssp. thelxiopeiaMaripasoulaERS977708...jpg2553977Heliconius melpomenethelxiopeiaHeliconiushttps://zenodo.org/record/2553977/files/13566_...non-hybrid26040_13566_H_m_thelxiopeia_V.JPG.jpgimages/Heliconius melpomene ssp. thelxiopeia/2...b5ed68f937132cbbb04a81d550c9f17e
13301CAM0135662603913566_H_m_thelxiopeia_D.JPG.jpgdorsalHeliconius_wing_old_photos_2001_2019_part3.csvhttps://zenodo.org/record/255397713,566Heliconius melpomene ssp. thelxiopeiaMaripasoulaERS977708...jpg2553977Heliconius melpomenethelxiopeiaHeliconiushttps://zenodo.org/record/2553977/files/13566_...non-hybrid26039_13566_H_m_thelxiopeia_D.JPG.jpgimages/Heliconius melpomene ssp. thelxiopeia/2...cb107e2d6a2c3c84b68bbf4e3cfa7af7
13302CAM0137152604113715_H_m_meriana_D.JPG.jpgdorsalHeliconius_wing_old_photos_2001_2019_part3.csvhttps://zenodo.org/record/255397713,715Heliconius melpomene ssp. merianaN. Wakapou, Maripausala FR GUIANAERS977704...jpg2553977Heliconius melpomenemerianaHeliconiushttps://zenodo.org/record/2553977/files/13715_...non-hybrid26041_13715_H_m_meriana_D.JPG.jpgimages/Heliconius melpomene ssp. meriana/26041...8c77ecb2d8d878f8ac8b097ad361deda
13303CAM0137152604213715_H_m_meriana_V.JPG.jpgventralHeliconius_wing_old_photos_2001_2019_part3.csvhttps://zenodo.org/record/255397713,715Heliconius melpomene ssp. merianaN. Wakapou, Maripausala FR GUIANAERS977704...jpg2553977Heliconius melpomenemerianaHeliconiushttps://zenodo.org/record/2553977/files/13715_...non-hybrid26042_13715_H_m_meriana_V.JPG.jpgimages/Heliconius melpomene ssp. meriana/26042...fcf74c73537323bb90127cf92775ac08
13304CAM0138192604413819_H_m_meriana_V.JPG.jpgventralHeliconius_wing_old_photos_2001_2019_part3.csvhttps://zenodo.org/record/255397713,819Heliconius melpomene ssp. merianaN. Wakapou, Maripausala FR GUIANAERS977703...jpg2553977Heliconius melpomenemerianaHeliconiushttps://zenodo.org/record/2553977/files/13819_...non-hybrid26044_13819_H_m_meriana_V.JPG.jpgimages/Heliconius melpomene ssp. meriana/26044...601b67512a8c25e5f25a9da89841e8c2
13305CAM0138192604313819_H_m_meriana_D.JPG.jpgdorsalHeliconius_wing_old_photos_2001_2019_part3.csvhttps://zenodo.org/record/255397713,819Heliconius melpomene ssp. merianaN. Wakapou, Maripausala FR GUIANAERS977703...jpg2553977Heliconius melpomenemerianaHeliconiushttps://zenodo.org/record/2553977/files/13819_...non-hybrid26043_13819_H_m_meriana_D.JPG.jpgimages/Heliconius melpomene ssp. meriana/26043...fe4cf831c5203ad6c9010fc047b7fa10
\n", "

6 rows × 31 columns

\n", "
" ], "text/plain": [ " CAMID X Image_name View \\\n", "13300 CAM013566 26040 13566_H_m_thelxiopeia_V.JPG.jpg ventral \n", "13301 CAM013566 26039 13566_H_m_thelxiopeia_D.JPG.jpg dorsal \n", "13302 CAM013715 26041 13715_H_m_meriana_D.JPG.jpg dorsal \n", "13303 CAM013715 26042 13715_H_m_meriana_V.JPG.jpg ventral \n", "13304 CAM013819 26044 13819_H_m_meriana_V.JPG.jpg ventral \n", "13305 CAM013819 26043 13819_H_m_meriana_D.JPG.jpg dorsal \n", "\n", " zenodo_name \\\n", "13300 Heliconius_wing_old_photos_2001_2019_part3.csv \n", "13301 Heliconius_wing_old_photos_2001_2019_part3.csv \n", "13302 Heliconius_wing_old_photos_2001_2019_part3.csv \n", "13303 Heliconius_wing_old_photos_2001_2019_part3.csv \n", "13304 Heliconius_wing_old_photos_2001_2019_part3.csv \n", "13305 Heliconius_wing_old_photos_2001_2019_part3.csv \n", "\n", " zenodo_link Sequence \\\n", "13300 https://zenodo.org/record/2553977 13,566 \n", "13301 https://zenodo.org/record/2553977 13,566 \n", "13302 https://zenodo.org/record/2553977 13,715 \n", "13303 https://zenodo.org/record/2553977 13,715 \n", "13304 https://zenodo.org/record/2553977 13,819 \n", "13305 https://zenodo.org/record/2553977 13,819 \n", "\n", " Taxonomic_Name \\\n", "13300 Heliconius melpomene ssp. thelxiopeia \n", "13301 Heliconius melpomene ssp. thelxiopeia \n", "13302 Heliconius melpomene ssp. meriana \n", "13303 Heliconius melpomene ssp. meriana \n", "13304 Heliconius melpomene ssp. meriana \n", "13305 Heliconius melpomene ssp. meriana \n", "\n", " Locality Sample_accession ... file_type \\\n", "13300 Maripasoula ERS977708 ... jpg \n", "13301 Maripasoula ERS977708 ... jpg \n", "13302 N. Wakapou, Maripausala FR GUIANA ERS977704 ... jpg \n", "13303 N. Wakapou, Maripausala FR GUIANA ERS977704 ... jpg \n", "13304 N. Wakapou, Maripausala FR GUIANA ERS977703 ... jpg \n", "13305 N. Wakapou, Maripausala FR GUIANA ERS977703 ... jpg \n", "\n", " record_number species subspecies genus \\\n", "13300 2553977 Heliconius melpomene thelxiopeia Heliconius \n", "13301 2553977 Heliconius melpomene thelxiopeia Heliconius \n", "13302 2553977 Heliconius melpomene meriana Heliconius \n", "13303 2553977 Heliconius melpomene meriana Heliconius \n", "13304 2553977 Heliconius melpomene meriana Heliconius \n", "13305 2553977 Heliconius melpomene meriana Heliconius \n", "\n", " file_url hybrid_stat \\\n", "13300 https://zenodo.org/record/2553977/files/13566_... non-hybrid \n", "13301 https://zenodo.org/record/2553977/files/13566_... non-hybrid \n", "13302 https://zenodo.org/record/2553977/files/13715_... non-hybrid \n", "13303 https://zenodo.org/record/2553977/files/13715_... non-hybrid \n", "13304 https://zenodo.org/record/2553977/files/13819_... non-hybrid \n", "13305 https://zenodo.org/record/2553977/files/13819_... non-hybrid \n", "\n", " filename \\\n", "13300 26040_13566_H_m_thelxiopeia_V.JPG.jpg \n", "13301 26039_13566_H_m_thelxiopeia_D.JPG.jpg \n", "13302 26041_13715_H_m_meriana_D.JPG.jpg \n", "13303 26042_13715_H_m_meriana_V.JPG.jpg \n", "13304 26044_13819_H_m_meriana_V.JPG.jpg \n", "13305 26043_13819_H_m_meriana_D.JPG.jpg \n", "\n", " filepath \\\n", "13300 images/Heliconius melpomene ssp. thelxiopeia/2... \n", "13301 images/Heliconius melpomene ssp. thelxiopeia/2... \n", "13302 images/Heliconius melpomene ssp. meriana/26041... \n", "13303 images/Heliconius melpomene ssp. meriana/26042... \n", "13304 images/Heliconius melpomene ssp. meriana/26044... \n", "13305 images/Heliconius melpomene ssp. meriana/26043... \n", "\n", " md5 \n", "13300 b5ed68f937132cbbb04a81d550c9f17e \n", "13301 cb107e2d6a2c3c84b68bbf4e3cfa7af7 \n", "13302 8c77ecb2d8d878f8ac8b097ad361deda \n", "13303 fcf74c73537323bb90127cf92775ac08 \n", "13304 601b67512a8c25e5f25a9da89841e8c2 \n", "13305 fe4cf831c5203ad6c9010fc047b7fa10 \n", "\n", "[6 rows x 31 columns]" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "master.loc[master.Stage.notna()]" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "CAMID 820\n", "X 4447\n", "Image_name 4447\n", "View 2\n", "zenodo_name 4\n", "zenodo_link 4\n", "Sequence 820\n", "Taxonomic_Name 8\n", "Locality 0\n", "Sample_accession 0\n", "Collected_by 0\n", "Other_ID 0\n", "Date 160\n", "Dataset 1\n", "Store 10\n", "Brood 49\n", "Death_Date 0\n", "Cross_Type 30\n", "Stage 0\n", "Sex 2\n", "Unit_Type 1\n", "file_type 2\n", "record_number 4\n", "species 2\n", "subspecies 21\n", "genus 1\n", "file_url 4447\n", "hybrid_stat 2\n", "filename 4447\n", "filepath 4447\n", "md5 4447\n", "dtype: int64" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "master.loc[master.Cross_Type.notna()].nunique()" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "View\n", "dorsal 17224\n", "ventral 17156\n", "hindwing dorsal 254\n", "hindwing ventral 254\n", "forewing dorsal 252\n", "forewing ventral 252\n", "dorsal and ventral 18\n", "Name: count, dtype: int64" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "master.View.value_counts()" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Sex\n", "Male 15904\n", "Female 11323\n", "Unknown 283\n", "Name: count, dtype: int64" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "master.Sex.value_counts()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Generate master_licenses CSV file to re-run [`get_licenses.py`](https://huggingface.co/datasets/imageomics/Comparison-Subset-Jiggins/blob/main/scripts/get_licenses.py) for nicely formatted licensing info of the 29 included records.\n" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(29, 2)" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "master_licenses = master[[\"record_number\", \"zenodo_link\"]]\n", "master_licenses = master_licenses.loc[~master_licenses.duplicated([\"record_number\", \"zenodo_link\"], keep = \"first\")]\n", "master_licenses.shape" ] }, { "cell_type": "code", "execution_count": 25, "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", "
record_numberurl
04289223https://zenodo.org/record/4289223
1454288311https://zenodo.org/record/4288311
\n", "
" ], "text/plain": [ " record_number url\n", "0 4289223 https://zenodo.org/record/4289223\n", "145 4288311 https://zenodo.org/record/4288311" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "master_licenses.rename(columns = {\"zenodo_link\": \"url\"}, inplace = True)\n", "master_licenses.head(2)" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [], "source": [ "# Save to CSV to run through get licenses script\n", "master_licenses.to_csv(\"../metadata/master_licenses.csv\", index = False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Make Heliconius Master Subset\n", "\n", "Now make the Heliconius master CSV, and check stats to update README." ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "CAMID 10086\n", "X 29134\n", "Image_name 29134\n", "View 3\n", "zenodo_name 31\n", "zenodo_link 29\n", "Sequence 9008\n", "Taxonomic_Name 131\n", "Locality 471\n", "Sample_accession 1559\n", "Collected_by 12\n", "Other_ID 1865\n", "Date 773\n", "Dataset 7\n", "Store 121\n", "Brood 224\n", "Death_Date 79\n", "Cross_Type 30\n", "Stage 1\n", "Sex 3\n", "Unit_Type 4\n", "file_type 3\n", "record_number 29\n", "species 36\n", "subspecies 110\n", "genus 1\n", "file_url 29134\n", "hybrid_stat 2\n", "filename 29134\n", "filepath 29134\n", "md5 29134\n", "dtype: int64" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "heliconius_master = master.loc[master.genus.str.lower() == \"heliconius\"].copy()\n", "heliconius_master.nunique()" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "View\n", "dorsal 14202\n", "ventral 14135\n", "dorsal and ventral 18\n", "Name: count, dtype: int64" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "heliconius_master.View.value_counts()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Save Heliconius Subset to CSV" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [], "source": [ "heliconius_master.to_csv(\"../Jiggins_Heliconius_Master.csv\", index = False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Make Dorsal Subset\n", "\n", "We'll now make a CSV of all dorsal images." ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "CAMID 11746\n", "X 17748\n", "Image_name 17748\n", "View 4\n", "zenodo_name 31\n", "zenodo_link 29\n", "Sequence 10683\n", "Taxonomic_Name 358\n", "Locality 640\n", "Sample_accession 1552\n", "Collected_by 12\n", "Other_ID 2889\n", "Date 788\n", "Dataset 7\n", "Store 137\n", "Brood 215\n", "Death_Date 61\n", "Cross_Type 30\n", "Stage 1\n", "Sex 3\n", "Unit_Type 4\n", "file_type 3\n", "record_number 29\n", "species 241\n", "subspecies 152\n", "genus 92\n", "file_url 17748\n", "hybrid_stat 2\n", "filename 17748\n", "filepath 17748\n", "md5 17748\n", "dtype: int64" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dorsal_views = [view for view in list(master.View.dropna().unique()) if \"dorsal\" in view]\n", "\n", "dorsal_master = master.loc[master[\"View\"].isin(dorsal_views)].copy()\n", "dorsal_master.nunique()" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "CAM_dupe\n", "False 15449\n", "True 2299\n", "Name: count, dtype: int64" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dorsal_master[\"CAM_dupe\"] = dorsal_master.duplicated([\"CAMID\", \"file_type\"], keep = False)\n", "dorsal_master.CAM_dupe.value_counts()" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "CAM_dupe\n", "False 15431\n", "True 1793\n", "single-wing 506\n", "both-wings 18\n", "Name: count, dtype: int64" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Adding label for both wings alters counts, as in, some only have the double wing image\n", "dorsal_master.loc[dorsal_master[\"View\"].isin([\"forewing dorsal\", \"hindwing dorsal\"]), \"CAM_dupe\"] = \"single-wing\"\n", "dorsal_master.loc[dorsal_master[\"View\"] == \"dorsal and ventral\", \"CAM_dupe\"] = \"both-wings\"\n", "dorsal_master.CAM_dupe.value_counts()" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "881\n", "11446\n" ] }, { "data": { "text/plain": [ "13" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "print(dorsal_master.loc[dorsal_master[\"CAM_dupe\"] == True, \"CAMID\"].nunique())\n", "print(dorsal_master.loc[dorsal_master[\"CAM_dupe\"] == False, \"CAMID\"].nunique())\n", "dorsal_master.loc[dorsal_master[\"CAM_dupe\"] == True, \"record_number\"].nunique()" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "file_type\n", "raw 253\n", "jpg 253\n", "Name: count, dtype: int64" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dorsal_master.loc[dorsal_master[\"CAM_dupe\"] == \"single-wing\", \"file_type\"].value_counts()" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "file_type\n", "jpg 17\n", "tif 1\n", "Name: count, dtype: int64" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dorsal_master.loc[dorsal_master[\"CAM_dupe\"] == \"both-wings\", \"file_type\"].value_counts()" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "file_type\n", "jpg 1775\n", "tif 16\n", "raw 2\n", "Name: count, dtype: int64" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dorsal_master.loc[dorsal_master[\"CAM_dupe\"] == True, \"file_type\"].value_counts()" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "file_type\n", "jpg 10700\n", "raw 4713\n", "tif 18\n", "Name: count, dtype: int64" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dorsal_master.loc[dorsal_master[\"CAM_dupe\"] == False, \"file_type\"].value_counts()" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False 10717\n", "True 2028\n", "Name: count, dtype: int64" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dorsal_master.loc[dorsal_master[\"file_type\"] == \"jpg\"].duplicated(subset = \"CAMID\", keep = False).value_counts()" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False 4714\n", "True 254\n", "Name: count, dtype: int64" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dorsal_master.loc[dorsal_master[\"file_type\"] == \"raw\"].duplicated(subset = \"CAMID\", keep = False).value_counts()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Generally speaking, it seems RAW images will be unique, as there is only one CAMID that gets duplicated across the raw images (2 photos of that specimen that are RAW) outside of the single wing views.\n", "\n", "### Save Dorsal Subset to CSV" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [], "source": [ "dorsal_master.to_csv(\"../Jiggins_Zenodo_dorsal_Img_Master.csv\", index = False)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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 }