|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""Archival NOAA NWP forecasting data covering most of 2016-2022. """ |
|
import numpy as np |
|
import xarray as xr |
|
import json |
|
|
|
import datasets |
|
|
|
|
|
|
|
_CITATION = """\ |
|
@InProceedings{ocf:gfs, |
|
title = {GFS Forecast Dataset}, |
|
author={Jacob Bieker}, |
|
year={2022} |
|
} |
|
""" |
|
|
|
|
|
_DESCRIPTION = """\ |
|
This dataset consists of various NOAA datasets related to operational forecasts, including FNL Analysis files, |
|
GFS operational forecasts, and the raw observations used to initialize the grid. |
|
""" |
|
|
|
_HOMEPAGE = "https://mtarchive.geol.iastate.edu/" |
|
|
|
_LICENSE = "US Government data, Open license, no restrictions" |
|
|
|
|
|
|
|
_URLS = { |
|
"gfs_v16": "gfs_v16.json", |
|
"raw": "raw.json", |
|
"analysis": "analysis.json", |
|
} |
|
|
|
class GFEReforecastDataset(datasets.GeneratorBasedBuilder): |
|
"""Archival MRMS Precipitation Rate Radar data for the continental US, covering most of 2016-2022.""" |
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig(name="analysis", version=VERSION, description="FNL 0.25 degree Analysis files"), |
|
datasets.BuilderConfig(name="raw_analysis", version=VERSION, description="FNL 0.25 degree Analysis files coupled with raw observations"), |
|
datasets.BuilderConfig(name="gfs_v16", version=VERSION, description="GFS v16 Forecasts from April 2021 through 2022, returned as a 696 channel image"), |
|
datasets.BuilderConfig(name="raw_gfs_v16", version=VERSION, description="GFS v16 Forecasts from April 2021 through 2022, returned as a 696 channel image, coupled with raw observations"), |
|
datasets.BuilderConfig(name="gfs_v16_variables", version=VERSION, description="GFS v16 Forecasts from April 2021 through 2022 with one returned array per variable"), |
|
] |
|
|
|
DEFAULT_CONFIG_NAME = "gfs_v16" |
|
|
|
def _info(self): |
|
features = {} |
|
if "v16" in self.config.name: |
|
|
|
features = { |
|
"current_state": datasets.Array3D((721,1440,696), dtype="float32"), |
|
"next_state": datasets.Array3D((721,1440,696), dtype="float32"), |
|
"timestamp": datasets.Sequence(datasets.Value("timestamp[ns]")), |
|
"latitude": datasets.Sequence(datasets.Value("float32")), |
|
"longitude": datasets.Sequence(datasets.Value("float32")) |
|
|
|
} |
|
elif "analysis" in self.config.name: |
|
|
|
features = { |
|
"current_state": datasets.Array3D((721,1440,322), dtype="float32"), |
|
"next_state": datasets.Array3D((721,1440,322), dtype="float32"), |
|
"timestamp": datasets.Sequence(datasets.Value("timestamp[ns]")), |
|
"latitude": datasets.Sequence(datasets.Value("float32")), |
|
"longitude": datasets.Sequence(datasets.Value("float32")) |
|
|
|
} |
|
if "raw" in self.config.name: |
|
|
|
raw_features = {"observations": datasets.Array2D((256000,1), dtype="float32"), |
|
"observation_type": datasets.Array2D((256000,1), dtype="string"), |
|
"observation_lat": datasets.Array2D((256000,1), dtype="float32"), |
|
"observation_lon": datasets.Array2D((256000,1), dtype="float32"), |
|
} |
|
features = features.update(raw_features) |
|
|
|
features = datasets.Features(features) |
|
|
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=features, |
|
|
|
|
|
|
|
|
|
homepage=_HOMEPAGE, |
|
|
|
license=_LICENSE, |
|
|
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
|
|
|
|
|
|
|
|
|
|
urls = _URLS[self.config.name] |
|
streaming = dl_manager.is_streaming |
|
if streaming: |
|
urls = dl_manager.download_and_extract(urls) |
|
else: |
|
with open(filepath, "r") as f: |
|
filepaths = json.load(f) |
|
data_dir = dl_manager.download_and_extract(filepaths) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"filepath": urls if streaming else data_dir, |
|
"split": "train", |
|
"streaming": streaming, |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
|
|
gen_kwargs={ |
|
"filepath": urls if streaming else data_dir, |
|
"split": "test" |
|
"streaming": streaming, |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
|
|
gen_kwargs={ |
|
"filepath": urls if streaming else data_dir, |
|
"split": "valid", |
|
"streaming": streaming |
|
}, |
|
), |
|
] |
|
|
|
|
|
def _generate_examples(self, filepath, split, streaming): |
|
|
|
|
|
if streaming: |
|
with open(filepath, "r") as f: |
|
filepaths = json.load(f) |
|
filepaths = ['zip:///::https://huggingface.co/datasets/openclimatefix/gfs-reforecast/resolve/main/' + f for f in filepaths] |
|
else: |
|
filepaths = filepath |
|
if "v16" in self.config.name: |
|
idx = 0 |
|
for f in filepaths: |
|
dataset = xr.open_dataset(f, engine='zarr', chunks={}) |
|
try: |
|
for t in range(len(dataset["time"].values)-1): |
|
data_t = dataset.isel(time=t) |
|
data_t1 = dataset.isel(time=(t+1)) |
|
value = {"current_state": np.stack([data_t[v].values for v in sorted(data_t.data_vars)], axis=2), |
|
"next_state": np.stack([data_t1[v].values for v in sorted(data_t.data_vars)], axis=2), |
|
"timestamp": data_t["time"].values, |
|
"latitude": data_t["latitude"].values, |
|
"longitude": data_t["longitude"].values} |
|
idx += 1 |
|
yield idx, value |
|
except: |
|
|
|
continue |
|
|