xiazeyu commited on
Commit
468d79c
1 Parent(s): 89a31b6

Add conversion script

Browse files
Files changed (1) hide show
  1. script.py +50 -0
script.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+
3
+ import datasets
4
+ import numpy as np
5
+ from PIL import Image
6
+
7
+ project_name = 'xiazeyu/WildfireSimMaps'
8
+
9
+ map_names = sorted([x.name for x in Path('dataset').iterdir() if x.is_dir()])
10
+
11
+ _CITATION = """\
12
+ """
13
+
14
+ _DESCRIPTION = 'A real-world dataset for wildfire simulation.'
15
+
16
+ _HOMEPAGE = 'https://huggingface.co/datasets/xiazeyu/WildfireSimMaps'
17
+
18
+ _LICENSE = 'CC BY-NC 4.0'
19
+
20
+
21
+ def load_map(map_name):
22
+ map_root = Path('dataset') / map_name
23
+
24
+ return {'canopy': np.array(Image.open(map_root / 'canopy.tif')),
25
+ 'density': np.array(Image.open(map_root / 'density.tif')),
26
+ 'slope': np.array(Image.open(map_root / 'slope.tif')), }
27
+
28
+
29
+ data = {'name': [], 'canopy': [], 'density': [], "slope": [], 'shape': [], }
30
+
31
+ for name in map_names:
32
+ map_data = load_map(name)
33
+ data['name'].append(name)
34
+ data['canopy'].append(map_data['canopy'].flatten())
35
+ data['density'].append(map_data['density'].flatten())
36
+ data['slope'].append(map_data['slope'].flatten())
37
+ data['shape'].append(map_data['canopy'].shape)
38
+
39
+ features = datasets.Features({'name': datasets.Value('string'), 'canopy': datasets.Sequence(datasets.Value('int8')),
40
+ 'density': datasets.Sequence(datasets.Value('float32')),
41
+ 'slope': datasets.Sequence(datasets.Value('int8')),
42
+ 'shape': datasets.Sequence(datasets.Value('int16'), length=2), })
43
+ data_info = datasets.DatasetInfo(description=_DESCRIPTION, features=features, homepage=_HOMEPAGE, license=_LICENSE,
44
+ citation=_CITATION, )
45
+
46
+ ds = datasets.Dataset.from_dict(data, features=features, info=data_info, )
47
+
48
+ ds.VERSION = datasets.Version("1.0.0")
49
+
50
+ ds.push_to_hub(project_name)