Python scipy.interpolate.Akima1DInterpolator() Examples
The following are 7
code examples of scipy.interpolate.Akima1DInterpolator().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
scipy.interpolate
, or try the search function
.
Example #1
Source File: fitting.py From grizli with MIT License | 6 votes |
def compute_cdf_percentiles(fit, cdf_sigmas=CDF_SIGMAS): """ Compute tabulated percentiles of the PDF """ from scipy.interpolate import Akima1DInterpolator from scipy.integrate import cumtrapz import scipy.stats if cdf_sigmas is None: cdf_sigmas = CDF_SIGMAS cdf_y = scipy.stats.norm.cdf(cdf_sigmas) if len(fit['zgrid']) == 1: return np.ones_like(cdf_y)*fit['zgrid'][0], cdf_y spl = Akima1DInterpolator(fit['zgrid'], np.log(fit['pdf']), axis=1) zrfine = [fit['zgrid'].min(), fit['zgrid'].max()] zfine = utils.log_zgrid(zr=zrfine, dz=0.0001) ok = np.isfinite(spl(zfine)) pz_fine = np.exp(spl(zfine)) pz_fine[~ok] = 0 cdf_fine = cumtrapz(pz_fine, x=zfine) cdf_x = np.interp(cdf_y, cdf_fine/cdf_fine[-1], zfine[1:]) return cdf_x, cdf_y
Example #2
Source File: missing.py From recruit with Apache License 2.0 | 4 votes |
def _akima_interpolate(xi, yi, x, der=0, axis=0): """ Convenience function for akima interpolation. xi and yi are arrays of values used to approximate some function f, with ``yi = f(xi)``. See `Akima1DInterpolator` for details. Parameters ---------- xi : array_like A sorted list of x-coordinates, of length N. yi : array_like A 1-D array of real values. `yi`'s length along the interpolation axis must be equal to the length of `xi`. If N-D array, use axis parameter to select correct axis. x : scalar or array_like Of length M. der : int or list, optional How many derivatives to extract; None for all potentially nonzero derivatives (that is a number equal to the number of points), or a list of derivatives to extract. This number includes the function value as 0th derivative. axis : int, optional Axis in the yi array corresponding to the x-coordinate values. See Also -------- scipy.interpolate.Akima1DInterpolator Returns ------- y : scalar or array_like The result, of length R or length M or M by R, """ from scipy import interpolate try: P = interpolate.Akima1DInterpolator(xi, yi, axis=axis) except TypeError: # Scipy earlier than 0.17.0 missing axis P = interpolate.Akima1DInterpolator(xi, yi) if der == 0: return P(x) elif interpolate._isscalar(der): return P(x, der=der) else: return [P(x, nu) for nu in der]
Example #3
Source File: missing.py From vnpy_crypto with MIT License | 4 votes |
def _akima_interpolate(xi, yi, x, der=0, axis=0): """ Convenience function for akima interpolation. xi and yi are arrays of values used to approximate some function f, with ``yi = f(xi)``. See `Akima1DInterpolator` for details. Parameters ---------- xi : array_like A sorted list of x-coordinates, of length N. yi : array_like A 1-D array of real values. `yi`'s length along the interpolation axis must be equal to the length of `xi`. If N-D array, use axis parameter to select correct axis. x : scalar or array_like Of length M. der : int or list, optional How many derivatives to extract; None for all potentially nonzero derivatives (that is a number equal to the number of points), or a list of derivatives to extract. This number includes the function value as 0th derivative. axis : int, optional Axis in the yi array corresponding to the x-coordinate values. See Also -------- scipy.interpolate.Akima1DInterpolator Returns ------- y : scalar or array_like The result, of length R or length M or M by R, """ from scipy import interpolate try: P = interpolate.Akima1DInterpolator(xi, yi, axis=axis) except TypeError: # Scipy earlier than 0.17.0 missing axis P = interpolate.Akima1DInterpolator(xi, yi) if der == 0: return P(x) elif interpolate._isscalar(der): return P(x, der=der) else: return [P(x, nu) for nu in der]
Example #4
Source File: missing.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 4 votes |
def _akima_interpolate(xi, yi, x, der=0, axis=0): """ Convenience function for akima interpolation. xi and yi are arrays of values used to approximate some function f, with ``yi = f(xi)``. See `Akima1DInterpolator` for details. Parameters ---------- xi : array_like A sorted list of x-coordinates, of length N. yi : array_like A 1-D array of real values. `yi`'s length along the interpolation axis must be equal to the length of `xi`. If N-D array, use axis parameter to select correct axis. x : scalar or array_like Of length M. der : int or list, optional How many derivatives to extract; None for all potentially nonzero derivatives (that is a number equal to the number of points), or a list of derivatives to extract. This number includes the function value as 0th derivative. axis : int, optional Axis in the yi array corresponding to the x-coordinate values. See Also -------- scipy.interpolate.Akima1DInterpolator Returns ------- y : scalar or array_like The result, of length R or length M or M by R, """ from scipy import interpolate try: P = interpolate.Akima1DInterpolator(xi, yi, axis=axis) except TypeError: # Scipy earlier than 0.17.0 missing axis P = interpolate.Akima1DInterpolator(xi, yi) if der == 0: return P(x) elif interpolate._isscalar(der): return P(x, der=der) else: return [P(x, nu) for nu in der]
Example #5
Source File: missing.py From Splunking-Crime with GNU Affero General Public License v3.0 | 4 votes |
def _akima_interpolate(xi, yi, x, der=0, axis=0): """ Convenience function for akima interpolation. xi and yi are arrays of values used to approximate some function f, with ``yi = f(xi)``. See `Akima1DInterpolator` for details. Parameters ---------- xi : array_like A sorted list of x-coordinates, of length N. yi : array_like A 1-D array of real values. `yi`'s length along the interpolation axis must be equal to the length of `xi`. If N-D array, use axis parameter to select correct axis. x : scalar or array_like Of length M. der : int or list, optional How many derivatives to extract; None for all potentially nonzero derivatives (that is a number equal to the number of points), or a list of derivatives to extract. This number includes the function value as 0th derivative. axis : int, optional Axis in the yi array corresponding to the x-coordinate values. See Also -------- scipy.interpolate.Akima1DInterpolator Returns ------- y : scalar or array_like The result, of length R or length M or M by R, """ from scipy import interpolate try: P = interpolate.Akima1DInterpolator(xi, yi, axis=axis) except TypeError: # Scipy earlier than 0.17.0 missing axis P = interpolate.Akima1DInterpolator(xi, yi) if der == 0: return P(x) elif interpolate._isscalar(der): return P(x, der=der) else: return [P(x, nu) for nu in der]
Example #6
Source File: missing.py From elasticintel with GNU General Public License v3.0 | 4 votes |
def _akima_interpolate(xi, yi, x, der=0, axis=0): """ Convenience function for akima interpolation. xi and yi are arrays of values used to approximate some function f, with ``yi = f(xi)``. See `Akima1DInterpolator` for details. Parameters ---------- xi : array_like A sorted list of x-coordinates, of length N. yi : array_like A 1-D array of real values. `yi`'s length along the interpolation axis must be equal to the length of `xi`. If N-D array, use axis parameter to select correct axis. x : scalar or array_like Of length M. der : int or list, optional How many derivatives to extract; None for all potentially nonzero derivatives (that is a number equal to the number of points), or a list of derivatives to extract. This number includes the function value as 0th derivative. axis : int, optional Axis in the yi array corresponding to the x-coordinate values. See Also -------- scipy.interpolate.Akima1DInterpolator Returns ------- y : scalar or array_like The result, of length R or length M or M by R, """ from scipy import interpolate try: P = interpolate.Akima1DInterpolator(xi, yi, axis=axis) except TypeError: # Scipy earlier than 0.17.0 missing axis P = interpolate.Akima1DInterpolator(xi, yi) if der == 0: return P(x) elif interpolate._isscalar(der): return P(x, der=der) else: return [P(x, nu) for nu in der]
Example #7
Source File: batteries.py From dymos with Apache License 2.0 | 4 votes |
def setup(self): num_nodes = self.options['num_nodes'] # Inputs self.add_input('I_Li', val=np.ones(num_nodes), units='A', desc='Current demanded per cell') # State Variables self.add_input('SOC', val=np.ones(num_nodes), units=None, desc='State of charge') # Outputs self.add_output('V_L', val=np.ones(num_nodes), units='V', desc='Terminal voltage of the battery') self.add_output('dXdt:SOC', val=np.ones(num_nodes), units='1/s', desc='Time derivative of state of charge') self.add_output('V_oc', val=np.ones(num_nodes), units='V', desc='Open Circuit Voltage') self.add_output('I_pack', val=0.1*np.ones(num_nodes), units='A', desc='Total Pack Current') self.add_output('V_pack', val=9.0*np.ones(num_nodes), units='V', desc='Total Pack Voltage') self.add_output('P_pack', val=1.0*np.ones(num_nodes), units='W', desc='Total Pack Power') # Derivatives row_col = np.arange(num_nodes) self.declare_partials(of='V_oc', wrt=['SOC'], rows=row_col, cols=row_col) self.declare_partials(of='V_L', wrt=['SOC'], rows=row_col, cols=row_col) self.declare_partials(of='V_L', wrt=['I_Li'], rows=row_col, cols=row_col) self.declare_partials(of='dXdt:SOC', wrt=['I_Li'], rows=row_col, cols=row_col) self.declare_partials(of='I_pack', wrt=['I_Li'], rows=row_col, cols=row_col) self.declare_partials(of='V_pack', wrt=['SOC', 'I_Li'], rows=row_col, cols=row_col) self.declare_partials(of='P_pack', wrt=['SOC', 'I_Li'], rows=row_col, cols=row_col) self.voltage_model = Akima1DInterpolator(train_SOC, train_V_oc) self.voltage_model_derivative = self.voltage_model.derivative()