当前位置: 首页>>代码示例>>Python>>正文


Python pylab.sin函数代码示例

本文整理汇总了Python中pylab.sin函数的典型用法代码示例。如果您正苦于以下问题:Python sin函数的具体用法?Python sin怎么用?Python sin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了sin函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: calculateFDunc

    def calculateFDunc(self):
        #Calculates the uncertainty of the FFT according to:
        #   - J. M. Fornies-Marquina, J. Letosa, M. Garcia-Garcia, J. M. Artacho, "Error Propagation for the transformation of time domain into frequency domain", IEEE Trans. Magn, Vol. 33, No. 2, March 1997, pp. 1456-1459
        #return asarray _tdData
        #Assumes tha the amplitude of each time sample is statistically independent from the amplitude of the other time
        #samples

        # Calculates uncertainty of the real and imaginary part of the FFT and ther covariance
        unc_E_real = []
        unc_E_imag = []
        cov = []
        for f in self.getfreqs():
            unc_E_real.append(py.sum((py.cos(2*py.pi*f*self._tdData.getTimes())*self._tdData.getUncEX())**2))
            unc_E_imag.append(py.sum((py.sin(2*py.pi*f*self._tdData.getTimes())*self._tdData.getUncEX())**2))
            cov.append(-0.5*sum(py.sin(4*py.pi*f*self._tdData.getTimes())*self._tdData.getUncEX()**2))
        
        unc_E_real = py.sqrt(py.asarray(unc_E_real))
        unc_E_imag = py.sqrt(py.asarray(unc_E_imag))
        cov = py.asarray(cov)
        
        # Calculates the uncertainty of the modulus and phase of the FFT
        unc_E_abs = py.sqrt((self.getFReal()**2*unc_E_real**2+self.getFImag()**2*unc_E_imag**2+2*self.getFReal()*self.getFImag()*cov)/self.getFAbs()**2)
        unc_E_ph = py.sqrt((self.getFImag()**2*unc_E_real**2+self.getFReal()**2*unc_E_imag**2-2*self.getFReal()*self.getFImag()*cov)/self.getFAbs()**4)
        
        t=py.column_stack((self.getfreqs(),unc_E_real,unc_E_imag,unc_E_abs,unc_E_ph))
        return self.getcroppedData(t)  
开发者ID:DavidJahn86,项目名称:terapy,代码行数:26,代码来源:TeraData.py

示例2: get_first_init

def get_first_init(x0,epsilon,N):
    x_new = pl.copy(x0)
    print('getting the first initial condition')
    print('fiducial initial: '+str(x0))
    # multi particle array layout [nth particle v, (n-1)th particle v , ..., 0th v, nth particle x, x, ... , 0th particle x]
    
    # we will use a change of coordinates to get the location of the particle relative to x0. First
    # we just find some random point a distace epsilon from the origin.
    # need 2DN random angles 
    angle_arr = pl.array([])
    purturbs = pl.array([])

    # This is just an n-sphere 
    for i in range(2*N):
        angle_arr = pl.append(angle_arr,random.random()*2.0*pl.pi)
        cur_purt = epsilon
        for a,b in enumerate(angle_arr[:-1]):
            cur_purt *= pl.sin(b)
        if i == (2*N-1):
            cur_purt = pl.sin(angle_arr[i])
        else:
            cur_purt = pl.cos(angle_arr[i])

        purturbs = pl.append(purturbs,cur_purt)

    print('sqrt of sum of squars should be epsilon -> is it? --> ' +str(pl.sqrt(pl.dot(purturbs,purturbs))))
    print('len(purturbs) == 2N ? ' +str(len(purturbs)==(2*N)))

    return x_new+purturbs
开发者ID:OvenO,项目名称:BlueDat,代码行数:29,代码来源:lyapunov.py

示例3: findcurve

def findcurve(psi1,psi2,n=3,nn_fit=4,nn_out=100):
    '''
    Function to find the elastica curve for start and end orientations
    psi1 and psi2. It finds the best curve across all directions from start
    and end, i.e. the direction independent elastica curve.
    
    Inputs
    ------------
    psi1,psi2: start and end orientations.
    n:     degree of estimation polynomial.
    nn:    number of points on the curve.
             - nn_fit: for fittin purposes
             - nn_out: for the output
    
    Outputs
    ------------
    Returns a tuple (s,psi). 
    s:   points on the curve.
    psi: curvature of the curve as a function of s.
    E:   curvature energy of the curve
    '''
    # 
    
    # define the starting conditions
    a0 = pl.zeros(n+1) 
    
    # Set a high energy: 
    E_best = 10000  
    
    # and predfine output curve
    s       = pl.linspace(0,1,nn_out) # points on the curve
    psi_out = pl.zeros(nn_out)        # curvature at points in curve
    
    
    # across all the start and end directions find the curve with the lowest energy    
    for dpsi1 in (-pl.pi,0,pl.pi):
        for dpsi2 in (-pl.pi,0,pl.pi):
            # For the starting variables,
            # the first two polygon variables can be estimated from the Sharon paper derivation
            # For different starting variables the solution can be hard to find            
            a0[-2] = 4*(   pl.arcsin(- (pl.sin(psi1+dpsi1)+ pl.sin(psi2+dpsi2))/4)    -(psi1+dpsi1+psi2+dpsi2)/2       )
            a0[-1] = 2*a0[-2]/pl.cos( (psi1+dpsi1+psi2+dpsi2)/2 + a0[-2]/4  )               
            
            # find the best variables to minimize the elastica energy
            fit = fsolve(errors,a0,args=(psi1+dpsi1,psi2+dpsi2,nn_fit))
    
            # find the curve and its derivative for the fitted variables
            a    = fit[:-1]
            psi  = Psi(a,s,psi1+dpsi1,psi2+dpsi2)
            dpsi = dPsi(a,s,psi1+dpsi1,psi2+dpsi2)
    
            # find the energy of this curve
            E = sum(dpsi**2)*s[1]
            
            # check against the lowest energy
            if E_best > E:
                E_best = E
                psi_out[:] = pl.copy(psi)    
    
    return (s,psi_out,E_best)
开发者ID:swkeemink,项目名称:elastica,代码行数:60,代码来源:elastica.py

示例4: get_touchdown

    def get_touchdown(self, t, y, params):
        """
        Compute the touchdown position of the leg w.r.t. CoM velocity
        
        :args:
            t (float): time
            y (6x float): state of the CoM
            params (4x float): leg parameter: stiffness, l0, alpha, beta
        
        :returns:
            [xFoot, yFoot, zFoot] the position of the leg tip
        """
        k, l0, alpha, beta = params
        vx, vz = y[3], y[5]
        
        a_v_com = -arctan2(vz, vx) # correct with our coordinate system
        #for debugging
        #print "v_com_angle:", a_v_com * 180. / pi
                
        xf = y[0] + l0 * cos(alpha) * cos(beta + a_v_com)
        yf = y[1] - l0 * sin(alpha)
        zf = y[2] - l0 * cos(alpha) * sin(beta + a_v_com)

        #for debugging
        #print "foot: %2.3f,%2.3f,%2.3f," % ( xf,yf, zf)
        
        return array([xf, yf, zf])
开发者ID:MMaus,项目名称:mutils,代码行数:27,代码来源:bslip.py

示例5: tests

def tests():
	x = pylab.arange(0.0, 2*pylab.pi, 0.01)
	list_y = (pylab.sin(x),pylab.sin(2*x))
	plot_and_format((x,), (list_y[0],))
	exportplot('test/test1_one_curve.png')
	pylab.clf()
	list_x = (x, x)
	plot_and_format(list_x, list_y)
	exportplot('test/test2_two_curves.png')
	pylab.clf()
	list_format = ('k-', 'r--')
	plot_and_format(list_x, list_y, list_format=list_format)
	exportplot('test/test3_two_curves_formatting.png')
	pylab.clf()
	plot_and_format(list_x, list_y, list_format=list_format, xlabel='hello x axis')
	exportplot('test/test4_two_curves_formatting_xlab.png')
	pylab.clf()
	plot_and_format(list_x, list_y, list_format=list_format, legend=['sin($x$)', 'sin($2x$)'])
	exportplot('test/test5_two_curves_formatting_legend.png')
	pylab.clf()
	plot_and_format(list_x, list_y, list_format=list_format, xticks={'ticks': [0, pylab.pi, 2*pylab.pi], 'labels':['0', '$\pi$', '$2\pi$']})
	exportplot('test/test6_two_curves_formatting_xticks.png')
	pylab.clf()
	plot_and_format(list_x, list_y, list_format=list_format, xticks={'ticks': [0, pylab.pi, 2*pylab.pi], 'labels':['0', '$\pi$', '$2\pi$']}, xlim=[0,2*pylab.pi])
	exportplot('test/test7_two_curves_formatting_xticks_xlim.png')
	pylab.clf()
开发者ID:DRemD,项目名称:opentraveldata,代码行数:26,代码来源:generic_plot.py

示例6: specgram_demo

def specgram_demo():
   '''
   the demo in matplotlib. But calls
   interactive.specgram
   '''
   from pylab import arange, sin, where, logical_and, randn, pi

   dt = 0.0005
   t = arange(0.0, 20.0, dt)
   s1 = sin(2*pi*100*t)
   s2 = 2*sin(2*pi*400*t)

   # create a transient "chirp"
   mask = where(logical_and(t>10, t<12), 1.0, 0.0)
   s2 = s2 * mask

   # add some noise into the mix
   nse = 0.01*randn(len(t))

   x = s1 + s2 + nse # the signal
   NFFT = 1024       # the length of the windowing segments
   Fs = int(1.0/dt)  # the sampling frequency

   from ifigure.interactive import figure, specgram, nsec, plot, isec, clog, hold

   figure()
   hold(True)
   nsec(2)
   isec(0)
   plot(t, x)
   isec(1)
   specgram(x, NFFT=NFFT, Fs=Fs, noverlap=900)
   clog()
开发者ID:piScope,项目名称:piScope,代码行数:33,代码来源:plot_demos.py

示例7: hillshade

def hillshade(data,scale=10.0,azdeg=165.0,altdeg=45.0):
  ''' 
    This code thanks to Ran Novitsky Nof
  http://rnovitsky.blogspot.co.uk/2010/04/using-hillshade-image-as-intensity.html
  Repeated here to make my cyclopean uk_map code prettier.

  convert data to hillshade based on matplotlib.colors.LightSource class.
    input:
         data - a 2-d array of data
         scale - scaling value of the data. higher number = lower gradient
         azdeg - where the light comes from: 0 south ; 90 east ; 180 north ;
                      270 west
         altdeg - where the light comes from: 0 horison ; 90 zenith
    output: a 2-d array of normalized hilshade
  '''
  
  from pylab import pi, gradient, arctan, hypot, arctan2, sin, cos
  # convert alt, az to radians
  az = azdeg*pi/180.0
  alt = altdeg*pi/180.0
  # gradient in x and y directions
  dx, dy = gradient(data/float(scale))
  slope = 0.5*pi - arctan(hypot(dx, dy))
  aspect = arctan2(dx, dy)
  intensity = sin(alt)*sin(slope) + cos(alt)*cos(slope)*cos(-az - aspect - 0.5*pi)
  intensity = (intensity - intensity.min())/(intensity.max() - intensity.min())
  return intensity
开发者ID:HeavyWeather,项目名称:Graphical,代码行数:27,代码来源:hillshade.py

示例8: main

def main():
    # Create the grid
    x = arange(-100, 101)
    y = arange(-100, 101)

    # Create the meshgrid
    Y, X = meshgrid(x, y)
    A = 1
    B = 2
    V = 6*pi / 201
    W = 4*pi / 201
    F = A*sin(V*X) + B*cos(W*Y)
    Fx = V*A*cos(V*X)
    Fy = W*B*-sin(W*Y)

    # Show the images
    show_image(F)
    show_image(Fx)
    show_image(Fy)

    # Create the grid for the quivers
    xs = arange(-100, 101, 10)
    ys = arange(-100, 101, 10)

    # Here we determine the direction of the quivers
    Ys, Xs = meshgrid(ys, xs)
    FFx = V*A*cos(V*Xs)
    FFy = W*B*-sin(W*Ys)

    # Draw the quivers and the image
    clf()
    imshow(F, cmap=cm.gray, extent=(-100, 100, -100, 100))
    quiver(ys, xs, -FFy, FFx, color='red')
    show()
开发者ID:latencie,项目名称:Beeldbewerken,代码行数:34,代码来源:exercise_1.py

示例9: f_mdl

def f_mdl(mdl, phi, maxord):
    """
    given a periodic function "mdl" consisting of n data points (ranging from  [0,2pi)),
    a fourier model of order maxord is computed for all phases in phi

    :args:
        mdl (1-by-k array): datapoints of the reference model, ranging from
           [0, 2pi). Length in datapoints is arbitrary.
        phi (1-by-n array): phases at which to evaluate the model
        maxord (int): order of the Fourier model to compute

    :returns:
       mdl_val (1-by-n array): value of the Fourier model obtained from mdl for
           the given phases phi
    
    """
    spec_fy = fft.fft(mdl)
    as_, ac_ = spec_fy.imag, spec_fy.real
    sigout = zeros(len(phi))
    for order in range(maxord):
        sigout -= sin(order * phi) * as_[order]
        sigout += cos(order * phi) * ac_[order]    
        sigout += cos(order * phi) * ac_[-order]
        sigout += sin(order * phi) * as_[-order]
    sigout /= len(mdl)
    return sigout
开发者ID:MMaus,项目名称:mutils,代码行数:26,代码来源:fourier.py

示例10: hillshade

def hillshade(data, scale=10.0, azdeg=165.0, altdeg=45.0):
    '''
    Convert data to hillshade based on matplotlib.colors.LightSource class.

    Args:
        data - a 2-d array of data
        scale - scaling value of the data. higher number = lower gradient
        azdeg - where the light comes from: 0 south ; 90 east ; 180 north ;
                        270 west
        altdeg - where the light comes from: 0 horison ; 90 zenith

    Returns:
        a 2-d array of normalized hilshade
    '''
    # convert alt, az to radians
    az = azdeg*pi/180.0
    alt = altdeg*pi/180.0
    # gradient in x and y directions
    dx, dy = gradient(data/float(scale))
    slope = 0.5*pi - arctan(hypot(dx, dy))
    aspect = arctan2(dx, dy)
    az = -az - aspect - 0.5*pi
    intensity = sin(alt)*sin(slope) + cos(alt)*cos(slope)*cos(az)
    mi, ma = intensity.min(), intensity.max()
    intensity = (intensity - mi)/(ma - mi)
    return intensity
开发者ID:stenotech,项目名称:geotransect,代码行数:26,代码来源:shading.py

示例11: haversine

def haversine (latlong1, latlong2, r):

    deltaLatlong = latlong1 - latlong2
    
    dLat = deltaLatlong[0]
    dLon = deltaLatlong[1]

    lat1 = latlong1[0]
    lat2 = latlong2[0]

    a = (sin (dLat/2) * sin (dLat/2) +
         sin (dLon/2) * sin (dLon/2) * cos (lat1) * cos (lat2))
    c = 2 * arctan2 (sqrt (a), sqrt (1-a))
    d = r * c

    # initial bearing
    y = sin (dLon) * cos (lat2)
    x = (cos (lat1)*sin (lat2) -
         sin (lat1)*cos (lat2)*cos (dLon))
    b1 = arctan2 (y, x);

    # final bearing
    dLon = -dLon
    dLat = -dLat
    tmp = lat1
    lat1 = lat2
    lat2 = tmp
    y = sin (dLon) * cos (lat2)
    x = (cos (lat1) * sin (lat2) - 
         sin (lat1) * cos (lat2) * cos (dLon))
    b2 = arctan2 (y, x)
    b2 = mod ((b2 + pi), 2*pi)

    return (d, b1, b2)
开发者ID:pjozog,项目名称:PylabUtils,代码行数:34,代码来源:haversine.py

示例12: sortAnglesCW

def sortAnglesCW(t1,t2):

    """
    Sort angles so that t2>t1 in a clockwise sense
    idea from `StackOverflow <http://stackoverflow.com/questions/242404/sort-four-points-in-clockwise-order>`_
    more description: `SoftSurfer <http://softsurfer.com/Archive/algorithm_0101/algorithm_0101.htm>`_

    If the signed area of the triangle formed between the points on a unit circle with angles t1 and t2
    and the origin is positive, the angles are sorted counterclockwise. Otherwise, the angles
    are sorted in a counter-clockwise manner.  Here we want the angles to be sorted CCW, so
    if area is negative, swap angles
    
    Area obtained from the cross product of a vector from origin 
    to 1 and a vector to point 2, so use right hand rule to get 
    sign of cross product with unit length
    """

    while (cos(t1)*sin(t2)-sin(t1)*cos(t2)>0):
        ##Swap angles
        temp=t1;
        t1=t2;
        t2=temp;
    #Make t1 between 0 and 2pi
    while (t1<0 or t1> 2.0*pi):
        if t1>2.0*pi:
            t1=t1-2*pi
        else:
            t1=t1+2*pi
    #Want t2 to be less than t1, but no more than 2*pi less
    while (t2<t1 and t1-t2>2*pi):
        t2=t2+2*pi
    while (t2>t1):
        t2=t2-2*pi
    return (t1,t2)
开发者ID:bansal16,项目名称:pdsim,代码行数:34,代码来源:plots.py

示例13: haversine

def haversine(location1, location2=None):  # calculates great circle distance
    __doc__ = """Returns the great circle distance of the given
    coordinates.
    
    INPUT:  location1 = ((lat1, lon1), ..., n(lat1, lon1))
           *location2 = ((lat2, lon2), ..., n(lat2, lon2))
           *if location2 is not given a square matrix of distances
             for location1 will be put out
    OUTPUT: distance in km
            (dist1  ...  ndist
              :            : 
             ndist1 ...  ndist)
            shape will depend on the input
    METHOD: a = sin(dLat / 2) * sin(dLat / 2) + 
                sin(dLon / 2) * sin(dLon / 2) * 
                cos(lat1) * cos(lat2)
            c = 2 * arctan2(sqrt(a), sqrt(1 - a))
            d = R * c
            
            where R is the earth's radius (6371 km)
            and d is the distance in km"""
    
    from itertools import product, combinations
    from pylab import   deg2rad, sin, cos, arctan2, \
                        meshgrid, sqrt, array, arange
    
    if location2: 
        location1 = array(location1, ndmin=2)
        location2 = array(location2, ndmin=2)
    elif location2 is None:
        location1 = array(location1, ndmin=2)
        location2 = location1.copy()
    
    # get all combinations using indicies
    ind1 = arange(location1.shape[0])
    ind2 = arange(location2.shape[0])
    ind  = array(list(product(ind1, ind2)))
    
    # using combination inds to get lats and lons
    lat1, lon1 = location1[ind[:,0]].T
    lat2, lon2 = location2[ind[:,1]].T
    
    # setting up variables for haversine
    R = 6371.
    dLat = deg2rad(lat2 - lat1)
    dLon = deg2rad(lon2 - lon1)
    lat1 = deg2rad(lat1)
    lat2 = deg2rad(lat2)
    
    # haversine formula
    a = sin(dLat / 2) * sin(dLat / 2) + \
        sin(dLon / 2) * sin(dLon / 2) * \
        cos(lat1) * cos(lat2)
    c = 2 * arctan2(sqrt(a), sqrt(1 - a))
    d = R * c
    
    # reshape accodring to the input
    D = d.reshape(location1.shape[0], location2.shape[0])
    
    return D
开发者ID:sigmamonster,项目名称:PyOceanMaps,代码行数:60,代码来源:haversine.py

示例14: measureDistance

def measureDistance(lat1, lon1, lat2, lon2):
    R = 6383.137 # Radius of earth at Chajnantor aprox. in KM
    dLat = (lat2 - lat1) * np.pi / 180.
    dLon = (lon2 - lon1) * np.pi / 180.
    a = pl.sin(dLat/2.) * pl.sin(dLat/2.) + pl.cos(lat1 * np.pi / 180.) * pl.cos(lat2 * np.pi / 180.) * pl.sin(dLon/2.) * pl.sin(dLon/2.)
    c = 2. * atan2(pl.sqrt(a), pl.sqrt(1-a))
    d = R * c
    return d * 1000. # meters
开发者ID:SDK,项目名称:sacm,代码行数:8,代码来源:sacm211.py

示例15: rotated_rectangle

 def rotated_rectangle(x0,y0,w,h,rot):
     
     x = np.array([-w/2,w/2,w/2,-w/2,-w/2])
     y = np.array([-h/2,-h/2,h/2,h/2,-h/2])
     
     xrot = x*cos(rot)-y*sin(rot)
     yrot = x*sin(rot)+y*cos(rot) 
     
     return xrot+x0, yrot+y0
开发者ID:ibell,项目名称:pdsim,代码行数:9,代码来源:plots.py


注:本文中的pylab.sin函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。