|
25 | 25 | <div class="document"> |
26 | 26 | <div class="documentwrapper"> |
27 | 27 | <div class="bodywrapper"> |
| 28 | + |
| 29 | + |
28 | 30 | <div class="body" role="main"> |
29 | 31 |
|
30 | 32 | <h1>Source code for prms_python.parameters</h1><div class="highlight"><pre> |
@@ -48,9 +50,18 @@ <h1>Source code for prms_python.parameters</h1><div class="highlight"><pre> |
48 | 50 |
|
49 | 51 | <div class="viewcode-block" id="Parameters"><a class="viewcode-back" href="../../api.html#prms_python.Parameters">[docs]</a><span class="k">class</span> <span class="nc">Parameters</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span> |
50 | 52 | <span class="sd">'''</span> |
51 | | -<span class="sd"> Disk-based representation of a PRMS parameter file. For the sake of</span> |
| 53 | +<span class="sd"> Disk-based representation of a PRMS parameter file. The ``Parameters``</span> |
| 54 | +<span class="sd"> object has the following instance attributes:</span> |
| 55 | + |
| 56 | +<span class="sd"> :ivar base_file: initial value: ``base_file``</span> |
| 57 | +<span class="sd"> :ivar base_file_reader: initial value: ``open(base_file)``</span> |
| 58 | +<span class="sd"> :ivar dimensions: initial value: ``collections.OrderedDict`` returned from ``self.__read_base(base_file)`` </span> |
| 59 | +<span class="sd"> :ivar base_params: initial value: ``list()`` returned from ``self.__read_base(base_file)``</span> |
| 60 | +<span class="sd"> :ivar param_arrays: initial value: empty ``dict()`` </span> |
| 61 | + |
| 62 | +<span class="sd"> For the sake of</span> |
52 | 63 | <span class="sd"> memory efficiency, we only load parameters from ``base_file`` that get</span> |
53 | | -<span class="sd"> modifified through item assignment, for example</span> |
| 64 | +<span class="sd"> modified through item assignment, for example</span> |
54 | 65 |
|
55 | 66 | <span class="sd"> >>> p = Parameters('example_params')</span> |
56 | 67 | <span class="sd"> >>> p['jh_coef'] = p['jh_coef']*1.1</span> |
@@ -59,13 +70,19 @@ <h1>Source code for prms_python.parameters</h1><div class="highlight"><pre> |
59 | 70 | <span class="sd"> will read parameter information from the params file to check that</span> |
60 | 71 | <span class="sd"> ``jh_coef`` is present in the parameter file, read the lines corresponding</span> |
61 | 72 | <span class="sd"> to ``jh_coef`` data and assign the new value as requested. Internally,</span> |
62 | | -<span class="sd"> a reference is kept to only modified parameter data,</span> |
63 | | -<span class="sd"> so when ``p.write(modified_params_file)`` is called, mostly this will copy</span> |
64 | | -<span class="sd"> from ``base_file`` to ``modified_params_file``.</span> |
| 73 | +<span class="sd"> a reference is kept to only modified parameter data, so when </span> |
| 74 | +<span class="sd"> ``p.write(modified_params_file)`` is called most copying is from ``base_file``</span> |
| 75 | +<span class="sd"> to ``modified_params_file``. When parameters are accessed using the </span> |
| 76 | +<span class="sd"> dictionary-like syntax, a ``np.ndarray`` representation of the parameter is </span> |
| 77 | +<span class="sd"> returned. As a result ``numpy`` mathematical rules including efficient </span> |
| 78 | +<span class="sd"> vectorization of math applied to arrays can be applied to modify parameters </span> |
| 79 | +<span class="sd"> directly. The ``Parameter`` objects user methods allow for visualization of </span> |
| 80 | +<span class="sd"> most PRMS parameters, function based modification of parameters, and a write </span> |
| 81 | +<span class="sd"> function that writes the data back to PRMS text format. </span> |
| 82 | + |
65 | 83 | <span class="sd"> '''</span> |
66 | 84 |
|
67 | 85 | <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">base_file</span><span class="p">):</span> |
68 | | - |
69 | 86 | <span class="bp">self</span><span class="o">.</span><span class="n">base_file</span> <span class="o">=</span> <span class="n">base_file</span> |
70 | 87 | <span class="bp">self</span><span class="o">.</span><span class="n">base_file_reader</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">base_file</span><span class="p">)</span> |
71 | 88 | <span class="bp">self</span><span class="o">.</span><span class="n">dimensions</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">base_params</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__read_base</span><span class="p">(</span><span class="n">base_file</span><span class="p">)</span> |
@@ -133,15 +150,16 @@ <h1>Source code for prms_python.parameters</h1><div class="highlight"><pre> |
133 | 150 | <div class="viewcode-block" id="Parameters.plot"><a class="viewcode-back" href="../../api.html#prms_python.Parameters.plot">[docs]</a> <span class="k">def</span> <span class="nf">plot</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">nrows</span><span class="p">,</span> <span class="n">which</span><span class="o">=</span><span class="s1">'all'</span><span class="p">,</span> <span class="n">out_dir</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">xlabel</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>\ |
134 | 151 | <span class="n">ylabel</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">cbar_label</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">title</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">mpl_style</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span> |
135 | 152 | <span class="sd">"""</span> |
136 | | -<span class="sd"> Plot PRMS parameters as time series or 2D spatial grid depending on </span> |
137 | | -<span class="sd"> parameter dimension. The PRMS parameter file is assumed to represent </span> |
138 | | -<span class="sd"> a model that was set up on a uniform rectangular grid with the spatial </span> |
| 153 | +<span class="sd"> Versatile method that plots series or 2D spatial grid depending on </span> |
| 154 | +<span class="sd"> parameter dimension. The PRMS parameter file is assumed to hold parameters </span> |
| 155 | +<span class="sd"> for a model that was set up on a uniform rectangular grid with the spatial </span> |
139 | 156 | <span class="sd"> index of HRUs starting in the upper left corner and moving left to </span> |
140 | | -<span class="sd"> right across columns and down rows. </span> |
| 157 | +<span class="sd"> right across columns and down rows. Default function is to print four</span> |
| 158 | +<span class="sd"> files, each with plots of varying parameter dimensions as explained </span> |
| 159 | +<span class="sd"> under Kwargs ``which`` and more detailed explanation in the example</span> |
| 160 | +<span class="sd"> `Jupyter notebook <https://github.com/PRMS-Python/PRMS-Python/blob/master/notebooks/param_examples.ipynb>`_.</span> |
141 | 161 | <span class="sd"> </span> |
142 | 162 | <span class="sd"> Arguments:</span> |
143 | | -<span class="sd"> params (prms_python.Parameters): An instance of Parameters that </span> |
144 | | -<span class="sd"> corresponds with the PRMS parameter file to plot. </span> |
145 | 163 | <span class="sd"> nrows (int): The number of rows in the PRMS model grid for plotting </span> |
146 | 164 | <span class="sd"> spatial parameters. Function will only work for rectangular </span> |
147 | 165 | <span class="sd"> gridded models with HRU indices starting in the upper left cell </span> |
@@ -152,14 +170,14 @@ <h1>Source code for prms_python.parameters</h1><div class="highlight"><pre> |
152 | 170 | <span class="sd"> the function will print 3 multipage pdfs, one for nhru </span> |
153 | 171 | <span class="sd"> dimensional parameters, one for nhru by monthly parameters, one </span> |
154 | 172 | <span class="sd"> for other parameters of length > 1, and one html file containing</span> |
155 | | -<span class="sd"> single valued parameters</span> |
| 173 | +<span class="sd"> single valued parameters.</span> |
| 174 | + |
156 | 175 | <span class="sd"> out_dir (str): path to an output dir, default current directory</span> |
157 | 176 | <span class="sd"> xlabel (str): x label for plot(s)</span> |
158 | 177 | <span class="sd"> ylabel (str): y label for plot(s)</span> |
159 | 178 | <span class="sd"> cbar_label (str): label for colorbar on spatial plot(s)</span> |
160 | 179 | <span class="sd"> title (str): plot title</span> |
161 | | -<span class="sd"> mpl_style (str, list): name or list of names of matplotlib style </span> |
162 | | -<span class="sd"> sheets to use for plot(s)</span> |
| 180 | +<span class="sd"> mpl_style (str, list): name or list of names of matplotlib style sheets to use for plot(s).</span> |
163 | 181 | <span class="sd"> </span> |
164 | 182 | <span class="sd"> Returns: </span> |
165 | 183 | <span class="sd"> None</span> |
@@ -332,7 +350,7 @@ <h1>Source code for prms_python.parameters</h1><div class="highlight"><pre> |
332 | 350 |
|
333 | 351 | <span class="k">def</span> <span class="nf">__make_dimensions_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">base_file</span><span class="p">):</span> |
334 | 352 | <span class="sd">"""</span> |
335 | | -<span class="sd"> Extract dimensions and each dimension length. Run before</span> |
| 353 | +<span class="sd"> Extract dimensions and each dimension length. Runs before</span> |
336 | 354 | <span class="sd"> __make_parameter_dict.</span> |
337 | 355 | <span class="sd"> """</span> |
338 | 356 | <span class="n">ret</span> <span class="o">=</span> <span class="n">OrderedDict</span><span class="p">()</span> |
@@ -535,6 +553,7 @@ <h1>Source code for prms_python.parameters</h1><div class="highlight"><pre> |
535 | 553 | </pre></div> |
536 | 554 |
|
537 | 555 | </div> |
| 556 | + |
538 | 557 | </div> |
539 | 558 | </div> |
540 | 559 | <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> |
@@ -598,8 +617,8 @@ <h3>Quick search</h3> |
598 | 617 | ©2016, John Volk and Matthew Turner. |
599 | 618 |
|
600 | 619 | | |
601 | | - Powered by <a href="http://sphinx-doc.org/">Sphinx 1.7.5</a> |
602 | | - & <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.10</a> |
| 620 | + Powered by <a href="http://sphinx-doc.org/">Sphinx 1.7.6</a> |
| 621 | + & <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.11</a> |
603 | 622 |
|
604 | 623 | </div> |
605 | 624 |
|
|