You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Topology objects are currently propagated through operations. This is desirable, since their size can be relatively large, and we would be copying quite a lot of data potentially.
However, it means that "action at a distance" may give unexpected results: when changing some UgridDataArray b, where b is derived from a (through e.g. full_like), a is changed as well.
The easiest solution to this is to make the grid topology objects as immutable as possible. We should shield attributes such as node_x and node_y, and make them properties instead (like most of the other attributes).
To support transformations of the geometry (which is currently technically possible through mutation), we should implement specific methods instead which return a new object.
set_crs should also be updated, since it currently mutates (something I wasn't sure about, it matches geopandas...)
There might be some other methods which actually mutate.
The text was updated successfully, but these errors were encountered:
I think I'd suggest adding the following method to AbstractUgrid:
@staticmethoddef_immutable_array_view(array: np.ndarray) ->np.ndarray:
""" Let's look at the following example, where face_x is a property returning a view on a numpy array: >>> grid.face_x -= 10.0 This fails, since the face_x property does not have a setter. However, the minus operation does work. So the operation fails halfway. """array=array.view()
array.flags.writeable=Falsereturnarray
Topology objects are currently propagated through operations. This is desirable, since their size can be relatively large, and we would be copying quite a lot of data potentially.
However, it means that "action at a distance" may give unexpected results: when changing some UgridDataArray
b
, whereb
is derived froma
(through e.g.full_like
),a
is changed as well.The easiest solution to this is to make the grid topology objects as immutable as possible. We should shield attributes such as node_x and node_y, and make them properties instead (like most of the other attributes).
To support transformations of the geometry (which is currently technically possible through mutation), we should implement specific methods instead which return a new object.
set_crs
should also be updated, since it currently mutates (something I wasn't sure about, it matches geopandas...)There might be some other methods which actually mutate.
The text was updated successfully, but these errors were encountered: