ecmwf / ecmwf-opendata

A package to download ECMWF open data
Apache License 2.0
174 stars 27 forks source link

Not specifying step will not return all available steps #23

Open notoriusjack opened 1 year ago

notoriusjack commented 1 year ago

According to the documentation, not specifying step should return all available time steps, however if I try to do so I only get back the first time step 0

from ecmwf.opendata import Client
def get_ECMWF_open_data_grib_ensemble(target, stream, param, number):
    try:
        client = Client(source="ecmwf")
        downloaded_file = client.retrieve(
            target = target,
            stream=stream,
            param=param,
            number=number,
        )
        return downloaded_file

    except:
        print('The ECMWF service is not currently available, please try again later')

grib_stream = 'enfo'
grib_format = 'grib2'
grib_target = f'aaa_{grib_stream}.{grib_format}'
grib_param = ["10u", "10v"]
grib_number = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]
grib_file = get_ECMWF_open_data_grib_ensemble(grib_target, grib_stream, grib_param, grib_number)

ds = xr.open_mfdataset(grib_target, engine='cfgrib', parallel=True, chunks={'step': 3, 'number': 3,},
                               backend_kwargs={'filter_by_keys': {'typeOfLevel': 'heightAboveGround', 'topLevel': 10}, })
print(ds)

ensemble = 11 #21
mask = (ds.number.values == ensemble)
xarr = ds.sel(number=mask).squeeze(drop=True)
print('xarr')
print(xarr)

print(xarr.coords['step'].values)
e22tracey commented 5 months ago

I've also come across this issue. Hopefully this comment bumps the issue.