コード例 #1
0
ファイル: haversine.py プロジェクト: sigmamonster/PyOceanMaps
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
コード例 #2
0
ファイル: haversine.py プロジェクト: sigmamonster/PyOceanMaps
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
コード例 #3
0
    def get_lines_for_frame(self, frame, root_offset=None):
        lines = []

        def draw_line_to_children(bone, ppos, P, rpos):
            for child in self.hierarchy[bone]:
                cbone = self.bones[child]

                C = self.__local_matrices[child + '__C']
                Cinv = self.__local_matrices[child + '__Cinv']
                B = self.__local_matrices[child + '__B']

                #Motion matrix
                M = eye(4)
                try:
                    for dof, val in zip(cbone.dof, frame[child]):
                        val = pl.deg2rad(val)
                        R = eye(4)
                        if dof == 'rx':
                            R = Rx(val)
                        elif dof == 'ry':
                            R = Ry(val)
                        elif dof == 'rz':
                            R = Rz(val)

                        #M = dot(M, R)
                        M = dot(R, M)
                except:  #We might not have dof data for the current bone
                    pass

                #Local transform
                L = C.dot(M).dot(Cinv).dot(B)
                #Full transform
                A = dot(P, L)

                cpos = dot(A, [0, 0, 0, 1]) + rpos

                if child[0] == 'rtoes' or child == 'ltoes':
                    continue

                lines.append([ppos[:3], cpos[:3]])

                draw_line_to_children(child, cpos, A, rpos)

        #Root orientation and translation
        transf = frame['root'].copy()
        if root_offset is not None:
            transf[0:3] += root_offset

        R = dot(Rz(pl.deg2rad(transf[5])),
                dot(Ry(pl.deg2rad(transf[4])), Rx(pl.deg2rad(transf[3]))))
        B = T(transf[0:3])
        rpos = dot(B, [0, 0, 0, 1]) / 0.45 * Skeleton.SCALE
        draw_line_to_children('root', rpos, R, rpos)

        return lines
コード例 #4
0
        def draw_line_to_children(bone, ppos, P, rpos, ppindex):
            for child in self.hierarchy[bone]:
                cbone = self.bones[child]
                C = self.__local_matrices[child + '__C']
                Cinv = self.__local_matrices[child + '__Cinv']
                B = self.__local_matrices[child + '__B']

                #Motion matrix
                M = eye(4)
                try:
                    for dof, val in zip(cbone.dof, frame[child]):
                        val = pl.deg2rad(val)
                        R = eye(4)
                        if dof == 'rx':
                            R = Rx(val)
                        elif dof == 'ry':
                            R = Ry(val)
                        elif dof == 'rz':
                            R = Rz(val)

                        M = dot(R, M)
                except:  #We might not have dof data for the current bone
                    pass

                L = C.dot(M).dot(Cinv).dot(B)

                #Full transform
                A = dot(P, L)

                cpos = dot(A, [0, 0, 0, 1]) + rpos

                coords.append(cpos[:3])
                draw_line_to_children(child, cpos, A, rpos, len(coords) - 1)
コード例 #5
0
    def estimate_haversine(self):
        if self.verbose:
            print("Estimating Spatial locality with Haversine distance .")
        self.haversine = DistanceMetric.get_metric("haversine")
        # prepare features  Coordinates
        longi, lat = pl.deg2rad(
            hp.pix2ang(
                nside=self._nside,
                ipix=pl.arange(hp.nside2npix(self._nside)),
                lonlat=True,
            ))
        mask = pl.ma.masked_inside(longi, 0, pl.pi).mask
        longi[mask] = -longi[mask]
        longi[pl.logical_not(mask)] = 2 * pl.pi - longi[pl.logical_not(mask)]
        Theta = pl.array([lat[self.galactic_mask],
                          longi[self.galactic_mask]]).T

        angdist_matr = self.haversine.pairwise(Theta)
        angdist_matr = pl.ma.fix_invalid(angdist_matr, fill_value=pl.pi).data

        # all the distances are equally weighted and so far range in 0,1

        weight_eucl = 1.0 / self._distance_matr.max()
        weight_hav = 1.0 / angdist_matr.max()

        self._distance_matr = pl.multiply(weight_eucl * self._distance_matr,
                                          weight_hav * angdist_matr)

        self._X = pl.concatenate([self._X, Theta], axis=1)
        pass
コード例 #6
0
    def convert(node):
        if node is 'root':
            transf = [pl.deg2rad(x) for x in frame['root']]
            return pl.dot(Rz(transf[5]), pl.dot(Ry(transf[4]), Rx(transf[3])))

        cbone = skeleton.bones[node]
        #Motion matrix
        M = pl.eye(4)
        try:
            for dof, val in zip(cbone.dof, frame[node]):
                val = pl.deg2rad(val)
                R = pl.eye(4)
                if dof == 'rx':
                    R = Rx(val)
                elif dof == 'ry':
                    R = Ry(val)
                elif dof == 'rz':
                    R = Rz(val)

                M = pl.dot(R, M)
        except:  #We might not have dof data for the current bone
            pass
        return M
コード例 #7
0
ファイル: Actor.py プロジェクト: ml4ai/b3
 def checkFOV(self, aOther_Pt):
     #Get Angle (in Radians) Limits (and their Slopes)
     nAngView = pylab.deg2rad(25)
     if self.nHeading == '-': return False
     aThis_Pt, aOther_Pt = list(self.aPos), list(aOther_Pt)
     nRad1, nRad2 = self.nHeading + nAngView, self.nHeading - nAngView
     nSlope1, nSlope2, nMaxSlope = pylab.tan(nRad1), pylab.tan(nRad2), 10000
     # @UnusedVariable
     aThis_Pt[1], aOther_Pt[1] = self.nFrm_Height - aThis_Pt[
         1], self.nFrm_Height - aOther_Pt[1]
     aOther_Pt[0], b = (aOther_Pt[0] - aThis_Pt[0]), aThis_Pt[1]
     nOtherX, nOtherY = aOther_Pt[0], aOther_Pt[1]
     #         #Avoid Multiplications where the Slope is close to Infinite
     #         if abs(nSlope1) >= nMaxSlope:
     #             y2 = nSlope2*nOtherX + b;
     #             if nRad2 < pylab.pi/2.0: return (nOtherX>=0) and (nOtherY>=y2);
     #             else: return (nOtherX<=0) and (nOtherY<=y2);
     #         if abs(nSlope2) >= nMaxSlope:
     #             y1 = nSlope1*nOtherX + b;
     #             if nRad1 > (3*pylab.pi)/2.0: return (nOtherX>=0) and (nOtherY<=y1);
     #             else: return (nOtherX<=0) and (nOtherY>=y1);
     #Check position of AngViews
     y1 = nSlope1 * nOtherX + b
     y2 = nSlope2 * nOtherX + b
     nUpLeft, nDownLeft = pylab.pi / 2.0, (3 * pylab.pi) / 2.0
     bAngView1_Left = (nRad1 > nUpLeft) and (nRad1 < nDownLeft)
     #AngView1 on Left Side
     bAngView2_Left = (nRad2 > nUpLeft) and (nRad2 < nDownLeft)
     #AngView2 on Left Side
     bBothLeft = (bAngView1_Left) and (bAngView2_Left)
     bBothRight = (bAngView1_Left == False) and (bAngView2_Left == False)
     bBothUp = (bAngView1_Left) and (bAngView2_Left == False)
     bBothDown = (bAngView1_Left == False) and (bAngView2_Left)
     if bBothLeft and (nOtherY >= y1) and (nOtherY <= y2): return True
     if bBothRight and (nOtherY <= y1) and (nOtherY >= y2): return True
     if bBothUp and (nOtherY >= y1) and (nOtherY >= y2): return True
     if bBothDown and (nOtherY <= y1) and (nOtherY <= y2): return True
     return False
コード例 #8
0
b_coils_list = []
r_b_coils_list = []
z_b_coils_list = []
b_coils_r_width_list = []
b_coils_z_width_list = []
r_floop_list = []
z_floop_list = []

array_radius = 1.15

array_r_width = 0.1
array_z_width = 0.1

delta_theta_degrees = 15.0
delta_theta = P.deg2rad(delta_theta_degrees)

n_coils_each_side = 5

theta_start_degrees = 270.0
theta_start = P.deg2rad(theta_start_degrees)
theta_end = theta_start + (n_coils_each_side - 1) * delta_theta

for theta in P.linspace(theta_start, theta_end, n_coils_each_side):
    r_coil = r_0 + array_radius * P.cos(theta)
    z_coil = array_radius * P.sin(theta)
    r_b_coils_list.append(r_coil)
    z_b_coils_list.append(z_coil)
    r_floop = r_0 + a * P.cos(theta)
    z_floop = a * P.sin(theta)
    r_floop_list.append(r_floop)
コード例 #9
0
ファイル: symbolic.py プロジェクト: kangwonlee/15ecaa
print "diff(sin(2*x), x, 2) =", diff(sin(2 * x), x, 2)

print "diff(sin(2*x), x, 3) =", diff(sin(2 * x), x, 3)

print '''2.10.3.3'''

print "series(cos(x), x) =", series(cos(x), x)

print "series(1/cos(x), x) =", series(1 / cos(x), x)

# Series 설명을 위하여 그래프를 그림
# 그래프 그리기 관련 기능 등을 담고 있는 pylab 모듈을 불러 들임
import pylab

x_deg = pylab.arange(-90, 90 + 1)
x_rad = pylab.deg2rad(x_deg)
y_cos = pylab.cos(x_rad)
y_series_1 = 1 * pylab.ones_like(x_rad)
y_series_2 = 1 - x_rad ** 2 / 2
y_series_3 = 1 - x_rad ** 2 / 2 + x_rad ** 4 / 24

pylab.plot(x_deg, y_cos, label='cos')
pylab.plot(x_deg, y_series_1, label='series 1')
pylab.plot(x_deg, y_series_2, label='series 2')
pylab.plot(x_deg, y_series_3, label='series 3')
pylab.grid()
pylab.legend(loc=0)
# pylab.show()

print '''2.10.3.5'''
print "integrate(6*x**5, x) =", integrate(6 * x ** 5, x)
コード例 #10
0
ny = 50
nz = 8

m = dolfin.UnitCubeMesh(nx,ny,nz)
Q = dolfin.FunctionSpace(m,"CG",1)
u = dolfin.Function(Q)
v = dolfin.Function(Q)
w = dolfin.Function(Q)
S = dolfin.Function(Q)

dolfin.File('./results_stokes/u.xml') >> u
dolfin.File('./results_stokes/v.xml') >> v
dolfin.File('./results_stokes/w.xml') >> w
dolfin.File('./results_stokes/S.xml') >> S

theta = pylab.deg2rad(-3.0)
profile = pylab.linspace(0,1,100)
S0 = pylab.sin(theta)/pylab.cos(theta)*profile*100000.0
U = pylab.zeros(100)
s = pylab.zeros(100)

for ii,x in enumerate(profile):
    uu = u(x,0.5,0.99999)
    vv = v(x,0.5,0.99999)
    ww = w(x,0.5,0.99999)
    SS = S(x,0.5,0.99999)
    U[ii] = pylab.sqrt(uu**2 + vv**2 + ww**2)
    s[ii] = SS

data = zip(profile,s-S0,U)
pickle.dump(data,open("djb2f{0:03d}.p".format(0),'w'))
コード例 #11
0
def parse_asf(filename, description = "", remove_noisy_channels = True):

    noisy_channels =  {'rtoes', 'ltoes', 'rthumb', 'lthumb', 'rfingers',
                       'lfingers', 'rhand', 'lhand'}
    data = []
    with open(filename,'r') as asf:
        data = asf.readlines()

    data = [line.strip() for line in data]  # Remove leading and trailing whitespace to simplify matters

    #---
    #Skip to bonedata
    bonedata = -1
    for i, line in enumerate(data):
        if line == ':bonedata':
            bonedata = i
            break

    if bonedata < 0:
        print('No bonedata found!')
        return

    bones = dict()
    bone = None
    end_bones = -1
    in_limits = False

    for i, line in enumerate(data[bonedata+1:]):
        tokens = line.split()

        #End of bonedata structure?
        if tokens[0][0] == ':':
            end_bones = i
            break

        #Begin of a single bone?
        if tokens[0] == 'begin':
            bone = Bone()

        #End of a single bone?
        if tokens[0] == 'end':
            if remove_noisy_channels and bone.name in noisy_channels:
                continue
            bones[bone.name] = bone

        #Bone data
        if tokens[0] == 'name':
            bone.name = tokens[1]

        if tokens[0] == 'direction':
            bone.direction = parse_array(tokens[1:4])

        if tokens[0] == 'length':
            bone.length = float(tokens[1])/0.45 * Skeleton.SCALE

        #TODO: Do I need to take the axis order into account for our data?
        if tokens[0] == 'axis':
            bone.axis = pl.deg2rad(parse_array(tokens[1:4]))

        if tokens[0] == 'dof':
            bone.dof = tokens[1:]

        #---
        #Axis limits
        #Assumes that "dof" was already set up
        if tokens[0] == 'limits':
            in_limits = True
            bone.limits.append((float(tokens[1][1:]), float(tokens[2][:-1])))
        elif in_limits:
            bone.limits.append((float(tokens[0][1:]), float(tokens[1][:-1])))
        if len(bone.limits) == len(bone.dof):
            in_limits = False


    #---
    #Skip to hierarchy
    hierarchy_index = -1
    for i, line in enumerate(data[bonedata+end_bones:]):
        if line == ':hierarchy':
            hierarchy_index = i
            break

    if hierarchy_index < 0:
        print('No hierarchy found!')
        return

    hierarchy_index += bonedata + end_bones

    skeleton = Skeleton(description)
    skeleton.bones = bones
    for line in data[hierarchy_index+1:]:
        tokens = line.split()

        #Begin of hierarchy?
        if tokens[0] == 'begin':
            continue

        #End of hierarchy?
        if tokens[0] == 'end':
            break

        skeleton.hierarchy[tokens[0]] = [c for c in tokens[1:] if c not in noisy_channels]

    return skeleton
コード例 #12
0
def cart2spherical(x, y, z):
    return array([
        arctan2(y, x) * 180 / pi,
        arccos(z / (sqrt(x**2 + y**2 + z**2))) * 180 / pi
    ])


def cart2spherical_dcase(x, y, z):
    phi = arctan2(y, x) * 180 / pi
    theta = arccos(z / (sqrt(x**2 + y**2 + z**2))) * 180 / pi
    return array([phi, 90 - theta])


# Gradangaben von Theta im Intervall [0,180] statt wie bei DCASE [90,-90]
M1 = spherical2cart(deg2rad(45), deg2rad(55), 0.042)
M2 = spherical2cart(deg2rad(315), deg2rad(125), 0.042)
M3 = spherical2cart(deg2rad(135), deg2rad(125), 0.042)
M4 = spherical2cart(deg2rad(225), deg2rad(55), 0.042)

mg = MicGeom()
mg.mpos_tot = array([M1, M2, M3,
                     M4]).T  # add microphone positions to MicGeom object

# define evaluation grid
# Hier könntest du vielleicht eine neue Spherical Grid Klasse schreiben oder
# eine ArbitraryGrid Klasse, damit wir ein sinnvolles Gitter zur Lokalisierung
# verwenden können.
# Als Anregung siehe: https://spaudiopy.readthedocs.io/en/latest/spaudiopy.grids.html
#
rg = SphericalGrid_Equiangular(NPOINTS_AZI, NPOINTS_ELE)
コード例 #13
0
ファイル: ISMIP_HOM_C_BP.py プロジェクト: JacobDowns/VarGlaS
import sys
src_directory = '../../../'
sys.path.append(src_directory)

from src.model                 import Model
from src.solvers               import SteadySolver
from src.physical_constants    import IceParameters
from src.helper                import default_nonlin_solver_params
from dolfin                    import set_log_active, File, Expression, pi
from pylab                     import sin, tan, deg2rad

set_log_active(True)

alpha = deg2rad(0.1)
lengths = [40000]
for L in [40000]:
  class Surface(Expression):
    def __init__(self):
      pass
    def eval(self,values,x):
      values[0] = -x[0]*tan(alpha)

  class Bed(Expression):
    def __init__(self):
      pass
    def eval(self,values,x):
      values[0] = -x[0]*tan(alpha) - 1000.0

  class Beta2(Expression):
    def __init__(self):
      pass
コード例 #14
0
#!/usr/bin/env python
# -*- coding: utf8 -*-
# Soubor:  mpl.py
# Autor:   Marek Nožka, nozka <@t> spseol <d.t> cz
# Licence: GNU/GPL
# Úloha:   výkon střídavého proudu
##############################################################################
from __future__ import division, print_function, unicode_literals

import pylab as lab
from pylab import pi

f = 50
T = 1/f
fi = lab.deg2rad(int(raw_input("zadej fázový posuv > ")))

t = lab.linspace(0, 1.8 * T, 300)
u = 1.5 * lab.sin(2*pi*f*t)
i = 1.2 * lab.sin(2*pi*f*t + fi)

lab.figure(1)
lab.plot(t, u, label='napětí')
lab.plot(t, i, label='proud')
lab.plot(t, u*i, label='výkon')
lab.grid(True)
lab.xlim(min(t), max(t))
lab.legend()

lab.show()
コード例 #15
0
ファイル: ISMIP_HOM_A_BP.py プロジェクト: mauro3/VarGlaS
import sys
src_directory = '../../../'
sys.path.append(src_directory)

from src.model              import Model
from src.solvers            import SteadySolver
from src.physical_constants import IceParameters
from src.helper             import default_nonlin_solver_params
from dolfin                 import set_log_active, File, Expression, pi
from pylab                  import sin, tan, deg2rad

set_log_active(True)

alpha   = deg2rad(0.5)
lengths = [40000]
for L in lengths:

  class Surface(Expression):
    def __init__(self):
      pass
    def eval(self,values,x):
      values[0] = - x[0] * tan(alpha)


  class Bed(Expression):
    def __init__(self):
      pass
    def eval(self,values,x):
      values[0] = - x[0] * tan(alpha) \
                  - 1000.0 \
                  + 500.0 * sin(2*pi*x[0]/L) * sin(2*pi*x[1]/L)
コード例 #16
0
print "diff(sin(x), x) = ", diff(sin(x), x)
print "diff(sin(2*x), x)", diff(sin(2 * x), x)
print "diff(tan(x), x) = ", diff(tan(x), x)
print "limit((tan(x+y)-tan(x))/y,y,0) =", limit((tan(x + y) - tan(x)) / y, y,
                                                0)
print "diff(sin(2*x), x, 1) =", diff(sin(2 * x), x, 1)
print "diff(sin(2*x), x, 2) =", diff(sin(2 * x), x, 2)
print "diff(sin(2*x), x, 3) =", diff(sin(2 * x), x, 3)
print '''2.10.3.3'''
print "series(cos(x), x) =", series(cos(x), x)
print "series(1/cos(x), x) = ", series(1 / cos(x), x)

import pylab

x_deg = pylab.arange(-90, 90 + 1)
x_rad = pylab.deg2rad(x_deg)
y_cos = pylab.cos(x_rad)
y_series_1 = 1 * pylab.ones_like(x_rad)
y_series_2 = 1 - x_rad**2 / 2
y_series_3 = 1 - x_rad**2 / 2 + x_rad**4 / 24

pylab.plot(x_deg, y_cos, label='cos')
pylab.plot(x_deg, y_series_1, label='series 1')
pylab.plot(x_deg, y_series_2, label='series 2')
pylab.plot(x_deg, y_series_3, label='series 3')
pylab.grid()
pylab.legend(loc=0)
#pylab.show()

print '''2.10.3.5'''
print "integrate(6*x**5, x) =", integrate(6 * x**5, x)
コード例 #17
0
ファイル: ISMIP_HOM_F.py プロジェクト: JacobDowns/VarGlaS
import sys
src_directory = '../../../'
sys.path.append(src_directory)

import src.model
import src.solvers
import src.physical_constants
import src.helper
from pylab  import sin, cos, exp, deg2rad
from dolfin import Expression, File, set_log_active

set_log_active(True)

theta = deg2rad(-3.0)
L     = 100000.
H     = 1000.0
a0    = 100
sigma = 10000

class Surface(Expression):
  def __init__(self):
    pass
  def eval(self, values, x):
    values[0] = sin(theta) / cos(theta) * x[0]

class Bed(Expression):
  def __init__(self):
    pass
  def eval(self, values, x):
    y_0       = -H + a0 * (exp(-((x[0]-L/2.)**2 + (x[1]-L/2.)**2) / sigma**2))
    values[0] = sin(theta)/cos(theta) * (x[0] + sin(theta)*y_0) + cos(theta)*y_0
コード例 #18
0
ファイル: ISMIP_HOM_A_stokes.py プロジェクト: mauro3/VarGlaS
import sys
src_directory = '../../../'
sys.path.append(src_directory)

import src.model
import src.solvers
import src.physical_constants
from src.helper import default_nonlin_solver_params
import pylab
import dolfin

dolfin.set_log_active(True)

alpha = pylab.deg2rad(0.5)
lengths = [40000]
for L in lengths:

    class Surface(dolfin.Expression):
        def __init__(self):
            pass
        def eval(self,values,x):
            values[0] = -x[0]*pylab.tan(alpha)

	
    class Bed(dolfin.Expression):
        def __init__(self):
            pass
        def eval(self,values,x):
            values[0] = -x[0]*pylab.tan(alpha) - 1000.0 + 500.0*pylab.sin(2*pylab.pi*x[0]/L)*pylab.sin(2*pylab.pi*x[1]/L)

    nonlin_solver_params = default_nonlin_solver_params()
コード例 #19
0
# -*- coding: utf-8 -*-

import pylab as pl

theta_deg = pl.arange(0, 360 + 0.05, 0.1)

theta_rad = pl.deg2rad(theta_deg)

sine = pl.sin(theta_rad)

pl.plot(theta_deg, sine)

pl.grid(True)

pl.show()
#[F5] or right click & "Run Python File in Terminal"
コード例 #20
0
PHI = x[0:4]
 

p_guess = [1,1,1,1,1,1,1,1,1,1,1,1]

system = cp.system.System(x = x, u = u, p = p, f = f, phi = PHI)

## set the bound 

# state
vt_max    =  3;            # deviation on airspeed
alpha_max =  0.0698;   # deviation in angle of attack 4 deg
theta_min = -0.4712; # pitchAngleMinimum            [rad]
theta_max =  0.6283; # pitchAngleMaximum            [rad]
q_max     =  0.6283;         # pitchRateMaximum             [rad/s]
de_bound  = pl.deg2rad(5);   # elevator deflection          [rad]

# input
dde_bound = 3.25;          # 3.25 FCC [rad/s]

#      [  vt   ,   alpha   , theta    ,   q   ,    de    ]
xmin = [-vt_max, -alpha_max, theta_min, -q_max, -de_bound]
xmax = [ vt_max,  alpha_max, theta_max,  q_max,  de_bound]  
# derivatives of elevator deflection bound bound    3.25 FCC [rad/s]   
umin = [-dde_bound] 
umax = [+dde_bound]

doe  = cp.doe.DoE(system = system, time_points = time, uinit = u_guess, pdata = p_guess, x0 = x0, \
                    umin = umin, umax = umax, xmin = xmin, xmax = xmax, wv = wv)   

doe.print_initial_experimental_properties()
コード例 #21
0
ファイル: sinus_2.py プロジェクト: tlapicka/2012-2013.3L
lab.xlim(0,0.6)   # nastavím začátek a konec os
lab.ylim(-1,5)

lab.title(u'Můj první graf $x_{12} = \\frac{-b\\pm\\sqrt{D}}{2a}$')
lab.xlabel('t[s]')  # popisek os
lab.ylabel('$u_1[V]$')

lab.grid()  # mřížka

##################################################
# teď už fakt nakreslím ten sinus

from pylab import pi

f =  3 # frakvence
fi = lab.deg2rad(60) # počáteční fáce

# vytvořím časovou osu
t = lab.linspace(0,1,1000)

# vypočítám napětí pro všechny časy
u = 3*lab.sin(2*pi*f*t+fi)


lab.figure() # nový obrázek
lab.plot(t,u,':')
lab.title('Funkce sinus')
lab.xlabel('t[s]')
lab.ylabel('u[V]')
lab.grid()
コード例 #22
0
ファイル: sinus.py プロジェクト: tlapicka/2012-2013.3B
# interactive mode
# lab.ion()
# lab.ioff()

f = 50

t = lab.linspace(0, 0.035, 100)
u = 2 * lab.sin(2 * pi * f * t)

lab.plot(t, u)
lab.grid(which="both")
lab.xlim([min(t), max(t)])
lab.ylim([-4, 4])

# lab.xticks(lab.arange(0,0.035,0.002), 1000* lab.arange(0,0.035,0.002))
# lab.yticks( lab.arange(-4,4,0.5) )

lab.xlabel("t[s]")

lab.ylabel("u[V]")
lab.title(ur"$u=\sin(2 \pi f t)$")


i = 2 * lab.sin(2 * pi * f * t + lab.deg2rad(0))
lab.plot(t, i)

lab.plot(t, u * i)


lab.show()