pr/3
#3
by
keeganskeate
- opened
- README.md +33 -15
- cannabis_tests.py +198 -269
README.md
CHANGED
|
@@ -42,13 +42,13 @@ tags:
|
|
| 42 |
|
| 43 |
## Dataset Description
|
| 44 |
|
| 45 |
-
- **Homepage:** <https://
|
| 46 |
- **Repository:** <https://huggingface.co/datasets/cannlytics/cannabis_tests>
|
| 47 |
- **Point of Contact:** <dev@cannlytics.com>
|
| 48 |
|
| 49 |
### Dataset Summary
|
| 50 |
|
| 51 |
-
This dataset is a collection of public cannabis lab test results parsed by CoADoc
|
| 52 |
|
| 53 |
## Dataset Structure
|
| 54 |
|
|
@@ -63,24 +63,20 @@ The dataset is partitioned into the various sources of lab results.
|
|
| 63 |
|
| 64 |
### Data Instances
|
| 65 |
|
| 66 |
-
You can load `details
|
| 67 |
|
| 68 |
```py
|
| 69 |
from datasets import load_dataset
|
| 70 |
|
| 71 |
-
#
|
| 72 |
-
dataset = 'cannlytics/cannabis_tests'
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
# Load Raw Garden lab test results.
|
| 78 |
-
rawgarden_results = load_dataset(dataset, 'rawgarden_results')
|
| 79 |
-
|
| 80 |
-
# Load Raw Garden lab test values.
|
| 81 |
-
rawgarden_values = load_dataset(dataset, 'rawgarden_values')
|
| 82 |
```
|
| 83 |
|
|
|
|
|
|
|
| 84 |
### Data Fields
|
| 85 |
|
| 86 |
Below is a non-exhaustive list of fields, used to standardize the various data that are encountered, that you may expect encounter in the parsed COA data.
|
|
@@ -147,7 +143,29 @@ Each result can contain the following fields.
|
|
| 147 |
|
| 148 |
### Data Splits
|
| 149 |
|
| 150 |
-
The data is split into
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
## Dataset Creation
|
| 153 |
|
|
|
|
| 42 |
|
| 43 |
## Dataset Description
|
| 44 |
|
| 45 |
+
- **Homepage:** <https://github.com/cannlytics/cannlytics>
|
| 46 |
- **Repository:** <https://huggingface.co/datasets/cannlytics/cannabis_tests>
|
| 47 |
- **Point of Contact:** <dev@cannlytics.com>
|
| 48 |
|
| 49 |
### Dataset Summary
|
| 50 |
|
| 51 |
+
This dataset is a collection of public cannabis lab test results parsed by `CoADoc`, a certificate of analysis (COA) parsing tool.
|
| 52 |
|
| 53 |
## Dataset Structure
|
| 54 |
|
|
|
|
| 63 |
|
| 64 |
### Data Instances
|
| 65 |
|
| 66 |
+
You can load the `details` for each of the dataset files. For example:
|
| 67 |
|
| 68 |
```py
|
| 69 |
from datasets import load_dataset
|
| 70 |
|
| 71 |
+
# Download Raw Garden lab result details.
|
| 72 |
+
dataset = load_dataset('cannlytics/cannabis_tests', 'rawgarden')
|
| 73 |
+
details = dataset['details']
|
| 74 |
+
assert len(details) > 0
|
| 75 |
+
print('Downloaded %i observations.' % len(details))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
```
|
| 77 |
|
| 78 |
+
> Note: Configurations for `results` and `values` are planned. For now, you can create these data with `CoADoc().save(details, out_file)`.
|
| 79 |
+
|
| 80 |
### Data Fields
|
| 81 |
|
| 82 |
Below is a non-exhaustive list of fields, used to standardize the various data that are encountered, that you may expect encounter in the parsed COA data.
|
|
|
|
| 143 |
|
| 144 |
### Data Splits
|
| 145 |
|
| 146 |
+
The data is split into `details`, `results`, and `values` data. Configurations for `results` and `values` are planned. For now, you can create these data with:
|
| 147 |
+
|
| 148 |
+
```py
|
| 149 |
+
from cannlytics.data.coas import CoADoc
|
| 150 |
+
from datasets import load_dataset
|
| 151 |
+
|
| 152 |
+
# Download Raw Garden lab result details.
|
| 153 |
+
dataset = load_dataset('cannlytics/cannabis_tests', 'rawgarden')
|
| 154 |
+
details = dataset['details']
|
| 155 |
+
|
| 156 |
+
# Save the data locally with "Details", "Results", and "Values" worksheets.
|
| 157 |
+
outfile = 'details.xlsx'
|
| 158 |
+
parser = CoADoc()
|
| 159 |
+
parser.save(details, outfile)
|
| 160 |
+
|
| 161 |
+
# Read the values.
|
| 162 |
+
values = pd.read_excel(outfile, sheet_name='Values')
|
| 163 |
+
|
| 164 |
+
# Read the results.
|
| 165 |
+
results = pd.read_excel(outfile, sheet_name='Results')
|
| 166 |
+
```
|
| 167 |
+
|
| 168 |
+
<!-- Training data is used for training your models. Validation data is used for evaluating your trained models, to help you determine a final model. Test data is used to evaluate your final model. -->
|
| 169 |
|
| 170 |
## Dataset Creation
|
| 171 |
|
cannabis_tests.py
CHANGED
|
@@ -6,14 +6,23 @@ Authors:
|
|
| 6 |
Keegan Skeate <https://github.com/keeganskeate>
|
| 7 |
Candace O'Sullivan-Sutherland <https://github.com/candy-o>
|
| 8 |
Created: 9/10/2022
|
| 9 |
-
Updated: 9/
|
| 10 |
License: <https://github.com/cannlytics/cannlytics/blob/main/LICENSE>
|
| 11 |
"""
|
| 12 |
-
import datasets
|
| 13 |
-
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
@inproceedings{cannlytics2022cannabis_tests,
|
| 18 |
author = {Skeate, Keegan and O'Sullivan-Sutherland, Candace},
|
| 19 |
title = {Cannabis Tests: Curated Cannabis Lab Test Results},
|
|
@@ -24,178 +33,144 @@ CANNABIS_TESTS_CITATION = """\
|
|
| 24 |
publisher = {Cannlytics}
|
| 25 |
}
|
| 26 |
"""
|
| 27 |
-
CANNABIS_TESTS_DESCRIPTION = """\
|
| 28 |
-
Cannabis lab test results (https://cannlytics.com/data/tests) is a
|
| 29 |
-
dataset of curated cannabis lab test results.
|
| 30 |
-
"""
|
| 31 |
-
CANNABIS_TESTS_URL = 'https://huggingface.co/datasets/cannlytics/cannabis_tests'
|
| 32 |
|
| 33 |
# Raw Garden constants.
|
| 34 |
-
# RAWGARDEN_DATA_URL = 'https://cannlytics.page.link/rawgarden'
|
| 35 |
-
RAWGARDEN_DETAILS_URL = 'https://firebasestorage.googleapis.com/v0/b/cannlytics.appspot.com/o/data%2Flab_results%2Frawgarden%2Fdetails.csv?alt=media&token=e5b5273a-049a-4092-98d7-90a62ef399a3'
|
| 36 |
-
RAWGARDEN_RESULTS_URL = 'https://cannlytics.page.link/rawgarden-results'
|
| 37 |
-
RAWGARDEN_VALUES_URL = 'https://cannlytics.page.link/rawgarden-values'
|
| 38 |
RAWGARDEN_URL = 'https://github.com/cannlytics/cannlytics/tree/main/ai/curation/get_rawgarden_data'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
RAWGARDEN_DESCRIPTION = """\
|
| 40 |
Raw Garden lab test results (https://cannlytics.com/data/tests) is a
|
| 41 |
dataset of curated cannabis lab test results from Raw Garden, a large
|
| 42 |
cannabis processor in California.
|
| 43 |
"""
|
| 44 |
-
# RAWGARDEN_RESULTS = {
|
| 45 |
-
# 'sample_hash': datasets.Value(dtype='string', id=None),
|
| 46 |
-
# 'results_hash': datasets.Value(dtype='string', id=None),
|
| 47 |
-
# 'sample_id': datasets.Value(dtype='string', id=None),
|
| 48 |
-
# 'product_name': datasets.Value(dtype='string', id=None),
|
| 49 |
-
# 'producer': datasets.Value(dtype='string', id=None),
|
| 50 |
-
# 'product_type': datasets.Value(dtype='string', id=None),
|
| 51 |
-
# 'product_subtype': datasets.Value(dtype='string', id=None),
|
| 52 |
-
# 'date_tested': datasets.Value(dtype='string', id=None),
|
| 53 |
-
# 'analysis': datasets.Value(dtype='string', id=None),
|
| 54 |
-
# 'key': datasets.Value(dtype='string', id=None),
|
| 55 |
-
# 'limit': datasets.Value(dtype='double', id=None),
|
| 56 |
-
# 'lod': datasets.Value(dtype='double', id=None),
|
| 57 |
-
# 'lodloq': datasets.Value(dtype='double', id=None),
|
| 58 |
-
# 'loq': datasets.Value(dtype='double', id=None),
|
| 59 |
-
# 'margin_of_error': datasets.Value(dtype='double', id=None),
|
| 60 |
-
# 'mg_g': datasets.Value(dtype='double', id=None),
|
| 61 |
-
# 'name': datasets.Value(dtype='string', id=None),
|
| 62 |
-
# 'status': datasets.Value(dtype='string', id=None),
|
| 63 |
-
# 'units': datasets.Value(dtype='string', id=None),
|
| 64 |
-
# 'value': datasets.Value(dtype='double', id=None),
|
| 65 |
-
# }
|
| 66 |
RAWGARDEN_DETAILS = datasets.Features({
|
| 67 |
-
'sample_hash': datasets.Value(dtype='string'
|
| 68 |
-
'results_hash': datasets.Value(dtype='string'
|
| 69 |
-
'sample_id': datasets.Value(dtype='string'
|
| 70 |
-
'product_name': datasets.Value(dtype='string'
|
| 71 |
-
'producer': datasets.Value(dtype='string'
|
| 72 |
-
'product_type': datasets.Value(dtype='string'
|
| 73 |
-
'product_subtype': datasets.Value(dtype='string'
|
| 74 |
-
'date_tested': datasets.Value(dtype='string'
|
| 75 |
-
'analyses': datasets.Value(dtype='string'
|
| 76 |
-
'batch_number': datasets.Value(dtype='string'
|
| 77 |
-
'batch_size': datasets.Value(dtype='string'
|
| 78 |
-
'batch_units': datasets.Value(dtype='string'
|
| 79 |
-
'cannabinoids_method': datasets.Value(dtype='string'
|
| 80 |
-
'cannabinoids_status': datasets.Value(dtype='string'
|
| 81 |
-
'coa_algorithm': datasets.Value(dtype='string'
|
| 82 |
-
'coa_algorithm_entry_point': datasets.Value(dtype='string'
|
| 83 |
-
'coa_parsed_at': datasets.Value(dtype='string'
|
| 84 |
-
'coa_pdf': datasets.Value(dtype='string'
|
| 85 |
-
'coa_urls': datasets.Value(dtype='string'
|
| 86 |
-
'date_collected': datasets.Value(dtype='string'
|
| 87 |
-
'date_produced': datasets.Value(dtype='string'
|
| 88 |
-
'date_received': datasets.Value(dtype='string'
|
| 89 |
-
'date_retail': datasets.Value(dtype='string'
|
| 90 |
-
'delta_9_thc_per_unit': datasets.Value(dtype='string'
|
| 91 |
-
'distributor': datasets.Value(dtype='string'
|
| 92 |
-
'distributor_address': datasets.Value(dtype='string'
|
| 93 |
-
'distributor_city': datasets.Value(dtype='string'
|
| 94 |
-
'distributor_license_number': datasets.Value(dtype='string'
|
| 95 |
-
'distributor_state': datasets.Value(dtype='string'
|
| 96 |
-
'distributor_street': datasets.Value(dtype='string'
|
| 97 |
-
'distributor_zipcode': datasets.Value(dtype='float64'
|
| 98 |
-
'foreign_matter_method': datasets.Value(dtype='string'
|
| 99 |
-
'foreign_matter_status': datasets.Value(dtype='string'
|
| 100 |
-
'heavy_metals_method': datasets.Value(dtype='string'
|
| 101 |
-
'heavy_metals_status': datasets.Value(dtype='string'
|
| 102 |
-
'images': datasets.Value(dtype='string'
|
| 103 |
-
'lab': datasets.Value(dtype='string'
|
| 104 |
-
'lab_address': datasets.Value(dtype='string'
|
| 105 |
-
'lab_city': datasets.Value(dtype='string'
|
| 106 |
-
'lab_county': datasets.Value(dtype='string'
|
| 107 |
-
'lab_email': datasets.Value(dtype='string'
|
| 108 |
-
'lab_id': datasets.Value(dtype='string'
|
| 109 |
-
'lab_image_url': datasets.Value(dtype='string'
|
| 110 |
-
'lab_latitude': datasets.Value(dtype='float64'
|
| 111 |
-
'lab_license_number': datasets.Value(dtype='string'
|
| 112 |
-
'lab_longitude': datasets.Value(dtype='float64'
|
| 113 |
-
'lab_phone': datasets.Value(dtype='string'
|
| 114 |
-
'lab_results_url': datasets.Value(dtype='string'
|
| 115 |
-
'lab_state': datasets.Value(dtype='string'
|
| 116 |
-
'lab_street': datasets.Value(dtype='string'
|
| 117 |
-
'lab_website': datasets.Value(dtype='string'
|
| 118 |
-
'lab_zipcode': datasets.Value(dtype='int64'
|
| 119 |
-
'lims': datasets.Value(dtype='string'
|
| 120 |
-
'metrc_ids': datasets.Value(dtype='string'
|
| 121 |
-
'metrc_lab_id': datasets.Value(dtype='string'
|
| 122 |
-
'metrc_source_id': datasets.Value(dtype='string'
|
| 123 |
-
'microbes_method': datasets.Value(dtype='string'
|
| 124 |
-
'microbes_status': datasets.Value(dtype='string'
|
| 125 |
-
'moisture_content': datasets.Value(dtype='string'
|
| 126 |
-
'moisture_method': datasets.Value(dtype='string'
|
| 127 |
-
'mycotoxins_method': datasets.Value(dtype='string'
|
| 128 |
-
'mycotoxins_status': datasets.Value(dtype='string'
|
| 129 |
-
'notes': datasets.Value(dtype='string'
|
| 130 |
-
'pesticides_method': datasets.Value(dtype='string'
|
| 131 |
-
'pesticides_status': datasets.Value(dtype='string'
|
| 132 |
-
'producer_address': datasets.Value(dtype='string'
|
| 133 |
-
'producer_city': datasets.Value(dtype='string'
|
| 134 |
-
'producer_image_url': datasets.Value(dtype='string'
|
| 135 |
-
'producer_license_number': datasets.Value(dtype='string'
|
| 136 |
-
'producer_state': datasets.Value(dtype='string'
|
| 137 |
-
'producer_street': datasets.Value(dtype='string'
|
| 138 |
-
'producer_url': datasets.Value(dtype='string'
|
| 139 |
-
'producer_zipcode': datasets.Value(dtype='float64'
|
| 140 |
-
'product_size': datasets.Value(dtype='string'
|
| 141 |
-
'public': datasets.Value(dtype='float64'
|
| 142 |
-
'residual_solvents_method': datasets.Value(dtype='string'
|
| 143 |
-
'residual_solvents_status': datasets.Value(dtype='string'
|
| 144 |
-
'results': datasets.Value(dtype='string'
|
| 145 |
-
'sample_number': datasets.Value(dtype='float64'
|
| 146 |
-
'sample_size': datasets.Value(dtype='string'
|
| 147 |
-
'sampling_method': datasets.Value(dtype='string'
|
| 148 |
-
'serving_size': datasets.Value(dtype='string'
|
| 149 |
-
'status': datasets.Value(dtype='string'
|
| 150 |
-
'sum_of_cannabinoids': datasets.Value(dtype='float64'
|
| 151 |
-
'terpenes_method': datasets.Value(dtype='string'
|
| 152 |
-
'terpenes_status': datasets.Value(dtype='string'
|
| 153 |
-
'total_cannabinoids': datasets.Value(dtype='float64'
|
| 154 |
-
'total_cbc': datasets.Value(dtype='float64'
|
| 155 |
-
'total_cbd': datasets.Value(dtype='float64'
|
| 156 |
-
'total_cbdv': datasets.Value(dtype='float64'
|
| 157 |
-
'total_cbg': datasets.Value(dtype='float64'
|
| 158 |
-
'total_terpenes': datasets.Value(dtype='float64'
|
| 159 |
-
'total_terpenes_mg_g': datasets.Value(dtype='float64'
|
| 160 |
-
'total_thc': datasets.Value(dtype='float64'
|
| 161 |
-
'total_thcv': datasets.Value(dtype='float64'
|
| 162 |
-
'url': datasets.Value(dtype='string'
|
| 163 |
-
'water_activity_method': datasets.Value(dtype='string'
|
| 164 |
-
'water_activity_status': datasets.Value(dtype='string'
|
| 165 |
})
|
| 166 |
-
#
|
| 167 |
-
# '
|
| 168 |
-
#
|
| 169 |
-
|
| 170 |
-
#
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
#
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
# SC Labs constants.
|
| 191 |
-
SCLABS_DATA_URL = 'https://cannlytics.page.link/sclabs'
|
| 192 |
-
SCLABS_URL = 'https://github.com/cannlytics/cannlytics/tree/main/ai/curation/get_sc_labs_data'
|
| 193 |
-
SCLABS_DESCRIPTION = """\
|
| 194 |
-
SC Labs lab test results (https://cannlytics.com/data/tests) is a
|
| 195 |
-
dataset of curated cannabis lab test results from SC Labs, a lab that
|
| 196 |
-
tests cannabis in California.
|
| 197 |
-
"""
|
| 198 |
-
SCLABS_FEATURES = []
|
| 199 |
|
| 200 |
|
| 201 |
class CannabisTestsConfig(datasets.BuilderConfig):
|
|
@@ -203,130 +178,84 @@ class CannabisTestsConfig(datasets.BuilderConfig):
|
|
| 203 |
|
| 204 |
def __init__(
|
| 205 |
self,
|
|
|
|
|
|
|
| 206 |
features,
|
| 207 |
-
data_url,
|
| 208 |
-
citation,
|
| 209 |
-
url,
|
| 210 |
-
label_classes=('False', 'True'),
|
| 211 |
**kwargs
|
| 212 |
):
|
| 213 |
"""BuilderConfig for Cannabis Tests.
|
| 214 |
Args:
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
citation (str): A citation for the data set.
|
| 219 |
-
url (str): A URL for information about the data set.
|
| 220 |
-
label_classes (list[str]): The list of classes for the label if
|
| 221 |
-
the label is present as a string. Non-string labels will be
|
| 222 |
-
cast to either 'False' or 'True'.
|
| 223 |
-
**kwargs: Keyword arguments forwarded to super.
|
| 224 |
"""
|
| 225 |
-
super(CannabisTestsConfig, self).__init__(version=datasets.Version("1.0.2"), **kwargs)
|
| 226 |
self.features = features
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
|
| 233 |
class CannabisTests(datasets.GeneratorBasedBuilder):
|
| 234 |
"""The Cannabis Tests dataset."""
|
| 235 |
|
| 236 |
-
VERSION = datasets.Version(
|
| 237 |
-
|
|
|
|
| 238 |
BUILDER_CONFIGS = [
|
| 239 |
CannabisTestsConfig(
|
| 240 |
-
name='
|
| 241 |
description=RAWGARDEN_DESCRIPTION,
|
| 242 |
features=RAWGARDEN_DETAILS,
|
| 243 |
-
data_url=RAWGARDEN_DETAILS_URL,
|
| 244 |
-
citation=CANNABIS_TESTS_CITATION,
|
| 245 |
-
url=RAWGARDEN_URL,
|
| 246 |
),
|
| 247 |
-
# CannabisTestsConfig(
|
| 248 |
-
# name='rawgarden_results',
|
| 249 |
-
# description=RAWGARDEN_DESCRIPTION,
|
| 250 |
-
# features=RAWGARDEN_RESULTS,
|
| 251 |
-
# data_url=RAWGARDEN_RESULTS_URL,
|
| 252 |
-
# citation=CANNABIS_TESTS_CITATION,
|
| 253 |
-
# url=RAWGARDEN_URL,
|
| 254 |
-
# ),
|
| 255 |
-
# CannabisTestsConfig(
|
| 256 |
-
# name='rawgarden_values',
|
| 257 |
-
# description=RAWGARDEN_DESCRIPTION,
|
| 258 |
-
# features=RAWGARDEN_VALUES,
|
| 259 |
-
# data_url=RAWGARDEN_VALUES_URL,
|
| 260 |
-
# citation=CANNABIS_TESTS_CITATION,
|
| 261 |
-
# url=RAWGARDEN_URL,
|
| 262 |
-
# ),
|
| 263 |
-
# CannabisTestsConfig(
|
| 264 |
-
# name='mcrlabs',
|
| 265 |
-
# description=MCRLABS_DESCRIPTION,
|
| 266 |
-
# features=MCRLABS_FEATURES,
|
| 267 |
-
# data_url=MCRLABS_DATA_URL,
|
| 268 |
-
# citation=CANNABIS_TESTS_CITATION,
|
| 269 |
-
# url=MCRLABS_URL,
|
| 270 |
-
# ),
|
| 271 |
-
# CannabisTestsConfig(
|
| 272 |
-
# name='psilabs',
|
| 273 |
-
# description=PSILABS_DESCRIPTION,
|
| 274 |
-
# features=PSILABS_FEATURES,
|
| 275 |
-
# data_url=PSILABS_DATA_URL,
|
| 276 |
-
# citation=CANNABIS_TESTS_CITATION,
|
| 277 |
-
# url=PSILABS_URL,
|
| 278 |
-
# ),
|
| 279 |
-
# CannabisTestsConfig(
|
| 280 |
-
# name='sclabs',
|
| 281 |
-
# description=SCLABS_DESCRIPTION,
|
| 282 |
-
# features=SCLABS_FEATURES,
|
| 283 |
-
# data_url=SCLABS_DATA_URL,
|
| 284 |
-
# citation=CANNABIS_TESTS_CITATION,
|
| 285 |
-
# url=SCLABS_URL,
|
| 286 |
-
# ),
|
| 287 |
]
|
| 288 |
|
| 289 |
-
DEFAULT_CONFIG_NAME = 'rawgarden_details'
|
| 290 |
-
|
| 291 |
def _info(self):
|
| 292 |
-
# features = {feature: datasets.datasets.Value('string') for feature in self.config.features}
|
| 293 |
-
|
| 294 |
-
# TODO: Define all numeric features.
|
| 295 |
-
# features['span1_index'] = datasets.datasets.Value('int32')
|
| 296 |
-
|
| 297 |
-
# TODO: Define all image features.
|
| 298 |
-
|
| 299 |
-
# TODO: Define all sequence features.
|
| 300 |
-
# features["answers"] = datasets.features.Sequence(
|
| 301 |
-
# {"text": datasets.datasets.Value("string"), "answer_start": datasets.datasets.Value("int32"),}
|
| 302 |
-
# )
|
| 303 |
-
|
| 304 |
return datasets.DatasetInfo(
|
| 305 |
-
|
| 306 |
-
description=CANNABIS_TESTS_DESCRIPTION,
|
| 307 |
-
features=RAWGARDEN_DETAILS,
|
| 308 |
-
homepage=CANNABIS_TESTS_URL,
|
| 309 |
supervised_keys=None,
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
|
| 314 |
-
# def _generate_examples(self, filepath):
|
| 315 |
-
# """This function returns the examples in raw (text) form."""
|
| 316 |
-
# with open(filepath, encoding='utf-8') as f:
|
| 317 |
-
# for line in f:
|
| 318 |
-
# row = json.loads(line)
|
| 319 |
-
# product_name = row.get('product_name', '').strip()
|
| 320 |
-
# for i, result in enumerate(row['results']):
|
| 321 |
-
# _id = str(i)
|
| 322 |
-
# yield _id, {
|
| 323 |
-
# 'product_name': product_name,
|
| 324 |
-
# 'analyte': result.get('key', ''),
|
| 325 |
-
# 'value': result.get('value', 0),
|
| 326 |
-
# }
|
| 327 |
|
|
|
|
| 328 |
|
| 329 |
-
|
| 330 |
|
| 331 |
-
#
|
| 332 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
Keegan Skeate <https://github.com/keeganskeate>
|
| 7 |
Candace O'Sullivan-Sutherland <https://github.com/candy-o>
|
| 8 |
Created: 9/10/2022
|
| 9 |
+
Updated: 9/14/2022
|
| 10 |
License: <https://github.com/cannlytics/cannlytics/blob/main/LICENSE>
|
| 11 |
"""
|
| 12 |
+
import datasets
|
| 13 |
+
import pandas as pd
|
| 14 |
|
| 15 |
+
|
| 16 |
+
# === Constants. ===
|
| 17 |
+
|
| 18 |
+
_VERSION = '1.0.1'
|
| 19 |
+
_HOMEPAGE = 'https://huggingface.co/datasets/cannlytics/cannabis_tests'
|
| 20 |
+
_LICENSE = "https://opendatacommons.org/licenses/by/4-0/"
|
| 21 |
+
_DESCRIPTION = """\
|
| 22 |
+
Cannabis lab test results (https://cannlytics.com/data/tests) is a
|
| 23 |
+
dataset of curated cannabis lab test results.
|
| 24 |
+
"""
|
| 25 |
+
_CITATION = """\
|
| 26 |
@inproceedings{cannlytics2022cannabis_tests,
|
| 27 |
author = {Skeate, Keegan and O'Sullivan-Sutherland, Candace},
|
| 28 |
title = {Cannabis Tests: Curated Cannabis Lab Test Results},
|
|
|
|
| 33 |
publisher = {Cannlytics}
|
| 34 |
}
|
| 35 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
# Raw Garden constants.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
RAWGARDEN_URL = 'https://github.com/cannlytics/cannlytics/tree/main/ai/curation/get_rawgarden_data'
|
| 39 |
+
RAWGARDEN_DATA_URLS = {
|
| 40 |
+
'rawgarden': 'https://cannlytics.page.link/?link=https://firebasestorage.googleapis.com/v0/b/cannlytics.appspot.com/o/data%252Flab_results%252Frawgarden%252Fdetails.csv?alt%3Dmedia%26token%3De5b5273a-049a-4092-98d7-90a62ef399a3',
|
| 41 |
+
# 'rawgarden_details': 'https://cannlytics.page.link/?link=https://firebasestorage.googleapis.com/v0/b/cannlytics.appspot.com/o/data%252Flab_results%252Frawgarden%252Fdetails.csv?alt%3Dmedia%26token%3De5b5273a-049a-4092-98d7-90a62ef399a3',
|
| 42 |
+
# 'rawgarden_results': 'https://cannlytics.page.link/?link=https://firebasestorage.googleapis.com/v0/b/cannlytics.appspot.com/o/data%252Flab_results%252Frawgarden%252Fresults.csv?alt%3Dmedia%26token%3Ddd868e72-edde-4278-9725-b33368a35d54',
|
| 43 |
+
# 'rawgarden_values': 'https://cannlytics.page.link/?link=https://firebasestorage.googleapis.com/v0/b/cannlytics.appspot.com/o/data%252Flab_results%252Frawgarden%252Fvalues.csv?alt%3Dmedia%26token%3D5d427468-c33e-4e45-ae40-efd10fdca644',
|
| 44 |
+
}
|
| 45 |
RAWGARDEN_DESCRIPTION = """\
|
| 46 |
Raw Garden lab test results (https://cannlytics.com/data/tests) is a
|
| 47 |
dataset of curated cannabis lab test results from Raw Garden, a large
|
| 48 |
cannabis processor in California.
|
| 49 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
RAWGARDEN_DETAILS = datasets.Features({
|
| 51 |
+
'sample_hash': datasets.Value(dtype='string'),
|
| 52 |
+
'results_hash': datasets.Value(dtype='string'),
|
| 53 |
+
'sample_id': datasets.Value(dtype='string'),
|
| 54 |
+
'product_name': datasets.Value(dtype='string'),
|
| 55 |
+
'producer': datasets.Value(dtype='string'),
|
| 56 |
+
'product_type': datasets.Value(dtype='string'),
|
| 57 |
+
'product_subtype': datasets.Value(dtype='string'),
|
| 58 |
+
'date_tested': datasets.Value(dtype='string'),
|
| 59 |
+
'analyses': datasets.Value(dtype='string'),
|
| 60 |
+
'batch_number': datasets.Value(dtype='string'),
|
| 61 |
+
'batch_size': datasets.Value(dtype='string'),
|
| 62 |
+
'batch_units': datasets.Value(dtype='string'),
|
| 63 |
+
'cannabinoids_method': datasets.Value(dtype='string'),
|
| 64 |
+
'cannabinoids_status': datasets.Value(dtype='string'),
|
| 65 |
+
'coa_algorithm': datasets.Value(dtype='string'),
|
| 66 |
+
'coa_algorithm_entry_point': datasets.Value(dtype='string'),
|
| 67 |
+
'coa_parsed_at': datasets.Value(dtype='string'),
|
| 68 |
+
'coa_pdf': datasets.Value(dtype='string'),
|
| 69 |
+
'coa_urls': datasets.Value(dtype='string'),
|
| 70 |
+
'date_collected': datasets.Value(dtype='string'),
|
| 71 |
+
'date_produced': datasets.Value(dtype='string'),
|
| 72 |
+
'date_received': datasets.Value(dtype='string'),
|
| 73 |
+
'date_retail': datasets.Value(dtype='string'),
|
| 74 |
+
'delta_9_thc_per_unit': datasets.Value(dtype='string'),
|
| 75 |
+
'distributor': datasets.Value(dtype='string'),
|
| 76 |
+
'distributor_address': datasets.Value(dtype='string'),
|
| 77 |
+
'distributor_city': datasets.Value(dtype='string'),
|
| 78 |
+
'distributor_license_number': datasets.Value(dtype='string'),
|
| 79 |
+
'distributor_state': datasets.Value(dtype='string'),
|
| 80 |
+
'distributor_street': datasets.Value(dtype='string'),
|
| 81 |
+
'distributor_zipcode': datasets.Value(dtype='float64'),
|
| 82 |
+
'foreign_matter_method': datasets.Value(dtype='string'),
|
| 83 |
+
'foreign_matter_status': datasets.Value(dtype='string'),
|
| 84 |
+
'heavy_metals_method': datasets.Value(dtype='string'),
|
| 85 |
+
'heavy_metals_status': datasets.Value(dtype='string'),
|
| 86 |
+
'images': datasets.Value(dtype='string'),
|
| 87 |
+
'lab': datasets.Value(dtype='string'),
|
| 88 |
+
'lab_address': datasets.Value(dtype='string'),
|
| 89 |
+
'lab_city': datasets.Value(dtype='string'),
|
| 90 |
+
'lab_county': datasets.Value(dtype='string'),
|
| 91 |
+
'lab_email': datasets.Value(dtype='string'),
|
| 92 |
+
'lab_id': datasets.Value(dtype='string'),
|
| 93 |
+
'lab_image_url': datasets.Value(dtype='string'),
|
| 94 |
+
'lab_latitude': datasets.Value(dtype='float64'),
|
| 95 |
+
'lab_license_number': datasets.Value(dtype='string'),
|
| 96 |
+
'lab_longitude': datasets.Value(dtype='float64'),
|
| 97 |
+
'lab_phone': datasets.Value(dtype='string'),
|
| 98 |
+
'lab_results_url': datasets.Value(dtype='string'),
|
| 99 |
+
'lab_state': datasets.Value(dtype='string'),
|
| 100 |
+
'lab_street': datasets.Value(dtype='string'),
|
| 101 |
+
'lab_website': datasets.Value(dtype='string'),
|
| 102 |
+
'lab_zipcode': datasets.Value(dtype='int64'),
|
| 103 |
+
'lims': datasets.Value(dtype='string'),
|
| 104 |
+
'metrc_ids': datasets.Value(dtype='string'),
|
| 105 |
+
'metrc_lab_id': datasets.Value(dtype='string'),
|
| 106 |
+
'metrc_source_id': datasets.Value(dtype='string'),
|
| 107 |
+
'microbes_method': datasets.Value(dtype='string'),
|
| 108 |
+
'microbes_status': datasets.Value(dtype='string'),
|
| 109 |
+
'moisture_content': datasets.Value(dtype='string'),
|
| 110 |
+
'moisture_method': datasets.Value(dtype='string'),
|
| 111 |
+
'mycotoxins_method': datasets.Value(dtype='string'),
|
| 112 |
+
'mycotoxins_status': datasets.Value(dtype='string'),
|
| 113 |
+
'notes': datasets.Value(dtype='string'),
|
| 114 |
+
'pesticides_method': datasets.Value(dtype='string'),
|
| 115 |
+
'pesticides_status': datasets.Value(dtype='string'),
|
| 116 |
+
'producer_address': datasets.Value(dtype='string'),
|
| 117 |
+
'producer_city': datasets.Value(dtype='string'),
|
| 118 |
+
'producer_image_url': datasets.Value(dtype='string'),
|
| 119 |
+
'producer_license_number': datasets.Value(dtype='string'),
|
| 120 |
+
'producer_state': datasets.Value(dtype='string'),
|
| 121 |
+
'producer_street': datasets.Value(dtype='string'),
|
| 122 |
+
'producer_url': datasets.Value(dtype='string'),
|
| 123 |
+
'producer_zipcode': datasets.Value(dtype='float64'),
|
| 124 |
+
'product_size': datasets.Value(dtype='string'),
|
| 125 |
+
'public': datasets.Value(dtype='float64'),
|
| 126 |
+
'residual_solvents_method': datasets.Value(dtype='string'),
|
| 127 |
+
'residual_solvents_status': datasets.Value(dtype='string'),
|
| 128 |
+
'results': datasets.Value(dtype='string'),
|
| 129 |
+
'sample_number': datasets.Value(dtype='float64'),
|
| 130 |
+
'sample_size': datasets.Value(dtype='string'),
|
| 131 |
+
'sampling_method': datasets.Value(dtype='string'),
|
| 132 |
+
'serving_size': datasets.Value(dtype='string'),
|
| 133 |
+
'status': datasets.Value(dtype='string'),
|
| 134 |
+
'sum_of_cannabinoids': datasets.Value(dtype='float64'),
|
| 135 |
+
'terpenes_method': datasets.Value(dtype='string'),
|
| 136 |
+
'terpenes_status': datasets.Value(dtype='string'),
|
| 137 |
+
'total_cannabinoids': datasets.Value(dtype='float64'),
|
| 138 |
+
'total_cbc': datasets.Value(dtype='float64'),
|
| 139 |
+
'total_cbd': datasets.Value(dtype='float64'),
|
| 140 |
+
'total_cbdv': datasets.Value(dtype='float64'),
|
| 141 |
+
'total_cbg': datasets.Value(dtype='float64'),
|
| 142 |
+
'total_terpenes': datasets.Value(dtype='float64'),
|
| 143 |
+
'total_terpenes_mg_g': datasets.Value(dtype='float64'),
|
| 144 |
+
'total_thc': datasets.Value(dtype='float64'),
|
| 145 |
+
'total_thcv': datasets.Value(dtype='float64'),
|
| 146 |
+
'url': datasets.Value(dtype='string'),
|
| 147 |
+
'water_activity_method': datasets.Value(dtype='string'),
|
| 148 |
+
'water_activity_status': datasets.Value(dtype='string')
|
| 149 |
})
|
| 150 |
+
# RAWGARDEN_RESULTS = datasets.Features({
|
| 151 |
+
# 'sample_hash': datasets.Value(dtype='string'),
|
| 152 |
+
# 'results_hash': datasets.Value(dtype='string'),
|
| 153 |
+
# 'sample_id': datasets.Value(dtype='string'),
|
| 154 |
+
# 'product_name': datasets.Value(dtype='string'),
|
| 155 |
+
# 'producer': datasets.Value(dtype='string'),
|
| 156 |
+
# 'product_type': datasets.Value(dtype='string'),
|
| 157 |
+
# 'product_subtype': datasets.Value(dtype='string'),
|
| 158 |
+
# 'date_tested': datasets.Value(dtype='string'),
|
| 159 |
+
# 'analysis': datasets.Value(dtype='string'),
|
| 160 |
+
# 'key': datasets.Value(dtype='string'),
|
| 161 |
+
# 'limit': datasets.Value(dtype='double'),
|
| 162 |
+
# 'lod': datasets.Value(dtype='double'),
|
| 163 |
+
# 'lodloq': datasets.Value(dtype='double'),
|
| 164 |
+
# 'loq': datasets.Value(dtype='double'),
|
| 165 |
+
# 'margin_of_error': datasets.Value(dtype='double'),
|
| 166 |
+
# 'mg_g': datasets.Value(dtype='double'),
|
| 167 |
+
# 'name': datasets.Value(dtype='string'),
|
| 168 |
+
# 'status': datasets.Value(dtype='string'),
|
| 169 |
+
# 'units': datasets.Value(dtype='string'),
|
| 170 |
+
# 'value': datasets.Value(dtype='double'),
|
| 171 |
+
# })
|
| 172 |
+
# TODO: Determine standard values?
|
| 173 |
+
# RAWGARDEN_VALUES = datasets.Features({})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
|
| 175 |
|
| 176 |
class CannabisTestsConfig(datasets.BuilderConfig):
|
|
|
|
| 178 |
|
| 179 |
def __init__(
|
| 180 |
self,
|
| 181 |
+
name,
|
| 182 |
+
description,
|
| 183 |
features,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
**kwargs
|
| 185 |
):
|
| 186 |
"""BuilderConfig for Cannabis Tests.
|
| 187 |
Args:
|
| 188 |
+
name (str): Configuration name that determines setup.
|
| 189 |
+
description (str): A description for the configuration.
|
| 190 |
+
**kwargs: Keyword arguments forwarded to super.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
"""
|
|
|
|
| 192 |
self.features = features
|
| 193 |
+
super().__init__(
|
| 194 |
+
name=name,
|
| 195 |
+
description=description,
|
| 196 |
+
**kwargs,
|
| 197 |
+
)
|
| 198 |
|
| 199 |
class CannabisTests(datasets.GeneratorBasedBuilder):
|
| 200 |
"""The Cannabis Tests dataset."""
|
| 201 |
|
| 202 |
+
VERSION = datasets.Version(_VERSION)
|
| 203 |
+
BUILDER_CONFIG_CLASS = CannabisTestsConfig
|
| 204 |
+
DEFAULT_CONFIG_NAME = 'rawgarden'
|
| 205 |
BUILDER_CONFIGS = [
|
| 206 |
CannabisTestsConfig(
|
| 207 |
+
name='rawgarden',
|
| 208 |
description=RAWGARDEN_DESCRIPTION,
|
| 209 |
features=RAWGARDEN_DETAILS,
|
|
|
|
|
|
|
|
|
|
| 210 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
]
|
| 212 |
|
|
|
|
|
|
|
| 213 |
def _info(self):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
return datasets.DatasetInfo(
|
| 215 |
+
features=self.config.features,
|
|
|
|
|
|
|
|
|
|
| 216 |
supervised_keys=None,
|
| 217 |
+
homepage=_HOMEPAGE,
|
| 218 |
+
citation=_CITATION,
|
| 219 |
+
description=_DESCRIPTION,
|
| 220 |
+
license=_LICENSE,
|
| 221 |
+
version=_VERSION,
|
| 222 |
+
)
|
| 223 |
+
|
| 224 |
+
def _split_generators(self, dl_manager):
|
| 225 |
+
"""Returns SplitGenerators."""
|
| 226 |
+
# Future work: Make `urls` source-dynamic based on config,
|
| 227 |
+
# i.e. allow for MCR Labs, SC Labs, etc.
|
| 228 |
+
config_name = self.config.name
|
| 229 |
+
urls = {config_name: RAWGARDEN_DATA_URLS[config_name]}
|
| 230 |
+
downloaded_files = dl_manager.download_and_extract(urls)
|
| 231 |
+
filepath = downloaded_files[config_name]
|
| 232 |
+
return [
|
| 233 |
+
datasets.SplitGenerator(
|
| 234 |
+
name='details',
|
| 235 |
+
gen_kwargs={'filepath': filepath},
|
| 236 |
+
),
|
| 237 |
+
# Future work: Also return `results` and `values`?
|
| 238 |
+
]
|
| 239 |
+
|
| 240 |
+
def _generate_examples(self, filepath):
|
| 241 |
+
"""This function returns the examples in the raw (text) form."""
|
| 242 |
+
with open(filepath) as f:
|
| 243 |
+
df = pd.read_csv(filepath)
|
| 244 |
+
for index, row in df.iterrows():
|
| 245 |
+
if self.config.name.endswith('results'):
|
| 246 |
+
_id = index
|
| 247 |
+
else:
|
| 248 |
+
_id = row['sample_hash']
|
| 249 |
+
obs = row.to_dict()
|
| 250 |
+
yield _id, obs
|
| 251 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
|
| 253 |
+
if __name__ == '__main__':
|
| 254 |
|
| 255 |
+
from datasets import load_dataset
|
| 256 |
|
| 257 |
+
# Download details.
|
| 258 |
+
dataset = load_dataset('cannabis_tests.py', 'rawgarden')
|
| 259 |
+
details = dataset['details']
|
| 260 |
+
assert len(details) > 0
|
| 261 |
+
print('Downloaded %i observations.' % len(details))
|