Skip to content

Commit

Permalink
geometry spherical polygon weights
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhassell committed Sep 28, 2023
1 parent a7ce7b3 commit 726223e
Show file tree
Hide file tree
Showing 3 changed files with 490 additions and 210 deletions.
2 changes: 1 addition & 1 deletion cf/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def __init__(
copy=True,
dtype=None,
mask=None,
masked_values=None,
masked_values=None,
to_memory=False,
init_options=None,
_use_array=True,
Expand Down
58 changes: 34 additions & 24 deletions cf/test/test_weights.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,51 @@
import numpy as np
import cf

f = cf.example_field(6)
f.del_construct('auxiliarycoordinate3')
f.del_construct('grid_mapping_name:latitude_longitude')
f.del_construct("auxiliarycoordinate3")
f.del_construct("grid_mapping_name:latitude_longitude")
g = f.copy()
g.dump()


lon = cf.AuxiliaryCoordinate()
lon.standard_name = 'longitude'
bounds = cf.Data([
[315, 45, 45, 315, 999,999,999,999],
[90 , 0, 0, 45, 75, 135, 90, 0]

], 'degrees_east', masked_values=999).reshape(2, 1, 8)
lon.standard_name = "longitude"
bounds = cf.Data(
[[315, 45, 45, 315, 999, 999, 999], [90, 90, 0, 45, 45, 135, 90]],
"degrees_east",
masked_values=999,
).reshape(2, 1, 7)
lon.set_bounds(cf.Bounds(data=bounds))
lon.set_geometry('polygon')
lon.set_geometry("polygon")

lat = cf.AuxiliaryCoordinate()
lat.standard_name = 'latitude'
bounds = cf.Data([
[0, 0, 90, 0,999,999,999,999],
[0 , 90, 0, 0, -90, 0, 0, 90]

], 'degrees_north', masked_values=999).reshape(2, 1, 8)
lat.standard_name = "latitude"
bounds = cf.Data(
[[0, 0, 90, 0, 999, 999, 999], [0, 90, 0, 0, -90, 0, 0]],
"degrees_north",
masked_values=999,
).reshape(2, 1, 7)
lat.set_bounds(cf.Bounds(data=bounds))
lat.set_geometry('polygon')
lat.set_geometry("polygon")
lon.dump()
f.del_construct('longitude')
f.del_construct('latitude')
f.del_construct("longitude")
f.del_construct("latitude")

#f.dump()
f.set_construct(lon, axes='domainaxis0')
f.set_construct(lat, axes='domainaxis0')
print (f.constructs)
# f.dump()
f.set_construct(lon, axes="domainaxis0")
f.set_construct(lat, axes="domainaxis0")
print(f.constructs)

f.dump()

sphere_area = 4 * np.pi


w = f.weights('X', great_circle=True)
print (repr(w), w.array, np.array([sphere_area/8, sphere_area/4]))

print (w.array == np.array([sphere_area/8, sphere_area/4]))

w = f.weights('X', great_circle=True, measure=True, radius = 2)
print (repr(w), w.array, 4* np.array([sphere_area/8, sphere_area/4]))

f.collapse('X: mean', verbose=-1, weights=True, great_circle=True)
print (w.array - 4 * np.array([sphere_area/8, sphere_area/4]))
Loading

0 comments on commit 726223e

Please sign in to comment.