From 8b5b51a8597cf8f926b06858dbc87b50f42af425 Mon Sep 17 00:00:00 2001 From: wpbonelli Date: Tue, 25 Feb 2025 21:09:27 -0500 Subject: [PATCH] cleanup old stuff --- docs/dev/sdd.md | 59 ------------------------------------------------- flopy4/todo.md | 28 ----------------------- 2 files changed, 87 deletions(-) delete mode 100644 flopy4/todo.md diff --git a/docs/dev/sdd.md b/docs/dev/sdd.md index 56109c04..f4fec143 100644 --- a/docs/dev/sdd.md +++ b/docs/dev/sdd.md @@ -90,65 +90,6 @@ Combining these patterns naively would result in several challenges, involving d 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`). -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. - -```mermaid -sequenceDiagram - Note over User: Initialize component - User->>Component: __init__() - Component->>__dict__: [populate] - Note over Component,__dict__: attrs-generated initialization - create participant DataTree - Component->>DataTree: [create] - __dict__->>DataTree: [transfer] - Note over Component,DataTree: xarray data tree initialization - destroy __dict__ - Component-x__dict__: - Note over Component,__dict__: __dict__ empty except tree - opt bind parent, if exists - Component-->>Parent: [bind parent component] - DataTree-->>ParentTree: [bind parent tree] - DataTree<<-->>ParentTree: [share dimensions] - end - DataTree->>Component: [return] - Component->>User: [return] - - Note over User: Get variable - User->>Component: .var - alt is array - Component->>DataTree: .data["var"] - else is dim - Component->>DataTree: .data.dims["var"] - else is scalar - Component->>DataTree: .data.attrs["var"] - end - Note over Component,DataTree: override __getattr__, redirect to tree - DataTree->>Component: [return value] - Component->>User: [return value] - - Note over User: Set variable - User->>Component: .var = ... - alt is array - Component->>DataTree: .data["var"] = ... - DataTree->>DataTree: [check dimensions] - else is scalar - Component->>DataTree: .data.attrs["var"] = ... - end - Note over Component,DataTree: use attrs on_setattr hook - DataTree->>Component: [return] - Component->>User: [return] -``` - -We can override `__getattr__` to redirect attribute access to `xarray`. - -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`. - -Other `attrs` functionality should "just work" (e.g. validation, `__repr__`, `__eq__`, etc), due to the operation of `__getattr__` under the hood. - -This combined concept can be packaged in a class decorator, which can be applied to component classes. - -The `attrs.field` decorator can be used for component variables. We can define a separate decorator for subcomponents. - ## Data types 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. diff --git a/flopy4/todo.md b/flopy4/todo.md deleted file mode 100644 index c7517d3f..00000000 --- a/flopy4/todo.md +++ /dev/null @@ -1,28 +0,0 @@ -# todo - -- deduplicate data trees - -Each component should get a view into the root (as far as it's aware) tree -unless it's the root (i.e. simulation) itself, or it's not attached to any -parent context, in which case it's the root of its own tree. - -Currently it's massively duplicative, since each component -has a subtree of its own, next to the one its parent owns -and in which its tree appears. need to have a single tree -at the root, then each component's data is a view into it. - -- subcomponent accessors - -I think for access by name we want dict style e.g. `gwf["chd1"]`, -like imod-python does it? - -By type, e.g. `gwf.chd`, where it's either a single component, -or a dict by name (or auto-increment index) for multipackages? - -- first class dimension support - -Right now array variables just declare their expected dimension. And the -dimensions are looked up by unguided search across the data tree's vars, -from the root down. Let variables declare themselves as dimensions? With -optional coordinate arrays autogenerated in the right size and added to -the dataset? And allow local vs global dimensions?