.gitattributes CHANGED
@@ -56,3 +56,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
56
  data/v1-dev-names.csv filter=lfs diff=lfs merge=lfs -text
57
  notebooks/BioCLIP_taxa_viz_bySource.ipynb filter=lfs diff=lfs merge=lfs -text
58
  statistics.csv filter=lfs diff=lfs merge=lfs -text
 
 
56
  data/v1-dev-names.csv filter=lfs diff=lfs merge=lfs -text
57
  notebooks/BioCLIP_taxa_viz_bySource.ipynb filter=lfs diff=lfs merge=lfs -text
58
  statistics.csv filter=lfs diff=lfs merge=lfs -text
59
+ data/catalog*.csv filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -10,38 +10,32 @@ This repo contains the analysis of the TreeOfLife10M dataset as it's being craft
10
  ### Data
11
 
12
  The `data` folder contains
13
- - `statistics.csv`: the metadata and identifiers for all images in the dataset. This includes original data source, unique identifier within TreeOfLife10M, and the
14
- associated taxa information for the image. This is the file that will be updated, while preserving the `v1-dev-names.csv` file for ease of comparison.
15
- - `stats_avg_std_byClass.csv`: average and standard distribution of images given by class in `statistics.csv`. This is for both all
16
  images, and images that have labels.
17
 
18
- - `v1-dev-names.csv`: the metadata and identifiers for all images in the dataset. This includes original data source, unique identifier within TreeOfLife10M, and the
19
- associated taxa information for the image.
20
  - `taxa_counts.csv`: count of distinct lower taxa within each higher taxon from `kingdom` down to
21
- `genus`, though the genus count was interrupted and therefore is incomplete.
22
- - `avg_std_byClass.csv`: average and standard distribution of images given by class. This is for both all
23
- images, and images that have labels. Note that kingdoms have not been merged and no standardization has
24
- been performed on the taxonomic hierarchy prior to creation of this file.
25
- - `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.
26
 
27
 
28
  ### Notebooks
29
 
30
  The `notebooks` folder contains
31
- - `ToL_stats_EDA.ipynb`: more full EDA of TreeOfLife10M dataset using `statistics.csv`.
32
- - `ToL_stats_EDA.py`: py file paired to `ToL_stats_EDA.ipynb` to facilitate diff checking in case of cell text changes in notebook.
33
 
34
- - `BioCLIP_data_viz.ipynb`: notebook with quick basic stats for `v1-dev-names.csv`, generates
35
- `taxa_counts.csv`.
36
- - `BioCLIP_taxa_viz_bySource.ipynb`: generates data visualizations, in particular, the generation of
37
- visualizations in visuals and some histograms. The treemaps produced in the notebook are interactive.
38
  - `ToL_EDA.ipynb`: more full EDA of TreeOfLife10M dataset. Explores the labeling inconsistencies for
39
- direction of standardization efforts.
40
- - `missing_taxa_testGen.ipynb`: generates `tol_hierarchy_test.csv` to test `check_taxa` script. Also observes species labeled as `(unidentified)` in EOL data.
41
 
42
- Note: run `pip install -r requirements.txt` before starting the notebooks.
43
 
44
  ### Visuals
45
 
46
  Visualizations generated to demonstrate the distribution and diversity within the phyla of TreeOfLife10M.
47
- There is also one for just the iNat21 data included.
 
10
  ### Data
11
 
12
  The `data` folder contains
13
+ - `catalog.csv`: the metadata and identifiers for all images in the dataset. This includes original data source, unique identifier within TreeOfLife10M, and the associated taxa information for the image. This is the file that will be updated, while preserving the `catalog-v1-dev.csv` file for ease of comparison.
14
+ - `stats_avg_std_byClass.csv`: average and standard distribution of images given by class in `catalog.csv`. This is for both all
 
15
  images, and images that have labels.
16
 
17
+ - `catalog-v1-dev.csv`: the metadata and identifiers for all images in the dataset. This includes original data source, unique identifier within TreeOfLife10M, and the associated taxa information for the image. This file will be maintained for v1 reference, and as such will not be updated.
 
18
  - `taxa_counts.csv`: count of distinct lower taxa within each higher taxon from `kingdom` down to
19
+ `genus` in `catalog-v1-dev.csv`, though the genus count was interrupted and therefore is incomplete.
20
+ - `avg_std_byClass.csv`: average and standard distribution of images in `catalog-v1-dev.csv` given by class (taxonomic rank). This is for both all images, and images that have labels. Note that kingdoms had not been merged and no standardization was performed on the taxonomic hierarchy prior to creation of this file.
21
+ - `tol_hierarchy_test.csv`: Subset of `catalog-v1-dev.csv` for testing the [`check_taxa` script](https://github.com/Imageomics/open_clip/blob/main/scripts/evobio10m/check_taxa.py) to ensure the hierarchy is properly filled in after data generation.
 
 
22
 
23
 
24
  ### Notebooks
25
 
26
  The `notebooks` folder contains
27
+ - `ToL_catalog_EDA.ipynb`: more full EDA of TreeOfLife10M dataset using `catalog.csv`. To be updated as `catalog.csv` is updated, i.e., as the dataset is updated.
28
+ - `ToL_catalog_EDA.py`: py file paired to `ToL_catalog_EDA.ipynb` to facilitate diff checking in case of cell text changes in notebook.
29
 
30
+ - `BioCLIP_data_viz.ipynb`: notebook with quick basic stats for `catalog-v1-dev.csv`, generates `taxa_counts.csv`.
31
+ - `BioCLIP_taxa_viz_bySource.ipynb`: generates data visualizations, in particular, the generation of visualizations in `visuals` folder and some histograms. The treemaps produced in the notebook are interactive.
 
 
32
  - `ToL_EDA.ipynb`: more full EDA of TreeOfLife10M dataset. Explores the labeling inconsistencies for
33
+ direction of standardization efforts. Maintained for v1 reference, should not be updated.
34
+ - `missing_taxa_testGen.ipynb`: generates `tol_hierarchy_test.csv` to test [`check_taxa` script](https://github.com/Imageomics/open_clip/blob/main/scripts/evobio10m/check_taxa.py). Also observes species labeled as `(unidentified)` in EOL data.
35
 
36
+ **Note:** run `pip install -r requirements.txt` before starting the visualization notebooks.
37
 
38
  ### Visuals
39
 
40
  Visualizations generated to demonstrate the distribution and diversity within the phyla of TreeOfLife10M.
41
+ There is also one for just the iNat21 data included.
data/{v1-dev-names.csv → catalog-v1-dev.csv} RENAMED
File without changes
data/{statistics.csv → catalog.csv} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:995cfb557048441d0426da39c0eece02493208ed92bb615d6a50d683dca9616b
3
- size 1646503457
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:315576dd390920972ad48accbef002b5f19ca6838a6035cd1f32f09e3ee6d411
3
+ size 2018327986
data/missing_taxa_output.txt CHANGED
@@ -1,4 +1,5 @@
1
- Output of Data Check for First Full Version of BioCLIP training data (initial submission):
 
2
 
3
  [2023-10-25 10:20:12,498] [WARNING] [root] There are 5 kingdoms instead of 3.
4
  [2023-10-25 10:20:13,673] [WARNING] [root] 1300744 entries are missing rank kingdom, but have genus label.
@@ -18,8 +19,9 @@ Output of Data Check for First Full Version of BioCLIP training data (initial su
18
  [2023-10-25 10:20:16,644] [WARNING] [root] There are 755133 samples for which the species column may have genus and species.
19
  [2023-10-25 10:20:17,199] [WARNING] [root] 2470 species are labeled as '(unidentified)'.
20
 
 
21
 
22
- Output of Data Check for next iteration where taxon matching was performed (statistics.csv):
23
 
24
  [2023-10-25 10:25:28,242] [WARNING] [root] There are 7 kingdoms instead of 3.
25
  [2023-10-25 10:25:29,234] [WARNING] [root] 14795 entries are missing rank kingdom, but have genus label.
@@ -41,4 +43,30 @@ Output of Data Check for next iteration where taxon matching was performed (stat
41
  [2023-10-25 10:25:30,662] [WARNING] [root] 74 entries have family and species labels but no genus.
42
  [2023-10-25 10:25:31,992] [WARNING] [root] There are 158279 samples for which the species column may have genus and species.
43
  Added check for nulls in common column (wasn't an issue in the first iteration):
44
- [2023-10-25 11:39:11,384] [WARNING] [root] 915509 entries have null common. They are from ['EOL' 'BIOSCAN'].
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ Output of Data Check for First Full Version of BioCLIP training data (catalog-v1-dev.csv):
3
 
4
  [2023-10-25 10:20:12,498] [WARNING] [root] There are 5 kingdoms instead of 3.
5
  [2023-10-25 10:20:13,673] [WARNING] [root] 1300744 entries are missing rank kingdom, but have genus label.
 
19
  [2023-10-25 10:20:16,644] [WARNING] [root] There are 755133 samples for which the species column may have genus and species.
20
  [2023-10-25 10:20:17,199] [WARNING] [root] 2470 species are labeled as '(unidentified)'.
21
 
22
+ ------------------------------------------------------------------------------------------------------
23
 
24
+ Output of Data Check for next iteration where taxon matching was performed (catalog.csv, from pr1):
25
 
26
  [2023-10-25 10:25:28,242] [WARNING] [root] There are 7 kingdoms instead of 3.
27
  [2023-10-25 10:25:29,234] [WARNING] [root] 14795 entries are missing rank kingdom, but have genus label.
 
43
  [2023-10-25 10:25:30,662] [WARNING] [root] 74 entries have family and species labels but no genus.
44
  [2023-10-25 10:25:31,992] [WARNING] [root] There are 158279 samples for which the species column may have genus and species.
45
  Added check for nulls in common column (wasn't an issue in the first iteration):
46
+ [2023-10-25 11:39:11,384] [WARNING] [root] 915509 entries have null common. They are from ['EOL' 'BIOSCAN'].
47
+
48
+ ------------------------------------------------------------------------------------------------------
49
+
50
+ Output of taxa check for catalog.csv v3.2 (taxa check now also removes duplicate entries for small training) (from pr2):
51
+
52
+ [2023-10-26 13:44:09,780] [WARNING] [root] There are 7 kingdoms instead of 3.
53
+ [2023-10-26 13:44:11,325] [WARNING] [root] 160824 entries are missing rank kingdom, but have genus label.
54
+ [2023-10-26 13:44:11,613] [WARNING] [root] 151405 entries are missing rank phylum, but have genus label.
55
+ [2023-10-26 13:44:11,910] [WARNING] [root] 161871 entries are missing rank class, but have genus label.
56
+ [2023-10-26 13:44:12,199] [WARNING] [root] 156405 entries are missing rank order, but have genus label.
57
+ [2023-10-26 13:44:12,483] [WARNING] [root] 153279 entries are missing rank family, but have genus label.
58
+ [2023-10-26 13:44:12,782] [WARNING] [root] 315 entries are missing rank kingdom, but have family label.
59
+ [2023-10-26 13:44:12,809] [WARNING] [root] 289 entries are missing rank phylum, but have family label.
60
+ [2023-10-26 13:44:12,837] [WARNING] [root] 792 entries are missing rank class, but have family label.
61
+ [2023-10-26 13:44:12,865] [WARNING] [root] 414 entries are missing rank order, but have family label.
62
+ [2023-10-26 13:44:12,905] [WARNING] [root] 170 entries are missing rank kingdom, but have order label.
63
+ [2023-10-26 13:44:12,906] [WARNING] [root] 105 entries are missing rank phylum, but have order label.
64
+ [2023-10-26 13:44:12,908] [WARNING] [root] 1263 entries are missing rank class, but have order label.
65
+ [2023-10-26 13:44:12,949] [WARNING] [root] 41 entries have kingdom and species labels but no genus.
66
+ [2023-10-26 13:44:12,953] [WARNING] [root] 41 entries have phylum and species labels but no genus.
67
+ [2023-10-26 13:44:12,957] [WARNING] [root] 41 entries have class and species labels but no genus.
68
+ [2023-10-26 13:44:12,961] [WARNING] [root] 41 entries have order and species labels but no genus.
69
+ [2023-10-26 13:44:12,965] [WARNING] [root] 41 entries have family and species labels but no genus.
70
+ [2023-10-26 13:44:14,425] [WARNING] [root] There are 149057 samples for which the species column may have genus and species.
71
+
72
+ ------------------------------------------------------------------------------------------------------
data/stats_avg_std_byClass.csv CHANGED
@@ -1,9 +1,9 @@
1
  class,average_all_imgs,standard_deviation,avg_labeled,std_dev_labeled
2
- kingdom,1490931.5714285714,1221.0370884737988,1313721.0,1146.1766879499862
3
- phylum,115961.34444444445,340.53097428052627,102281.77777777778,319.8152244308857
4
- class,37008.93971631206,192.3770768992815,32562.521276595744,180.45088328017613
5
- order,7858.826054216867,88.65002004634216,6912.875753012048,83.14370543229384
6
- family,1344.5659623808297,36.66832369199374,1178.8904921412006,34.33497476540795
7
- genus,146.0490770931583,12.085076627525302,116.09587315803468,10.77477949463629
8
- species,62.11105754924716,7.881056880218995,49.31926441706838,7.0227675753272925
9
- common,23.720875419344868,4.8704081368346195,19.653807515023683,4.4332614986061545
 
1
  class,average_all_imgs,standard_deviation,avg_labeled,std_dev_labeled
2
+ kingdom,1490931.5714285714,1221.0370884737988,1383385.142857143,1176.1739424324717
3
+ phylum,115961.34444444445,340.53097428052627,107705.3111111111,328.1848733733947
4
+ class,36748.31338028169,191.69849603030715,34047.58450704225,184.5198756422794
5
+ order,7841.1126972201355,88.55005757886403,7262.970698722765,85.22306435890911
6
+ family,1339.3892453798767,36.59766721226746,1236.6025410677619,35.165359959308844
7
+ genus,141.30713405635214,11.887267728807664,120.2536794075037,10.966023864988792
8
+ species,63.3115005702361,7.9568524285823035,52.917740409114074,7.274458083535438
9
+ common,23.458496762142808,4.8433972335688935,22.625316649171822,4.756607682915612
notebooks/ToL_EDA.ipynb CHANGED
@@ -28,7 +28,7 @@
28
  }
29
  ],
30
  "source": [
31
- "df = pd.read_csv(\"../data/v1-dev-names.csv\")"
32
  ]
33
  },
34
  {
 
28
  }
29
  ],
30
  "source": [
31
+ "df = pd.read_csv(\"../data/catalog-v1-dev.csv\")"
32
  ]
33
  },
34
  {
notebooks/{ToL_stats_EDA.ipynb → ToL_catalog_EDA.ipynb} RENAMED
The diff for this file is too large to render. See raw diff
 
notebooks/{ToL_stats_EDA.py → ToL_catalog_EDA.py} RENAMED
@@ -21,7 +21,7 @@ sns.set_style("whitegrid")
21
  sns.set(rc = {'figure.figsize': (10,10)})
22
 
23
  # %%
24
- df = pd.read_csv("../data/statistics.csv")
25
 
26
  # %%
27
  df.head()
@@ -30,29 +30,38 @@ df.head()
30
  df.info(show_counts = True)
31
 
32
  # %% [markdown]
33
- # Original version had 10,436,521 entries; was the validation set left out (there does seem to be about 5-10% less of each source).
 
 
 
 
 
 
 
 
 
34
  #
35
- # Labeling definitely has far better coverage now.
36
 
37
  # %%
38
  df.nunique()
39
 
40
  # %% [markdown]
41
- # There are 498,053 unique EOL page IDs, suggesting 498,053 unique classes among the 5,938,235 images pulled from EOL (and maintained here). Presumably this would represent the number of species or other lowest rank taxa covered.
42
 
43
  # %% [markdown]
44
- # Notice that we have 7 unique kingdoms, when there are only...
45
 
46
  # %%
47
  df['kingdom'].value_counts()
48
 
49
  # %% [markdown]
50
- # `Metazoa` and `Archaeplastida` have been replaced by `Animalia` and `Plantae`.
51
  #
52
  # We now have other single-celled organisms for kingdom
53
 
54
  # %%
55
- taxa = list(df.columns[8:15])
56
  taxa
57
 
58
  # %% [markdown]
@@ -63,39 +72,39 @@ df_all_taxa = df.dropna(subset = taxa)
63
  df_all_taxa[taxa].info(show_counts = True)
64
 
65
  # %% [markdown]
66
- # We have 7,901,259 images with full taxonomic labels.
67
  #
68
- # Notice that we have gaps in the taxonomic hierarchy (both higher and lower values), as this is less than the number of species labels in the dataset and species had the least non-null values.
69
  #
70
- # We did hit the 7M+ entries with full taxonomic labels expectation, so that's good.
71
 
72
  # %% [markdown]
73
- # More detail on these missing values from [`check_taxa` script](https://github.com/Imageomics/open_clip/blob/main/scripts/evobio10m/check_taxa.py)
74
  #
75
  # ```
76
- # [2023-10-25 10:25:28,242] [WARNING] [root] There are 7 kingdoms instead of 3.
77
- # [2023-10-25 10:25:29,234] [WARNING] [root] 14795 entries are missing rank kingdom, but have genus label.
78
- # [2023-10-25 10:25:29,477] [WARNING] [root] 5824 entries are missing rank phylum, but have genus label.
79
- # [2023-10-25 10:25:29,719] [WARNING] [root] 15763 entries are missing rank class, but have genus label.
80
- # [2023-10-25 10:25:29,958] [WARNING] [root] 10550 entries are missing rank order, but have genus label.
81
- # [2023-10-25 10:25:30,203] [WARNING] [root] 7539 entries are missing rank family, but have genus label.
82
- # [2023-10-25 10:25:30,470] [WARNING] [root] 296 entries are missing rank kingdom, but have family label.
83
- # [2023-10-25 10:25:30,495] [WARNING] [root] 272 entries are missing rank phylum, but have family label.
84
- # [2023-10-25 10:25:30,520] [WARNING] [root] 753 entries are missing rank class, but have family label.
85
- # [2023-10-25 10:25:30,545] [WARNING] [root] 395 entries are missing rank order, but have family label.
86
- # [2023-10-25 10:25:30,590] [WARNING] [root] 156 entries are missing rank kingdom, but have order label.
87
- # [2023-10-25 10:25:30,591] [WARNING] [root] 100 entries are missing rank phylum, but have order label.
88
- # [2023-10-25 10:25:30,592] [WARNING] [root] 1187 entries are missing rank class, but have order label.
89
- # [2023-10-25 10:25:30,637] [WARNING] [root] 74 entries have kingdom and species labels but no genus.
90
- # [2023-10-25 10:25:30,644] [WARNING] [root] 74 entries have phylum and species labels but no genus.
91
- # [2023-10-25 10:25:30,650] [WARNING] [root] 74 entries have class and species labels but no genus.
92
- # [2023-10-25 10:25:30,656] [WARNING] [root] 74 entries have order and species labels but no genus.
93
- # [2023-10-25 10:25:30,662] [WARNING] [root] 74 entries have family and species labels but no genus.
94
- # [2023-10-25 10:25:31,992] [WARNING] [root] There are 158279 samples for which the species column may have genus and species.
95
  # ```
96
 
97
  # %% [markdown]
98
- # Can we get some more information on those 74 entries that are missing genus?
99
 
100
  # %%
101
  missing_genus = df.dropna(subset = ['kingdom', 'phylum', 'class', 'order', 'family', 'species'])
@@ -110,6 +119,9 @@ print("The taxa missing genus are: ")
110
  for taxon in taxa:
111
  print(taxon, ": ", missing_genus[taxon].unique())
112
 
 
 
 
113
  # %% [markdown]
114
  # Let's add a column indicating the original data source so we can also get some stats by datasource.
115
 
@@ -120,13 +132,13 @@ df.loc[df['bioscan_filename'].notna(), 'data_source'] = 'BIOSCAN'
120
  df.loc[df['eol_content_id'].notna(), 'data_source'] = 'EOL'
121
 
122
  # %%
123
- df.loc[df['common'].isna(), 'data_source'].unique()
124
-
125
- # %%
126
  missing_genus.data_source.unique()
127
 
128
  # %% [markdown]
129
- # Missing genus with all other taxa occurs in both BIOSCAN and EOL.
130
 
131
  # %% [markdown]
132
  # First, check their unique class values (`common`).
@@ -141,15 +153,17 @@ df.loc[df['data_source'] == 'iNat21', 'common'].nunique()
141
  df.loc[df['data_source'] == 'BIOSCAN', 'common'].nunique()
142
 
143
  # %% [markdown]
144
- # iNat's number of unique values in `common` has gone up by 6...why?
 
 
145
  #
146
- # BIOSCAN and EOL's counts went down, as expected (this is just training set and the common mapping was not done if scientific name was not provided, so we wouldn't see many for BIOSCAN).
147
 
148
  # %% [markdown]
149
  # Make `df_taxa` with just taxa columns (+ `common` & `data_source`) so it's smaller to process faster.
150
 
151
  # %%
152
- taxa_com = list(df.columns[8:16]) # taxa + common
153
  taxa_com.insert(0, 'data_source')
154
  df_taxa = df[taxa_com]
155
 
@@ -171,7 +185,7 @@ eol_df = df_taxa.loc[df_taxa.data_source == 'EOL']
171
  inat21_df.info(show_counts = True)
172
 
173
  # %% [markdown]
174
- # iNat21 isn't missing anything, as expected, and we have 2,552,501 of 2,686,843 images (training, validation set is separate).
175
  #
176
  # Quick view of diversity in iNat21.
177
 
@@ -205,13 +219,15 @@ inat21_df_unique_taxa.info(show_counts = True)
205
  bioscan_df.info(show_counts = True)
206
 
207
  # %% [markdown]
208
- # All images are labeled down to `order`, most (98.6%) are labeled to the `family` level, but we only have 22.5% and 7.5% with `genus` or `species` level designation, respectively. These proportions were maintained when the validation set was removed.
 
 
209
 
210
  # %%
211
  bioscan_df.nunique()
212
 
213
  # %% [markdown]
214
- # We did lose 2 families, 37 genera, and 1,354 species to the validation set. Note, they may be (likely are) represented in EOL and/or iNat.
215
 
216
  # %%
217
  bioscan_df['kingdom'].value_counts()
@@ -235,7 +251,7 @@ bioscan_df.loc[bioscan_df['genus'].notna()].sample(7)
235
  bioscan_df.loc[bioscan_df['genus'].isna()].sample(7)
236
 
237
  # %% [markdown]
238
- # When the `genus` is null, we no longer get `common` of all higher order taxa available; though we are going to go back to this with the next iteration it seems.
239
 
240
  # %%
241
  #number of unique 7-tuples in BIOSCAN
@@ -246,23 +262,22 @@ bioscan_df_unique_taxa = bioscan_df.loc[~bioscan_df['duplicate']]
246
  bioscan_df_unique_taxa.info(show_counts = True)
247
 
248
  # %% [markdown]
249
- # We should be able to fill all in for all values of `species` that also have `genus` indicated since they are all in `Animalia`. Is `genus` labeled for all entries with `species` labeled?
250
-
251
- # %%
252
- bioscan_df.loc[bioscan_df.species.notna()].info(show_counts = True)
253
 
254
  # %% [markdown]
255
- # There are only 8 images where the `species` is labeled, but the `genus` isn't. There must be 1 in the validation set.
256
 
257
  # %%
258
- bioscan_df.loc[(bioscan_df.species.notna()) & (bioscan_df.genus.isna())]
259
 
260
 
261
  # %% [markdown]
262
- # It seems the `genus` is `tetramalaise01` ([genus page for tetraMalaise01](https://v3.boldsystems.org/index.php/Taxbrowser_Taxonpage?taxid=1074204)).
263
 
264
  # %% [markdown]
265
- # In general, when the species is listed in BIOSCAN it is listed as `genus-species`. This is certainly true here and would work to fill the 9 missing genera.
 
 
266
  #
267
  # Let's check those stats again, we did confirm it earlier, but would also like to check EOL as it had a similar issue for some entries.
268
 
@@ -305,7 +320,7 @@ bioscan_long_species = bioscan_species_len_df.loc[bioscan_species_len_df["len_sp
305
  bioscan_long_species.info(show_counts = True)
306
 
307
  # %% [markdown]
308
- # Not all species indicated have length greater than 1 now.
309
 
310
  # %%
311
  bioscan_species_len_df.len_species.value_counts()
@@ -322,11 +337,8 @@ bioscan_long_species.sample(7)
322
  # %%
323
  bioscan_long_species.loc[bioscan_long_species['len_species'] > 2].sample(10)
324
 
325
- # %%
326
- bioscan_df.loc[bioscan_df["genus"] == "Psychoda", "species"].unique()
327
-
328
  # %% [markdown]
329
- # We can see that the case of "Psychoda" was resolved appropriately.
330
 
331
  # %% [markdown]
332
  # It would seem the "sp. ..." is used to indicate they are likely the same species, though the actual species is not designated (either unnamed or undetermined). This is information we should retain, but the duplicated genus can be removed.
@@ -344,9 +356,9 @@ eol_df.nunique()
344
  eol_df.loc[eol_df.species.isna()].nunique()
345
 
346
  # %% [markdown]
347
- # There are 498,053 (training + val 570,515) unique page IDs from EOL in this training set, which clearly represent varying levels of taxa.
348
  #
349
- # Unique species + unique common where species is null (197,301) does not reach this number.
350
 
351
  # %%
352
  eol_df['kingdom'].value_counts()
@@ -354,7 +366,7 @@ eol_df['kingdom'].value_counts()
354
  # %% [markdown]
355
  # We have much greater kingdom variety here.
356
  #
357
- # We have already observed that not all ranks are filled in at the higher levels, sometimes having just one gap. This has been greatly improved from the first iteration.
358
 
359
  # %%
360
  #number of unique 7-tuples in EOL
@@ -365,15 +377,17 @@ eol_df_unique_taxa = eol_df.loc[~eol_df['duplicate']]
365
  eol_df_unique_taxa.info(show_counts = True)
366
 
367
  # %% [markdown]
368
- # The actual number of distinct creatures is likely higher, as evidenced below where we have unique common names listed in `common` but all taxa are null.
369
  #
370
- # We should be able to fill all in for all values of `species` that also have `genus` indicated. Is `genus` labeled for all entries with `species` labeled?
371
 
372
  # %%
373
  eol_df.loc[eol_df.species.notna()].info(show_counts = True)
374
 
375
  # %% [markdown]
376
  # Not all labeled species have higher order taxa, but they do all have `common` (likely because if there is no common name, it pulls scientific name (genus-species)).
 
 
377
 
378
  # %% [markdown]
379
  # Let's get a quick sample of the `common` column for images both with and without `species` labels.
@@ -390,46 +404,7 @@ eol_df.loc[eol_df.species.notna()].sample(7)
390
  eol_df.loc[eol_df.species.isna()].sample(7)
391
 
392
  # %% [markdown]
393
- # Here are a lot of higher-order taxa missing species...let's check for the details noted below.
394
- #
395
- # From original check:
396
- # All `common` values are filled in with predominently common names. It seems we could map these back to some level of taxa with the taxon-common matching? Though why would these EOL images have common without any other designation?
397
- #
398
- # Good example of strange inconsistency: the `American red raspberry` is `Rubus strigosus`, and a quick Google search easily provides the entire taxonomy.
399
- #
400
- # `Cremastobaeus` seems to be a genus of wasp.
401
-
402
- # %%
403
- eol_df.loc[eol_df.common == "American red raspberry"]
404
-
405
- # %%
406
- eol_df.loc[eol_df.common == "Rubus strigosus"]
407
-
408
- # %% [markdown]
409
- # We seem to have lost the raspberry...
410
-
411
- # %%
412
- eol_df.loc[eol_df.species == "strigosus"]
413
-
414
- # %%
415
- eol_df_unique_taxa.loc[eol_df_unique_taxa.species == "strigosus"]
416
-
417
- # %% [markdown]
418
- # It seems likely the row with the null values is our lost raspberry.
419
- #
420
- # Also good evidence of the duplication of species names across kingdoms and other taxa.
421
-
422
- # %% [markdown]
423
- # Rubus strigosus is apparently a subspecies of "Rubus idaeus", and we are not looking at the subspecies level.
424
-
425
- # %%
426
- eol_df_unique_taxa.loc[eol_df_unique_taxa.species == "idaeus"]
427
-
428
- # %% [markdown]
429
- # Though the question remains, why did we lose the common name?
430
-
431
- # %% [markdown]
432
- # Let's check the `species` length in EOL as well, we know there are some that have genus-species.
433
 
434
  # %%
435
  eol_species_len = check_sci_name(eol_df)
@@ -446,9 +421,11 @@ eol_long_species.info(show_counts = True)
446
  eol_long_species.len_species.value_counts()
447
 
448
  # %% [markdown]
449
- # Observe, we did not wind up with any of length 2, so this issue was partially resolved.
450
  #
451
  # Why are some more than 10 words long?
 
 
452
 
453
  # %%
454
  eol_long_species.loc[eol_long_species["len_species"] > 7].sample(7)
@@ -456,11 +433,17 @@ eol_long_species.loc[eol_long_species["len_species"] > 7].sample(7)
456
  # %%
457
  eol_long_species.nunique()
458
 
 
 
 
459
  # %%
460
  eol_long_species.loc[eol_long_species["len_species"] < 7].sample(7)
461
 
462
  # %% [markdown]
463
- # Quick search: "Adelpha godmani" is a butterfly with species name given by Fruhstorfer in 1913 ([source](https://butterfliesofamerica.com/L/t/Adelpha_godmani_a.htm)).
 
 
 
464
 
465
  # %% [markdown]
466
  # ### Label Overlap Check
@@ -523,7 +506,7 @@ avg_std
523
  avg_std.to_csv("../data/stats_avg_std_byClass.csv", index = False)
524
 
525
  # %% [markdown]
526
- # Observe that the Plant and Animal `kingdom`s are actually much more heavily represented than Fungi.
527
 
528
  # %%
529
  sns.set(rc = {'figure.figsize': (10,6)})
 
21
  sns.set(rc = {'figure.figsize': (10,10)})
22
 
23
  # %%
24
+ df = pd.read_csv("../data/catalog.csv")
25
 
26
  # %%
27
  df.head()
 
30
  df.info(show_counts = True)
31
 
32
  # %% [markdown]
33
+ # The `train_small` is duplicates of `train`, so we will drop those to analyze the full training set plus val.
34
+
35
+ # %%
36
+ df = df.loc[df.split != 'train_small']
37
+
38
+ # %%
39
+ df.info(show_counts = True)
40
+
41
+ # %% [markdown]
42
+ # Original version had 10,436,521 entries; we expected loss of about 84K from the genera with label "unknown", but there's still another ~300K missing for this 10,065,845. Likely due to dropping subspecies, which will now be integrated back in under their species for the next round.
43
  #
44
+ # Labeling definitely has far better coverage from original, and even improves over the last version (of course `common` is completely filled, but we also gained almost 50K more taxa labels across the board).
45
 
46
  # %%
47
  df.nunique()
48
 
49
  # %% [markdown]
50
+ # There are 503,595 unique EOL page IDs, suggesting 503,595 unique classes among the 6,250,689 images pulled from EOL (and maintained here). Presumably this would represent the number of species or other lowest rank taxa covered by EOL.
51
 
52
  # %% [markdown]
53
+ # Notice that we have 7 unique kingdoms, which we're sticking with.
54
 
55
  # %%
56
  df['kingdom'].value_counts()
57
 
58
  # %% [markdown]
59
+ # `Metazoa` and `Archaeplastida` have been replaced by `Animalia` and `Plantae`, setting them as the dominant kingdoms represented (which we'd expect).
60
  #
61
  # We now have other single-celled organisms for kingdom
62
 
63
  # %%
64
+ taxa = list(df.columns[9:16])
65
  taxa
66
 
67
  # %% [markdown]
 
72
  df_all_taxa[taxa].info(show_counts = True)
73
 
74
  # %% [markdown]
75
+ # We have 8,320,837 images with full taxonomic labels.
76
  #
77
+ # Notice that we still have gaps in the taxonomic hierarchy (both higher and lower values), as this is less than the number of species labels in the dataset and species had the least non-null values.
78
  #
79
+ # We did hit 8M+ entries with full taxonomic labels, so that's really good, especially considering 1,043,863 of the BIOSCAN sourced images don't have species labels.
80
 
81
  # %% [markdown]
82
+ # More detail on these missing values from [`check_taxa` script](https://github.com/Imageomics/open_clip/blob/main/scripts/evobio10m/check_taxa.py) are displayed below. Note: full record of taxa check output is in `data/missing_taxa_output.txt`.
83
  #
84
  # ```
85
+ # [2023-10-26 13:44:09,780] [WARNING] [root] There are 7 kingdoms instead of 3.
86
+ # [2023-10-26 13:44:11,325] [WARNING] [root] 160824 entries are missing rank kingdom, but have genus label.
87
+ # [2023-10-26 13:44:11,613] [WARNING] [root] 151405 entries are missing rank phylum, but have genus label.
88
+ # [2023-10-26 13:44:11,910] [WARNING] [root] 161871 entries are missing rank class, but have genus label.
89
+ # [2023-10-26 13:44:12,199] [WARNING] [root] 156405 entries are missing rank order, but have genus label.
90
+ # [2023-10-26 13:44:12,483] [WARNING] [root] 153279 entries are missing rank family, but have genus label.
91
+ # [2023-10-26 13:44:12,782] [WARNING] [root] 315 entries are missing rank kingdom, but have family label.
92
+ # [2023-10-26 13:44:12,809] [WARNING] [root] 289 entries are missing rank phylum, but have family label.
93
+ # [2023-10-26 13:44:12,837] [WARNING] [root] 792 entries are missing rank class, but have family label.
94
+ # [2023-10-26 13:44:12,865] [WARNING] [root] 414 entries are missing rank order, but have family label.
95
+ # [2023-10-26 13:44:12,905] [WARNING] [root] 170 entries are missing rank kingdom, but have order label.
96
+ # [2023-10-26 13:44:12,906] [WARNING] [root] 105 entries are missing rank phylum, but have order label.
97
+ # [2023-10-26 13:44:12,908] [WARNING] [root] 1263 entries are missing rank class, but have order label.
98
+ # [2023-10-26 13:44:12,949] [WARNING] [root] 41 entries have kingdom and species labels but no genus.
99
+ # [2023-10-26 13:44:12,953] [WARNING] [root] 41 entries have phylum and species labels but no genus.
100
+ # [2023-10-26 13:44:12,957] [WARNING] [root] 41 entries have class and species labels but no genus.
101
+ # [2023-10-26 13:44:12,961] [WARNING] [root] 41 entries have order and species labels but no genus.
102
+ # [2023-10-26 13:44:12,965] [WARNING] [root] 41 entries have family and species labels but no genus.
103
+ # [2023-10-26 13:44:14,425] [WARNING] [root] There are 149057 samples for which the species column may have genus and species.
104
  # ```
105
 
106
  # %% [markdown]
107
+ # Can we get some more information on those 41 entries that are still missing genus?
108
 
109
  # %%
110
  missing_genus = df.dropna(subset = ['kingdom', 'phylum', 'class', 'order', 'family', 'species'])
 
119
  for taxon in taxa:
120
  print(taxon, ": ", missing_genus[taxon].unique())
121
 
122
+ # %% [markdown]
123
+ # "celebensis" is new, but next iteration should resolve these.
124
+
125
  # %% [markdown]
126
  # Let's add a column indicating the original data source so we can also get some stats by datasource.
127
 
 
132
  df.loc[df['eol_content_id'].notna(), 'data_source'] = 'EOL'
133
 
134
  # %%
135
+ # re-do missing genus with the data source to check if it's just EOL or Bioscan too
136
+ missing_genus = df.dropna(subset = ['kingdom', 'phylum', 'class', 'order', 'family', 'species'])
137
+ missing_genus = missing_genus.loc[missing_genus.genus.isna()]
138
  missing_genus.data_source.unique()
139
 
140
  # %% [markdown]
141
+ # Missing genus with all other taxa occurs only in EOL now, so should get fixed.
142
 
143
  # %% [markdown]
144
  # First, check their unique class values (`common`).
 
153
  df.loc[df['data_source'] == 'BIOSCAN', 'common'].nunique()
154
 
155
  # %% [markdown]
156
+ # iNat's number of unique values in `common` is still up by 6 from the original --- probably pulled from ITIS instead and that has more listed?
157
+ #
158
+ # EOL's went back up a bit, though still about 70-80K less than the original version.
159
  #
160
+ # BIOSCAN's counts went down even more...
161
 
162
  # %% [markdown]
163
  # Make `df_taxa` with just taxa columns (+ `common` & `data_source`) so it's smaller to process faster.
164
 
165
  # %%
166
+ taxa_com = list(df.columns[9:17]) # taxa + common
167
  taxa_com.insert(0, 'data_source')
168
  df_taxa = df[taxa_com]
169
 
 
185
  inat21_df.info(show_counts = True)
186
 
187
  # %% [markdown]
188
+ # iNat21 isn't missing anything, as expected, and we have 2,686,843 images.
189
  #
190
  # Quick view of diversity in iNat21.
191
 
 
219
  bioscan_df.info(show_counts = True)
220
 
221
  # %% [markdown]
222
+ # All images are labeled down to `order`, most (98.6%) are labeled to the `family` level, but we only have 22.5% and 7.5% with `genus` or `species` level designation, respectively.
223
+ #
224
+ # There seems to be 1 less genus from the original and 3 less species...
225
 
226
  # %%
227
  bioscan_df.nunique()
228
 
229
  # %% [markdown]
230
+ # We have half as many unique species and 3,000 less unique common names as in the original. Can this be accounted for by the adjustment in genus?
231
 
232
  # %%
233
  bioscan_df['kingdom'].value_counts()
 
251
  bioscan_df.loc[bioscan_df['genus'].isna()].sample(7)
252
 
253
  # %% [markdown]
254
+ # When the `genus` is null, we again have `common` as a list of all higher order taxa available.
255
 
256
  # %%
257
  #number of unique 7-tuples in BIOSCAN
 
262
  bioscan_df_unique_taxa.info(show_counts = True)
263
 
264
  # %% [markdown]
265
+ # 7,831 unique.
 
 
 
266
 
267
  # %% [markdown]
268
+ # We should be able to fill all in for all values of `species` that also have `genus` indicated since they are all in `Animalia`. Is `genus` labeled for all entries with `species` labeled?
269
 
270
  # %%
271
+ bioscan_df.loc[bioscan_df.species.notna()].info(show_counts = True)
272
 
273
 
274
  # %% [markdown]
275
+ # All resolved now.
276
 
277
  # %% [markdown]
278
+ # In general, when the species is listed in BIOSCAN it is listed as `genus-species`.
279
+ #
280
+ # This should have been resolved.
281
  #
282
  # Let's check those stats again, we did confirm it earlier, but would also like to check EOL as it had a similar issue for some entries.
283
 
 
320
  bioscan_long_species.info(show_counts = True)
321
 
322
  # %% [markdown]
323
+ # Not all species indicated have length greater than 1 now, though this number has actually gone up by 140 since the last iteration.
324
 
325
  # %%
326
  bioscan_species_len_df.len_species.value_counts()
 
337
  # %%
338
  bioscan_long_species.loc[bioscan_long_species['len_species'] > 2].sample(10)
339
 
 
 
 
340
  # %% [markdown]
341
+ # This looks like about what we expected.
342
 
343
  # %% [markdown]
344
  # It would seem the "sp. ..." is used to indicate they are likely the same species, though the actual species is not designated (either unnamed or undetermined). This is information we should retain, but the duplicated genus can be removed.
 
356
  eol_df.loc[eol_df.species.isna()].nunique()
357
 
358
  # %% [markdown]
359
+ # There are 503,595 unique page IDs from EOL in this dataset, which clearly represent varying levels of taxa.
360
  #
361
+ # Unique species + unique common where species is null (39,233) does not reach this number. But we have added SO many more phyla through family!
362
 
363
  # %%
364
  eol_df['kingdom'].value_counts()
 
366
  # %% [markdown]
367
  # We have much greater kingdom variety here.
368
  #
369
+ # We have already observed that not all ranks are filled in at the higher levels, sometimes having just one gap. This has been greatly improved from the first iteration and we'll get one more pass.
370
 
371
  # %%
372
  #number of unique 7-tuples in EOL
 
377
  eol_df_unique_taxa.info(show_counts = True)
378
 
379
  # %% [markdown]
380
+ # This is quite a good number of unqiue taxa.
381
  #
382
+ # Is `genus` labeled for all entries with `species` labeled?
383
 
384
  # %%
385
  eol_df.loc[eol_df.species.notna()].info(show_counts = True)
386
 
387
  # %% [markdown]
388
  # Not all labeled species have higher order taxa, but they do all have `common` (likely because if there is no common name, it pulls scientific name (genus-species)).
389
+ #
390
+ # This will hopefully be filled with the next iteration.
391
 
392
  # %% [markdown]
393
  # Let's get a quick sample of the `common` column for images both with and without `species` labels.
 
404
  eol_df.loc[eol_df.species.isna()].sample(7)
405
 
406
  # %% [markdown]
407
+ # Let's check the `species` length in EOL as well, we know there are some that have genus-species. And others with hybrids that get VERY long.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
408
 
409
  # %%
410
  eol_species_len = check_sci_name(eol_df)
 
421
  eol_long_species.len_species.value_counts()
422
 
423
  # %% [markdown]
424
+ # We have length 2 all the way to 26.
425
  #
426
  # Why are some more than 10 words long?
427
+ # - Seem to be hybrids, getting genus added now
428
+ # - We have one that says "Bee"... it was "bee bees ntomology apoidea extrememarco insects..."
429
 
430
  # %%
431
  eol_long_species.loc[eol_long_species["len_species"] > 7].sample(7)
 
433
  # %%
434
  eol_long_species.nunique()
435
 
436
+ # %% [markdown]
437
+ # Genus was filled out much more from the last iteration (from only 47 to 8,587 unique instances), also doesn't have any nulls now (pulling that first word from species column).
438
+
439
  # %%
440
  eol_long_species.loc[eol_long_species["len_species"] < 7].sample(7)
441
 
442
  # %% [markdown]
443
+ # There are inconsistencies we likely can't resolve, some have names following the species (in the scientific name standard format of genus-species-namer-year) while others have "sp. __ " which is often used to indicate unknown species (pronounced "spa"), but the following bit may be used to indicate multiple images with unknown species are likely of the same species.
444
+ #
445
+ #
446
+ # Ex from earlier: "Adelpha godmani" is a butterfly with species name given by Fruhstorfer in 1913 ([source](https://butterfliesofamerica.com/L/t/Adelpha_godmani_a.htm)), it was listed as "adelpha godmani fruhstorfer".
447
 
448
  # %% [markdown]
449
  # ### Label Overlap Check
 
506
  avg_std.to_csv("../data/stats_avg_std_byClass.csv", index = False)
507
 
508
  # %% [markdown]
509
+ # Observe that the Plant and Animal `kingdom`s are actually much more heavily represented than Fungi (it didn't look this way before we standardized the kingdoms).
510
 
511
  # %%
512
  sns.set(rc = {'figure.figsize': (10,6)})