|
1 | 1 | # # Input data model |
2 | 2 | # |
| 3 | +# TODO: flesh this out, describe prospective plan for type hints, |
| 4 | +# determine whether we want to work directly with numpy or with |
| 5 | +# e.g. xarray, etc. This will probably evolve for a while as we |
| 6 | +# rework the prototype with c/attrs |
| 7 | +# |
3 | 8 | # FloPy organizes input variables in components: simulations, models, |
4 | 9 | # packages, and subpackages. |
5 | 10 | # |
6 | | -# The MODFLOW 6 data model is arranged in the following way: |
7 | | -# |
8 | 11 | # ```mermaid |
9 | 12 | # classDiagram |
10 | 13 | # Simulation *-- "1+" Package |
|
17 | 20 | # Package *-- "1+" Variable |
18 | 21 | # ``` |
19 | 22 | # |
20 | | -# Components are generally mutable and variables can be manipulated at will. |
| 23 | +# Components are generally mutable: subcomponents can be added/removed and |
| 24 | +# variables can be manipulated. |
21 | 25 | # |
22 | 26 | # # Variable types |
23 | 27 | # |
24 | | -# Variables are generally scalars, arrays, or composite data types: list, |
25 | | -# sum, union. |
| 28 | +# Variables are scalars, paths, arrays, or composite types: list, sum, union. |
| 29 | +# |
| 30 | +# MODFLOW 6 defines the following scalars types: |
| 31 | +# |
| 32 | +# - `keyword` |
| 33 | +# - `integer` |
| 34 | +# - `double precision` |
| 35 | +# - `string` |
| 36 | +# |
| 37 | +# And the following composites: |
26 | 38 | # |
27 | | -# The variable type structure can be summarized briefly as: |
| 39 | +# - `record`: product type |
| 40 | +# - `keystring`: union type |
| 41 | +# - `recarray`: list type |
| 42 | +# |
| 43 | +# Scalars may (and `recarray` must) have a `shape`. If a scalar has a `shape`, |
| 44 | +# its type becomes a homogeneous scalar array. A `recarray` may contain records |
| 45 | +# or unions of records as items. |
| 46 | +# |
| 47 | +# We map this typology roughly to the following in Python: |
28 | 48 |
|
29 | 49 | # + |
30 | 50 | from os import PathLike |
31 | 51 | from typing import ( |
| 52 | + Any, |
32 | 53 | Iterable, |
33 | 54 | Tuple, |
34 | 55 | Union, |
35 | 56 | ) |
36 | 57 |
|
37 | 58 | from numpy.typing import ArrayLike |
| 59 | +from pandas import DataFrame |
38 | 60 |
|
39 | 61 | Scalar = Union[bool, int, float, str] |
40 | 62 | Path = PathLike |
41 | 63 | Array = ArrayLike |
42 | 64 | Record = Tuple[Union[Scalar, "Record"], ...] |
43 | | -Table = Iterable["Record"] |
44 | | -Variable = Union[Scalar, Array, Table, Record] |
| 65 | +Table = Union[Iterable[Record], DataFrame] |
| 66 | +List = Iterable[Any] |
| 67 | +Variable = Union[Scalar, Array, Record, Table, List] |
45 | 68 | # - |
| 69 | + |
| 70 | +# Note that: |
| 71 | +# |
| 72 | +# - Keystrings are omitted above, since a keystring simply becomes a |
| 73 | +# `Union` of records or scalars. |
| 74 | +# - List input may be regular (items all have the same record type) or |
| 75 | +# irregular (items are unions of records). |
| 76 | +# - A table is a special case of list input; since it is regular it can |
| 77 | +# be represented as a dataframe. |
| 78 | +# - While MODFLOW 6 typically formulates file path inputs as records with |
| 79 | +# 3 fields (identifying keyword, `filein`/`fileout`, and filename), FloPy |
| 80 | +# simply accepts `PathLike`. |
0 commit comments