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
Copy file name to clipboardExpand all lines: docs/dev/sdd.md
-59Lines changed: 0 additions & 59 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -90,65 +90,6 @@ Combining these patterns naively would result in several challenges, involving d
90
90
91
91
Ultimately, we'd like a mapping between an abstract hierarchy of components and variables, as defined in MF6 definition files, to a Python representation which is self-describing (courtesy of `attrs`) and self-aligning (courtesy of `xarray`).
92
92
93
-
We can arrange for `attrs` to proxy `xarray`. Each component can own a node in an `xarray.DataTree`, say, in `.data`, which can serve as the component's backing store.
94
-
95
-
```mermaid
96
-
sequenceDiagram
97
-
Note over User: Initialize component
98
-
User->>Component: __init__()
99
-
Component->>__dict__: [populate]
100
-
Note over Component,__dict__: attrs-generated initialization
101
-
create participant DataTree
102
-
Component->>DataTree: [create]
103
-
__dict__->>DataTree: [transfer]
104
-
Note over Component,DataTree: xarray data tree initialization
105
-
destroy __dict__
106
-
Component-x__dict__:
107
-
Note over Component,__dict__: __dict__ empty except tree
108
-
opt bind parent, if exists
109
-
Component-->>Parent: [bind parent component]
110
-
DataTree-->>ParentTree: [bind parent tree]
111
-
DataTree<<-->>ParentTree: [share dimensions]
112
-
end
113
-
DataTree->>Component: [return]
114
-
Component->>User: [return]
115
-
116
-
Note over User: Get variable
117
-
User->>Component: .var
118
-
alt is array
119
-
Component->>DataTree: .data["var"]
120
-
else is dim
121
-
Component->>DataTree: .data.dims["var"]
122
-
else is scalar
123
-
Component->>DataTree: .data.attrs["var"]
124
-
end
125
-
Note over Component,DataTree: override __getattr__, redirect to tree
126
-
DataTree->>Component: [return value]
127
-
Component->>User: [return value]
128
-
129
-
Note over User: Set variable
130
-
User->>Component: .var = ...
131
-
alt is array
132
-
Component->>DataTree: .data["var"] = ...
133
-
DataTree->>DataTree: [check dimensions]
134
-
else is scalar
135
-
Component->>DataTree: .data.attrs["var"] = ...
136
-
end
137
-
Note over Component,DataTree: use attrs on_setattr hook
138
-
DataTree->>Component: [return]
139
-
Component->>User: [return]
140
-
```
141
-
142
-
We can override `__getattr__` to redirect attribute access to `xarray`.
143
-
144
-
Likewise, we can use [`on_setattr`](https://www.attrs.org/en/stable/api.html#core) to intercept values sent to the `attrs` attributes and send them to `xarray`.
145
-
146
-
Other `attrs` functionality should "just work" (e.g. validation, `__repr__`, `__eq__`, etc), due to the operation of `__getattr__` under the hood.
147
-
148
-
This combined concept can be packaged in a class decorator, which can be applied to component classes.
149
-
150
-
The `attrs.field` decorator can be used for component variables. We can define a separate decorator for subcomponents.
151
-
152
93
## Data types
153
94
154
95
MODFLOW 6 defines a [type system for input variables](https://github.com/MODFLOW-USGS/modflow6/tree/develop/doc/mf6io/mf6ivar#variable-types). We adapt this for Python.
0 commit comments