[Python] Getting [Errno 22] Invalid argument when trying to access data variables

Discussão em 'Python' iniciado por Stack, Março 23, 2025.

  1. Stack

    Stack Membro Participativo

    I have a grib file containing reanalysis (an), ensemble mean (em), and ensemble spread (es) data. The dataset I access is the analysis data,

    import xarray as xr
    import cfgrib
    file = 'C:/Users/Downloads/04292020_rean_ensmean_ensspread.grib'
    ds = xr.open_dataset(file,engine = "cfgrib",filter_by_keys={'dataType': 'an'}) # an accesses analysis data

    time = 5;
    res = 2; #2 = half degree
    [phi,theta] = np.meshgrid(ds.variables['longitude'][::res].values,ds.variables['latitude'][::res].values)
    divergence = ds.variables['d'][time,:,::res,::res].values


    I'm able to access longitude and latitude values just fine, but if I try to access one of the field variable's values like divergence, it returns this error every time. Here's the head data assuming it's useful:

    # <bound method Dataset.head of <xarray.Dataset> Size: 20GB
    # Dimensions: (time: 16, isobaricInhPa: 23, latitude: 721, longitude: 1440)
    # Coordinates:
    # number int32 4B ...
    # * time (time) datetime64[ns] 128B 2020-04-29 ... 2020-04-29T23:00:00
    # step timedelta64[ns] 8B ...
    # * isobaricInhPa (isobaricInhPa) float64 184B 1e+03 975.0 ... 225.0 200.0
    # * latitude (latitude) float64 6kB 90.0 89.75 89.5 ... -89.5 -89.75 -90.0
    # * longitude (longitude) float64 12kB 0.0 0.25 0.5 ... 359.2 359.5 359.8
    # valid_time (time) datetime64[ns] 128B ...
    # Data variables: (12/13)
    # d (time, isobaricInhPa, latitude, longitude) float32 2GB ...
    # cc (time, isobaricInhPa, latitude, longitude) float32 2GB ...
    # z (time, isobaricInhPa, latitude, longitude) float32 2GB ...
    # pv (time, isobaricInhPa, latitude, longitude) float32 2GB ...
    # r (time, isobaricInhPa, latitude, longitude) float32 2GB ...
    # clwc (time, isobaricInhPa, latitude, longitude) float32 2GB ...
    # ...
    # crwc (time, isobaricInhPa, latitude, longitude) float32 2GB ...
    # t (time, isobaricInhPa, latitude, longitude) float32 2GB ...
    # u (time, isobaricInhPa, latitude, longitude) float32 2GB ...
    # v (time, isobaricInhPa, latitude, longitude) float32 2GB ...
    # w (time, isobaricInhPa, latitude, longitude) float32 2GB ...
    # vo (time, isobaricInhPa, latitude, longitude) float32 2GB ...
    # Attributes:
    # GRIB_edition: 1
    # GRIB_centre: ecmf
    # GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
    # GRIB_subCentre: 0
    # Conventions: CF-1.7
    # institution: European Centre for Medium-Range Weather Forecasts
    # history: 2025-03-23T18:13 GRIB to CDM+CF via cfgrib-0.9.1...>

    Continue reading...

Compartilhe esta Página