Skip to content

Commit

Permalink
Add impulse response functions to all rfunc (#472)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Vonk <vonk.mart@gmail.com>
Co-authored-by: Mark Bakker <markbak@gmail.com>
  • Loading branch information
3 people committed Jan 19, 2023
1 parent 5218cd6 commit d1f56bf
Show file tree
Hide file tree
Showing 9 changed files with 758 additions and 279 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Pastas
- scipy>=1.3
- numba>=0.51

To install the most important optional dependencies (solvers such as LmFit) at the same time with Pastas use::
To install the most important optional dependencies (solver LmFit and function visualisation Latexify) at the same time with Pastas use::

pip install pastas[full]

Expand Down
439 changes: 367 additions & 72 deletions doc/concepts/check_response_functions.ipynb

Large diffs are not rendered by default.

17 changes: 10 additions & 7 deletions doc/concepts/response_functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
},
Expand Down Expand Up @@ -390,9 +391,9 @@
"# compare pastas.Hantush to pastas.HantushWellModel\n",
"\n",
"hantush = ps.Hantush()\n",
"hantush._set_init_parameter_settings(up=-1)\n",
"hantush._update_rfunc_settings(up=-1)\n",
"hantushwm = ps.HantushWellModel()\n",
"hantushwm._set_init_parameter_settings(up=-1)\n",
"hantushwm._update_rfunc_settings(up=-1)\n",
"hantushwm.set_distances = 1.0\n",
"\n",
"bprime = np.log(1 / (4 * T * c))\n",
Expand All @@ -417,11 +418,8 @@
}
],
"metadata": {
"interpreter": {
"hash": "dace5e1b41a98a8e52d2a8eebc3b981caf2c12e7a76736ebfb89a489e3b62e79"
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "pastas_dev",
"language": "python",
"name": "python3"
},
Expand All @@ -435,7 +433,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.9.15 | packaged by conda-forge | (main, Nov 22 2022, 08:41:22) [MSC v.1929 64 bit (AMD64)]"
},
"latex_envs": {
"LaTeX_envs_menu_present": true,
Expand Down Expand Up @@ -463,6 +461,11 @@
},
"source": []
}
},
"vscode": {
"interpreter": {
"hash": "29475f8be425919747d373d827cb41e481e140756dd3c75aa328bf3399a0138e"
}
}
},
"nbformat": 4,
Expand Down
17 changes: 10 additions & 7 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.napoleon",
"sphinx.ext.doctest",
"sphinx.ext.intersphinx",
Expand Down Expand Up @@ -97,7 +98,7 @@

html_theme_options = {
"github_url": "https://github.com/pastas/pastas",
"use_edit_page_button": False,
"use_edit_page_button": True,
}

html_context = {
Expand All @@ -115,8 +116,10 @@
autodoc_typehints = "description"
autodoc_typehints_format = "short"
autosummary_generate = True
numpydoc_class_members_toctree = False

numpydoc_class_members_toctree = True
numpydoc_show_class_members = False
autoclass_content = "class"

# If true, links to the reST sources are added to the pages.
# html_show_sourcelink = True
Expand Down Expand Up @@ -243,11 +246,11 @@ class MyReferenceStyle(AuthorYearReferenceStyle):

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
"python": ("https://docs.python.org/3/", None),
"numpy": ("https://numpy.org/devdocs/", None),
"pandas": ("https://pandas.pydata.org/pandas-docs/stable/", None),
"scipy": ("https://docs.scipy.org/doc/scipy/objects.inv", None),
"matplotlib": ("https://matplotlib.org/stable/objects.inv", None),
"python": ("https://docs.python.org/3", None),
"numpy": ("https://numpy.org/devdocs", None),
"pandas": ("https://pandas.pydata.org/pandas-docs/stable", None),
"scipy": ("https://docs.scipy.org/doc/scipy", None),
"matplotlib": ("https://matplotlib.org/stable", None),
}

# Allow errors in notebooks, so we can see the error online
Expand Down
1 change: 1 addition & 0 deletions pastas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
Kraijenhoff,
One,
Polder,
Edelman,
Spline,
)
from .solver import LeastSquares, LmfitSolve
Expand Down
53 changes: 44 additions & 9 deletions pastas/decorators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from functools import wraps
from logging import getLogger

from typing import Optional, Dict
from pastas.typing import Function, TimestampType

logger = getLogger(__name__)

USE_NUMBA = True
Expand All @@ -11,9 +14,9 @@ def set_use_numba(b: bool) -> None:
USE_NUMBA = b


def set_parameter(function):
def set_parameter(function: Function) -> Function:
@wraps(function)
def _set_parameter(self, name, value, **kwargs):
def _set_parameter(self, name: str, value: float, **kwargs):
if name not in self.parameters.index:
logger.error(
"Parameter name %s does not exist, please choose from %s",
Expand All @@ -26,9 +29,9 @@ def _set_parameter(self, name, value, **kwargs):
return _set_parameter


def get_stressmodel(function):
def get_stressmodel(function: Function) -> Function:
@wraps(function)
def _get_stressmodel(self, name, **kwargs):
def _get_stressmodel(self, name: str, **kwargs):
if name not in self.stressmodels.keys():
logger.error(
"The stressmodel name you provided is not in the stressmodels dict. "
Expand All @@ -41,9 +44,15 @@ def _get_stressmodel(self, name, **kwargs):
return _get_stressmodel


def model_tmin_tmax(function):
def model_tmin_tmax(function: Function) -> Function:
@wraps(function)
def _model_tmin_tmax(self, tmin=None, tmax=None, *args, **kwargs):
def _model_tmin_tmax(
self,
tmin: Optional[TimestampType] = None,
tmax: Optional[TimestampType] = None,
*args,
**kwargs
):
if tmin is None:
tmin = self.ml.settings["tmin"]
if tmax is None:
Expand All @@ -54,7 +63,7 @@ def _model_tmin_tmax(self, tmin=None, tmax=None, *args, **kwargs):
return _model_tmin_tmax


def PastasDeprecationWarning(function):
def PastasDeprecationWarning(function: Function) -> Function:
@wraps(function)
def _function(*args, **kwargs):
logger.warning(
Expand All @@ -66,8 +75,8 @@ def _function(*args, **kwargs):
return _function


def njit(function=None, parallel=False):
def njit_decorator(f):
def njit(function: Optional[Function] = None, parallel: bool = False) -> Function:
def njit_decorator(f: Function):
try:
if not USE_NUMBA:
return f
Expand All @@ -83,3 +92,29 @@ def njit_decorator(f):
return njit_decorator(function)

return njit_decorator


def latexfun(
function: Optional[Function] = None,
identifiers: Optional[Dict[str, str]] = None,
use_math_symbols: bool = True,
use_raw_function_name: bool = False,
) -> Function:
def latexify_decorator(f: Function) -> Function:
try:
import latexify

flatex = latexify.function(
f,
identifiers=identifiers,
use_math_symbols=use_math_symbols,
use_raw_function_name=use_raw_function_name,
)
return flatex
except ImportError:
return f

if function:
return latexify_decorator(function)

return latexify_decorator

0 comments on commit d1f56bf

Please sign in to comment.