egrace479 commited on
Commit
2b1d4ae
·
1 Parent(s): 219f8f3

Generated CSV for testing check_taxa script (auto-check for filled-in taxonomic hierarchy).

Browse files
README.md CHANGED
@@ -12,6 +12,7 @@ associated taxa information for the image.
12
  - `avg_std_byClass.csv`: average and standard distribution of images given by class. This is for both all
13
  images, and images that have labels. Note that kingdoms have not been merged and no standardization has
14
  been performed on the taxonomic hierarchy prior to creation of this file.
 
15
 
16
  ### Notebooks
17
 
@@ -22,6 +23,7 @@ The `notebooks` folder contains
22
  visualizations in visuals and some histograms. The treemaps produced in the notebook are interactive.
23
  - `ToL_EDA.ipynb`: more full EDA of TreeOfLife10M dataset. Explores the labeling inconsistencies for
24
  direction of standardization efforts.
 
25
 
26
  Note: run `pip install -r requirements.txt` before starting the notebooks.
27
 
 
12
  - `avg_std_byClass.csv`: average and standard distribution of images given by class. This is for both all
13
  images, and images that have labels. Note that kingdoms have not been merged and no standardization has
14
  been performed on the taxonomic hierarchy prior to creation of this file.
15
+ - `tol_hierarchy_test.csv`: Subset of `v1-dev-names.csv` for testing the [`check_taxa` script](https://github.com/Imageomics/open_clip/tree/main/scripts/evobio10m) to ensure the hierarchy is properly filled in after data generation.
16
 
17
  ### Notebooks
18
 
 
23
  visualizations in visuals and some histograms. The treemaps produced in the notebook are interactive.
24
  - `ToL_EDA.ipynb`: more full EDA of TreeOfLife10M dataset. Explores the labeling inconsistencies for
25
  direction of standardization efforts.
26
+ - `missing_taxa_testGen.ipynb`: generates `tol_hierarchy_test.csv` to test `check_taxa` script. Also observes species labeled as `(unidentified)` in EOL data.
27
 
28
  Note: run `pip install -r requirements.txt` before starting the notebooks.
29
 
data/tol_hierarchy_test.csv ADDED
The diff for this file is too large to render. See raw diff
 
notebooks/missing_taxa_testGen.ipynb ADDED
@@ -0,0 +1,897 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": "code",
14
+ "execution_count": 2,
15
+ "metadata": {},
16
+ "outputs": [
17
+ {
18
+ "name": "stderr",
19
+ "output_type": "stream",
20
+ "text": [
21
+ "/var/folders/nv/f0fq1p1n1_3b11x579py_0q80000gq/T/ipykernel_70089/3694103411.py:1: DtypeWarning: Columns (4,5,6) have mixed types. Specify dtype option on import or set low_memory=False.\n",
22
+ " df = pd.read_csv(\"../data/v1-dev-names.csv\")\n"
23
+ ]
24
+ }
25
+ ],
26
+ "source": [
27
+ "df = pd.read_csv(\"../data/v1-dev-names.csv\")"
28
+ ]
29
+ },
30
+ {
31
+ "cell_type": "code",
32
+ "execution_count": 3,
33
+ "metadata": {},
34
+ "outputs": [],
35
+ "source": [
36
+ "# Add data_source column for easier slicing\n",
37
+ "df.loc[df['inat21_filename'].notna(), 'data_source'] = 'iNat21'\n",
38
+ "df.loc[df['bioscan_filename'].notna(), 'data_source'] = 'BIOSCAN'\n",
39
+ "df.loc[df['eol_content_id'].notna(), 'data_source'] = 'EOL'"
40
+ ]
41
+ },
42
+ {
43
+ "cell_type": "markdown",
44
+ "metadata": {},
45
+ "source": [
46
+ "Let's get the data that's not in iNat for testing since we know all issues found were in BIOSCAN and EOL (plus the combination of the two for more than 3 kingdoms)."
47
+ ]
48
+ },
49
+ {
50
+ "cell_type": "code",
51
+ "execution_count": 4,
52
+ "metadata": {},
53
+ "outputs": [
54
+ {
55
+ "name": "stdout",
56
+ "output_type": "stream",
57
+ "text": [
58
+ "<class 'pandas.core.frame.DataFrame'>\n",
59
+ "Index: 1000 entries, 7986767 to 8659983\n",
60
+ "Data columns (total 17 columns):\n",
61
+ " # Column Non-Null Count Dtype \n",
62
+ "--- ------ -------------- ----- \n",
63
+ " 0 treeoflife_id 1000 non-null object \n",
64
+ " 1 eol_content_id 655 non-null float64\n",
65
+ " 2 eol_page_id 655 non-null float64\n",
66
+ " 3 bioscan_part 93 non-null float64\n",
67
+ " 4 bioscan_filename 93 non-null object \n",
68
+ " 5 inat21_filename 252 non-null object \n",
69
+ " 6 inat21_cls_name 252 non-null object \n",
70
+ " 7 inat21_cls_num 252 non-null float64\n",
71
+ " 8 kingdom 728 non-null object \n",
72
+ " 9 phylum 728 non-null object \n",
73
+ " 10 class 628 non-null object \n",
74
+ " 11 order 726 non-null object \n",
75
+ " 12 family 721 non-null object \n",
76
+ " 13 genus 779 non-null object \n",
77
+ " 14 species 685 non-null object \n",
78
+ " 15 common 1000 non-null object \n",
79
+ " 16 data_source 1000 non-null object \n",
80
+ "dtypes: float64(4), object(13)\n",
81
+ "memory usage: 140.6+ KB\n"
82
+ ]
83
+ }
84
+ ],
85
+ "source": [
86
+ "df_small = df.loc[df.data_source != 'iNat'].sample(1000)\n",
87
+ "df_small.info(show_counts = True)"
88
+ ]
89
+ },
90
+ {
91
+ "cell_type": "code",
92
+ "execution_count": 5,
93
+ "metadata": {},
94
+ "outputs": [
95
+ {
96
+ "name": "stdout",
97
+ "output_type": "stream",
98
+ "text": [
99
+ "<class 'pandas.core.frame.DataFrame'>\n",
100
+ "Index: 779 entries, 7986767 to 8659983\n",
101
+ "Data columns (total 17 columns):\n",
102
+ " # Column Non-Null Count Dtype \n",
103
+ "--- ------ -------------- ----- \n",
104
+ " 0 treeoflife_id 779 non-null object \n",
105
+ " 1 eol_content_id 506 non-null float64\n",
106
+ " 2 eol_page_id 506 non-null float64\n",
107
+ " 3 bioscan_part 21 non-null float64\n",
108
+ " 4 bioscan_filename 21 non-null object \n",
109
+ " 5 inat21_filename 252 non-null object \n",
110
+ " 6 inat21_cls_name 252 non-null object \n",
111
+ " 7 inat21_cls_num 252 non-null float64\n",
112
+ " 8 kingdom 647 non-null object \n",
113
+ " 9 phylum 647 non-null object \n",
114
+ " 10 class 549 non-null object \n",
115
+ " 11 order 645 non-null object \n",
116
+ " 12 family 643 non-null object \n",
117
+ " 13 genus 779 non-null object \n",
118
+ " 14 species 684 non-null object \n",
119
+ " 15 common 779 non-null object \n",
120
+ " 16 data_source 779 non-null object \n",
121
+ "dtypes: float64(4), object(13)\n",
122
+ "memory usage: 109.5+ KB\n"
123
+ ]
124
+ }
125
+ ],
126
+ "source": [
127
+ "df_small.loc[df_small.genus.notna()].info(show_counts = True)"
128
+ ]
129
+ },
130
+ {
131
+ "cell_type": "markdown",
132
+ "metadata": {},
133
+ "source": [
134
+ "We have less `species` indicated than `genus`, so let's get some samples of null `genus` with non-null `species`."
135
+ ]
136
+ },
137
+ {
138
+ "cell_type": "code",
139
+ "execution_count": 6,
140
+ "metadata": {},
141
+ "outputs": [
142
+ {
143
+ "name": "stdout",
144
+ "output_type": "stream",
145
+ "text": [
146
+ "<class 'pandas.core.frame.DataFrame'>\n",
147
+ "Index: 2375692 entries, 4 to 10436517\n",
148
+ "Data columns (total 17 columns):\n",
149
+ " # Column Non-Null Count Dtype \n",
150
+ "--- ------ -------------- ----- \n",
151
+ " 0 treeoflife_id 2375692 non-null object \n",
152
+ " 1 eol_content_id 1501528 non-null float64\n",
153
+ " 2 eol_page_id 1501528 non-null float64\n",
154
+ " 3 bioscan_part 874164 non-null float64\n",
155
+ " 4 bioscan_filename 874164 non-null object \n",
156
+ " 5 inat21_filename 0 non-null object \n",
157
+ " 6 inat21_cls_name 0 non-null object \n",
158
+ " 7 inat21_cls_num 0 non-null float64\n",
159
+ " 8 kingdom 974474 non-null object \n",
160
+ " 9 phylum 974438 non-null object \n",
161
+ " 10 class 965636 non-null object \n",
162
+ " 11 order 974301 non-null object \n",
163
+ " 12 family 956107 non-null object \n",
164
+ " 13 genus 0 non-null object \n",
165
+ " 14 species 253 non-null object \n",
166
+ " 15 common 2375692 non-null object \n",
167
+ " 16 data_source 2375692 non-null object \n",
168
+ "dtypes: float64(4), object(13)\n",
169
+ "memory usage: 326.3+ MB\n"
170
+ ]
171
+ }
172
+ ],
173
+ "source": [
174
+ "bio_eol = df.loc[df.data_source != 'iNat']\n",
175
+ "null_genus = bio_eol.loc[bio_eol.genus.isna()]\n",
176
+ "null_genus.info(show_counts = True)"
177
+ ]
178
+ },
179
+ {
180
+ "cell_type": "markdown",
181
+ "metadata": {},
182
+ "source": [
183
+ "Add a sample of these to our test dataset."
184
+ ]
185
+ },
186
+ {
187
+ "cell_type": "code",
188
+ "execution_count": 7,
189
+ "metadata": {},
190
+ "outputs": [],
191
+ "source": [
192
+ "df_test = pd.concat([df_small, null_genus.loc[null_genus.species.notna()].sample(100)])"
193
+ ]
194
+ },
195
+ {
196
+ "cell_type": "markdown",
197
+ "metadata": {},
198
+ "source": [
199
+ "We also want to check for scientific name in the `species` column (i.e., genus species). This can cause inaccuracies in our counts, impact `common` column, and cause inconsistencies in the text training. "
200
+ ]
201
+ },
202
+ {
203
+ "cell_type": "code",
204
+ "execution_count": 9,
205
+ "metadata": {},
206
+ "outputs": [
207
+ {
208
+ "data": {
209
+ "text/plain": [
210
+ "10002735 caprata\n",
211
+ "5642543 paradidyma malaise2555\n",
212
+ "5208448 lapponicum\n",
213
+ "1762361 irrorata\n",
214
+ "556451 perplexus\n",
215
+ "3296890 (unidentified)\n",
216
+ "2533982 senegalia senegal\n",
217
+ "9869450 punctinalis\n",
218
+ "4220628 coriaria welw. ex oliv.\n",
219
+ "7126430 micrantha\n",
220
+ "Name: species, dtype: object"
221
+ ]
222
+ },
223
+ "execution_count": 9,
224
+ "metadata": {},
225
+ "output_type": "execute_result"
226
+ }
227
+ ],
228
+ "source": [
229
+ "df_test.loc[df_test['species'].notna(), 'species'].sample(10)"
230
+ ]
231
+ },
232
+ {
233
+ "cell_type": "code",
234
+ "execution_count": 10,
235
+ "metadata": {},
236
+ "outputs": [
237
+ {
238
+ "name": "stdout",
239
+ "output_type": "stream",
240
+ "text": [
241
+ "161\n"
242
+ ]
243
+ }
244
+ ],
245
+ "source": [
246
+ "count = 0\n",
247
+ "for species in list(df_test.loc[df_test['species'].notna(), 'species']):\n",
248
+ " if len(species.split(\" \")) > 1:\n",
249
+ " count += 1\n",
250
+ "print(count)"
251
+ ]
252
+ },
253
+ {
254
+ "cell_type": "markdown",
255
+ "metadata": {},
256
+ "source": [
257
+ "Good, these are represented too, so we can save this file."
258
+ ]
259
+ },
260
+ {
261
+ "cell_type": "code",
262
+ "execution_count": 11,
263
+ "metadata": {},
264
+ "outputs": [],
265
+ "source": [
266
+ "df_test.to_csv(\"../data/tol_hierarchy_test.csv\", index = False)"
267
+ ]
268
+ },
269
+ {
270
+ "cell_type": "markdown",
271
+ "metadata": {},
272
+ "source": [
273
+ "There is also apparently a species which is labeled as `(unidentified)`. Let's check where that is and if there's more than one (in our full dataset)."
274
+ ]
275
+ },
276
+ {
277
+ "cell_type": "code",
278
+ "execution_count": 12,
279
+ "metadata": {},
280
+ "outputs": [
281
+ {
282
+ "name": "stdout",
283
+ "output_type": "stream",
284
+ "text": [
285
+ "<class 'pandas.core.frame.DataFrame'>\n",
286
+ "Index: 2470 entries, 1236 to 10435982\n",
287
+ "Data columns (total 17 columns):\n",
288
+ " # Column Non-Null Count Dtype \n",
289
+ "--- ------ -------------- ----- \n",
290
+ " 0 treeoflife_id 2470 non-null object \n",
291
+ " 1 eol_content_id 2470 non-null float64\n",
292
+ " 2 eol_page_id 2470 non-null float64\n",
293
+ " 3 bioscan_part 0 non-null float64\n",
294
+ " 4 bioscan_filename 0 non-null object \n",
295
+ " 5 inat21_filename 0 non-null object \n",
296
+ " 6 inat21_cls_name 0 non-null object \n",
297
+ " 7 inat21_cls_num 0 non-null float64\n",
298
+ " 8 kingdom 0 non-null object \n",
299
+ " 9 phylum 0 non-null object \n",
300
+ " 10 class 0 non-null object \n",
301
+ " 11 order 0 non-null object \n",
302
+ " 12 family 0 non-null object \n",
303
+ " 13 genus 2470 non-null object \n",
304
+ " 14 species 2470 non-null object \n",
305
+ " 15 common 2470 non-null object \n",
306
+ " 16 data_source 2470 non-null object \n",
307
+ "dtypes: float64(4), object(13)\n",
308
+ "memory usage: 347.3+ KB\n"
309
+ ]
310
+ }
311
+ ],
312
+ "source": [
313
+ "df.loc[df.species == \"(unidentified)\"].info(show_counts = True)"
314
+ ]
315
+ },
316
+ {
317
+ "cell_type": "markdown",
318
+ "metadata": {},
319
+ "source": [
320
+ "Okay, there are a LOT of them. All in EOL. They do seem to have `genus` label, but nothing else, so let's look at a subset of these."
321
+ ]
322
+ },
323
+ {
324
+ "cell_type": "code",
325
+ "execution_count": 13,
326
+ "metadata": {},
327
+ "outputs": [
328
+ {
329
+ "data": {
330
+ "text/html": [
331
+ "<div>\n",
332
+ "<style scoped>\n",
333
+ " .dataframe tbody tr th:only-of-type {\n",
334
+ " vertical-align: middle;\n",
335
+ " }\n",
336
+ "\n",
337
+ " .dataframe tbody tr th {\n",
338
+ " vertical-align: top;\n",
339
+ " }\n",
340
+ "\n",
341
+ " .dataframe thead th {\n",
342
+ " text-align: right;\n",
343
+ " }\n",
344
+ "</style>\n",
345
+ "<table border=\"1\" class=\"dataframe\">\n",
346
+ " <thead>\n",
347
+ " <tr style=\"text-align: right;\">\n",
348
+ " <th></th>\n",
349
+ " <th>treeoflife_id</th>\n",
350
+ " <th>eol_content_id</th>\n",
351
+ " <th>eol_page_id</th>\n",
352
+ " <th>bioscan_part</th>\n",
353
+ " <th>bioscan_filename</th>\n",
354
+ " <th>inat21_filename</th>\n",
355
+ " <th>inat21_cls_name</th>\n",
356
+ " <th>inat21_cls_num</th>\n",
357
+ " <th>kingdom</th>\n",
358
+ " <th>phylum</th>\n",
359
+ " <th>class</th>\n",
360
+ " <th>order</th>\n",
361
+ " <th>family</th>\n",
362
+ " <th>genus</th>\n",
363
+ " <th>species</th>\n",
364
+ " <th>common</th>\n",
365
+ " <th>data_source</th>\n",
366
+ " </tr>\n",
367
+ " </thead>\n",
368
+ " <tbody>\n",
369
+ " <tr>\n",
370
+ " <th>10369023</th>\n",
371
+ " <td>b98a7e24-4848-4134-bad3-eedfce536fab</td>\n",
372
+ " <td>14844649.0</td>\n",
373
+ " <td>64430448.0</td>\n",
374
+ " <td>NaN</td>\n",
375
+ " <td>NaN</td>\n",
376
+ " <td>NaN</td>\n",
377
+ " <td>NaN</td>\n",
378
+ " <td>NaN</td>\n",
379
+ " <td>NaN</td>\n",
380
+ " <td>NaN</td>\n",
381
+ " <td>NaN</td>\n",
382
+ " <td>NaN</td>\n",
383
+ " <td>NaN</td>\n",
384
+ " <td>Cis</td>\n",
385
+ " <td>(unidentified)</td>\n",
386
+ " <td>Cis (unidentified)</td>\n",
387
+ " <td>EOL</td>\n",
388
+ " </tr>\n",
389
+ " <tr>\n",
390
+ " <th>7268955</th>\n",
391
+ " <td>228a79c2-a482-4cd4-9a56-a000c4780b68</td>\n",
392
+ " <td>14842294.0</td>\n",
393
+ " <td>64429582.0</td>\n",
394
+ " <td>NaN</td>\n",
395
+ " <td>NaN</td>\n",
396
+ " <td>NaN</td>\n",
397
+ " <td>NaN</td>\n",
398
+ " <td>NaN</td>\n",
399
+ " <td>NaN</td>\n",
400
+ " <td>NaN</td>\n",
401
+ " <td>NaN</td>\n",
402
+ " <td>NaN</td>\n",
403
+ " <td>NaN</td>\n",
404
+ " <td>Sarcophaga</td>\n",
405
+ " <td>(unidentified)</td>\n",
406
+ " <td>Sarcophaga (unidentified)</td>\n",
407
+ " <td>EOL</td>\n",
408
+ " </tr>\n",
409
+ " <tr>\n",
410
+ " <th>1549482</th>\n",
411
+ " <td>f81c2ce7-b2dc-4d13-8991-5a20907610bb</td>\n",
412
+ " <td>14842814.0</td>\n",
413
+ " <td>64432966.0</td>\n",
414
+ " <td>NaN</td>\n",
415
+ " <td>NaN</td>\n",
416
+ " <td>NaN</td>\n",
417
+ " <td>NaN</td>\n",
418
+ " <td>NaN</td>\n",
419
+ " <td>NaN</td>\n",
420
+ " <td>NaN</td>\n",
421
+ " <td>NaN</td>\n",
422
+ " <td>NaN</td>\n",
423
+ " <td>NaN</td>\n",
424
+ " <td>Chromista</td>\n",
425
+ " <td>(unidentified)</td>\n",
426
+ " <td>Chromista (unidentified)</td>\n",
427
+ " <td>EOL</td>\n",
428
+ " </tr>\n",
429
+ " <tr>\n",
430
+ " <th>6552233</th>\n",
431
+ " <td>724ac709-31ee-41df-b1b2-a4fbcda8a867</td>\n",
432
+ " <td>14845112.0</td>\n",
433
+ " <td>64430050.0</td>\n",
434
+ " <td>NaN</td>\n",
435
+ " <td>NaN</td>\n",
436
+ " <td>NaN</td>\n",
437
+ " <td>NaN</td>\n",
438
+ " <td>NaN</td>\n",
439
+ " <td>NaN</td>\n",
440
+ " <td>NaN</td>\n",
441
+ " <td>NaN</td>\n",
442
+ " <td>NaN</td>\n",
443
+ " <td>NaN</td>\n",
444
+ " <td>Myrmica</td>\n",
445
+ " <td>(unidentified)</td>\n",
446
+ " <td>Myrmica (unidentified)</td>\n",
447
+ " <td>EOL</td>\n",
448
+ " </tr>\n",
449
+ " <tr>\n",
450
+ " <th>7064292</th>\n",
451
+ " <td>079cac60-e040-4ae0-a587-d9a73b0bff65</td>\n",
452
+ " <td>14851701.0</td>\n",
453
+ " <td>64429842.0</td>\n",
454
+ " <td>NaN</td>\n",
455
+ " <td>NaN</td>\n",
456
+ " <td>NaN</td>\n",
457
+ " <td>NaN</td>\n",
458
+ " <td>NaN</td>\n",
459
+ " <td>NaN</td>\n",
460
+ " <td>NaN</td>\n",
461
+ " <td>NaN</td>\n",
462
+ " <td>NaN</td>\n",
463
+ " <td>NaN</td>\n",
464
+ " <td>Phygadeuon</td>\n",
465
+ " <td>(unidentified)</td>\n",
466
+ " <td>Phygadeuon (unidentified)</td>\n",
467
+ " <td>EOL</td>\n",
468
+ " </tr>\n",
469
+ " <tr>\n",
470
+ " <th>972647</th>\n",
471
+ " <td>01633bbe-44f9-4e8d-b4db-d2d9678906eb</td>\n",
472
+ " <td>14845039.0</td>\n",
473
+ " <td>64429476.0</td>\n",
474
+ " <td>NaN</td>\n",
475
+ " <td>NaN</td>\n",
476
+ " <td>NaN</td>\n",
477
+ " <td>NaN</td>\n",
478
+ " <td>NaN</td>\n",
479
+ " <td>NaN</td>\n",
480
+ " <td>NaN</td>\n",
481
+ " <td>NaN</td>\n",
482
+ " <td>NaN</td>\n",
483
+ " <td>NaN</td>\n",
484
+ " <td>Cheilosia</td>\n",
485
+ " <td>(unidentified)</td>\n",
486
+ " <td>Cheilosia (unidentified)</td>\n",
487
+ " <td>EOL</td>\n",
488
+ " </tr>\n",
489
+ " <tr>\n",
490
+ " <th>6605868</th>\n",
491
+ " <td>9a4cf29a-06d5-4c1c-94dc-6f0486347755</td>\n",
492
+ " <td>14843938.0</td>\n",
493
+ " <td>64427784.0</td>\n",
494
+ " <td>NaN</td>\n",
495
+ " <td>NaN</td>\n",
496
+ " <td>NaN</td>\n",
497
+ " <td>NaN</td>\n",
498
+ " <td>NaN</td>\n",
499
+ " <td>NaN</td>\n",
500
+ " <td>NaN</td>\n",
501
+ " <td>NaN</td>\n",
502
+ " <td>NaN</td>\n",
503
+ " <td>NaN</td>\n",
504
+ " <td>Entoloma</td>\n",
505
+ " <td>(unidentified)</td>\n",
506
+ " <td>Entoloma (unidentified)</td>\n",
507
+ " <td>EOL</td>\n",
508
+ " </tr>\n",
509
+ " <tr>\n",
510
+ " <th>1138925</th>\n",
511
+ " <td>2b4c8067-3595-4d87-897e-9d3600e3a86f</td>\n",
512
+ " <td>14842566.0</td>\n",
513
+ " <td>64430882.0</td>\n",
514
+ " <td>NaN</td>\n",
515
+ " <td>NaN</td>\n",
516
+ " <td>NaN</td>\n",
517
+ " <td>NaN</td>\n",
518
+ " <td>NaN</td>\n",
519
+ " <td>NaN</td>\n",
520
+ " <td>NaN</td>\n",
521
+ " <td>NaN</td>\n",
522
+ " <td>NaN</td>\n",
523
+ " <td>NaN</td>\n",
524
+ " <td>Hydropsyche</td>\n",
525
+ " <td>(unidentified)</td>\n",
526
+ " <td>Hydropsyche (unidentified)</td>\n",
527
+ " <td>EOL</td>\n",
528
+ " </tr>\n",
529
+ " <tr>\n",
530
+ " <th>2018314</th>\n",
531
+ " <td>2726bcc0-5c18-401a-a0a0-ad4a2cb4e302</td>\n",
532
+ " <td>14845986.0</td>\n",
533
+ " <td>64426150.0</td>\n",
534
+ " <td>NaN</td>\n",
535
+ " <td>NaN</td>\n",
536
+ " <td>NaN</td>\n",
537
+ " <td>NaN</td>\n",
538
+ " <td>NaN</td>\n",
539
+ " <td>NaN</td>\n",
540
+ " <td>NaN</td>\n",
541
+ " <td>NaN</td>\n",
542
+ " <td>NaN</td>\n",
543
+ " <td>NaN</td>\n",
544
+ " <td>Chlorophyta</td>\n",
545
+ " <td>(unidentified)</td>\n",
546
+ " <td>Chlorophyta (unidentified)</td>\n",
547
+ " <td>EOL</td>\n",
548
+ " </tr>\n",
549
+ " <tr>\n",
550
+ " <th>1675874</th>\n",
551
+ " <td>578809ee-126c-468e-a39b-2878e1dafc21</td>\n",
552
+ " <td>14845571.0</td>\n",
553
+ " <td>64431544.0</td>\n",
554
+ " <td>NaN</td>\n",
555
+ " <td>NaN</td>\n",
556
+ " <td>NaN</td>\n",
557
+ " <td>NaN</td>\n",
558
+ " <td>NaN</td>\n",
559
+ " <td>NaN</td>\n",
560
+ " <td>NaN</td>\n",
561
+ " <td>NaN</td>\n",
562
+ " <td>NaN</td>\n",
563
+ " <td>NaN</td>\n",
564
+ " <td>Porifera</td>\n",
565
+ " <td>(unidentified)</td>\n",
566
+ " <td>Porifera (unidentified)</td>\n",
567
+ " <td>EOL</td>\n",
568
+ " </tr>\n",
569
+ " </tbody>\n",
570
+ "</table>\n",
571
+ "</div>"
572
+ ],
573
+ "text/plain": [
574
+ " treeoflife_id eol_content_id eol_page_id \n",
575
+ "10369023 b98a7e24-4848-4134-bad3-eedfce536fab 14844649.0 64430448.0 \\\n",
576
+ "7268955 228a79c2-a482-4cd4-9a56-a000c4780b68 14842294.0 64429582.0 \n",
577
+ "1549482 f81c2ce7-b2dc-4d13-8991-5a20907610bb 14842814.0 64432966.0 \n",
578
+ "6552233 724ac709-31ee-41df-b1b2-a4fbcda8a867 14845112.0 64430050.0 \n",
579
+ "7064292 079cac60-e040-4ae0-a587-d9a73b0bff65 14851701.0 64429842.0 \n",
580
+ "972647 01633bbe-44f9-4e8d-b4db-d2d9678906eb 14845039.0 64429476.0 \n",
581
+ "6605868 9a4cf29a-06d5-4c1c-94dc-6f0486347755 14843938.0 64427784.0 \n",
582
+ "1138925 2b4c8067-3595-4d87-897e-9d3600e3a86f 14842566.0 64430882.0 \n",
583
+ "2018314 2726bcc0-5c18-401a-a0a0-ad4a2cb4e302 14845986.0 64426150.0 \n",
584
+ "1675874 578809ee-126c-468e-a39b-2878e1dafc21 14845571.0 64431544.0 \n",
585
+ "\n",
586
+ " bioscan_part bioscan_filename inat21_filename inat21_cls_name \n",
587
+ "10369023 NaN NaN NaN NaN \\\n",
588
+ "7268955 NaN NaN NaN NaN \n",
589
+ "1549482 NaN NaN NaN NaN \n",
590
+ "6552233 NaN NaN NaN NaN \n",
591
+ "7064292 NaN NaN NaN NaN \n",
592
+ "972647 NaN NaN NaN NaN \n",
593
+ "6605868 NaN NaN NaN NaN \n",
594
+ "1138925 NaN NaN NaN NaN \n",
595
+ "2018314 NaN NaN NaN NaN \n",
596
+ "1675874 NaN NaN NaN NaN \n",
597
+ "\n",
598
+ " inat21_cls_num kingdom phylum class order family genus \n",
599
+ "10369023 NaN NaN NaN NaN NaN NaN Cis \\\n",
600
+ "7268955 NaN NaN NaN NaN NaN NaN Sarcophaga \n",
601
+ "1549482 NaN NaN NaN NaN NaN NaN Chromista \n",
602
+ "6552233 NaN NaN NaN NaN NaN NaN Myrmica \n",
603
+ "7064292 NaN NaN NaN NaN NaN NaN Phygadeuon \n",
604
+ "972647 NaN NaN NaN NaN NaN NaN Cheilosia \n",
605
+ "6605868 NaN NaN NaN NaN NaN NaN Entoloma \n",
606
+ "1138925 NaN NaN NaN NaN NaN NaN Hydropsyche \n",
607
+ "2018314 NaN NaN NaN NaN NaN NaN Chlorophyta \n",
608
+ "1675874 NaN NaN NaN NaN NaN NaN Porifera \n",
609
+ "\n",
610
+ " species common data_source \n",
611
+ "10369023 (unidentified) Cis (unidentified) EOL \n",
612
+ "7268955 (unidentified) Sarcophaga (unidentified) EOL \n",
613
+ "1549482 (unidentified) Chromista (unidentified) EOL \n",
614
+ "6552233 (unidentified) Myrmica (unidentified) EOL \n",
615
+ "7064292 (unidentified) Phygadeuon (unidentified) EOL \n",
616
+ "972647 (unidentified) Cheilosia (unidentified) EOL \n",
617
+ "6605868 (unidentified) Entoloma (unidentified) EOL \n",
618
+ "1138925 (unidentified) Hydropsyche (unidentified) EOL \n",
619
+ "2018314 (unidentified) Chlorophyta (unidentified) EOL \n",
620
+ "1675874 (unidentified) Porifera (unidentified) EOL "
621
+ ]
622
+ },
623
+ "execution_count": 13,
624
+ "metadata": {},
625
+ "output_type": "execute_result"
626
+ }
627
+ ],
628
+ "source": [
629
+ "df.loc[df.species == \"(unidentified)\"].sample(10)"
630
+ ]
631
+ },
632
+ {
633
+ "cell_type": "markdown",
634
+ "metadata": {},
635
+ "source": [
636
+ "We need to check EOL for `(unidentified)` as we had removed `not_classified` from BIOSCAN. Probably something else to add to the `check_taxa` script."
637
+ ]
638
+ },
639
+ {
640
+ "cell_type": "markdown",
641
+ "metadata": {},
642
+ "source": [
643
+ "Now let's generate the stats we should get warnings for so that we can write a test function for this script as well.\n",
644
+ "\n",
645
+ "Truncate this to just taxa columns so only the pertinent info is printed."
646
+ ]
647
+ },
648
+ {
649
+ "cell_type": "code",
650
+ "execution_count": 14,
651
+ "metadata": {},
652
+ "outputs": [],
653
+ "source": [
654
+ "TAXA = [\"kingdom\",\n",
655
+ " \"phylum\",\n",
656
+ " \"class\",\n",
657
+ " \"order\",\n",
658
+ " \"family\",\n",
659
+ " \"genus\",\n",
660
+ " \"species\"\n",
661
+ " ]"
662
+ ]
663
+ },
664
+ {
665
+ "cell_type": "code",
666
+ "execution_count": 15,
667
+ "metadata": {},
668
+ "outputs": [],
669
+ "source": [
670
+ "df_test_taxa = df_test[TAXA]"
671
+ ]
672
+ },
673
+ {
674
+ "cell_type": "code",
675
+ "execution_count": 16,
676
+ "metadata": {},
677
+ "outputs": [
678
+ {
679
+ "name": "stdout",
680
+ "output_type": "stream",
681
+ "text": [
682
+ "<class 'pandas.core.frame.DataFrame'>\n",
683
+ "Index: 779 entries, 7986767 to 8659983\n",
684
+ "Data columns (total 7 columns):\n",
685
+ " # Column Non-Null Count Dtype \n",
686
+ "--- ------ -------------- ----- \n",
687
+ " 0 kingdom 647 non-null object\n",
688
+ " 1 phylum 647 non-null object\n",
689
+ " 2 class 549 non-null object\n",
690
+ " 3 order 645 non-null object\n",
691
+ " 4 family 643 non-null object\n",
692
+ " 5 genus 779 non-null object\n",
693
+ " 6 species 684 non-null object\n",
694
+ "dtypes: object(7)\n",
695
+ "memory usage: 48.7+ KB\n"
696
+ ]
697
+ }
698
+ ],
699
+ "source": [
700
+ "df_test_taxa.loc[df_test_taxa.genus.notna()].info(show_counts = True)"
701
+ ]
702
+ },
703
+ {
704
+ "cell_type": "markdown",
705
+ "metadata": {},
706
+ "source": [
707
+ "We should have\n",
708
+ " - 132 missing `kingdom` and `phylum`\n",
709
+ " - 230 missing `class`\n",
710
+ " - 134 missing `family`"
711
+ ]
712
+ },
713
+ {
714
+ "cell_type": "code",
715
+ "execution_count": 19,
716
+ "metadata": {},
717
+ "outputs": [
718
+ {
719
+ "data": {
720
+ "text/plain": [
721
+ "101"
722
+ ]
723
+ },
724
+ "execution_count": 19,
725
+ "metadata": {},
726
+ "output_type": "execute_result"
727
+ }
728
+ ],
729
+ "source": [
730
+ "df_test_taxa.loc[df_test_taxa['genus'].isna(), 'species'].notna().sum()"
731
+ ]
732
+ },
733
+ {
734
+ "cell_type": "markdown",
735
+ "metadata": {},
736
+ "source": [
737
+ "101 entries for which `species` is non-null, but `genus` is missing."
738
+ ]
739
+ },
740
+ {
741
+ "cell_type": "code",
742
+ "execution_count": 20,
743
+ "metadata": {},
744
+ "outputs": [],
745
+ "source": [
746
+ "missing_genera = df_test_taxa.loc[df_test_taxa['genus'].isna()]"
747
+ ]
748
+ },
749
+ {
750
+ "cell_type": "code",
751
+ "execution_count": 21,
752
+ "metadata": {},
753
+ "outputs": [
754
+ {
755
+ "name": "stdout",
756
+ "output_type": "stream",
757
+ "text": [
758
+ "<class 'pandas.core.frame.DataFrame'>\n",
759
+ "Index: 143 entries, 4772452 to 3877527\n",
760
+ "Data columns (total 7 columns):\n",
761
+ " # Column Non-Null Count Dtype \n",
762
+ "--- ------ -------------- ----- \n",
763
+ " 0 kingdom 3 non-null object\n",
764
+ " 1 phylum 3 non-null object\n",
765
+ " 2 class 3 non-null object\n",
766
+ " 3 order 3 non-null object\n",
767
+ " 4 family 0 non-null object\n",
768
+ " 5 genus 0 non-null object\n",
769
+ " 6 species 0 non-null object\n",
770
+ "dtypes: object(7)\n",
771
+ "memory usage: 8.9+ KB\n"
772
+ ]
773
+ }
774
+ ],
775
+ "source": [
776
+ "missing_genera.loc[missing_genera.family.isna()].info(show_counts = True)"
777
+ ]
778
+ },
779
+ {
780
+ "cell_type": "markdown",
781
+ "metadata": {},
782
+ "source": [
783
+ "Only 3 instances where `family` is null and higher order taxa are not."
784
+ ]
785
+ },
786
+ {
787
+ "cell_type": "code",
788
+ "execution_count": 22,
789
+ "metadata": {},
790
+ "outputs": [
791
+ {
792
+ "name": "stdout",
793
+ "output_type": "stream",
794
+ "text": [
795
+ "<class 'pandas.core.frame.DataFrame'>\n",
796
+ "Index: 178 entries, 4943756 to 1467368\n",
797
+ "Data columns (total 7 columns):\n",
798
+ " # Column Non-Null Count Dtype \n",
799
+ "--- ------ -------------- ----- \n",
800
+ " 0 kingdom 178 non-null object\n",
801
+ " 1 phylum 178 non-null object\n",
802
+ " 2 class 141 non-null object\n",
803
+ " 3 order 178 non-null object\n",
804
+ " 4 family 178 non-null object\n",
805
+ " 5 genus 0 non-null object\n",
806
+ " 6 species 101 non-null object\n",
807
+ "dtypes: object(7)\n",
808
+ "memory usage: 11.1+ KB\n"
809
+ ]
810
+ }
811
+ ],
812
+ "source": [
813
+ "missing_genera.loc[missing_genera.family.notna()].info(show_counts = True)"
814
+ ]
815
+ },
816
+ {
817
+ "cell_type": "markdown",
818
+ "metadata": {},
819
+ "source": [
820
+ "For `family`, there should be a warning that 37 `class` values are not indicated."
821
+ ]
822
+ },
823
+ {
824
+ "cell_type": "markdown",
825
+ "metadata": {},
826
+ "source": [
827
+ "We do want to check if there are cases of null genus with labeled species and other taxa."
828
+ ]
829
+ },
830
+ {
831
+ "cell_type": "code",
832
+ "execution_count": 23,
833
+ "metadata": {},
834
+ "outputs": [
835
+ {
836
+ "name": "stdout",
837
+ "output_type": "stream",
838
+ "text": [
839
+ "<class 'pandas.core.frame.DataFrame'>\n",
840
+ "Index: 101 entries, 10434700 to 1467368\n",
841
+ "Data columns (total 7 columns):\n",
842
+ " # Column Non-Null Count Dtype \n",
843
+ "--- ------ -------------- ----- \n",
844
+ " 0 kingdom 101 non-null object\n",
845
+ " 1 phylum 101 non-null object\n",
846
+ " 2 class 65 non-null object\n",
847
+ " 3 order 101 non-null object\n",
848
+ " 4 family 101 non-null object\n",
849
+ " 5 genus 0 non-null object\n",
850
+ " 6 species 101 non-null object\n",
851
+ "dtypes: object(7)\n",
852
+ "memory usage: 6.3+ KB\n"
853
+ ]
854
+ }
855
+ ],
856
+ "source": [
857
+ "missing_genera.loc[missing_genera.species.notna()].info(show_counts = True)"
858
+ ]
859
+ },
860
+ {
861
+ "cell_type": "markdown",
862
+ "metadata": {},
863
+ "source": [
864
+ "We should have\n",
865
+ " - no instances of missing `kingdom`, `phylum`, `order`, or `family` \n",
866
+ " - 36 instances of missing `class`"
867
+ ]
868
+ },
869
+ {
870
+ "cell_type": "markdown",
871
+ "metadata": {},
872
+ "source": []
873
+ }
874
+ ],
875
+ "metadata": {
876
+ "kernelspec": {
877
+ "display_name": "std",
878
+ "language": "python",
879
+ "name": "python3"
880
+ },
881
+ "language_info": {
882
+ "codemirror_mode": {
883
+ "name": "ipython",
884
+ "version": 3
885
+ },
886
+ "file_extension": ".py",
887
+ "mimetype": "text/x-python",
888
+ "name": "python",
889
+ "nbconvert_exporter": "python",
890
+ "pygments_lexer": "ipython3",
891
+ "version": "3.11.3"
892
+ },
893
+ "orig_nbformat": 4
894
+ },
895
+ "nbformat": 4,
896
+ "nbformat_minor": 2
897
+ }