Datasets:

DOI:
License:

streaming

#10
by partiboi69 - opened

I was trying to find a way to download the data for a given day with a script. I was wondering if you have a demo script for this since I found it quite tricky to do. The ideal solution would be to be able to access only some of the variables in the the zarr files by streaming them as described here: https://github.com/huggingface/datasets/issues/4096
Unfortunately I could not run any of the code in this github issue, I thought maybe you could point me to a script you already have to do this.

partiboi69 changed discussion status to closed
partiboi69 changed discussion status to open
Open Climate Fix org

Hi @partiboi69 ,

Unfortunately, HF streaming is currently unavailable for most of our datasets, as it requires a processing script like this one which most of our datasets lack. xr.open_dataset() by URL most likely gets tripped up by authentication, as dwd-icon-eu requires you to be logged in to use (setting up .netrc, .dodsrc and .cookie files might solve this if you want to give it a try, but I haven't tried that. You can see a bit more here).

As for downloading data for a given day, something like this should work for you:
huggingface-cli download openclimatefix/dwd-icon-eu --repo-type dataset --include "data/2023/12/17/20231217*.zarr.zip"

Open Climate Fix org

If you are logged in, you should be able to use the HF Filesystem API to stream in the data (https://huggingface.co/docs/huggingface_hub/main/en/guides/hf_file_system) as it is the same fsspec compatible interface that Xarray uses. The dataset scripts in some of our repos should give a good starting point for that. I can also add an example one here as well, to enable streaming, as it is a lot of data that is available.

Open Climate Fix org
edited Sep 16

Thanks for the tip @jacobbieker :)

@partiboi69 so this seems to work:

import xarray as xr
import ocf_blosc2
from huggingface_hub import HfFileSystem

fs = HfFileSystem()

url = "datasets/openclimatefix/dwd-icon-eu/data/2021/11/10/*.zarr.zip"
zarr_paths = ["zip:///::hf://"+s for s in fs.glob(url)]
xr.open_mfdataset(zarr_paths, engine="zarr", combine="nested", concat_dim="time")

(you can open more files by wildcarding the day dir etc; this is still lazy but will take a while to open, the example above opens in just under 14 secs and that's just 4 files)

NB: you have to call fs.glob() on your wildcard beforehand because xarray struggles to resolve both zip and hf prepends under the hood and returns an empty list

@AUdaltsova @jacobbieker that works!! thanks a lot!

AUdaltsova changed discussion status to closed
AUdaltsova changed discussion status to open
AUdaltsova changed discussion title from sreaming to streaming

Sign up or log in to comment