Skip to content

Commit

Permalink
add info on slicing
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Moodie committed Aug 9, 2021
1 parent 35f8b1c commit f6610f4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
17 changes: 15 additions & 2 deletions docs/source/guides/developer_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,20 @@ From these results, we can see that the values returned from the built-in unifor
Model development
-----------------

.. todo::
Slicing and neighbors
~~~~~~~~~~~~~~~~~~~~~

add some notes about slicing arrays, and how we pad them with a custom pad operation when needed. Look at shared tools docs for starting point.
Slicing an array to find the array values of neighbors is a common operation in the model.
The preferred way to slice is by 1) padding the array with :func:`~pyDeltaRCM.shared_tools.custom_pad`, and 2) looping through rows and columns to directly index. This approach makes for readable and reasonably fast code; for example, to find any cells that are higher than all neighbors:

.. code::
pad_eta = shared_tools.custom_pad(self.eta)
for i in range(self.L):
for j in range(self.W):
eta_nbrs = pad_eta[i - 1 + 1:i + 2 + 1, j - 1 + 1:j + 2 + 1]
eta_nbrs[1, 1] = -np.inf
np.all(self.eta[i, j] > eta_nbrs)
There are also several model attributes that may be helpful in development; we suggest using these builtins rather than creating your own whenever possible (see :meth:`~pyDeltaRCM.init_tools.init_tools.set_constants` and the model source code).
10 changes: 10 additions & 0 deletions pyDeltaRCM/init_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,16 @@ def set_constants(self):
Configure constants, including coordinates and distances, as well as
environmental constants (gravity), and kernels for smoothing
topography.
Some of the constants defined herein:
* `self.g`, gravitational acceleration
* `self.distances`, distance from cell `i,j` to neighbors (and self) # noqa: E501
* `self.iwalk`, step distance cross domain to cell in indexed direction
* `self.jwalk`, step distance down domain to cell in indexed direction
* `self.ravel_walk`, flattened index distance to cell in indexed direction
Each of these attributes also has a `self.xxxxx_flat` sibling
attribute, which is simply the flattened version of that attribute.
"""
_msg = 'Setting model constants'
self.log_info(_msg, verbosity=1)
Expand Down

0 comments on commit f6610f4

Please sign in to comment.