Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit 9bf8cdd

Browse files
Merge pull request #639 from openclimatefix/batch-fix
dont error on first batch - this is when the batches are shuffled
2 parents 6509d83 + 43bd4f8 commit 9bf8cdd

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

nowcasting_dataset/dataset/batch.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,32 @@ def load_netcdf(
159159
metadata = load_from_csv(path=local_netcdf_path, batch_size=batch_size, batch_idx=batch_idx)
160160
batch_dict["metadata"] = metadata.dict()
161161

162+
# quick options to turn on when using legacy data e.g v15
163+
legacy_data = False
164+
if legacy_data:
165+
# legacy GSP
166+
if "gsp" in batch_dict.keys():
167+
batch_dict["gsp"] = batch_dict["gsp"].rename(
168+
{"x_coords": "x_osgb", "y_coords": "y_osgb"}
169+
)
170+
171+
# legacy PV
172+
if "pv" in batch_dict.keys():
173+
batch_dict["pv"] = batch_dict["pv"].rename(
174+
{"x_coords": "x_osgb", "y_coords": "y_osgb"}
175+
)
176+
177+
# legacy NWP
178+
if "nwp" in batch_dict.keys():
179+
batch_dict["nwp"] = batch_dict["nwp"].rename(
180+
{
181+
"x_index": "x_osgb_index",
182+
"y_index": "y_osgb_index",
183+
"x": "x_osgb",
184+
"y": "y_osgb",
185+
}
186+
)
187+
162188
try:
163189
batch = Batch(**batch_dict)
164190
except Exception as e:
@@ -191,7 +217,7 @@ def download_batch_and_load_batch(
191217

192218
if batch_idx == 0:
193219
for data_source in data_sources_names:
194-
os.makedirs(f"{tmp_path}/{data_source}")
220+
os.makedirs(f"{tmp_path}/{data_source}", exist_ok=True)
195221

196222
# download all data files
197223
for data_source in data_sources_names:

0 commit comments

Comments
 (0)