0

Considering a given dataset "data", extracted from a netcdf4 file containing a variable named clcalispo2. I am working with python and f I do:

print(data['clcalipso2'].ncattrs())

I got this output:

clcalipso2 <class 'netCDF4._netCDF4.Variable'>
float32 clcalipso2(levStat, loc)
long_name: CALIPSO Cloud Fraction Undetected by CloudSat
units: %
standard_name: cloud_area_fraction_in_atmosphere_layer
unlimited dimensions:
current shape = (40, 153)
filling on, default _FillValue of 9.969209968386869e+36 used

I can easily extract the field attribute by doing:

print(data['clcalipso2'].ncattrs())

which yields:

['long_name', 'units', 'standard_name']

But me I am actually interested in extracting the variable dimension name, in this example: (levStat, loc). There is a simple way to do it (appart than using the output as a string and doing some string manipulations?)

Thanks in advance for the help

vincent
  • 11
  • 3

2 Answers2

1

I found the soluition, I am posting it here in case that may be useful for somebody else:

print(data['clcalipso2'].dimensions)

yields

(levStat, loc)
vincent
  • 11
  • 3
0

Note, I came to this looking for a different answer, "what are the dimensions of a netcdf variable?"

Found that if I have a netcdf class where I loaded the u and v wind component (with the dimensions of (longitude, latitude, level, time).

I wanted to know that its dimension was 4.

This worked print(nc.variables['u'].ndim)

  • Please use code formatting for better readability – benicamera Oct 04 '22 at 07:38
  • If you have a new question, please ask it by clicking the [Ask Question](https://stackoverflow.com/questions/ask) button. Include a link to this question if it helps provide context. - [From Review](/review/late-answers/32836915) – Arusekk Oct 06 '22 at 13:57