Hi,
I agree, again the NetCDF files are wrong.
Reproducing the error:
import os
import tempfile
import xarray as xr
import cdsapi
from common_library.secrets import DictSecretHandler
CDSAPI_URL = 'https://cds.climate.copernicus.eu/api/v2'
CDSAPI_TIMEOUT_IN_SECONDS = 600
CDSAPI_MAX_VARIABLES_SINGLE_REQUEST = 8
secret = DictSecretHandler(os.environ.get('CDSAPI_SECRET_ID'), 'uid', 'api_key')
api_key = f'{secret.username}:{secret.password}'
request = {
'variable': ['2m_temperature', '10m_v_component_of_wind', '10m_u_component_of_wind', '100m_u_component_of_wind',
'100m_v_component_of_wind'],
'product_type': 'reanalysis',
'year': ['2024'],
'month': ['4'],
'day': ['13'],
'time': ['00:00', '01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '08:00', '09:00', '10:00', '11:00',
'12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00', '21:00', '22:00',
'23:00']}
with tempfile.TemporaryDirectory() as tmpdir:
cdsapi_client = cdsapi.Client(key=api_key, url=CDSAPI_URL, verify=0, wait_until_complete=True,
timeout=CDSAPI_TIMEOUT_IN_SECONDS)
cdsapi_client.retrieve(
'reanalysis-era5-single-levels',
{
**request,
'format': 'netcdf',
},
f'{tmpdir}/download.nc')
cdsapi_client.retrieve(
'reanalysis-era5-single-levels',
{
**request,
'format': 'grib'
},
f'{tmpdir}/download.grib')
print('open files')
nc_file = xr.open_dataset(f'{tmpdir}/download.nc')
grib_file = xr.open_dataset(f'{tmpdir}/download.grib', engine='cfgrib')
for label, data in [('netcdf', nc_file), ('grib', grib_file)]:
print('*'*50)
print(f'{label}: filter for all timestamps greater than the first timestamp in the dataset')
sub_file = data.where(data.time > data.time.values[0], drop=True)
# Check for any variation on temperature
print(f'{label}: min={data.t2m.min().values.squeeze().tolist()}, max={data.t2m.max().values.squeeze().tolist()}')
# Check for any variation for lat/lon of London
ldn = data.where((data.latitude == 51.5) & (data.longitude == 0), drop=True)
print(f'{label}: London Today={ldn.t2m.values.squeeze().tolist()}\n')
Output:
**************************************************
netcdf: filter for all timestamps greater than the first timestamp in the dataset
netcdf: min=-19.75750732421875, max=23.306658803851832
netcdf: London Today=[3.4316706415036435, 3.4316706415036435, 3.4316706415036435, 3.4316706415036435, 3.4316706415036435, 3.4316706415036435, 3.4316706415036435, 3.4316706415036435, 3.4316706415036435, 3.4316706415036435, 3.4316706415036435, 3.4316706415036435, 3.4316706415036435, 3.4316706415036435, 3.4316706415036435, 3.4316706415036435, 3.4316706415036435, 3.4316706415036435, 3.4316706415036435, 3.4316706415036435, 3.4316706415036435, 3.4316706415036435, 3.4316706415036435]
**************************************************
grib: filter for all timestamps greater than the first timestamp in the dataset
grib: min=204.82492065429688, max=318.05517578125
grib: London Today=[284.96112060546875, 284.63232421875, 284.28533935546875, 284.16351318359375, 284.24078369140625, 284.4186706542969, 285.5191650390625, 286.7073974609375, 287.9845886230469, 289.4714050292969, 290.4076843261719, 291.31036376953125, 291.82720947265625, 291.900634765625, 291.72698974609375, 291.271484375, 290.62744140625, 289.7354736328125, 288.738037109375, 287.45587158203125, 286.1479797363281, 284.7046203613281, 284.1304931640625]