本文整理汇总了Python中scipy.interpolate.RectBivariateSpline.ev方法的典型用法代码示例。如果您正苦于以下问题:Python RectBivariateSpline.ev方法的具体用法?Python RectBivariateSpline.ev怎么用?Python RectBivariateSpline.ev使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.interpolate.RectBivariateSpline
的用法示例。
在下文中一共展示了RectBivariateSpline.ev方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: buildSection
# 需要导入模块: from scipy.interpolate import RectBivariateSpline [as 别名]
# 或者: from scipy.interpolate.RectBivariateSpline import ev [as 别名]
def buildSection(self, xo = None, yo = None, xm = None, ym = None,
pts = 100, gfilter = 5):
"""
Extract a slice from the 3D data set and compute the stratigraphic layers.
Parameters
----------
variable: xo, yo
Lower X,Y coordinates of the cross-section.
variable: xm, ym
Upper X,Y coordinates of the cross-section.
variable: pts
Number of points to discretise the cross-section.
variable: gfilter
Gaussian smoothing filter.
"""
if xm > self.x.max():
xm = self.x.max()
if ym > self.y.max():
ym = self.y.max()
if xo < self.x.min():
xo = self.x.min()
if yo < self.y.min():
yo = self.y.min()
xsec, ysec = self._cross_section(xo, yo, xm, ym, pts)
self.dist = np.sqrt(( xsec - xo )**2 + ( ysec - yo )**2)
self.xsec = xsec
self.ysec = ysec
for k in range(self.nz):
# Thick
rect_B_spline = RectBivariateSpline(self.yi, self.xi, self.th[:,:,k])
data = rect_B_spline.ev(ysec, xsec)
secTh = filters.gaussian_filter1d(data,sigma=gfilter)
secTh[secTh < 0] = 0
self.secTh.append(secTh)
# Elev
rect_B_spline1 = RectBivariateSpline(self.yi, self.xi, self.elev[:,:,k])
data1 = rect_B_spline1.ev(ysec, xsec)
secElev = filters.gaussian_filter1d(data1,sigma=gfilter)
self.secElev.append(secElev)
# Depth
rect_B_spline2 = RectBivariateSpline(self.yi, self.xi, self.dep[:,:,k])
data2 = rect_B_spline2.ev(ysec, xsec)
secDep = filters.gaussian_filter1d(data2,sigma=gfilter)
self.secDep.append(secDep)
# Ensure the spline interpolation does not create underlying layers above upper ones
topsec = self.secDep[self.nz-1]
for k in range(self.nz-2,-1,-1):
secDep = self.secDep[k]
self.secDep[k] = np.minimum(secDep, topsec)
topsec = self.secDep[k]
return
示例2: __init__
# 需要导入模块: from scipy.interpolate import RectBivariateSpline [as 别名]
# 或者: from scipy.interpolate.RectBivariateSpline import ev [as 别名]
def __init__(self, periods):
"""
Create an instance of LB13.
Args:
periods (numpy.array): An array of periods that will be requested
from the function. Values must be [0.01 -> 10.0], and must me
sorted from smallest to largest.
Returns:
An instance of :class:`LothBaker2013`.
"""
if np.any(periods < 0.01):
raise ValueError('The periods must be greater or equal to 0.01s')
if np.any(periods > 10):
raise ValueError('The periods must be less or equal to 10s')
rbs1 = RectBivariateSpline(Tlist, Tlist, B1, kx=1, ky=1)
rbs2 = RectBivariateSpline(Tlist, Tlist, B2, kx=1, ky=1)
rbs3 = RectBivariateSpline(Tlist, Tlist, B3, kx=1, ky=1)
#
# Build new tables with entries at the periods we will use
#
tlist = list(zip(*it.product(periods, periods)))
nper = np.size(periods)
self.b1 = rbs1.ev(tlist[0], tlist[1]).reshape((nper, nper))
self.b2 = rbs2.ev(tlist[0], tlist[1]).reshape((nper, nper))
self.b3 = rbs3.ev(tlist[0], tlist[1]).reshape((nper, nper))
示例3: main
# 需要导入模块: from scipy.interpolate import RectBivariateSpline [as 别名]
# 或者: from scipy.interpolate.RectBivariateSpline import ev [as 别名]
def main():
filenameEffArea='aeff_P7REP_ULTRACLEAN_V15_back.fits'
directoryEffectiveArea='/Users/dspolyar/Documents/IRF/EffectiveArea/'
print pyfits.info( directoryEffectiveArea+filenameEffArea)
CTHETA_LO, CTHETA_HI, energyLow, energyHigh, EFFAREA = importEffectiveArea(directoryEffectiveArea+filenameEffArea)
energylog, Ctheta=centeringDataAndConvertingToLog(energyHigh,energyLow,CTHETA_HI,CTHETA_LO)
SplineEffectiveArea=RectBivariateSpline(Ctheta,energylog,EFFAREA)
plotofEffectiveArea(SplineEffectiveArea,EFFAREA,energylog,Ctheta)
print SplineEffectiveArea.ev(1.,5.)
示例4: resample2d
# 需要导入模块: from scipy.interpolate import RectBivariateSpline [as 别名]
# 或者: from scipy.interpolate.RectBivariateSpline import ev [as 别名]
def resample2d(i_data, i_s, i_e, i_i, o_s, o_e, o_i, kx=3, ky=3, s=0,
gauss_sig=0, median_boxcar_size=0, clip=True):
'''
Resample a square 2D input grid with extents defined by [i_s] and [i_e] with
increment [i_i] to a new 2D grid with extents defined by [o_s] and [o_e]
with increment [o_i].
Returns a 2D resampled array, with options for smoothing (gaussian and
median) and clipping.
'''
# calculate bivariate spline, G, using input grid and data
grid_pre_rebin = np.arange(i_s, i_e, i_i)
G = RectBivariateSpline(grid_pre_rebin, grid_pre_rebin, i_data, kx=kx, ky=ky)
# evaluate this spline at new points on output grid
grid_x, grid_y = np.mgrid[o_s:o_e:o_i, o_s:o_e:o_i]
data = G.ev(grid_x, grid_y)
if gauss_sig != 0:
data = gaussian_filter(data, gauss_sig)
if median_boxcar_size != 0:
data = median_filter(data, median_boxcar_size)
if clip:
input_max = np.max(i_data)
input_min = np.min(i_data)
data[np.where(data>input_max)] = input_max
data[np.where(data<input_min)] = input_min
return data
示例5: plot
# 需要导入模块: from scipy.interpolate import RectBivariateSpline [as 别名]
# 或者: from scipy.interpolate.RectBivariateSpline import ev [as 别名]
def plot(self, ax, V=None, **kwargs):
'''Plot the contours into matplotlib axis.
Parameters
----------
ax : matplotlib.Axes
Axes to plot into
V : array-like
A list of contour values to plot. If not None, the internal contour
values will be overriden during plotting, but not inside the
object.
kwargs : dict
Keyword arguments to pass on to the ax.contour() method.
'''
if V is None:
V = self.V
d, X, Y = self.data.getData()
# hack - add zero value to close contours
d = np.hstack((d, np.zeros((d.shape[0], 1))))
d = np.vstack((d, np.zeros((1, d.shape[1]))))
dx = X[0, 1] - X[0, 0]
dy = Y[1, 0] - Y[0, 0]
x_longer = X[0, :].tolist()
x_longer.append(X[0, -1] + dx)
y_longer = Y[:, 0].tolist()
y_longer.append(Y[-1, 0] + dy)
x_interp, y_interp = np.meshgrid(
np.linspace(x_longer[0], x_longer[-1],
len(x_longer) * self.upsample_factor),
np.linspace(x_longer[0], y_longer[-1],
len(y_longer) * self.upsample_factor))
spl = RectBivariateSpline(x_longer, y_longer, d.T)
d_interp = spl.ev(x_interp, y_interp)
ax.contour(x_interp, y_interp, d_interp, V, **kwargs)
示例6: setModel
# 需要导入模块: from scipy.interpolate import RectBivariateSpline [as 别名]
# 或者: from scipy.interpolate.RectBivariateSpline import ev [as 别名]
def setModel(self,model,dx,think_positive=False):
'''
Set new model for the source.
:param model: ``(n, n)``
Numpy image array.
:param dx: scalar
Pixel size in microarcseconds.
:param think_positive: (optional) bool
Should we enforce that the source image has no negative pixel values?
'''
self.nx = int(ceil(model.shape[-1] * dx / self.dx)) # number of image pixels
self.model = model # source model
self.model_dx = dx # source model resolution
# load source image that has size and resolution compatible with the screen.
self.isrc = np.empty(2*(self.nx,))
self.think_positive = think_positive
M = self.model.shape[1] # size of original image array
f_img = RectBivariateSpline(self.model_dx/self.dx*(np.arange(M) - 0.5*(M-1)),\
self.model_dx/self.dx*(np.arange(M) - 0.5*(M-1)),\
self.model)
xx_,yy_ = np.meshgrid((np.arange(self.nx) - 0.5*(self.nx-1)),\
(np.arange(self.nx) - 0.5*(self.nx-1)),indexing='xy')
m = f_img.ev(yy_.flatten(),xx_.flatten()).reshape(2*(self.nx,))
self.isrc = m * (self.dx/self.model_dx)**2 # rescale for change in pixel size
if self.think_positive:
self.isrc[self.isrc < 0] = 0
if not self.live_dangerously: self._checkSanity()
示例7: calcAnker
# 需要导入模块: from scipy.interpolate import RectBivariateSpline [as 别名]
# 或者: from scipy.interpolate.RectBivariateSpline import ev [as 别名]
def calcAnker(IS, inputPoints, rasterdata, gp):
"""
"""
dhm = rasterdata['subraster']
[Xa, Ya, Xe, Ye] = inputPoints
# Letzte Koordinate in xi/yi entspricht nicht exakt den Endkoordinaten
Xe_ = gp['xi'][-1]
Ye_ = gp['yi'][-1]
AnkA_dist = IS['d_Anker_A'][0]
AnkE_dist = IS['d_Anker_E'][0]
stueA_H = IS['HM_Anfang'][0]
stueE_H = IS['HM_Ende_max'][0]
# X- und Y-Koordinate der Geodaten im Projektionssystem berechnen
dx = float(Xe - Xa)
dy = float(Ye - Ya)
if dx == 0:
dx = 0.0001
azimut = math.atan(dy/dx)
if dx > 0:
azimut += 2 * math.pi
else:
azimut += math.pi
# X- und Y-Koordinaten der beiden Ankerpunkte am Boden
AnkXa = Xa - AnkA_dist * math.cos(azimut)
AnkYa = Ya - AnkA_dist * math.sin(azimut)
AnkXe = Xe_ + AnkE_dist * math.cos(azimut)
AnkYe = Ye_ + AnkE_dist * math.sin(azimut)
# Linear Interpolation
# Koordinatenarrays des DHMs
coordX = gp['linspaces'][0]
coordY = gp['linspaces'][1]
# kx, ky bezeichnen grad der interpolation, 1=linear
spline = RectBivariateSpline(-coordY, coordX, dhm, kx=1, ky=1)
xi = np.array([AnkXa, Xa, Xe_, AnkXe])
yi = np.array([AnkYa, Ya, Ye_, AnkYe])
# Z-Koordinate der Anker für Anfangs- und Endpunkte
zAnker = spline.ev(-yi, xi) # Höhenangaben am Boden
AnkA_z = stueA_H + 0.1*(zAnker[1] - zAnker[0])
AnkE_z = stueE_H + 0.1*(zAnker[2] - zAnker[3])
if AnkA_dist == 0:
AnkA_z = 0.0
if AnkE_dist == 0:
AnkE_z = 0.0
Ank = [AnkA_dist, AnkA_z, AnkE_dist, AnkE_z]
# Ausdehnungen der Anker Felder, alles in [m]
#Ank = [d_Anker_A, z_Anker_A * 0.1, d_Anker_E, z_Anker_E * 0.1]
Laenge_Ankerseil = (AnkA_dist**2 + AnkA_z**2)**0.5 + \
(AnkE_dist**2 + AnkE_z**2)**0.5
# Eventuell nicht nötig
#IS['z_Anker_A'][0] = z_Anker_A
#IS['z_Anker_E'][0] = z_Anker_E
return [Ank, Laenge_Ankerseil, zAnker]
示例8: interpolate_individual
# 需要导入模块: from scipy.interpolate import RectBivariateSpline [as 别名]
# 或者: from scipy.interpolate.RectBivariateSpline import ev [as 别名]
def interpolate_individual(self, image):
# unpacking
ogridx, ogridy = self.ogrid
ngridx, ngridy = self.ngrid
f = RectBivariateSpline(ogridy, ogridx, image, kx=1, ky=1)
return f.ev(ngridy.flatten(), ngridx.flatten()).reshape(ngridx.shape)
示例9: getStraightenWormInt
# 需要导入模块: from scipy.interpolate import RectBivariateSpline [as 别名]
# 或者: from scipy.interpolate.RectBivariateSpline import ev [as 别名]
def getStraightenWormInt(worm_img, skeleton, half_width = -1, cnt_widths = np.zeros(0), width_resampling = 7, ang_smooth_win = 12, length_resampling = 49):
'''
Code to straighten the worm worms.
worm_image - image containing the worm
skeleton - worm skeleton
half_width - half width of the worm, if it is -1 it would try to calculated from cnt_widths
cnt_widths - contour widths used in case the half width is not given
width_resampling - number of data points used in the intensity map along the worm width
length_resampling - number of data points used in the intensity map along the worm length
ang_smooth_win - window used to calculate the skeleton angles.
A small value will introduce noise, therefore obtaining bad perpendicular segments.
A large value will over smooth the skeleton, therefore not capturing the correct shape.
'''
#if np.all(np.isnan(skeleton)):
# buff = np.empty((skeleton.shape[0], width_resampling))
# buff.fill(np.nan)
# return buff
assert half_width>0 or cnt_widths.size>0
assert not np.any(np.isnan(skeleton))
if ang_smooth_win%2 == 1:
ang_smooth_win += 1;
if skeleton.shape[0] != length_resampling:
skeleton, _ = curvspace(np.ascontiguousarray(skeleton), length_resampling)
skelX = skeleton[:,0];
skelY = skeleton[:,1];
assert np.max(skelX) < worm_img.shape[0]
assert np.max(skelY) < worm_img.shape[1]
assert np.min(skelY) >= 0
assert np.min(skelY) >= 0
#calculate smoothed angles
skel_angles = angleSmoothed(skelX, skelY, ang_smooth_win)
#%get the perpendicular angles to define line scans (orientation doesn't
#%matter here so subtracting pi/2 should always work)
perp_angles = skel_angles - np.pi/2;
#%for each skeleton point get the coordinates for two line scans: one in the
#%positive direction along perpAngles and one in the negative direction (use
#%two that both start on skeleton so that the intensities are the same in
#%the line scan)
#resample the points along the worm width
if half_width <= 0:
half_width = (np.median(cnt_widths[10:-10])/2.) #add half a pixel to get part of the contour
r_ind = np.linspace(-half_width, half_width, width_resampling)
#create the grid of points to be interpolated (make use of numpy implicit broadcasting Nx1 + 1xM = NxM)
grid_x = skelX + r_ind[:, np.newaxis]*np.cos(perp_angles);
grid_y = skelY + r_ind[:, np.newaxis]*np.sin(perp_angles);
f = RectBivariateSpline(np.arange(worm_img.shape[0]), np.arange(worm_img.shape[1]), worm_img)
return f.ev(grid_y, grid_x) #return interpolated intensity map
示例10: SplineEstimator
# 需要导入模块: from scipy.interpolate import RectBivariateSpline [as 别名]
# 或者: from scipy.interpolate.RectBivariateSpline import ev [as 别名]
class SplineEstimator(object):
def fit(self, x, y):
self.lut = RectBivariateSpline(x[1], x[0], y)
return self
def predict(self, X):
return self.lut.ev(X[:, 1], X[:, 0])
示例11: __init__
# 需要导入模块: from scipy.interpolate import RectBivariateSpline [as 别名]
# 或者: from scipy.interpolate.RectBivariateSpline import ev [as 别名]
def __init__(self, R_in, z_in, Raxis, zaxis, psi_in, R_out, z_out, psi_sep=0):
print('2d interp')
self.error = 0
# Check input dimensions, R_out z_out must be flat
if len(R_out) != len(z_out):
print('R and z must have the same dimensions')
self.error = 1
return
if np.array(R_out).ndim > 1:
print('R_out must be flat')
self.error = 2
return
if np.array(z_out).ndim > 1:
print('z_out must be flat')
self.error = 3
return
nz_psi, nR_psi = psi_in.shape
if len(R_in) != nR_psi:
print('Inconsistent R axis for psi_in')
self.error = 5
return
if len(z_in) != nz_psi:
print('Inconsistent z axis for psi_in')
self.error = 6
return
nRz = len(R_out)
self.psi_red = np.zeros(nRz)
# Bilinear interpolation
bisp = RectBivariateSpline(z_in, R_in, psi_in)
self.psi_axis = bisp.ev(zaxis, Raxis)
for jRz, R in enumerate(R_out):
z = z_out[jRz]
self.psi_red[jRz] = bisp.ev(z, R)
self.psi_norm = (self.psi_red - self.psi_axis)/(psi_sep - self.psi_axis)
self.rho_pol = np.sqrt(self.psi_norm)
示例12: getEroDep
# 需要导入模块: from scipy.interpolate import RectBivariateSpline [as 别名]
# 或者: from scipy.interpolate.RectBivariateSpline import ev [as 别名]
def getEroDep(self, xo = None, yo = None, xm = None, ym = None,
pts = 100, gfilter = 5):
"""
Extract a slice from the 3D data set and compute its deposition thicknesses.
Parameters
----------
variable: xo, yo
Lower X,Y coordinates of the cross-section
variable: xm, ym
Upper X,Y coordinates of the cross-section
variable: pts
Number of points to discretise the cross-section
variable: gfilter
Gaussian smoothing filter
"""
if xm > self.x.max():
xm = self.x.max()
if ym > self.y.max():
ym = self.y.max()
if xo < self.x.min():
xo = self.x.min()
if yo < self.y.min():
yo = self.y.min()
xsec, ysec = self._cross_section(xo, yo, xm, ym, pts)
self.dist = np.sqrt(( xsec - xo )**2 + ( ysec - yo )**2)
# Surface
rect_B_spline = RectBivariateSpline(self.y[:,0], self.x[0,:], self.z)
datatop = rect_B_spline.ev(ysec, xsec)
self.top = filters.gaussian_filter1d(datatop,sigma=gfilter)
# Cumchange
rect_B_spline = RectBivariateSpline(self.y[:,0], self.x[0,:], self.cumchange)
cumdat = rect_B_spline.ev(ysec, xsec)
gcum = filters.gaussian_filter1d(cumdat,sigma=gfilter)
self.depo = gcum.clip(min=0)
return
示例13: assign_phases_to_antennas
# 需要导入模块: from scipy.interpolate import RectBivariateSpline [as 别名]
# 或者: from scipy.interpolate.RectBivariateSpline import ev [as 别名]
def assign_phases_to_antennas(ant1,ant2,antX,antY,PhaseGrid,phase_x,phase_y,velocity,time):
'''
Given antenna IDs, coordinates, and the phase grid and its coordinates: Translate
the antennas across the grid and record the phase for each antenna. Returns a 1D array
of antenna phases (uncalibrated) for the 1st and 2nd antenna in each observation
'''
f_interp = RectBivariateSpline(phase_y,phase_x,PhaseGrid,kx=1,ky=1)
antenna1_phase = f_interp.ev(antY[ant1],antX[ant1]+velocity*time)
antenna2_phase = f_interp.ev(antY[ant2],antX[ant2]+velocity*time)
# Also want to get a 2d array of the phase of each antenna with time, to ease with calibration
Ntsteps = len(time)/(len(antX)*(len(antX)-1)/2)
antennaphases = np.zeros([len(antX),Ntsteps],float)
tstepsize = np.unique(time)[1]-np.unique(time[0])
for i in range(len(antX)):
antennaphases[i,:] = f_interp.ev(antY[i]*np.ones(Ntsteps),antX[i]+tstepsize*velocity*np.arange(Ntsteps))
return antenna1_phase,antenna2_phase,antennaphases
示例14: scatter
# 需要导入模块: from scipy.interpolate import RectBivariateSpline [as 别名]
# 或者: from scipy.interpolate.RectBivariateSpline import ev [as 别名]
def scatter(self,move_pix=0,scale=1):
'''
Generate the scattered image which is stored in the ``iss`` member.
:param move_pix: (optional) int
Number of pixels to roll the screen (for time evolution).
:param scale: (optional) scalar
Scale factor for gradient. To simulate the scattering effect at another
wavelength this is (lambda_new/lambda_old)**2
'''
M = self.model.shape[-1] # size of original image array
N = self.nx # size of output image array
#if not self.live_dangerously: self._checkSanity()
# calculate phase gradient
dphi_x,dphi_y = self._calculate_dphi(move_pix=move_pix)
if scale != 1:
dphi_x *= scale/sqrt(2.)
dphi_y *= scale/sqrt(2.)
xx_,yy = np.meshgrid((np.arange(N) - 0.5*(N-1)),\
(np.arange(N) - 0.5*(N-1)),indexing='xy')
# check whether we care about PA of scattering kernel
if self.pa != None:
f_model = RectBivariateSpline(self.model_dx/self.dx*(np.arange(M) - 0.5*(M-1)),\
self.model_dx/self.dx*(np.arange(M) - 0.5*(M-1)),\
self.model)
# apply rotation
theta = -(90 * pi / 180) + np.radians(self.pa) # rotate CW 90 deg, then CCW by PA
xx_ += dphi_x
yy += dphi_y
xx = cos(theta)*xx_ - sin(theta)*yy
yy = sin(theta)*xx_ + cos(theta)*yy
self.iss = f_model.ev(yy.flatten(),xx.flatten()).reshape((self.nx,self.nx))
# rotate back and clip for positive values for I
if self.think_positive:
self.iss = clip(rotate(self.iss,-1*theta/np.pi*180,reshape=False),a_min=0,a_max=1e30) * (self.dx/self.model_dx)**2
else:
self.iss = rotate(self.iss,-1*theta/np.pi*180,reshape=False) * (self.dx/self.model_dx)**2
# otherwise do a faster lookup rather than the expensive interpolation.
else:
yyi = np.rint((yy+dphi_y+self.nx/2)).astype(np.int) % self.nx
xxi = np.rint((xx_+dphi_x+self.nx/2)).astype(np.int) % self.nx
if self.think_positive:
self.iss = clip(self.isrc[yyi,xxi],a_min=0,a_max=1e30)
else:
self.iss = self.isrc[yyi,xxi]
示例15: x_sig
# 需要导入模块: from scipy.interpolate import RectBivariateSpline [as 别名]
# 或者: from scipy.interpolate.RectBivariateSpline import ev [as 别名]
def x_sig( self, x, sigma ):
eps_list, mu_q = self.spirrid_response
eps_sig = InterpolatedUnivariateSpline( mu_q[0, :], eps_list[1] )
if max( mu_q ) > sigma:
pass
else:
raise ValueError( 'applied stress higher than the maximum in micromechanical evaluation of a CB' )
eps = eps_sig( sigma )
spline = RectBivariateSpline( eps_list[0], eps_list[1], mu_q )
sigma_f = spline.ev( x, ones( len( x ) ) * eps ) / self.V_f
sigma_m = ( sigma - sigma_f * self.V_f ) / self.V_m
return sigma_m