Hi CMS Helpdesk:
I am trying to do a global land-only area-weighted average with CF Python of a field that is a 1D land-only array (instead of 2D). I’m using a script that Andy Heaps made to get these in the right 1D format instead of the 1D format that jules makes. But I get an error when I try to do this in CF Python. Can you advise me on this? See below.
Patrick
On Jasmin, I do this:
module load jaspy
python ~pmcguire/from_andyh/cf1dland_v1.py ~pmcguire/for_andyh/JULES2013.nc
cp -p converted.nc ~pmcguire/for_andyh/converted.nc
python
import cf
xx=cf.read(‘~pmcguire/for_andyh/converted.nc’)
xx[0]
<CF Field: long_name=Gridbox surface temperature(time(1), latitude(112), longitude(192)) K>
print(xx[0])
Field: long_name=Gridbox surface temperature (ncvar%Ts)
Data : long_name=Gridbox surface temperature(time(1), latitude(112), longitude(192)) K
Cell methods : time : mean
Dimension coords: time(1) = [2014-01-01 00:00:00] 365_day
: latitude(112) = [-55.625, …, 83.125] degrees_north
: longitude(192) = [0.9375, …, 359.0625] degrees_east
print(xx[0].collapse(‘mean’,axes=‘area’,measure=‘true’).array)
[[[281.92977735622253]]] #this seems right for Kelvin, but it isn’t area-weighted.
But when I try to do an area-weighted average, I get this error.
print(xx[0].collapse(‘mean’,axes=‘area’,measure=‘true’,weights=‘area’).array)
Traceback (most recent call last):
File “”, line 1, in
File “/home/users/pmcguire/.local/lib/python3.10/site-packages/cf/decorators.py”, line 71, in precede_with_kwarg_deprecation_check
operation_method_result = operation_method(self, *args, **kwargs)
File “/home/users/pmcguire/.local/lib/python3.10/site-packages/cfdm/decorators.py”, line 171, in verbose_override_wrapper
return method_with_verbose_kwarg(*args, **kwargs)
File “/home/users/pmcguire/.local/lib/python3.10/site-packages/cf/field.py”, line 8016, in collapse
d_weights = f.weights(
File “/home/users/pmcguire/.local/lib/python3.10/site-packages/cf/field.py”, line 4923, in weights
self._weights_geometry_area(
File “/home/users/pmcguire/.local/lib/python3.10/site-packages/cf/field.py”, line 2237, in _weights_geometry_area
axis, aux_X, aux_Y, aux_Z = self._weights_yyy(
File “/home/users/pmcguire/.local/lib/python3.10/site-packages/cf/field.py”, line 3036, in _weights_yyy
raise ValueError(
ValueError: Can’t create weights: Need both X and Y nodes to calculate polygon geometry weights