Here are the examples of the python api numpy.trapz taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
7 Examples
4
Example 1
Project: python-qinfer Source File: distributions.py
def _generate_interp(self):
xs = self._xs
pdfs = self._pdf(xs)
norm_factor = np.trapz(pdfs, xs)
self._cdfs = cuemtrapz(pdfs / norm_factor, xs, initial=0)
self._interp_inv_cdf = interp1d(self._cdfs, xs, bounds_error=False)
3
Example 2
def getAUC(fprs, tprs):
sortedFprs, sortedTprs = zip(*sorted(zip(*(fprs, tprs))))
sortedFprs = list(sortedFprs)
sortedTprs = list(sortedTprs)
if sortedFprs[-1] != 1.0:
sortedFprs.append(1.0)
sortedTprs.append(sortedTprs[-1])
return np.trapz(sortedTprs, sortedFprs)
3
Example 3
def integrate(self, wmin=None, wmax=None):
""" Calculates flux (erg/s/cm^2) in SED within given wavelength
range."""
if wmin is None:
wmin = self.wa[0]
if wmax is None:
wmax = self.wa[-1]
i,j = self.wa.searchsorted([wmin, wmax])
fl = np.trapz(self.fl[i:j], self.wa[i:j])
return fl
0
Example 4
Project: qutip Source File: test_correlation.py
def test_H_fn_td_corr():
"""
correlation: comparing TLS emission corr., H td (fn td format)
"""
# calculate emission zero-delay second order correlation, g2[0], for TLS
# with following parameters:
# gamma = 1, omega = 2, tp = 0.5
# Then: g2(0)~0.57
sm = destroy(2)
def H_func(t, args):
return 2 * args["H0"] * np.exp(-2 * (t-1)**2)
tlist = linspace(0, 5, 50)
corr = correlation_3op_2t(H_func, fock(2, 0), tlist, tlist,
[sm], sm.dag(), sm.dag() * sm, sm,
args={"H0": sm+sm.dag()})
# integrate w/ 2D trapezoidal rule
dt = (tlist[-1]-tlist[0]) / (np.shape(tlist)[0]-1)
s1 = corr[0, 0] + corr[-1, 0] + corr[0, -1] + corr[-1, -1]
s2 = sum(corr[1:-1, 0]) + sum(corr[1:-1, -1]) +\
sum(corr[0, 1:-1]) + sum(corr[-1, 1:-1])
s3 = sum(corr[1:-1, 1:-1])
exp_n_in = trapz(
mesolve(
H_func, fock(2, 0), tlist, [sm], [sm.dag()*sm],
args={"H0": sm+sm.dag()}
).expect[0], tlist
)
# factor of 2 from negative time correlations
g20 = abs(
sum(0.5*dt**2*(s1 + 2*s2 + 4*s3)) / exp_n_in**2
)
assert_(abs(g20-0.59) < 1e-2)
0
Example 5
Project: cameo Source File: analysis.py
def area_for(self, variable_id):
data_frame = self._phase_plane.sort_values(by=variable_id, ascending=True)
auc_max = trapz(data_frame.objective_upper_bound.values, x=data_frame[variable_id])
auc_min = trapz(data_frame.objective_lower_bound.values, x=data_frame[variable_id])
return auc_max - auc_min
0
Example 6
def execute(self):
self.gross_aep = self.turbine_number * np.trapz(self.power_curve, self.CDF_V)*365.0*24.0 # in kWh
self.net_aep = self.availability * (1-self.array_losses) * (1-self.other_losses) * self.gross_aep
self.capacity_factor = self.net_aep / (8760. * self.machine_rating * 1000.0 * self.turbine_number)
0
Example 7
Project: Barak Source File: pyvpfit.py
def calc_v90(tau):
""" Find the start and end indices of a tau array that give v90.
Defined by Prochaska and Wolfe 97.
Assumes equally spaced x values.
Returns
-------
imin, imax: int
The start and end indices of the region that contains 90% of
the optical depth.
"""
sumtau = np.trapz(tau)
assert sumtau > 0
lenv = len(tau)
# starting from the left v edge, increase v until int from left
# edge to v gives 5% of total integral
sum5perc = sumtau / 20.
tautotal = 0.
i = 1
while tautotal < sum5perc:
tautotal = np.trapz(tau[:i])
i += 1
if i == lenv:
raise Exception('Problem with velocity limits!')
imin = i - 1
# Do the same starting from the right edge.
tautotal = 0
i = -1
while tautotal < sum5perc:
tautotal = np.trapz(tau[i:])
i -= 1
if -i == lenv:
raise Exception('Problem with velocity limits!')
imax = len(tau) + (i + 2)
return imin, imax