|
17 | 17 | # - name: Jeremy White |
18 | 18 | # --- |
19 | 19 |
|
20 | | -# + [markdown] pycharm={"name": "#%% md\n"} |
21 | 20 | # # Formatting ASCII output arrays |
22 | 21 | # |
23 | 22 | # ### Configuring numeric arrays written by FloPy |
24 | 23 |
|
25 | | -# + [markdown] pycharm={"name": "#%% md\n"} |
26 | 24 | # load and run the Freyberg model |
27 | 25 |
|
28 | 26 |
|
29 | | -# + pycharm={"name": "#%%\n"} |
30 | 27 | import os |
31 | 28 | import sys |
32 | 29 | from pathlib import Path |
|
111 | 108 | errmsg = f"Error. Output file cannot be found: {f}" |
112 | 109 | print(errmsg) |
113 | 110 |
|
114 | | -# + [markdown] pycharm={"name": "#%% md\n"} |
115 | 111 | # Each ``Util2d`` instance now has a ```.format``` attribute, which is an ```ArrayFormat``` instance: |
116 | 112 |
|
117 | | -# + pycharm={"name": "#%%\n"} |
118 | 113 | print(ml.lpf.hk[0].format) |
119 | 114 |
|
120 | | -# + [markdown] pycharm={"name": "#%% md\n"} |
121 | 115 | # The ```ArrayFormat``` class exposes each of the attributes seen in the ```ArrayFormat.___str___()``` call. ```ArrayFormat``` also exposes ``.fortran``, ``.py`` and ``.numpy`` atrributes, which are the respective format descriptors: |
122 | 116 |
|
123 | | -# + pycharm={"name": "#%%\n"} |
124 | 117 | print(ml.dis.botm[0].format.fortran) |
125 | 118 | print(ml.dis.botm[0].format.py) |
126 | 119 | print(ml.dis.botm[0].format.numpy) |
127 | 120 |
|
128 | | -# + [markdown] pycharm={"name": "#%% md\n"} |
129 | 121 | # #### (re)-setting ```.format``` |
130 | 122 | # |
131 | 123 | # We can reset the format using a standard fortran type format descriptor |
132 | 124 |
|
133 | | -# + pycharm={"name": "#%%\n"} |
134 | 125 | ml.dis.botm[0].format.free = False |
135 | 126 | ml.dis.botm[0].format.fortran = "(20f10.4)" |
136 | 127 | print(ml.dis.botm[0].format.fortran) |
|
147 | 138 | else: |
148 | 139 | raise ValueError("Failed to run.") |
149 | 140 |
|
150 | | -# + [markdown] pycharm={"name": "#%% md\n"} |
151 | 141 | # Let's load the model we just wrote and check that the desired ```botm[0].format``` was used: |
152 | 142 |
|
153 | | -# + pycharm={"name": "#%%\n"} |
154 | 143 | ml1 = flopy.modflow.Modflow.load("freyberg.nam", model_ws=modelpth) |
155 | 144 | print(ml1.dis.botm[0].format) |
156 | 145 |
|
157 | | -# + [markdown] pycharm={"name": "#%% md\n"} |
158 | 146 | # We can also reset individual format components (we can also generate some warnings): |
159 | 147 |
|
160 | | -# + pycharm={"name": "#%%\n"} |
161 | 148 | ml.dis.botm[0].format.width = 9 |
162 | 149 | ml.dis.botm[0].format.decimal = 1 |
163 | 150 | print(ml1.dis.botm[0].format) |
164 | 151 |
|
165 | | -# + [markdown] pycharm={"name": "#%% md\n"} |
166 | 152 | # We can also select ``free`` format. Note that setting to free format resets the format attributes to the default, max precision: |
167 | 153 |
|
168 | | -# + pycharm={"name": "#%%\n"} |
169 | 154 | ml.dis.botm[0].format.free = True |
170 | 155 | print(ml1.dis.botm[0].format) |
171 | 156 | # - |
|
178 | 163 | else: |
179 | 164 | raise ValueError("Failed to run.") |
180 | 165 |
|
181 | | -# + pycharm={"name": "#%%\n"} |
182 | 166 | ml1 = flopy.modflow.Modflow.load("freyberg.nam", model_ws=modelpth) |
183 | 167 | print(ml1.dis.botm[0].format) |
0 commit comments