Roshal commited on
Commit
86e83a7
·
1 Parent(s): d787606

Create dataset.py

Browse files
Files changed (1) hide show
  1. dataset.py +63 -0
dataset.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import pyarrow.parquet as pq
3
+ import datasets
4
+ import pandas as pd
5
+ import numpy as np
6
+ import io
7
+
8
+ class WyvernEOConfig(datasets.BuilderConfig):
9
+ def __init__(self, **kwargs):
10
+ super().__init__(**kwargs)
11
+
12
+ class WyvernEO(datasets.GeneratorBasedBuilder):
13
+ BUILDER_CONFIGS = [
14
+ WyvernEOConfig(name="default", version=datasets.Version("1.0.0"), description="Wyvern EO imagery with masks")
15
+ ]
16
+
17
+ DEFAULT_CONFIG_NAME = "default"
18
+
19
+ def _info(self):
20
+ return datasets.DatasetInfo(
21
+ description="Wyvern dataset at 2400m tiles with imagery and quality masks.",
22
+ features=datasets.Features({
23
+ "tile_id": datasets.Value("string"),
24
+ "scene_id": datasets.Value("string"),
25
+ "start_datetime": datasets.Value("timestamp[us]"),
26
+ "end_datetime": datasets.Value("timestamp[us]"),
27
+ "image": datasets.Value("binary"),
28
+ "data_mask": datasets.Value("binary"),
29
+ "pixel_quality_mask": datasets.Value("binary"),
30
+ "shape": [datasets.Value("int32")],
31
+ }),
32
+ supervised_keys=None,
33
+ )
34
+
35
+ def _split_generators(self, dl_manager):
36
+ # Define relative path inside the repo
37
+ parquet_dir = "datasets_EO/Wyvern/grid_2400m"
38
+ return [
39
+ datasets.SplitGenerator(
40
+ name=datasets.Split.TRAIN,
41
+ gen_kwargs={"folder_path": parquet_dir},
42
+ )
43
+ ]
44
+
45
+ def _generate_examples(self, folder_path):
46
+ idx = 0
47
+ for fname in sorted(os.listdir(folder_path)):
48
+ if fname.endswith(".parquet"):
49
+ fpath = os.path.join(folder_path, fname)
50
+ table = pq.read_table(fpath)
51
+ df = table.to_pandas()
52
+ for _, row in df.iterrows():
53
+ yield idx, {
54
+ "tile_id": row["tile_id"],
55
+ "scene_id": row["scene_id"],
56
+ "start_datetime": row["start_datetime"],
57
+ "end_datetime": row["end_datetime"],
58
+ "image": row["image"],
59
+ "data_mask": row["data_mask"],
60
+ "pixel_quality_mask": row["pixel_quality_mask"],
61
+ "shape": row["shape"],
62
+ }
63
+ idx += 1