for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
# Licensed under a 3-clause BSD style license - see LICENSE
"""Utility functions used in mutis."""
import numpy as np
import scipy as sp
__all__ = ["get_grid", "memoize"]
def memoize(f):
This check looks for invalid names for a range of different identifiers.
You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.
If your project includes a Pylint configuration file, the settings contained in that file take precedence.
To find out more about Pylint, please refer to their site.
"""Decorator for recursive memoization."""
memo = {}
def helper(a, b):
x = np.array([a, b], dtype="object")
y = bytes(x)
if y not in memo:
memo
memo[y] = f(a, b)
return memo[y]
return helper
@memoize
def get_grid(x, y):
"""Compute a meshgrid with memoization."""
return np.meshgrid(x, y)
def interp_smooth_curve(x, y, s, N=None):
"""Return an interpolated and smoothed curve of len N. A gaussian kernel of std = s (in units of x) is used for smoothing.
This check looks for lines that are too long. You can specify the maximum line length.
If N is None, an array of the same length is returned (but interpolated so it is equispaced).
"""
s = s/np.ptp(x)*len(x)
if N is None:
N = len(x)
spl = sp.interpolate.splrep(x, y)
xs = np.linspace(min(x), max(x), N)
ys = sp.interpolate.splev(xs, spl)
ys = sp.ndimage.gaussian_filter1d(ys, s)
return xs, ys