Fix a Not Defined Variable `filepath` in streaming=False mode, and reshape ndim of timestamp from 0 to 1

#5
Files changed (1) hide show
  1. gfs-reforecast.py +13 -2
gfs-reforecast.py CHANGED
@@ -72,6 +72,17 @@ class GFEReforecastDataset(datasets.GeneratorBasedBuilder):
72
 
73
  DEFAULT_CONFIG_NAME = "gfs_v16" # It's not mandatory to have a default configuration. Just use one if it make sense.
74
 
 
 
 
 
 
 
 
 
 
 
 
75
  def _info(self):
76
  features = {}
77
  if "v16" in self.config.name:
@@ -133,7 +144,7 @@ class GFEReforecastDataset(datasets.GeneratorBasedBuilder):
133
  if streaming:
134
  urls = dl_manager.download_and_extract(urls)
135
  else:
136
- with open(filepath, "r") as f:
137
  filepaths = json.load(f)
138
  data_dir = dl_manager.download_and_extract(filepaths)
139
  return [
@@ -186,7 +197,7 @@ class GFEReforecastDataset(datasets.GeneratorBasedBuilder):
186
  data_t1 = dataset.isel(time=(t+1))
187
  value = {"current_state": np.stack([data_t[v].values for v in sorted(data_t.data_vars)], axis=2),
188
  "next_state": np.stack([data_t1[v].values for v in sorted(data_t.data_vars)], axis=2),
189
- "timestamp": data_t["time"].values,
190
  "latitude": data_t["latitude"].values,
191
  "longitude": data_t["longitude"].values}
192
  idx += 1
 
72
 
73
  DEFAULT_CONFIG_NAME = "gfs_v16" # It's not mandatory to have a default configuration. Just use one if it make sense.
74
 
75
+ def __init__(self, filepath="https://huggingface.co/datasets/openclimatefix/gfs-reforecast/resolve/main/gfs_v16.json", **kwargs):
76
+ """BuilderConfig for GFEReforecastDataset.
77
+
78
+ Args:
79
+ filepath: *string*, the path of a json file, which consists of the relative path of https://huggingface.co/datasets/openclimatefix/gfs-reforecast
80
+ to the data files we want to load, default = "https://huggingface.co/datasets/openclimatefix/gfs-reforecast/resolve/main/gfs_v16.json"
81
+ **kwargs: keyword arguments forwarded to super.
82
+ """
83
+ super().__init__(version=datasets.Version("1.0.0"), **kwargs)
84
+ self.filepath = filepath
85
+
86
  def _info(self):
87
  features = {}
88
  if "v16" in self.config.name:
 
144
  if streaming:
145
  urls = dl_manager.download_and_extract(urls)
146
  else:
147
+ with open(self.filepath, "r") as f:
148
  filepaths = json.load(f)
149
  data_dir = dl_manager.download_and_extract(filepaths)
150
  return [
 
197
  data_t1 = dataset.isel(time=(t+1))
198
  value = {"current_state": np.stack([data_t[v].values for v in sorted(data_t.data_vars)], axis=2),
199
  "next_state": np.stack([data_t1[v].values for v in sorted(data_t.data_vars)], axis=2),
200
+ "timestamp": data_t["time"].values.reshape(-1),
201
  "latitude": data_t["latitude"].values,
202
  "longitude": data_t["longitude"].values}
203
  idx += 1