xarray icon indicating copy to clipboard operation
xarray copied to clipboard

Loading icon-d2

Open RafaelAbel opened this issue 1 year ago • 3 comments

What is your issue?

Hej Everybody (Hi Julius :) ), we are using the DWD Icon models a lot, but I currently have the issue loading files with 'generalVerticalLayer', which is their description for a vertical axis. It seems to me, that xarray is not recognizing it as a coordinate.

cfgrib 0.9.8.5 xarray 0.19.0

import xarray as xr

file_list = ['icon-d2_germany_regular-lat-lon_model-level_2022052303_000_59_u.grib2',
        'icon-d2_germany_regular-lat-lon_model-level_2022052303_000_64_u.grib2']

ds = xr.open_dataset(file_list, engine='cfgrib')
ValueError: Could not find any dimension coordinates to use to order the datasets for concatenation

Find the data attached: icon-d2_germany_regular-lat-lon_model-level_2022052303_000_u.zip

RafaelAbel avatar Aug 12 '22 09:08 RafaelAbel

ds = xr.open_mfdataset(file_list, engine='cfgrib', combine="nested", concat_dim="generalVerticalLayer")

kmuehlbauer avatar Aug 12 '22 09:08 kmuehlbauer

Thanks for your help, Kai. I have a follow-up question:

What about when I have multiple timesteps...

import xarray as xr
import glob

file_list = glob.glob(target_dir + '*.grib2')

ds = xr.open_mfdataset(file_list, engine='cfgrib', combine="nested", concat_dim="generalVerticalLayer")

It does load the data, but it does not get the dimensions right. Note that I attached a new dataset, which in the end should have the dimensions lon, lat, vertical and time.

Thanks for your help!

icon-d2_germany_regular-lat-lon_model-level_u.zip

RafaelAbel avatar Aug 12 '22 10:08 RafaelAbel

This would be not as easy.

If you want to stick with a single line of code you would need to feed a nested list:

[[t0_f0, t0_f1, ...], [t1_f0, t1_f1, ...], [...]].

ds = xr.open_mfdataset(file_list, engine='cfgrib', combine="nested", concat_dim=["time", "generalVerticalLayer"], coords="minimal", compat="override") But note that it will take some coordinates from the first timestep only (eg. valid_time).

This might work without coords="minimal", compat="override", if you provide equivalent layers for each timestep.

You can break this into pieces:

d0 = xr.open_mfdataset(file_list[0], engine='cfgrib', combine="nested", concat_dim="generalVerticalLayer")
d1 = xr.open_mfdataset(file_list[1], engine='cfgrib', combine="nested", concat_dim="generalVerticalLayer")
ds = xr.concat([ds1, ds2], dim="time")

I'm not sure if there is an incantation to get it work with a oneliner, but others might know.

kmuehlbauer avatar Aug 12 '22 12:08 kmuehlbauer