|
from pathlib import Path |
|
|
|
import datasets |
|
import numpy as np |
|
from PIL import Image |
|
|
|
project_name = 'xiazeyu/WildfireSimMaps' |
|
|
|
map_names = sorted([x.name for x in Path('dataset').iterdir() if x.is_dir()]) |
|
|
|
_CITATION = """\ |
|
""" |
|
|
|
_DESCRIPTION = 'A real-world dataset for wildfire simulation.' |
|
|
|
_HOMEPAGE = 'https://huggingface.co./datasets/xiazeyu/WildfireSimMaps' |
|
|
|
_LICENSE = 'CC BY-NC 4.0' |
|
|
|
|
|
def load_map(map_name): |
|
map_root = Path('dataset') / map_name |
|
|
|
return {'canopy': np.array(Image.open(map_root / 'canopy.tif')), |
|
'density': np.array(Image.open(map_root / 'density.tif')), |
|
'slope': np.array(Image.open(map_root / 'slope.tif')), } |
|
|
|
|
|
data = {'name': [], 'canopy': [], 'density': [], "slope": [], 'shape': [], } |
|
|
|
for name in map_names: |
|
map_data = load_map(name) |
|
data['name'].append(name) |
|
data['canopy'].append(map_data['canopy'].flatten()) |
|
data['density'].append(map_data['density'].flatten()) |
|
data['slope'].append(map_data['slope'].flatten()) |
|
data['shape'].append(map_data['canopy'].shape) |
|
|
|
features = datasets.Features({'name': datasets.Value('string'), 'canopy': datasets.Sequence(datasets.Value('int8')), |
|
'density': datasets.Sequence(datasets.Value('float32')), |
|
'slope': datasets.Sequence(datasets.Value('int8')), |
|
'shape': datasets.Sequence(datasets.Value('int16'), length=2), }) |
|
data_info = datasets.DatasetInfo(description=_DESCRIPTION, features=features, homepage=_HOMEPAGE, license=_LICENSE, |
|
citation=_CITATION, ) |
|
|
|
ds = datasets.Dataset.from_dict(data, features=features, info=data_info, ) |
|
|
|
ds.VERSION = datasets.Version("1.0.0") |
|
|
|
ds.push_to_hub(project_name) |
|
|