egrace479 commited on
Commit
ba3ca2d
1 Parent(s): bb27758

Add notebook performing deduplication of the master files

Browse files
Files changed (1) hide show
  1. notebooks/dedupe_full_jiggins_DL.ipynb +1955 -0
notebooks/dedupe_full_jiggins_DL.ipynb ADDED
@@ -0,0 +1,1955 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "import pandas as pd"
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "markdown",
14
+ "metadata": {},
15
+ "source": [
16
+ "## Summary\n",
17
+ "\n",
18
+ "We explored our downloaded images in `EDA_full_jiggins_DL.ipynb`, and established the following causes of duplication along with remedies:\n",
19
+ "1. The \"patch\" record (record 3477891) which required alignment in `record_3477891_media_occurrence.ipynb`, resulting in `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",
20
+ " - Solution: This record will be removed.\n",
21
+ "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",
22
+ " - 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",
23
+ " - Solution: Copies of these images and their metadata will be retained from the newer record, record 4291095.\n",
24
+ " - 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",
25
+ " - 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",
26
+ " - 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",
27
+ " - 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",
28
+ "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",
29
+ " - Suggestion/Solution: When determining splits using this data, follow these steps:\n",
30
+ " 1. Ensure you are looking at only **_one_** view (eg., dorsal or ventral).\n",
31
+ " 2. Reduce to only unique `CAMID`s.\n",
32
+ " 3. Generate splits as desired.\n",
33
+ " 4. 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",
34
+ "\n",
35
+ "\n",
36
+ "## Generate \"Clean\" Master Metadata File\n",
37
+ "\n",
38
+ "We'll now generate a cleaned master metadata file from `metadata/Jiggins_Zenodo_Img_Master_3477891Patch_downloaded.csv` (generated in `notebooks/EDA_full_jiggins_DL.ipynb` from our download master file and checksums of successful downloads) following the solutions outlined above. "
39
+ ]
40
+ },
41
+ {
42
+ "cell_type": "code",
43
+ "execution_count": 2,
44
+ "metadata": {},
45
+ "outputs": [],
46
+ "source": [
47
+ "STATS_COLS = [\"X\",\n",
48
+ " \"CAMID\",\n",
49
+ " \"Image_name\",\n",
50
+ " \"md5\",\n",
51
+ " \"record_number\",\n",
52
+ " \"Taxonomic_Name\",\n",
53
+ " \"species\",\n",
54
+ " \"subspecies\",\n",
55
+ " \"genus\",\n",
56
+ " \"Cross_Type\",\n",
57
+ " \"View\",\n",
58
+ " \"Locality\",\n",
59
+ " \"Sex\",\n",
60
+ " \"Dataset\",\n",
61
+ " \"file_type\"]"
62
+ ]
63
+ },
64
+ {
65
+ "cell_type": "code",
66
+ "execution_count": 3,
67
+ "metadata": {},
68
+ "outputs": [
69
+ {
70
+ "name": "stdout",
71
+ "output_type": "stream",
72
+ "text": [
73
+ "<class 'pandas.core.frame.DataFrame'>\n",
74
+ "RangeIndex: 42143 entries, 0 to 42142\n",
75
+ "Data columns (total 15 columns):\n",
76
+ " # Column Non-Null Count Dtype \n",
77
+ "--- ------ -------------- ----- \n",
78
+ " 0 X 42143 non-null int64 \n",
79
+ " 1 CAMID 42143 non-null object\n",
80
+ " 2 Image_name 42143 non-null object\n",
81
+ " 3 md5 42143 non-null object\n",
82
+ " 4 record_number 42143 non-null int64 \n",
83
+ " 5 Taxonomic_Name 42143 non-null object\n",
84
+ " 6 species 42143 non-null object\n",
85
+ " 7 subspecies 24502 non-null object\n",
86
+ " 8 genus 42143 non-null object\n",
87
+ " 9 Cross_Type 4447 non-null object\n",
88
+ " 10 View 41364 non-null object\n",
89
+ " 11 Locality 29047 non-null object\n",
90
+ " 12 Sex 33254 non-null object\n",
91
+ " 13 Dataset 34924 non-null object\n",
92
+ " 14 file_type 42143 non-null object\n",
93
+ "dtypes: int64(2), object(13)\n",
94
+ "memory usage: 4.8+ MB\n"
95
+ ]
96
+ }
97
+ ],
98
+ "source": [
99
+ "df = pd.read_csv(\"../metadata/Jiggins_Zenodo_Img_Master_3477891Patch_downloaded.csv\", low_memory = False)\n",
100
+ "df[STATS_COLS].info()"
101
+ ]
102
+ },
103
+ {
104
+ "cell_type": "code",
105
+ "execution_count": 4,
106
+ "metadata": {},
107
+ "outputs": [
108
+ {
109
+ "data": {
110
+ "text/plain": [
111
+ "X 42143\n",
112
+ "CAMID 11968\n",
113
+ "Image_name 36216\n",
114
+ "md5 36212\n",
115
+ "record_number 30\n",
116
+ "Taxonomic_Name 366\n",
117
+ "species 246\n",
118
+ "subspecies 155\n",
119
+ "genus 94\n",
120
+ "Cross_Type 30\n",
121
+ "View 7\n",
122
+ "Locality 644\n",
123
+ "Sex 3\n",
124
+ "Dataset 7\n",
125
+ "file_type 3\n",
126
+ "dtype: int64"
127
+ ]
128
+ },
129
+ "execution_count": 4,
130
+ "metadata": {},
131
+ "output_type": "execute_result"
132
+ }
133
+ ],
134
+ "source": [
135
+ "df[STATS_COLS].nunique()"
136
+ ]
137
+ },
138
+ {
139
+ "cell_type": "markdown",
140
+ "metadata": {},
141
+ "source": [
142
+ "Observations:\n",
143
+ "- Half of the Zenodo records wind up with duplicated images. \n",
144
+ "- `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",
145
+ "- None of the cross types are duplicated.\n",
146
+ "- 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)"
147
+ ]
148
+ },
149
+ {
150
+ "cell_type": "markdown",
151
+ "metadata": {},
152
+ "source": [
153
+ "### Remove Record 3477891\n",
154
+ "\n",
155
+ "This is just a duplication of images and we already have from earlier records, along with some extra duplication that gets mislabeled."
156
+ ]
157
+ },
158
+ {
159
+ "cell_type": "code",
160
+ "execution_count": 5,
161
+ "metadata": {},
162
+ "outputs": [
163
+ {
164
+ "data": {
165
+ "text/plain": [
166
+ "X 36642\n",
167
+ "CAMID 11968\n",
168
+ "Image_name 36216\n",
169
+ "md5 36212\n",
170
+ "record_number 29\n",
171
+ "Taxonomic_Name 366\n",
172
+ "species 246\n",
173
+ "subspecies 155\n",
174
+ "genus 94\n",
175
+ "Cross_Type 30\n",
176
+ "View 7\n",
177
+ "Locality 644\n",
178
+ "Sex 3\n",
179
+ "Dataset 7\n",
180
+ "file_type 3\n",
181
+ "dtype: int64"
182
+ ]
183
+ },
184
+ "execution_count": 5,
185
+ "metadata": {},
186
+ "output_type": "execute_result"
187
+ }
188
+ ],
189
+ "source": [
190
+ "df_reduced = df.loc[df[\"record_number\"] != 3477891].copy()\n",
191
+ "df_reduced[STATS_COLS].nunique()"
192
+ ]
193
+ },
194
+ {
195
+ "cell_type": "markdown",
196
+ "metadata": {},
197
+ "source": [
198
+ "The only change is in `X` (our total entry count) and in `record_number` (expected since we removed one)."
199
+ ]
200
+ },
201
+ {
202
+ "cell_type": "markdown",
203
+ "metadata": {},
204
+ "source": [
205
+ "## Address Remaining Duplicates\n",
206
+ "\n",
207
+ "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",
208
+ "\n",
209
+ "### Record 4291095 & 2813153 Duplicates\n",
210
+ "\n",
211
+ "There are 415 duplicates across these two records, with `View` corrections in record 4291095, so we will remove the duplicates from record 2813153."
212
+ ]
213
+ },
214
+ {
215
+ "cell_type": "code",
216
+ "execution_count": 6,
217
+ "metadata": {},
218
+ "outputs": [
219
+ {
220
+ "data": {
221
+ "text/plain": [
222
+ "Index(['CAMID', 'X', 'Image_name', 'View', 'zenodo_name', 'zenodo_link',\n",
223
+ " 'Sequence', 'Taxonomic_Name', 'Locality', 'Sample_accession',\n",
224
+ " 'Collected_by', 'Other_ID', 'Date', 'Dataset', 'Store', 'Brood',\n",
225
+ " 'Death_Date', 'Cross_Type', 'Stage', 'Sex', 'Unit_Type', 'file_type',\n",
226
+ " 'record_number', 'species', 'subspecies', 'genus', 'file_url',\n",
227
+ " 'hybrid_stat', 'filename', 'filepath', 'md5'],\n",
228
+ " dtype='object')"
229
+ ]
230
+ },
231
+ "execution_count": 6,
232
+ "metadata": {},
233
+ "output_type": "execute_result"
234
+ }
235
+ ],
236
+ "source": [
237
+ "df_reduced.columns"
238
+ ]
239
+ },
240
+ {
241
+ "cell_type": "markdown",
242
+ "metadata": {},
243
+ "source": [
244
+ "We start by marking all duplicate images since the decision of which to keep is dependent on comparisons between them."
245
+ ]
246
+ },
247
+ {
248
+ "cell_type": "code",
249
+ "execution_count": 7,
250
+ "metadata": {},
251
+ "outputs": [
252
+ {
253
+ "data": {
254
+ "text/plain": [
255
+ "md5_duplicated\n",
256
+ "False 35782\n",
257
+ "True 860\n",
258
+ "Name: count, dtype: int64"
259
+ ]
260
+ },
261
+ "execution_count": 7,
262
+ "metadata": {},
263
+ "output_type": "execute_result"
264
+ }
265
+ ],
266
+ "source": [
267
+ "df_reduced[\"md5_duplicated\"] = df_reduced.duplicated(\"md5\", keep = False)\n",
268
+ "df_reduced[\"md5_duplicated\"].value_counts()"
269
+ ]
270
+ },
271
+ {
272
+ "cell_type": "code",
273
+ "execution_count": 8,
274
+ "metadata": {},
275
+ "outputs": [
276
+ {
277
+ "data": {
278
+ "text/plain": [
279
+ "415"
280
+ ]
281
+ },
282
+ "execution_count": 8,
283
+ "metadata": {},
284
+ "output_type": "execute_result"
285
+ }
286
+ ],
287
+ "source": [
288
+ "duplicates = df_reduced[df_reduced[\"md5_duplicated\"]]\n",
289
+ "dupes_2813153 = duplicates.loc[duplicates[\"record_number\"] == 2813153]\n",
290
+ "#print(duplicates.loc[duplicates[\"record_number\"] == 4291095])\n",
291
+ "dupes_2813153.shape[0]"
292
+ ]
293
+ },
294
+ {
295
+ "cell_type": "markdown",
296
+ "metadata": {},
297
+ "source": [
298
+ "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."
299
+ ]
300
+ },
301
+ {
302
+ "cell_type": "code",
303
+ "execution_count": 9,
304
+ "metadata": {},
305
+ "outputs": [],
306
+ "source": [
307
+ "X_dupes_2813153 = list(dupes_2813153.X)"
308
+ ]
309
+ },
310
+ {
311
+ "cell_type": "code",
312
+ "execution_count": 10,
313
+ "metadata": {},
314
+ "outputs": [
315
+ {
316
+ "data": {
317
+ "text/plain": [
318
+ "X 36227\n",
319
+ "CAMID 11968\n",
320
+ "Image_name 36216\n",
321
+ "md5 36212\n",
322
+ "record_number 29\n",
323
+ "Taxonomic_Name 366\n",
324
+ "species 246\n",
325
+ "subspecies 155\n",
326
+ "genus 94\n",
327
+ "Cross_Type 30\n",
328
+ "View 7\n",
329
+ "Locality 644\n",
330
+ "Sex 3\n",
331
+ "Dataset 7\n",
332
+ "file_type 3\n",
333
+ "dtype: int64"
334
+ ]
335
+ },
336
+ "execution_count": 10,
337
+ "metadata": {},
338
+ "output_type": "execute_result"
339
+ }
340
+ ],
341
+ "source": [
342
+ "df_reduced_2 = df_reduced.loc[~df_reduced[\"X\"].isin(X_dupes_2813153)]\n",
343
+ "df_reduced_2[STATS_COLS].nunique()"
344
+ ]
345
+ },
346
+ {
347
+ "cell_type": "markdown",
348
+ "metadata": {},
349
+ "source": [
350
+ "As expected, our numbers are holding steady with a reduction in `X` values of 415."
351
+ ]
352
+ },
353
+ {
354
+ "cell_type": "markdown",
355
+ "metadata": {},
356
+ "source": [
357
+ "### Record 5526257 Duplicates\n",
358
+ "\n",
359
+ "For record 5526257, the 10 duplicated entries are all the same, so we will just check `.duplicated` and keep the first instance of each."
360
+ ]
361
+ },
362
+ {
363
+ "cell_type": "code",
364
+ "execution_count": 11,
365
+ "metadata": {},
366
+ "outputs": [
367
+ {
368
+ "name": "stdout",
369
+ "output_type": "stream",
370
+ "text": [
371
+ "dupe_entries\n",
372
+ "False 10\n",
373
+ "True 10\n",
374
+ "Name: count, dtype: int64\n"
375
+ ]
376
+ },
377
+ {
378
+ "data": {
379
+ "text/plain": [
380
+ "10"
381
+ ]
382
+ },
383
+ "execution_count": 11,
384
+ "metadata": {},
385
+ "output_type": "execute_result"
386
+ }
387
+ ],
388
+ "source": [
389
+ "dupes_5526257 = duplicates.loc[duplicates[\"record_number\"] == 5526257].copy()\n",
390
+ "dupes_5526257[\"dupe_entries\"] = dupes_5526257.duplicated([\"CAMID\", \"Image_name\", \"View\", \"Taxonomic_Name\", \"Locality\", \"md5\"], keep = \"first\")\n",
391
+ "print(dupes_5526257[\"dupe_entries\"].value_counts())\n",
392
+ "\n",
393
+ "X_dupes_5526257 = list(dupes_5526257.loc[dupes_5526257[\"dupe_entries\"], \"X\"])\n",
394
+ "len(X_dupes_5526257)"
395
+ ]
396
+ },
397
+ {
398
+ "cell_type": "code",
399
+ "execution_count": 12,
400
+ "metadata": {},
401
+ "outputs": [
402
+ {
403
+ "data": {
404
+ "text/plain": [
405
+ "X 36217\n",
406
+ "CAMID 11968\n",
407
+ "Image_name 36216\n",
408
+ "md5 36212\n",
409
+ "record_number 29\n",
410
+ "Taxonomic_Name 366\n",
411
+ "species 246\n",
412
+ "subspecies 155\n",
413
+ "genus 94\n",
414
+ "Cross_Type 30\n",
415
+ "View 7\n",
416
+ "Locality 644\n",
417
+ "Sex 3\n",
418
+ "Dataset 7\n",
419
+ "file_type 3\n",
420
+ "dtype: int64"
421
+ ]
422
+ },
423
+ "execution_count": 12,
424
+ "metadata": {},
425
+ "output_type": "execute_result"
426
+ }
427
+ ],
428
+ "source": [
429
+ "df_reduced_3 = df_reduced_2.loc[~df_reduced_2[\"X\"].isin(X_dupes_5526257)]\n",
430
+ "df_reduced_3[STATS_COLS].nunique()"
431
+ ]
432
+ },
433
+ {
434
+ "cell_type": "markdown",
435
+ "metadata": {},
436
+ "source": [
437
+ "Reduction in `X` by 10, consistency in all other numbers.\n",
438
+ "\n",
439
+ "### Record 2552371 Duplicates\n",
440
+ "\n",
441
+ "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.)"
442
+ ]
443
+ },
444
+ {
445
+ "cell_type": "code",
446
+ "execution_count": 13,
447
+ "metadata": {},
448
+ "outputs": [
449
+ {
450
+ "data": {
451
+ "text/html": [
452
+ "<div>\n",
453
+ "<style scoped>\n",
454
+ " .dataframe tbody tr th:only-of-type {\n",
455
+ " vertical-align: middle;\n",
456
+ " }\n",
457
+ "\n",
458
+ " .dataframe tbody tr th {\n",
459
+ " vertical-align: top;\n",
460
+ " }\n",
461
+ "\n",
462
+ " .dataframe thead th {\n",
463
+ " text-align: right;\n",
464
+ " }\n",
465
+ "</style>\n",
466
+ "<table border=\"1\" class=\"dataframe\">\n",
467
+ " <thead>\n",
468
+ " <tr style=\"text-align: right;\">\n",
469
+ " <th></th>\n",
470
+ " <th>CAMID</th>\n",
471
+ " <th>X</th>\n",
472
+ " <th>Image_name</th>\n",
473
+ " <th>View</th>\n",
474
+ " <th>zenodo_name</th>\n",
475
+ " <th>zenodo_link</th>\n",
476
+ " <th>Sequence</th>\n",
477
+ " <th>Taxonomic_Name</th>\n",
478
+ " <th>Locality</th>\n",
479
+ " <th>Sample_accession</th>\n",
480
+ " <th>...</th>\n",
481
+ " <th>record_number</th>\n",
482
+ " <th>species</th>\n",
483
+ " <th>subspecies</th>\n",
484
+ " <th>genus</th>\n",
485
+ " <th>file_url</th>\n",
486
+ " <th>hybrid_stat</th>\n",
487
+ " <th>filename</th>\n",
488
+ " <th>filepath</th>\n",
489
+ " <th>md5</th>\n",
490
+ " <th>md5_duplicated</th>\n",
491
+ " </tr>\n",
492
+ " </thead>\n",
493
+ " <tbody>\n",
494
+ " <tr>\n",
495
+ " <th>11978</th>\n",
496
+ " <td>CAM010354</td>\n",
497
+ " <td>23471</td>\n",
498
+ " <td>10354d.jpg</td>\n",
499
+ " <td>dorsal</td>\n",
500
+ " <td>Heliconius_wing_old_photos_2001_2019_part1.csv</td>\n",
501
+ " <td>https://zenodo.org/record/2552371</td>\n",
502
+ " <td>10,354</td>\n",
503
+ " <td>Heliconius sp.</td>\n",
504
+ " <td>NaN</td>\n",
505
+ " <td>NaN</td>\n",
506
+ " <td>...</td>\n",
507
+ " <td>2552371</td>\n",
508
+ " <td>Heliconius sp.</td>\n",
509
+ " <td>NaN</td>\n",
510
+ " <td>Heliconius</td>\n",
511
+ " <td>https://zenodo.org/record/2552371/files/10354d...</td>\n",
512
+ " <td>NaN</td>\n",
513
+ " <td>23471_10354d.jpg</td>\n",
514
+ " <td>images/Heliconius sp./23471_10354d.jpg</td>\n",
515
+ " <td>84d4ac6527458786cdb33166cd80e0a8</td>\n",
516
+ " <td>True</td>\n",
517
+ " </tr>\n",
518
+ " <tr>\n",
519
+ " <th>12010</th>\n",
520
+ " <td>CAM010362</td>\n",
521
+ " <td>23484</td>\n",
522
+ " <td>10362v.jpg</td>\n",
523
+ " <td>ventral</td>\n",
524
+ " <td>Heliconius_wing_old_photos_2001_2019_part1.csv</td>\n",
525
+ " <td>https://zenodo.org/record/2552371</td>\n",
526
+ " <td>10,362</td>\n",
527
+ " <td>Heliconius sp.</td>\n",
528
+ " <td>NaN</td>\n",
529
+ " <td>NaN</td>\n",
530
+ " <td>...</td>\n",
531
+ " <td>2552371</td>\n",
532
+ " <td>Heliconius sp.</td>\n",
533
+ " <td>NaN</td>\n",
534
+ " <td>Heliconius</td>\n",
535
+ " <td>https://zenodo.org/record/2552371/files/10362v...</td>\n",
536
+ " <td>NaN</td>\n",
537
+ " <td>23484_10362v.jpg</td>\n",
538
+ " <td>images/Heliconius sp./23484_10362v.jpg</td>\n",
539
+ " <td>84d4ac6527458786cdb33166cd80e0a8</td>\n",
540
+ " <td>True</td>\n",
541
+ " </tr>\n",
542
+ " </tbody>\n",
543
+ "</table>\n",
544
+ "<p>2 rows × 32 columns</p>\n",
545
+ "</div>"
546
+ ],
547
+ "text/plain": [
548
+ " CAMID X Image_name View \\\n",
549
+ "11978 CAM010354 23471 10354d.jpg dorsal \n",
550
+ "12010 CAM010362 23484 10362v.jpg ventral \n",
551
+ "\n",
552
+ " zenodo_name \\\n",
553
+ "11978 Heliconius_wing_old_photos_2001_2019_part1.csv \n",
554
+ "12010 Heliconius_wing_old_photos_2001_2019_part1.csv \n",
555
+ "\n",
556
+ " zenodo_link Sequence Taxonomic_Name Locality \\\n",
557
+ "11978 https://zenodo.org/record/2552371 10,354 Heliconius sp. NaN \n",
558
+ "12010 https://zenodo.org/record/2552371 10,362 Heliconius sp. NaN \n",
559
+ "\n",
560
+ " Sample_accession ... record_number species subspecies \\\n",
561
+ "11978 NaN ... 2552371 Heliconius sp. NaN \n",
562
+ "12010 NaN ... 2552371 Heliconius sp. NaN \n",
563
+ "\n",
564
+ " genus file_url \\\n",
565
+ "11978 Heliconius https://zenodo.org/record/2552371/files/10354d... \n",
566
+ "12010 Heliconius https://zenodo.org/record/2552371/files/10362v... \n",
567
+ "\n",
568
+ " hybrid_stat filename filepath \\\n",
569
+ "11978 NaN 23471_10354d.jpg images/Heliconius sp./23471_10354d.jpg \n",
570
+ "12010 NaN 23484_10362v.jpg images/Heliconius sp./23484_10362v.jpg \n",
571
+ "\n",
572
+ " md5 md5_duplicated \n",
573
+ "11978 84d4ac6527458786cdb33166cd80e0a8 True \n",
574
+ "12010 84d4ac6527458786cdb33166cd80e0a8 True \n",
575
+ "\n",
576
+ "[2 rows x 32 columns]"
577
+ ]
578
+ },
579
+ "execution_count": 13,
580
+ "metadata": {},
581
+ "output_type": "execute_result"
582
+ }
583
+ ],
584
+ "source": [
585
+ "dupes_2552371 = duplicates.loc[duplicates[\"record_number\"] == 2552371]\n",
586
+ "X_dupes_2552371 = list(dupes_2552371[\"X\"])\n",
587
+ "dupes_2552371"
588
+ ]
589
+ },
590
+ {
591
+ "cell_type": "code",
592
+ "execution_count": 14,
593
+ "metadata": {},
594
+ "outputs": [
595
+ {
596
+ "data": {
597
+ "text/plain": [
598
+ "X 36215\n",
599
+ "CAMID 11968\n",
600
+ "Image_name 36214\n",
601
+ "md5 36211\n",
602
+ "record_number 29\n",
603
+ "Taxonomic_Name 366\n",
604
+ "species 246\n",
605
+ "subspecies 155\n",
606
+ "genus 94\n",
607
+ "Cross_Type 30\n",
608
+ "View 7\n",
609
+ "Locality 644\n",
610
+ "Sex 3\n",
611
+ "Dataset 7\n",
612
+ "file_type 3\n",
613
+ "dtype: int64"
614
+ ]
615
+ },
616
+ "execution_count": 14,
617
+ "metadata": {},
618
+ "output_type": "execute_result"
619
+ }
620
+ ],
621
+ "source": [
622
+ "df_reduced_4 = df_reduced_3.loc[~df_reduced_3[\"X\"].isin(X_dupes_2552371)]\n",
623
+ "df_reduced_4[STATS_COLS].nunique()"
624
+ ]
625
+ },
626
+ {
627
+ "cell_type": "markdown",
628
+ "metadata": {},
629
+ "source": [
630
+ "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."
631
+ ]
632
+ },
633
+ {
634
+ "cell_type": "markdown",
635
+ "metadata": {},
636
+ "source": [
637
+ "### Record 2553977 Duplicates\n",
638
+ "\n",
639
+ "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."
640
+ ]
641
+ },
642
+ {
643
+ "cell_type": "code",
644
+ "execution_count": 15,
645
+ "metadata": {},
646
+ "outputs": [
647
+ {
648
+ "data": {
649
+ "text/html": [
650
+ "<div>\n",
651
+ "<style scoped>\n",
652
+ " .dataframe tbody tr th:only-of-type {\n",
653
+ " vertical-align: middle;\n",
654
+ " }\n",
655
+ "\n",
656
+ " .dataframe tbody tr th {\n",
657
+ " vertical-align: top;\n",
658
+ " }\n",
659
+ "\n",
660
+ " .dataframe thead th {\n",
661
+ " text-align: right;\n",
662
+ " }\n",
663
+ "</style>\n",
664
+ "<table border=\"1\" class=\"dataframe\">\n",
665
+ " <thead>\n",
666
+ " <tr style=\"text-align: right;\">\n",
667
+ " <th></th>\n",
668
+ " <th>X</th>\n",
669
+ " <th>CAMID</th>\n",
670
+ " <th>Image_name</th>\n",
671
+ " <th>md5</th>\n",
672
+ " <th>record_number</th>\n",
673
+ " <th>Taxonomic_Name</th>\n",
674
+ " <th>species</th>\n",
675
+ " <th>subspecies</th>\n",
676
+ " <th>genus</th>\n",
677
+ " <th>Cross_Type</th>\n",
678
+ " <th>View</th>\n",
679
+ " <th>Locality</th>\n",
680
+ " <th>Sex</th>\n",
681
+ " <th>Dataset</th>\n",
682
+ " <th>file_type</th>\n",
683
+ " </tr>\n",
684
+ " </thead>\n",
685
+ " <tbody>\n",
686
+ " <tr>\n",
687
+ " <th>40141</th>\n",
688
+ " <td>26197</td>\n",
689
+ " <td>CAM050147</td>\n",
690
+ " <td>CAM050147_DS1_HW_IMG_8537_cut_3.tif</td>\n",
691
+ " <td>21e726df7076f5c13fe1441126bac4d5</td>\n",
692
+ " <td>2553977</td>\n",
693
+ " <td>Heliconius sara ssp. sara</td>\n",
694
+ " <td>Heliconius sara</td>\n",
695
+ " <td>sara</td>\n",
696
+ " <td>Heliconius</td>\n",
697
+ " <td>NaN</td>\n",
698
+ " <td>dorsal</td>\n",
699
+ " <td>Madingley</td>\n",
700
+ " <td>NaN</td>\n",
701
+ " <td>NaN</td>\n",
702
+ " <td>tif</td>\n",
703
+ " </tr>\n",
704
+ " <tr>\n",
705
+ " <th>40144</th>\n",
706
+ " <td>26196</td>\n",
707
+ " <td>CAM050147</td>\n",
708
+ " <td>CAM050147_DS1_HW_IMG_8537_cut_3.tif</td>\n",
709
+ " <td>21e726df7076f5c13fe1441126bac4d5</td>\n",
710
+ " <td>2553977</td>\n",
711
+ " <td>Heliconius sara ssp. sara</td>\n",
712
+ " <td>Heliconius sara</td>\n",
713
+ " <td>sara</td>\n",
714
+ " <td>Heliconius</td>\n",
715
+ " <td>NaN</td>\n",
716
+ " <td>dorsal</td>\n",
717
+ " <td>Madingley</td>\n",
718
+ " <td>NaN</td>\n",
719
+ " <td>NaN</td>\n",
720
+ " <td>tif</td>\n",
721
+ " </tr>\n",
722
+ " <tr>\n",
723
+ " <th>40112</th>\n",
724
+ " <td>26102</td>\n",
725
+ " <td>CAM050036</td>\n",
726
+ " <td>CAM050036_S1_9_FW_IMG_8547_wb_2.tif</td>\n",
727
+ " <td>34adbd5596f977834fb2c6876d2f4493</td>\n",
728
+ " <td>2553977</td>\n",
729
+ " <td>Heliconius sara ssp. sara</td>\n",
730
+ " <td>Heliconius sara</td>\n",
731
+ " <td>sara</td>\n",
732
+ " <td>Heliconius</td>\n",
733
+ " <td>NaN</td>\n",
734
+ " <td>dorsal</td>\n",
735
+ " <td>Gamboa_insectaries</td>\n",
736
+ " <td>NaN</td>\n",
737
+ " <td>NaN</td>\n",
738
+ " <td>tif</td>\n",
739
+ " </tr>\n",
740
+ " <tr>\n",
741
+ " <th>40116</th>\n",
742
+ " <td>26115</td>\n",
743
+ " <td>CAM050036</td>\n",
744
+ " <td>CAM050036_S1_9_FW_IMG_8547_cut_2.tif</td>\n",
745
+ " <td>34adbd5596f977834fb2c6876d2f4493</td>\n",
746
+ " <td>2553977</td>\n",
747
+ " <td>Heliconius sara ssp. sara</td>\n",
748
+ " <td>Heliconius sara</td>\n",
749
+ " <td>sara</td>\n",
750
+ " <td>Heliconius</td>\n",
751
+ " <td>NaN</td>\n",
752
+ " <td>dorsal</td>\n",
753
+ " <td>Gamboa_insectaries</td>\n",
754
+ " <td>NaN</td>\n",
755
+ " <td>NaN</td>\n",
756
+ " <td>tif</td>\n",
757
+ " </tr>\n",
758
+ " <tr>\n",
759
+ " <th>40138</th>\n",
760
+ " <td>26112</td>\n",
761
+ " <td>CAM050147</td>\n",
762
+ " <td>CAM050147_DS1_IMG_8513_4.tif</td>\n",
763
+ " <td>464801449aa127933d9619cb4e6f0a01</td>\n",
764
+ " <td>2553977</td>\n",
765
+ " <td>Heliconius sara ssp. sara</td>\n",
766
+ " <td>Heliconius sara</td>\n",
767
+ " <td>sara</td>\n",
768
+ " <td>Heliconius</td>\n",
769
+ " <td>NaN</td>\n",
770
+ " <td>dorsal</td>\n",
771
+ " <td>Madingley</td>\n",
772
+ " <td>NaN</td>\n",
773
+ " <td>NaN</td>\n",
774
+ " <td>tif</td>\n",
775
+ " </tr>\n",
776
+ " <tr>\n",
777
+ " <th>40145</th>\n",
778
+ " <td>26117</td>\n",
779
+ " <td>CAM050147</td>\n",
780
+ " <td>CAM050147_DS1_FW_IMG_8513_cut_4.tif</td>\n",
781
+ " <td>464801449aa127933d9619cb4e6f0a01</td>\n",
782
+ " <td>2553977</td>\n",
783
+ " <td>Heliconius sara ssp. sara</td>\n",
784
+ " <td>Heliconius sara</td>\n",
785
+ " <td>sara</td>\n",
786
+ " <td>Heliconius</td>\n",
787
+ " <td>NaN</td>\n",
788
+ " <td>dorsal</td>\n",
789
+ " <td>Madingley</td>\n",
790
+ " <td>NaN</td>\n",
791
+ " <td>NaN</td>\n",
792
+ " <td>tif</td>\n",
793
+ " </tr>\n",
794
+ " <tr>\n",
795
+ " <th>40113</th>\n",
796
+ " <td>26105</td>\n",
797
+ " <td>CAM050036</td>\n",
798
+ " <td>CAM050036_S1_9_HW_wt_IMG_8541_cut3.tif</td>\n",
799
+ " <td>6d63d659fbc02369010938bbc229ad4d</td>\n",
800
+ " <td>2553977</td>\n",
801
+ " <td>Heliconius sara ssp. sara</td>\n",
802
+ " <td>Heliconius sara</td>\n",
803
+ " <td>sara</td>\n",
804
+ " <td>Heliconius</td>\n",
805
+ " <td>NaN</td>\n",
806
+ " <td>dorsal</td>\n",
807
+ " <td>Gamboa_insectaries</td>\n",
808
+ " <td>NaN</td>\n",
809
+ " <td>NaN</td>\n",
810
+ " <td>tif</td>\n",
811
+ " </tr>\n",
812
+ " <tr>\n",
813
+ " <th>40120</th>\n",
814
+ " <td>26116</td>\n",
815
+ " <td>CAM050036</td>\n",
816
+ " <td>CAM050036_S1_9_HW_wt_IMG_8541_cut_3.tif</td>\n",
817
+ " <td>6d63d659fbc02369010938bbc229ad4d</td>\n",
818
+ " <td>2553977</td>\n",
819
+ " <td>Heliconius sara ssp. sara</td>\n",
820
+ " <td>Heliconius sara</td>\n",
821
+ " <td>sara</td>\n",
822
+ " <td>Heliconius</td>\n",
823
+ " <td>NaN</td>\n",
824
+ " <td>dorsal</td>\n",
825
+ " <td>Gamboa_insectaries</td>\n",
826
+ " <td>NaN</td>\n",
827
+ " <td>NaN</td>\n",
828
+ " <td>tif</td>\n",
829
+ " </tr>\n",
830
+ " </tbody>\n",
831
+ "</table>\n",
832
+ "</div>"
833
+ ],
834
+ "text/plain": [
835
+ " X CAMID Image_name \\\n",
836
+ "40141 26197 CAM050147 CAM050147_DS1_HW_IMG_8537_cut_3.tif \n",
837
+ "40144 26196 CAM050147 CAM050147_DS1_HW_IMG_8537_cut_3.tif \n",
838
+ "40112 26102 CAM050036 CAM050036_S1_9_FW_IMG_8547_wb_2.tif \n",
839
+ "40116 26115 CAM050036 CAM050036_S1_9_FW_IMG_8547_cut_2.tif \n",
840
+ "40138 26112 CAM050147 CAM050147_DS1_IMG_8513_4.tif \n",
841
+ "40145 26117 CAM050147 CAM050147_DS1_FW_IMG_8513_cut_4.tif \n",
842
+ "40113 26105 CAM050036 CAM050036_S1_9_HW_wt_IMG_8541_cut3.tif \n",
843
+ "40120 26116 CAM050036 CAM050036_S1_9_HW_wt_IMG_8541_cut_3.tif \n",
844
+ "\n",
845
+ " md5 record_number \\\n",
846
+ "40141 21e726df7076f5c13fe1441126bac4d5 2553977 \n",
847
+ "40144 21e726df7076f5c13fe1441126bac4d5 2553977 \n",
848
+ "40112 34adbd5596f977834fb2c6876d2f4493 2553977 \n",
849
+ "40116 34adbd5596f977834fb2c6876d2f4493 2553977 \n",
850
+ "40138 464801449aa127933d9619cb4e6f0a01 2553977 \n",
851
+ "40145 464801449aa127933d9619cb4e6f0a01 2553977 \n",
852
+ "40113 6d63d659fbc02369010938bbc229ad4d 2553977 \n",
853
+ "40120 6d63d659fbc02369010938bbc229ad4d 2553977 \n",
854
+ "\n",
855
+ " Taxonomic_Name species subspecies genus \\\n",
856
+ "40141 Heliconius sara ssp. sara Heliconius sara sara Heliconius \n",
857
+ "40144 Heliconius sara ssp. sara Heliconius sara sara Heliconius \n",
858
+ "40112 Heliconius sara ssp. sara Heliconius sara sara Heliconius \n",
859
+ "40116 Heliconius sara ssp. sara Heliconius sara sara Heliconius \n",
860
+ "40138 Heliconius sara ssp. sara Heliconius sara sara Heliconius \n",
861
+ "40145 Heliconius sara ssp. sara Heliconius sara sara Heliconius \n",
862
+ "40113 Heliconius sara ssp. sara Heliconius sara sara Heliconius \n",
863
+ "40120 Heliconius sara ssp. sara Heliconius sara sara Heliconius \n",
864
+ "\n",
865
+ " Cross_Type View Locality Sex Dataset file_type \n",
866
+ "40141 NaN dorsal Madingley NaN NaN tif \n",
867
+ "40144 NaN dorsal Madingley NaN NaN tif \n",
868
+ "40112 NaN dorsal Gamboa_insectaries NaN NaN tif \n",
869
+ "40116 NaN dorsal Gamboa_insectaries NaN NaN tif \n",
870
+ "40138 NaN dorsal Madingley NaN NaN tif \n",
871
+ "40145 NaN dorsal Madingley NaN NaN tif \n",
872
+ "40113 NaN dorsal Gamboa_insectaries NaN NaN tif \n",
873
+ "40120 NaN dorsal Gamboa_insectaries NaN NaN tif "
874
+ ]
875
+ },
876
+ "execution_count": 15,
877
+ "metadata": {},
878
+ "output_type": "execute_result"
879
+ }
880
+ ],
881
+ "source": [
882
+ "dupes_2553977 = duplicates.loc[duplicates[\"record_number\"] == 2553977]\n",
883
+ "dupes_2553977[STATS_COLS].sort_values(\"md5\")"
884
+ ]
885
+ },
886
+ {
887
+ "cell_type": "markdown",
888
+ "metadata": {},
889
+ "source": [
890
+ "For each of these, we want the one with `_cut_` in the `Image_name`."
891
+ ]
892
+ },
893
+ {
894
+ "cell_type": "code",
895
+ "execution_count": 16,
896
+ "metadata": {},
897
+ "outputs": [
898
+ {
899
+ "data": {
900
+ "text/plain": [
901
+ "[26102, 26105, 26112]"
902
+ ]
903
+ },
904
+ "execution_count": 16,
905
+ "metadata": {},
906
+ "output_type": "execute_result"
907
+ }
908
+ ],
909
+ "source": [
910
+ "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",
911
+ "\n",
912
+ "# Check we got the ones expected\n",
913
+ "X_dupes_2553977"
914
+ ]
915
+ },
916
+ {
917
+ "cell_type": "code",
918
+ "execution_count": 17,
919
+ "metadata": {},
920
+ "outputs": [],
921
+ "source": [
922
+ "# Add 26196, since both those entries (26196 and 26197) are the same\n",
923
+ "X_dupes_2553977.append(26196)\n"
924
+ ]
925
+ },
926
+ {
927
+ "cell_type": "code",
928
+ "execution_count": 18,
929
+ "metadata": {},
930
+ "outputs": [
931
+ {
932
+ "data": {
933
+ "text/plain": [
934
+ "X 36211\n",
935
+ "CAMID 11968\n",
936
+ "Image_name 36211\n",
937
+ "md5 36211\n",
938
+ "record_number 29\n",
939
+ "Taxonomic_Name 366\n",
940
+ "species 246\n",
941
+ "subspecies 155\n",
942
+ "genus 94\n",
943
+ "Cross_Type 30\n",
944
+ "View 7\n",
945
+ "Locality 644\n",
946
+ "Sex 3\n",
947
+ "Dataset 7\n",
948
+ "file_type 3\n",
949
+ "dtype: int64"
950
+ ]
951
+ },
952
+ "execution_count": 18,
953
+ "metadata": {},
954
+ "output_type": "execute_result"
955
+ }
956
+ ],
957
+ "source": [
958
+ "df_reduced_5 = df_reduced_4.loc[~df_reduced_4[\"X\"].isin(X_dupes_2553977)]\n",
959
+ "df_reduced_5[STATS_COLS].nunique()"
960
+ ]
961
+ },
962
+ {
963
+ "cell_type": "markdown",
964
+ "metadata": {},
965
+ "source": [
966
+ "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."
967
+ ]
968
+ },
969
+ {
970
+ "cell_type": "markdown",
971
+ "metadata": {},
972
+ "source": [
973
+ "## Save Reduced Master File of Unique Images\n",
974
+ "\n",
975
+ "Don't include last column indicating duplicate MD5s."
976
+ ]
977
+ },
978
+ {
979
+ "cell_type": "code",
980
+ "execution_count": 19,
981
+ "metadata": {},
982
+ "outputs": [],
983
+ "source": [
984
+ "df_reduced_5[list(df_reduced_5.columns)[:-1]].to_csv(\"../Jiggins_Zenodo_Img_Master.csv\", index = False)"
985
+ ]
986
+ },
987
+ {
988
+ "cell_type": "markdown",
989
+ "metadata": {},
990
+ "source": [
991
+ "# Generate New Master Heliconius and Dorsal Subsets\n",
992
+ "\n",
993
+ "## Read in New Master File\n",
994
+ "\n",
995
+ "First check on our stats noted in the README."
996
+ ]
997
+ },
998
+ {
999
+ "cell_type": "code",
1000
+ "execution_count": 20,
1001
+ "metadata": {},
1002
+ "outputs": [
1003
+ {
1004
+ "name": "stdout",
1005
+ "output_type": "stream",
1006
+ "text": [
1007
+ "<class 'pandas.core.frame.DataFrame'>\n",
1008
+ "RangeIndex: 36211 entries, 0 to 36210\n",
1009
+ "Data columns (total 31 columns):\n",
1010
+ " # Column Non-Null Count Dtype \n",
1011
+ "--- ------ -------------- ----- \n",
1012
+ " 0 CAMID 36211 non-null object\n",
1013
+ " 1 X 36211 non-null int64 \n",
1014
+ " 2 Image_name 36211 non-null object\n",
1015
+ " 3 View 35432 non-null object\n",
1016
+ " 4 zenodo_name 36211 non-null object\n",
1017
+ " 5 zenodo_link 36211 non-null object\n",
1018
+ " 6 Sequence 35279 non-null object\n",
1019
+ " 7 Taxonomic_Name 36211 non-null object\n",
1020
+ " 8 Locality 23127 non-null object\n",
1021
+ " 9 Sample_accession 3647 non-null object\n",
1022
+ " 10 Collected_by 3043 non-null object\n",
1023
+ " 11 Other_ID 11329 non-null object\n",
1024
+ " 12 Date 23040 non-null object\n",
1025
+ " 13 Dataset 29114 non-null object\n",
1026
+ " 14 Store 27813 non-null object\n",
1027
+ " 15 Brood 13847 non-null object\n",
1028
+ " 16 Death_Date 269 non-null object\n",
1029
+ " 17 Cross_Type 4447 non-null object\n",
1030
+ " 18 Stage 6 non-null object\n",
1031
+ " 19 Sex 27514 non-null object\n",
1032
+ " 20 Unit_Type 25060 non-null object\n",
1033
+ " 21 file_type 36211 non-null object\n",
1034
+ " 22 record_number 36211 non-null int64 \n",
1035
+ " 23 species 36211 non-null object\n",
1036
+ " 24 subspecies 20400 non-null object\n",
1037
+ " 25 genus 36211 non-null object\n",
1038
+ " 26 file_url 36211 non-null object\n",
1039
+ " 27 hybrid_stat 20948 non-null object\n",
1040
+ " 28 filename 36211 non-null object\n",
1041
+ " 29 filepath 36211 non-null object\n",
1042
+ " 30 md5 36211 non-null object\n",
1043
+ "dtypes: int64(2), object(29)\n",
1044
+ "memory usage: 8.6+ MB\n"
1045
+ ]
1046
+ }
1047
+ ],
1048
+ "source": [
1049
+ "master = pd.read_csv(\"../Jiggins_Zenodo_Img_Master.csv\", low_memory = False)\n",
1050
+ "master.info()"
1051
+ ]
1052
+ },
1053
+ {
1054
+ "cell_type": "code",
1055
+ "execution_count": 21,
1056
+ "metadata": {},
1057
+ "outputs": [
1058
+ {
1059
+ "data": {
1060
+ "text/html": [
1061
+ "<div>\n",
1062
+ "<style scoped>\n",
1063
+ " .dataframe tbody tr th:only-of-type {\n",
1064
+ " vertical-align: middle;\n",
1065
+ " }\n",
1066
+ "\n",
1067
+ " .dataframe tbody tr th {\n",
1068
+ " vertical-align: top;\n",
1069
+ " }\n",
1070
+ "\n",
1071
+ " .dataframe thead th {\n",
1072
+ " text-align: right;\n",
1073
+ " }\n",
1074
+ "</style>\n",
1075
+ "<table border=\"1\" class=\"dataframe\">\n",
1076
+ " <thead>\n",
1077
+ " <tr style=\"text-align: right;\">\n",
1078
+ " <th></th>\n",
1079
+ " <th>CAMID</th>\n",
1080
+ " <th>X</th>\n",
1081
+ " <th>Image_name</th>\n",
1082
+ " <th>View</th>\n",
1083
+ " <th>zenodo_name</th>\n",
1084
+ " <th>zenodo_link</th>\n",
1085
+ " <th>Sequence</th>\n",
1086
+ " <th>Taxonomic_Name</th>\n",
1087
+ " <th>Locality</th>\n",
1088
+ " <th>Sample_accession</th>\n",
1089
+ " <th>...</th>\n",
1090
+ " <th>file_type</th>\n",
1091
+ " <th>record_number</th>\n",
1092
+ " <th>species</th>\n",
1093
+ " <th>subspecies</th>\n",
1094
+ " <th>genus</th>\n",
1095
+ " <th>file_url</th>\n",
1096
+ " <th>hybrid_stat</th>\n",
1097
+ " <th>filename</th>\n",
1098
+ " <th>filepath</th>\n",
1099
+ " <th>md5</th>\n",
1100
+ " </tr>\n",
1101
+ " </thead>\n",
1102
+ " <tbody>\n",
1103
+ " <tr>\n",
1104
+ " <th>13300</th>\n",
1105
+ " <td>CAM013566</td>\n",
1106
+ " <td>26040</td>\n",
1107
+ " <td>13566_H_m_thelxiopeia_V.JPG.jpg</td>\n",
1108
+ " <td>ventral</td>\n",
1109
+ " <td>Heliconius_wing_old_photos_2001_2019_part3.csv</td>\n",
1110
+ " <td>https://zenodo.org/record/2553977</td>\n",
1111
+ " <td>13,566</td>\n",
1112
+ " <td>Heliconius melpomene ssp. thelxiopeia</td>\n",
1113
+ " <td>Maripasoula</td>\n",
1114
+ " <td>ERS977708</td>\n",
1115
+ " <td>...</td>\n",
1116
+ " <td>jpg</td>\n",
1117
+ " <td>2553977</td>\n",
1118
+ " <td>Heliconius melpomene</td>\n",
1119
+ " <td>thelxiopeia</td>\n",
1120
+ " <td>Heliconius</td>\n",
1121
+ " <td>https://zenodo.org/record/2553977/files/13566_...</td>\n",
1122
+ " <td>non-hybrid</td>\n",
1123
+ " <td>26040_13566_H_m_thelxiopeia_V.JPG.jpg</td>\n",
1124
+ " <td>images/Heliconius melpomene ssp. thelxiopeia/2...</td>\n",
1125
+ " <td>b5ed68f937132cbbb04a81d550c9f17e</td>\n",
1126
+ " </tr>\n",
1127
+ " <tr>\n",
1128
+ " <th>13301</th>\n",
1129
+ " <td>CAM013566</td>\n",
1130
+ " <td>26039</td>\n",
1131
+ " <td>13566_H_m_thelxiopeia_D.JPG.jpg</td>\n",
1132
+ " <td>dorsal</td>\n",
1133
+ " <td>Heliconius_wing_old_photos_2001_2019_part3.csv</td>\n",
1134
+ " <td>https://zenodo.org/record/2553977</td>\n",
1135
+ " <td>13,566</td>\n",
1136
+ " <td>Heliconius melpomene ssp. thelxiopeia</td>\n",
1137
+ " <td>Maripasoula</td>\n",
1138
+ " <td>ERS977708</td>\n",
1139
+ " <td>...</td>\n",
1140
+ " <td>jpg</td>\n",
1141
+ " <td>2553977</td>\n",
1142
+ " <td>Heliconius melpomene</td>\n",
1143
+ " <td>thelxiopeia</td>\n",
1144
+ " <td>Heliconius</td>\n",
1145
+ " <td>https://zenodo.org/record/2553977/files/13566_...</td>\n",
1146
+ " <td>non-hybrid</td>\n",
1147
+ " <td>26039_13566_H_m_thelxiopeia_D.JPG.jpg</td>\n",
1148
+ " <td>images/Heliconius melpomene ssp. thelxiopeia/2...</td>\n",
1149
+ " <td>cb107e2d6a2c3c84b68bbf4e3cfa7af7</td>\n",
1150
+ " </tr>\n",
1151
+ " <tr>\n",
1152
+ " <th>13302</th>\n",
1153
+ " <td>CAM013715</td>\n",
1154
+ " <td>26041</td>\n",
1155
+ " <td>13715_H_m_meriana_D.JPG.jpg</td>\n",
1156
+ " <td>dorsal</td>\n",
1157
+ " <td>Heliconius_wing_old_photos_2001_2019_part3.csv</td>\n",
1158
+ " <td>https://zenodo.org/record/2553977</td>\n",
1159
+ " <td>13,715</td>\n",
1160
+ " <td>Heliconius melpomene ssp. meriana</td>\n",
1161
+ " <td>N. Wakapou, Maripausala FR GUIANA</td>\n",
1162
+ " <td>ERS977704</td>\n",
1163
+ " <td>...</td>\n",
1164
+ " <td>jpg</td>\n",
1165
+ " <td>2553977</td>\n",
1166
+ " <td>Heliconius melpomene</td>\n",
1167
+ " <td>meriana</td>\n",
1168
+ " <td>Heliconius</td>\n",
1169
+ " <td>https://zenodo.org/record/2553977/files/13715_...</td>\n",
1170
+ " <td>non-hybrid</td>\n",
1171
+ " <td>26041_13715_H_m_meriana_D.JPG.jpg</td>\n",
1172
+ " <td>images/Heliconius melpomene ssp. meriana/26041...</td>\n",
1173
+ " <td>8c77ecb2d8d878f8ac8b097ad361deda</td>\n",
1174
+ " </tr>\n",
1175
+ " <tr>\n",
1176
+ " <th>13303</th>\n",
1177
+ " <td>CAM013715</td>\n",
1178
+ " <td>26042</td>\n",
1179
+ " <td>13715_H_m_meriana_V.JPG.jpg</td>\n",
1180
+ " <td>ventral</td>\n",
1181
+ " <td>Heliconius_wing_old_photos_2001_2019_part3.csv</td>\n",
1182
+ " <td>https://zenodo.org/record/2553977</td>\n",
1183
+ " <td>13,715</td>\n",
1184
+ " <td>Heliconius melpomene ssp. meriana</td>\n",
1185
+ " <td>N. Wakapou, Maripausala FR GUIANA</td>\n",
1186
+ " <td>ERS977704</td>\n",
1187
+ " <td>...</td>\n",
1188
+ " <td>jpg</td>\n",
1189
+ " <td>2553977</td>\n",
1190
+ " <td>Heliconius melpomene</td>\n",
1191
+ " <td>meriana</td>\n",
1192
+ " <td>Heliconius</td>\n",
1193
+ " <td>https://zenodo.org/record/2553977/files/13715_...</td>\n",
1194
+ " <td>non-hybrid</td>\n",
1195
+ " <td>26042_13715_H_m_meriana_V.JPG.jpg</td>\n",
1196
+ " <td>images/Heliconius melpomene ssp. meriana/26042...</td>\n",
1197
+ " <td>fcf74c73537323bb90127cf92775ac08</td>\n",
1198
+ " </tr>\n",
1199
+ " <tr>\n",
1200
+ " <th>13304</th>\n",
1201
+ " <td>CAM013819</td>\n",
1202
+ " <td>26044</td>\n",
1203
+ " <td>13819_H_m_meriana_V.JPG.jpg</td>\n",
1204
+ " <td>ventral</td>\n",
1205
+ " <td>Heliconius_wing_old_photos_2001_2019_part3.csv</td>\n",
1206
+ " <td>https://zenodo.org/record/2553977</td>\n",
1207
+ " <td>13,819</td>\n",
1208
+ " <td>Heliconius melpomene ssp. meriana</td>\n",
1209
+ " <td>N. Wakapou, Maripausala FR GUIANA</td>\n",
1210
+ " <td>ERS977703</td>\n",
1211
+ " <td>...</td>\n",
1212
+ " <td>jpg</td>\n",
1213
+ " <td>2553977</td>\n",
1214
+ " <td>Heliconius melpomene</td>\n",
1215
+ " <td>meriana</td>\n",
1216
+ " <td>Heliconius</td>\n",
1217
+ " <td>https://zenodo.org/record/2553977/files/13819_...</td>\n",
1218
+ " <td>non-hybrid</td>\n",
1219
+ " <td>26044_13819_H_m_meriana_V.JPG.jpg</td>\n",
1220
+ " <td>images/Heliconius melpomene ssp. meriana/26044...</td>\n",
1221
+ " <td>601b67512a8c25e5f25a9da89841e8c2</td>\n",
1222
+ " </tr>\n",
1223
+ " <tr>\n",
1224
+ " <th>13305</th>\n",
1225
+ " <td>CAM013819</td>\n",
1226
+ " <td>26043</td>\n",
1227
+ " <td>13819_H_m_meriana_D.JPG.jpg</td>\n",
1228
+ " <td>dorsal</td>\n",
1229
+ " <td>Heliconius_wing_old_photos_2001_2019_part3.csv</td>\n",
1230
+ " <td>https://zenodo.org/record/2553977</td>\n",
1231
+ " <td>13,819</td>\n",
1232
+ " <td>Heliconius melpomene ssp. meriana</td>\n",
1233
+ " <td>N. Wakapou, Maripausala FR GUIANA</td>\n",
1234
+ " <td>ERS977703</td>\n",
1235
+ " <td>...</td>\n",
1236
+ " <td>jpg</td>\n",
1237
+ " <td>2553977</td>\n",
1238
+ " <td>Heliconius melpomene</td>\n",
1239
+ " <td>meriana</td>\n",
1240
+ " <td>Heliconius</td>\n",
1241
+ " <td>https://zenodo.org/record/2553977/files/13819_...</td>\n",
1242
+ " <td>non-hybrid</td>\n",
1243
+ " <td>26043_13819_H_m_meriana_D.JPG.jpg</td>\n",
1244
+ " <td>images/Heliconius melpomene ssp. meriana/26043...</td>\n",
1245
+ " <td>fe4cf831c5203ad6c9010fc047b7fa10</td>\n",
1246
+ " </tr>\n",
1247
+ " </tbody>\n",
1248
+ "</table>\n",
1249
+ "<p>6 rows × 31 columns</p>\n",
1250
+ "</div>"
1251
+ ],
1252
+ "text/plain": [
1253
+ " CAMID X Image_name View \\\n",
1254
+ "13300 CAM013566 26040 13566_H_m_thelxiopeia_V.JPG.jpg ventral \n",
1255
+ "13301 CAM013566 26039 13566_H_m_thelxiopeia_D.JPG.jpg dorsal \n",
1256
+ "13302 CAM013715 26041 13715_H_m_meriana_D.JPG.jpg dorsal \n",
1257
+ "13303 CAM013715 26042 13715_H_m_meriana_V.JPG.jpg ventral \n",
1258
+ "13304 CAM013819 26044 13819_H_m_meriana_V.JPG.jpg ventral \n",
1259
+ "13305 CAM013819 26043 13819_H_m_meriana_D.JPG.jpg dorsal \n",
1260
+ "\n",
1261
+ " zenodo_name \\\n",
1262
+ "13300 Heliconius_wing_old_photos_2001_2019_part3.csv \n",
1263
+ "13301 Heliconius_wing_old_photos_2001_2019_part3.csv \n",
1264
+ "13302 Heliconius_wing_old_photos_2001_2019_part3.csv \n",
1265
+ "13303 Heliconius_wing_old_photos_2001_2019_part3.csv \n",
1266
+ "13304 Heliconius_wing_old_photos_2001_2019_part3.csv \n",
1267
+ "13305 Heliconius_wing_old_photos_2001_2019_part3.csv \n",
1268
+ "\n",
1269
+ " zenodo_link Sequence \\\n",
1270
+ "13300 https://zenodo.org/record/2553977 13,566 \n",
1271
+ "13301 https://zenodo.org/record/2553977 13,566 \n",
1272
+ "13302 https://zenodo.org/record/2553977 13,715 \n",
1273
+ "13303 https://zenodo.org/record/2553977 13,715 \n",
1274
+ "13304 https://zenodo.org/record/2553977 13,819 \n",
1275
+ "13305 https://zenodo.org/record/2553977 13,819 \n",
1276
+ "\n",
1277
+ " Taxonomic_Name \\\n",
1278
+ "13300 Heliconius melpomene ssp. thelxiopeia \n",
1279
+ "13301 Heliconius melpomene ssp. thelxiopeia \n",
1280
+ "13302 Heliconius melpomene ssp. meriana \n",
1281
+ "13303 Heliconius melpomene ssp. meriana \n",
1282
+ "13304 Heliconius melpomene ssp. meriana \n",
1283
+ "13305 Heliconius melpomene ssp. meriana \n",
1284
+ "\n",
1285
+ " Locality Sample_accession ... file_type \\\n",
1286
+ "13300 Maripasoula ERS977708 ... jpg \n",
1287
+ "13301 Maripasoula ERS977708 ... jpg \n",
1288
+ "13302 N. Wakapou, Maripausala FR GUIANA ERS977704 ... jpg \n",
1289
+ "13303 N. Wakapou, Maripausala FR GUIANA ERS977704 ... jpg \n",
1290
+ "13304 N. Wakapou, Maripausala FR GUIANA ERS977703 ... jpg \n",
1291
+ "13305 N. Wakapou, Maripausala FR GUIANA ERS977703 ... jpg \n",
1292
+ "\n",
1293
+ " record_number species subspecies genus \\\n",
1294
+ "13300 2553977 Heliconius melpomene thelxiopeia Heliconius \n",
1295
+ "13301 2553977 Heliconius melpomene thelxiopeia Heliconius \n",
1296
+ "13302 2553977 Heliconius melpomene meriana Heliconius \n",
1297
+ "13303 2553977 Heliconius melpomene meriana Heliconius \n",
1298
+ "13304 2553977 Heliconius melpomene meriana Heliconius \n",
1299
+ "13305 2553977 Heliconius melpomene meriana Heliconius \n",
1300
+ "\n",
1301
+ " file_url hybrid_stat \\\n",
1302
+ "13300 https://zenodo.org/record/2553977/files/13566_... non-hybrid \n",
1303
+ "13301 https://zenodo.org/record/2553977/files/13566_... non-hybrid \n",
1304
+ "13302 https://zenodo.org/record/2553977/files/13715_... non-hybrid \n",
1305
+ "13303 https://zenodo.org/record/2553977/files/13715_... non-hybrid \n",
1306
+ "13304 https://zenodo.org/record/2553977/files/13819_... non-hybrid \n",
1307
+ "13305 https://zenodo.org/record/2553977/files/13819_... non-hybrid \n",
1308
+ "\n",
1309
+ " filename \\\n",
1310
+ "13300 26040_13566_H_m_thelxiopeia_V.JPG.jpg \n",
1311
+ "13301 26039_13566_H_m_thelxiopeia_D.JPG.jpg \n",
1312
+ "13302 26041_13715_H_m_meriana_D.JPG.jpg \n",
1313
+ "13303 26042_13715_H_m_meriana_V.JPG.jpg \n",
1314
+ "13304 26044_13819_H_m_meriana_V.JPG.jpg \n",
1315
+ "13305 26043_13819_H_m_meriana_D.JPG.jpg \n",
1316
+ "\n",
1317
+ " filepath \\\n",
1318
+ "13300 images/Heliconius melpomene ssp. thelxiopeia/2... \n",
1319
+ "13301 images/Heliconius melpomene ssp. thelxiopeia/2... \n",
1320
+ "13302 images/Heliconius melpomene ssp. meriana/26041... \n",
1321
+ "13303 images/Heliconius melpomene ssp. meriana/26042... \n",
1322
+ "13304 images/Heliconius melpomene ssp. meriana/26044... \n",
1323
+ "13305 images/Heliconius melpomene ssp. meriana/26043... \n",
1324
+ "\n",
1325
+ " md5 \n",
1326
+ "13300 b5ed68f937132cbbb04a81d550c9f17e \n",
1327
+ "13301 cb107e2d6a2c3c84b68bbf4e3cfa7af7 \n",
1328
+ "13302 8c77ecb2d8d878f8ac8b097ad361deda \n",
1329
+ "13303 fcf74c73537323bb90127cf92775ac08 \n",
1330
+ "13304 601b67512a8c25e5f25a9da89841e8c2 \n",
1331
+ "13305 fe4cf831c5203ad6c9010fc047b7fa10 \n",
1332
+ "\n",
1333
+ "[6 rows x 31 columns]"
1334
+ ]
1335
+ },
1336
+ "execution_count": 21,
1337
+ "metadata": {},
1338
+ "output_type": "execute_result"
1339
+ }
1340
+ ],
1341
+ "source": [
1342
+ "master.loc[master.Stage.notna()]"
1343
+ ]
1344
+ },
1345
+ {
1346
+ "cell_type": "code",
1347
+ "execution_count": 22,
1348
+ "metadata": {},
1349
+ "outputs": [
1350
+ {
1351
+ "data": {
1352
+ "text/plain": [
1353
+ "CAMID 820\n",
1354
+ "X 4447\n",
1355
+ "Image_name 4447\n",
1356
+ "View 2\n",
1357
+ "zenodo_name 4\n",
1358
+ "zenodo_link 4\n",
1359
+ "Sequence 820\n",
1360
+ "Taxonomic_Name 8\n",
1361
+ "Locality 0\n",
1362
+ "Sample_accession 0\n",
1363
+ "Collected_by 0\n",
1364
+ "Other_ID 0\n",
1365
+ "Date 160\n",
1366
+ "Dataset 1\n",
1367
+ "Store 10\n",
1368
+ "Brood 49\n",
1369
+ "Death_Date 0\n",
1370
+ "Cross_Type 30\n",
1371
+ "Stage 0\n",
1372
+ "Sex 2\n",
1373
+ "Unit_Type 1\n",
1374
+ "file_type 2\n",
1375
+ "record_number 4\n",
1376
+ "species 2\n",
1377
+ "subspecies 21\n",
1378
+ "genus 1\n",
1379
+ "file_url 4447\n",
1380
+ "hybrid_stat 2\n",
1381
+ "filename 4447\n",
1382
+ "filepath 4447\n",
1383
+ "md5 4447\n",
1384
+ "dtype: int64"
1385
+ ]
1386
+ },
1387
+ "execution_count": 22,
1388
+ "metadata": {},
1389
+ "output_type": "execute_result"
1390
+ }
1391
+ ],
1392
+ "source": [
1393
+ "master.loc[master.Cross_Type.notna()].nunique()"
1394
+ ]
1395
+ },
1396
+ {
1397
+ "cell_type": "code",
1398
+ "execution_count": 23,
1399
+ "metadata": {},
1400
+ "outputs": [
1401
+ {
1402
+ "data": {
1403
+ "text/plain": [
1404
+ "View\n",
1405
+ "dorsal 17235\n",
1406
+ "ventral 17167\n",
1407
+ "hindwing dorsal 254\n",
1408
+ "hindwing ventral 254\n",
1409
+ "forewing dorsal 252\n",
1410
+ "forewing ventral 252\n",
1411
+ "dorsal and ventral 18\n",
1412
+ "Name: count, dtype: int64"
1413
+ ]
1414
+ },
1415
+ "execution_count": 23,
1416
+ "metadata": {},
1417
+ "output_type": "execute_result"
1418
+ }
1419
+ ],
1420
+ "source": [
1421
+ "master.View.value_counts()"
1422
+ ]
1423
+ },
1424
+ {
1425
+ "cell_type": "markdown",
1426
+ "metadata": {},
1427
+ "source": [
1428
+ "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"
1429
+ ]
1430
+ },
1431
+ {
1432
+ "cell_type": "code",
1433
+ "execution_count": 24,
1434
+ "metadata": {},
1435
+ "outputs": [
1436
+ {
1437
+ "data": {
1438
+ "text/plain": [
1439
+ "(29, 2)"
1440
+ ]
1441
+ },
1442
+ "execution_count": 24,
1443
+ "metadata": {},
1444
+ "output_type": "execute_result"
1445
+ }
1446
+ ],
1447
+ "source": [
1448
+ "master_licenses = master[[\"record_number\", \"zenodo_link\"]]\n",
1449
+ "master_licenses = master_licenses.loc[~master_licenses.duplicated([\"record_number\", \"zenodo_link\"], keep = \"first\")]\n",
1450
+ "master_licenses.shape"
1451
+ ]
1452
+ },
1453
+ {
1454
+ "cell_type": "code",
1455
+ "execution_count": 25,
1456
+ "metadata": {},
1457
+ "outputs": [
1458
+ {
1459
+ "data": {
1460
+ "text/html": [
1461
+ "<div>\n",
1462
+ "<style scoped>\n",
1463
+ " .dataframe tbody tr th:only-of-type {\n",
1464
+ " vertical-align: middle;\n",
1465
+ " }\n",
1466
+ "\n",
1467
+ " .dataframe tbody tr th {\n",
1468
+ " vertical-align: top;\n",
1469
+ " }\n",
1470
+ "\n",
1471
+ " .dataframe thead th {\n",
1472
+ " text-align: right;\n",
1473
+ " }\n",
1474
+ "</style>\n",
1475
+ "<table border=\"1\" class=\"dataframe\">\n",
1476
+ " <thead>\n",
1477
+ " <tr style=\"text-align: right;\">\n",
1478
+ " <th></th>\n",
1479
+ " <th>record_number</th>\n",
1480
+ " <th>url</th>\n",
1481
+ " </tr>\n",
1482
+ " </thead>\n",
1483
+ " <tbody>\n",
1484
+ " <tr>\n",
1485
+ " <th>0</th>\n",
1486
+ " <td>4289223</td>\n",
1487
+ " <td>https://zenodo.org/record/4289223</td>\n",
1488
+ " </tr>\n",
1489
+ " <tr>\n",
1490
+ " <th>145</th>\n",
1491
+ " <td>4288311</td>\n",
1492
+ " <td>https://zenodo.org/record/4288311</td>\n",
1493
+ " </tr>\n",
1494
+ " </tbody>\n",
1495
+ "</table>\n",
1496
+ "</div>"
1497
+ ],
1498
+ "text/plain": [
1499
+ " record_number url\n",
1500
+ "0 4289223 https://zenodo.org/record/4289223\n",
1501
+ "145 4288311 https://zenodo.org/record/4288311"
1502
+ ]
1503
+ },
1504
+ "execution_count": 25,
1505
+ "metadata": {},
1506
+ "output_type": "execute_result"
1507
+ }
1508
+ ],
1509
+ "source": [
1510
+ "master_licenses.rename(columns = {\"zenodo_link\": \"url\"}, inplace = True)\n",
1511
+ "master_licenses.head(2)"
1512
+ ]
1513
+ },
1514
+ {
1515
+ "cell_type": "code",
1516
+ "execution_count": 26,
1517
+ "metadata": {},
1518
+ "outputs": [],
1519
+ "source": [
1520
+ "# Save to CSV to run through get licenses script\n",
1521
+ "master_licenses.to_csv(\"../metadata/master_licenses.csv\", index = False)"
1522
+ ]
1523
+ },
1524
+ {
1525
+ "cell_type": "markdown",
1526
+ "metadata": {},
1527
+ "source": [
1528
+ "## Make Heliconius Master Subset\n",
1529
+ "\n",
1530
+ "Now make the Heliconius master CSV, and check stats to update README."
1531
+ ]
1532
+ },
1533
+ {
1534
+ "cell_type": "code",
1535
+ "execution_count": 27,
1536
+ "metadata": {},
1537
+ "outputs": [
1538
+ {
1539
+ "data": {
1540
+ "text/plain": [
1541
+ "CAMID 10086\n",
1542
+ "X 29134\n",
1543
+ "Image_name 29134\n",
1544
+ "View 3\n",
1545
+ "zenodo_name 31\n",
1546
+ "zenodo_link 29\n",
1547
+ "Sequence 9008\n",
1548
+ "Taxonomic_Name 132\n",
1549
+ "Locality 471\n",
1550
+ "Sample_accession 1559\n",
1551
+ "Collected_by 12\n",
1552
+ "Other_ID 1865\n",
1553
+ "Date 773\n",
1554
+ "Dataset 7\n",
1555
+ "Store 121\n",
1556
+ "Brood 224\n",
1557
+ "Death_Date 79\n",
1558
+ "Cross_Type 30\n",
1559
+ "Stage 1\n",
1560
+ "Sex 3\n",
1561
+ "Unit_Type 4\n",
1562
+ "file_type 3\n",
1563
+ "record_number 29\n",
1564
+ "species 37\n",
1565
+ "subspecies 110\n",
1566
+ "genus 1\n",
1567
+ "file_url 29134\n",
1568
+ "hybrid_stat 2\n",
1569
+ "filename 29134\n",
1570
+ "filepath 29134\n",
1571
+ "md5 29134\n",
1572
+ "dtype: int64"
1573
+ ]
1574
+ },
1575
+ "execution_count": 27,
1576
+ "metadata": {},
1577
+ "output_type": "execute_result"
1578
+ }
1579
+ ],
1580
+ "source": [
1581
+ "heliconius_master = master.loc[master.genus.str.lower() == \"heliconius\"].copy()\n",
1582
+ "heliconius_master.nunique()"
1583
+ ]
1584
+ },
1585
+ {
1586
+ "cell_type": "code",
1587
+ "execution_count": 28,
1588
+ "metadata": {},
1589
+ "outputs": [
1590
+ {
1591
+ "data": {
1592
+ "text/plain": [
1593
+ "View\n",
1594
+ "dorsal 14202\n",
1595
+ "ventral 14135\n",
1596
+ "dorsal and ventral 18\n",
1597
+ "Name: count, dtype: int64"
1598
+ ]
1599
+ },
1600
+ "execution_count": 28,
1601
+ "metadata": {},
1602
+ "output_type": "execute_result"
1603
+ }
1604
+ ],
1605
+ "source": [
1606
+ "heliconius_master.View.value_counts()"
1607
+ ]
1608
+ },
1609
+ {
1610
+ "cell_type": "markdown",
1611
+ "metadata": {},
1612
+ "source": [
1613
+ "### Save Heliconius Subset to CSV"
1614
+ ]
1615
+ },
1616
+ {
1617
+ "cell_type": "code",
1618
+ "execution_count": 29,
1619
+ "metadata": {},
1620
+ "outputs": [],
1621
+ "source": [
1622
+ "heliconius_master.to_csv(\"../Jiggins_Heliconius_Master.csv\", index = False)"
1623
+ ]
1624
+ },
1625
+ {
1626
+ "cell_type": "markdown",
1627
+ "metadata": {},
1628
+ "source": [
1629
+ "## Make Dorsal Subset\n",
1630
+ "\n",
1631
+ "We'll now make a CSV of all dorsal images."
1632
+ ]
1633
+ },
1634
+ {
1635
+ "cell_type": "code",
1636
+ "execution_count": 30,
1637
+ "metadata": {},
1638
+ "outputs": [
1639
+ {
1640
+ "data": {
1641
+ "text/plain": [
1642
+ "CAMID 11752\n",
1643
+ "X 17759\n",
1644
+ "Image_name 17759\n",
1645
+ "View 4\n",
1646
+ "zenodo_name 31\n",
1647
+ "zenodo_link 29\n",
1648
+ "Sequence 10689\n",
1649
+ "Taxonomic_Name 362\n",
1650
+ "Locality 641\n",
1651
+ "Sample_accession 1552\n",
1652
+ "Collected_by 12\n",
1653
+ "Other_ID 2890\n",
1654
+ "Date 788\n",
1655
+ "Dataset 7\n",
1656
+ "Store 137\n",
1657
+ "Brood 215\n",
1658
+ "Death_Date 61\n",
1659
+ "Cross_Type 30\n",
1660
+ "Stage 1\n",
1661
+ "Sex 3\n",
1662
+ "Unit_Type 4\n",
1663
+ "file_type 3\n",
1664
+ "record_number 29\n",
1665
+ "species 245\n",
1666
+ "subspecies 152\n",
1667
+ "genus 94\n",
1668
+ "file_url 17759\n",
1669
+ "hybrid_stat 2\n",
1670
+ "filename 17759\n",
1671
+ "filepath 17759\n",
1672
+ "md5 17759\n",
1673
+ "dtype: int64"
1674
+ ]
1675
+ },
1676
+ "execution_count": 30,
1677
+ "metadata": {},
1678
+ "output_type": "execute_result"
1679
+ }
1680
+ ],
1681
+ "source": [
1682
+ "dorsal_views = [view for view in list(master.View.dropna().unique()) if \"dorsal\" in view]\n",
1683
+ "\n",
1684
+ "dorsal_master = master.loc[master[\"View\"].isin(dorsal_views)].copy()\n",
1685
+ "dorsal_master.nunique()"
1686
+ ]
1687
+ },
1688
+ {
1689
+ "cell_type": "code",
1690
+ "execution_count": 31,
1691
+ "metadata": {},
1692
+ "outputs": [
1693
+ {
1694
+ "data": {
1695
+ "text/plain": [
1696
+ "CAM_dupe\n",
1697
+ "False 15460\n",
1698
+ "True 2299\n",
1699
+ "Name: count, dtype: int64"
1700
+ ]
1701
+ },
1702
+ "execution_count": 31,
1703
+ "metadata": {},
1704
+ "output_type": "execute_result"
1705
+ }
1706
+ ],
1707
+ "source": [
1708
+ "dorsal_master[\"CAM_dupe\"] = dorsal_master.duplicated([\"CAMID\", \"file_type\"], keep = False)\n",
1709
+ "dorsal_master.CAM_dupe.value_counts()"
1710
+ ]
1711
+ },
1712
+ {
1713
+ "cell_type": "code",
1714
+ "execution_count": 32,
1715
+ "metadata": {},
1716
+ "outputs": [
1717
+ {
1718
+ "data": {
1719
+ "text/plain": [
1720
+ "CAM_dupe\n",
1721
+ "False 15442\n",
1722
+ "True 1793\n",
1723
+ "single-wing 506\n",
1724
+ "both-wings 18\n",
1725
+ "Name: count, dtype: int64"
1726
+ ]
1727
+ },
1728
+ "execution_count": 32,
1729
+ "metadata": {},
1730
+ "output_type": "execute_result"
1731
+ }
1732
+ ],
1733
+ "source": [
1734
+ "# Adding label for both wings alters counts, as in, some only have the double wing image\n",
1735
+ "dorsal_master.loc[dorsal_master[\"View\"].isin([\"forewing dorsal\", \"hindwing dorsal\"]), \"CAM_dupe\"] = \"single-wing\"\n",
1736
+ "dorsal_master.loc[dorsal_master[\"View\"] == \"dorsal and ventral\", \"CAM_dupe\"] = \"both-wings\"\n",
1737
+ "dorsal_master.CAM_dupe.value_counts()"
1738
+ ]
1739
+ },
1740
+ {
1741
+ "cell_type": "code",
1742
+ "execution_count": 33,
1743
+ "metadata": {},
1744
+ "outputs": [
1745
+ {
1746
+ "name": "stdout",
1747
+ "output_type": "stream",
1748
+ "text": [
1749
+ "881\n",
1750
+ "11452\n"
1751
+ ]
1752
+ },
1753
+ {
1754
+ "data": {
1755
+ "text/plain": [
1756
+ "13"
1757
+ ]
1758
+ },
1759
+ "execution_count": 33,
1760
+ "metadata": {},
1761
+ "output_type": "execute_result"
1762
+ }
1763
+ ],
1764
+ "source": [
1765
+ "print(dorsal_master.loc[dorsal_master[\"CAM_dupe\"] == True, \"CAMID\"].nunique())\n",
1766
+ "print(dorsal_master.loc[dorsal_master[\"CAM_dupe\"] == False, \"CAMID\"].nunique())\n",
1767
+ "dorsal_master.loc[dorsal_master[\"CAM_dupe\"] == True, \"record_number\"].nunique()"
1768
+ ]
1769
+ },
1770
+ {
1771
+ "cell_type": "code",
1772
+ "execution_count": 34,
1773
+ "metadata": {},
1774
+ "outputs": [
1775
+ {
1776
+ "data": {
1777
+ "text/plain": [
1778
+ "file_type\n",
1779
+ "raw 253\n",
1780
+ "jpg 253\n",
1781
+ "Name: count, dtype: int64"
1782
+ ]
1783
+ },
1784
+ "execution_count": 34,
1785
+ "metadata": {},
1786
+ "output_type": "execute_result"
1787
+ }
1788
+ ],
1789
+ "source": [
1790
+ "dorsal_master.loc[dorsal_master[\"CAM_dupe\"] == \"single-wing\", \"file_type\"].value_counts()"
1791
+ ]
1792
+ },
1793
+ {
1794
+ "cell_type": "code",
1795
+ "execution_count": 35,
1796
+ "metadata": {},
1797
+ "outputs": [
1798
+ {
1799
+ "data": {
1800
+ "text/plain": [
1801
+ "file_type\n",
1802
+ "jpg 17\n",
1803
+ "tif 1\n",
1804
+ "Name: count, dtype: int64"
1805
+ ]
1806
+ },
1807
+ "execution_count": 35,
1808
+ "metadata": {},
1809
+ "output_type": "execute_result"
1810
+ }
1811
+ ],
1812
+ "source": [
1813
+ "dorsal_master.loc[dorsal_master[\"CAM_dupe\"] == \"both-wings\", \"file_type\"].value_counts()"
1814
+ ]
1815
+ },
1816
+ {
1817
+ "cell_type": "code",
1818
+ "execution_count": 36,
1819
+ "metadata": {},
1820
+ "outputs": [
1821
+ {
1822
+ "data": {
1823
+ "text/plain": [
1824
+ "file_type\n",
1825
+ "jpg 1775\n",
1826
+ "tif 16\n",
1827
+ "raw 2\n",
1828
+ "Name: count, dtype: int64"
1829
+ ]
1830
+ },
1831
+ "execution_count": 36,
1832
+ "metadata": {},
1833
+ "output_type": "execute_result"
1834
+ }
1835
+ ],
1836
+ "source": [
1837
+ "dorsal_master.loc[dorsal_master[\"CAM_dupe\"] == True, \"file_type\"].value_counts()"
1838
+ ]
1839
+ },
1840
+ {
1841
+ "cell_type": "code",
1842
+ "execution_count": 37,
1843
+ "metadata": {},
1844
+ "outputs": [
1845
+ {
1846
+ "data": {
1847
+ "text/plain": [
1848
+ "file_type\n",
1849
+ "jpg 10706\n",
1850
+ "raw 4718\n",
1851
+ "tif 18\n",
1852
+ "Name: count, dtype: int64"
1853
+ ]
1854
+ },
1855
+ "execution_count": 37,
1856
+ "metadata": {},
1857
+ "output_type": "execute_result"
1858
+ }
1859
+ ],
1860
+ "source": [
1861
+ "dorsal_master.loc[dorsal_master[\"CAM_dupe\"] == False, \"file_type\"].value_counts()"
1862
+ ]
1863
+ },
1864
+ {
1865
+ "cell_type": "code",
1866
+ "execution_count": 38,
1867
+ "metadata": {},
1868
+ "outputs": [
1869
+ {
1870
+ "data": {
1871
+ "text/plain": [
1872
+ "False 10723\n",
1873
+ "True 2028\n",
1874
+ "Name: count, dtype: int64"
1875
+ ]
1876
+ },
1877
+ "execution_count": 38,
1878
+ "metadata": {},
1879
+ "output_type": "execute_result"
1880
+ }
1881
+ ],
1882
+ "source": [
1883
+ "dorsal_master.loc[dorsal_master[\"file_type\"] == \"jpg\"].duplicated(subset = \"CAMID\", keep = False).value_counts()"
1884
+ ]
1885
+ },
1886
+ {
1887
+ "cell_type": "code",
1888
+ "execution_count": 39,
1889
+ "metadata": {},
1890
+ "outputs": [
1891
+ {
1892
+ "data": {
1893
+ "text/plain": [
1894
+ "False 4719\n",
1895
+ "True 254\n",
1896
+ "Name: count, dtype: int64"
1897
+ ]
1898
+ },
1899
+ "execution_count": 39,
1900
+ "metadata": {},
1901
+ "output_type": "execute_result"
1902
+ }
1903
+ ],
1904
+ "source": [
1905
+ "dorsal_master.loc[dorsal_master[\"file_type\"] == \"raw\"].duplicated(subset = \"CAMID\", keep = False).value_counts()"
1906
+ ]
1907
+ },
1908
+ {
1909
+ "cell_type": "markdown",
1910
+ "metadata": {},
1911
+ "source": [
1912
+ "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",
1913
+ "\n",
1914
+ "### Save Dorsal Subset to CSV"
1915
+ ]
1916
+ },
1917
+ {
1918
+ "cell_type": "code",
1919
+ "execution_count": 40,
1920
+ "metadata": {},
1921
+ "outputs": [],
1922
+ "source": [
1923
+ "dorsal_master.to_csv(\"../Jiggins_Zenodo_dorsal_Img_Master.csv\", index = False)"
1924
+ ]
1925
+ },
1926
+ {
1927
+ "cell_type": "code",
1928
+ "execution_count": null,
1929
+ "metadata": {},
1930
+ "outputs": [],
1931
+ "source": []
1932
+ }
1933
+ ],
1934
+ "metadata": {
1935
+ "kernelspec": {
1936
+ "display_name": "std",
1937
+ "language": "python",
1938
+ "name": "python3"
1939
+ },
1940
+ "language_info": {
1941
+ "codemirror_mode": {
1942
+ "name": "ipython",
1943
+ "version": 3
1944
+ },
1945
+ "file_extension": ".py",
1946
+ "mimetype": "text/x-python",
1947
+ "name": "python",
1948
+ "nbconvert_exporter": "python",
1949
+ "pygments_lexer": "ipython3",
1950
+ "version": "3.11.3"
1951
+ }
1952
+ },
1953
+ "nbformat": 4,
1954
+ "nbformat_minor": 2
1955
+ }