|
|
|
|
|
|
|
import csv |
|
import os |
|
import datasets |
|
import io |
|
import tarfile |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_DESCRIPTION = """\ |
|
Images taken from the Sage Waggle Node's top camera and the solar irradiance values were taken from the Argonne National Laboratory |
|
tower readings. We made sure to exclude night time photos since there is no sun and we exclusively used summer-time photos as we wanted |
|
to stick to a seasonal model that would be able to make estimates more consistently. Furthermore we also eventually downsized the images |
|
original 2000x2000 images to 500x500 images since the training was taking a bit too long when the images were larger. |
|
""" |
|
_HOMEPAGE = "https://sagecontinuum.org/" |
|
|
|
|
|
_LICENSE = "MIT" |
|
|
|
|
|
|
|
_URLS = "https://web.lcrc.anl.gov/public/waggle/datasets/solar-irradiance-sample-224.tar" |
|
|
|
|
|
class SolarIrradianceDataset(datasets.GeneratorBasedBuilder): |
|
|
|
VERSION = datasets.Version("1.1.0") |
|
|
|
def _info(self): |
|
|
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features= datasets.Features( |
|
{ |
|
"image": datasets.Image(), |
|
"irradiance": datasets.Value("float32") |
|
} |
|
), |
|
|
|
homepage=_HOMEPAGE, |
|
|
|
license=_LICENSE |
|
|
|
|
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
data_dir = dl_manager.download(_URLS) |
|
return [ |
|
datasets.SplitGenerator( |
|
name="full", |
|
|
|
gen_kwargs={ |
|
"files": dl_manager.iter_archive(data_dir) |
|
}, |
|
) |
|
] |
|
|
|
|
|
def _generate_examples(self, files): |
|
|
|
for file_path, file_obj in files: |
|
if ".csv" in file_path: |
|
csv_bytes = file_obj.read() |
|
csv_contents = str(csv_bytes,'UTF-8') |
|
break |
|
|
|
for file_path, file_obj in files: |
|
filename = os.path.basename(file_path) |
|
if ".jpg" in filename: |
|
for row in csv.DictReader(csv_contents.strip().splitlines(),delimiter=','): |
|
if os.path.basename(row['image']) == filename: |
|
yield file_path,{ |
|
"image": {"path": file_path, "bytes": file_obj.read()}, |
|
"irradiance": row['irradiance'] |
|
} |