Geoweaver commited on
Commit
fa624b2
·
verified ·
1 Parent(s): bbbdc3f

Create SnowWaterEquivalent_trainingdata.py

Browse files
Files changed (1) hide show
  1. SnowWaterEquivalent_trainingdata.py +79 -0
SnowWaterEquivalent_trainingdata.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import datasets
3
+
4
+ class SnowWaterEquivalentDataset(datasets.GeneratorBasedBuilder):
5
+ VERSION = datasets.Version("1.0.0")
6
+ BUILDER_CONFIGS = [
7
+ datasets.BuilderConfig(
8
+ name="default",
9
+ version=VERSION,
10
+ description="Default configuration for the SWE dataset."
11
+ )
12
+ ]
13
+
14
+ DEFAULT_CONFIG_NAME = "default"
15
+
16
+ _URL = "https://huggingface.co/datasets/Geoweaver/SnowWaterEquivalent_trainingdata"
17
+ _URLS = {
18
+ "train": _URL + "training_data.csv",
19
+ }
20
+
21
+ def _info(self):
22
+ return datasets.DatasetInfo(
23
+ description="Snow Water Equivalent dataset for climate and hydrological analysis.",
24
+ features=datasets.Features({ # load the features based on requirements
25
+ "date": datasets.Value("string"),
26
+ "lat": datasets.Value("float64"),
27
+ "lon": datasets.Value("float64"),
28
+ "SWE": datasets.Value("float64"),
29
+ "air_temperature_tmmn": datasets.Value("float64"),
30
+ "precipitation_amount": datasets.Value("float64"),
31
+ "relative_humidity_rmax": datasets.Value("float64"),
32
+ "relative_humidity_rmin": datasets.Value("float64"),
33
+ "wind_speed": datasets.Value("float64"),
34
+ "fsca": datasets.Value("float64"),
35
+ "cumulative_SWE": datasets.Value("float64"),
36
+ "station_name": datasets.Value("string"),
37
+ "Elevation": datasets.Value("float64"),
38
+ }),
39
+ supervised_keys=None,
40
+ homepage="https://huggingface.co/datasets/Geoweaver/SnowWaterEquivalent_trainingdata",
41
+ citation="""@misc {geoweaver_2025,
42
+ author = { {Geoweaver} },
43
+ title = { SnowWaterEquivalent_trainingdata},
44
+ year = 2025,
45
+ url = { https://huggingface.co/datasets/Geoweaver/SnowWaterEquivalent_trainingdata },
46
+ doi = { 10.57967/hf/4179 },
47
+ publisher = { Hugging Face }
48
+ }""",
49
+ )
50
+
51
+ def _split_generators(self, dl_manager: datasets.DownloadManager):
52
+ downloaded_files = dl_manager.download_and_extract(self._URLS)
53
+ return [
54
+ datasets.SplitGenerator(
55
+ name=datasets.Split.TRAIN,
56
+ gen_kwargs={"filepath": downloaded_files["train"]},
57
+ ),
58
+ ]
59
+
60
+ def _generate_examples(self, filepath):
61
+ with open(filepath, "r", encoding="utf-8") as f:
62
+ reader = csv.DictReader(f)
63
+ for idx, row in enumerate(reader):
64
+ yield idx, row
65
+ yield idx, {
66
+ "date": data["date"],
67
+ "lat": data["lat"],
68
+ "lon": data["lon"],
69
+ "SWE": data.get("SWE", None),
70
+ "air_temperature_tmmn": data.get("air_temperature_tmmn", None),
71
+ "precipitation_amount": data.get("precipitation_amount", None),
72
+ "relative_humidity_rmax": data.get("relative_humidity_rmax", None),
73
+ "relative_humidity_rmin": data.get("relative_humidity_rmin", None),
74
+ "wind_speed": data.get("wind_speed", None),
75
+ "fsca": data.get("fsca", None),
76
+ "cumulative_SWE": data.get("cumulative_SWE", None),
77
+ "station_name": data.get("station_name", "Unknown"),
78
+ "Elevation": data.get("Elevation", None),
79
+ }