Esempio n. 1
0
    def _spherepack_curl():
        """
        Calculate curl using SPHEREPACK spectral methods.
        
        If the value of R_sphere is not the same as the earth radius 
        used in package sphere, adjust curl to reflect R_sphere.  A 
        Numeric array is returned.

        SPHEREPACK outputs a number of diagnostic messages to
        stdout (and perhaps to stderr).  The one that's irritating
        is the one saying data will be converted to Float32.  Thus,
        we silently ensure that calculations are used only on Float32 
        data, to surpress the warnings.  I did this because redirect-
        ing stdout/stderr turned out to be too difficult; just
        altering the sys attributes didn't work.
        """
        import sphere

        sph_obj = sphere.Sphere( x.astype(ma.Float32) \
                               , y.astype(ma.Float32) )
        if np.allclose(np.array(R_sphere), sphere.radius):
            curl = sph_obj.vrt( Fx.astype(ma.Float32) \
                              , Fy.astype(ma.Float32) )
        else:
            curl = sph_obj.vrt( Fx.astype(ma.Float32) \
                              , Fy.astype(ma.Float32) ) \
                 * sphere.radius / R_sphere

        return curl
Esempio n. 2
0
def animate():
    #This opens the original code and reads it into a string so I can work with it
    file = open('base.pov')
    text = file.read()
    file.close()

    i = 0
    while i < 10:
        sphere1 = sphere.Sphere(0, 0, 1.4, 1)
        match = re.search("^sphere\s{.......................", text, re.DOTALL)
        insertString = ""
        if match:
            insertString += bounceBall(sphere1, match.group(), i)
            text = text.replace(match.group(), insertString)
        else:
            print "No match Found"

        outfile = 'tmp2.pov'
        fileOut = open(outfile, 'w')
        fileOut.write(text)
        fileOut.close()

        picNo = i
        pov_cmd = ' pvengine.exe +I%s +O%s -D -V +A +H600 +W800'
        cmd = pov_cmd % ('tmp2.pov', str(picNo).zfill(4) + "temp2.png")
        os.system(cmd)

        i += 1
    return i
Esempio n. 3
0
    def intersectsSprite(self, sprite):

        sph = sphere.Sphere()

        sph.center.set(0, 0, 0)
        sph.radius = 0.7071067811865476
        sph.applyMatrix4(sprite.matrixWorld)

        return self.intersectsSphere(sph)
Esempio n. 4
0
def setup():
    global shaderSystem, grid_image, grid_texture, planet, cam
    # One-time GL setup
    pyglet.gl.glClearColor(1, 1, 1, 1)
    shaderSystem = ShaderSystem()
    mainShader = shaderSystem.createShader("main")
    grid_image = pyglet.image.load('images/grid.png')
    grid_texture = grid_image.get_texture()
    planet = sphere.Sphere(1.0)
    cam = camera.Camera(position=Vector3(0.0, 0.0, -10.0))
    mainShader.unbind()
Esempio n. 5
0
 def __init__(self, points):
     '''
     Initializes the triangle by setting its 3 corner points.
     Inputs: points -> the three coordinate points of the triangle
     '''
     self.points = points
     p, q, r = self.points[:, 0], self.points[:, 1], self.points[:, 2]
     # calculate the triangle sphere's center and radius
     center, radius = sphere.calc_cr(p, q, r)
     # the bounding sphere of the triangle
     self.sphere = sphere.Sphere(center, radius)
Esempio n. 6
0
    def __init__(self, number_of_spheres, max_size, max_mass, box_size,
                 elasticity, friction):
        self.balls = []

        self.max_size = max_size
        self.max_mass = max_mass

        for i in range(number_of_spheres):
            self.balls.append(sphere.Sphere(elasticity, friction))

        for ball in self.balls:
            ball.reset(self.max_size, self.max_mass, box_size, self.balls)
Esempio n. 7
0
    def intersectsObject(self, object):

        sph = sphere.Sphere()

        geometry = object.geometry

        if geometry.boundingSphere is None:
            geometry.computeBoundingSphere()

        sph.copy(geometry.boundingSphere).applyMatrix4(object.matrixWorld)

        return self.intersectsSphere(sph)
Esempio n. 8
0
def main():
    while True:
        start_rad = float (input("What size Sphere do you want?\nEnter 0 to quit.") )
        if start_rad == 0:
            break
        else:
            mySphere = sphere.Sphere(start_rad)
            
            print("The Diameter of your Sphere is",
                  mySphere.diameter() )
            print("The Circumference of your Sphere is", mySphere.circumference())
            print("The Surface Area of your Sphere is", mySphere.surface())
            print("The Volume of your Sphere is", mySphere.volume())
def main():
    problema = sphere.Sphere()
    individuos = 32
    dimensiones = [2, 4, 8, 16]
    intervalos = 8
    a = 1
    Q = 20
    evaporacion = 0.9
    t0 = 0.00001
    generaciones = 2000
    for dim in dimensiones:
        for i in range(5):
            aco = ACO.ACO(i, individuos, dim, intervalos, a, Q, evaporacion,
                          t0, problema, generaciones)
            aco.run()
def main():
    problema = sphere.Sphere()
    problema_nombre = "sphere"
    cantidadParticulas = 50
    iteraciones = 2000
    dimensiones = 2
    for dim in range(4):
        for i in range(5):
            de = DifferentialEvolution.DE(iteraciones,
                                                cantidadParticulas,
                                                dimensiones,
                                                problema,
                                                problema_nombre,
                                                i)
            de.run()
        dimensiones = dimensiones*2
def main():
    problema = sphere.Sphere()
    problema_nombre = "sphere"
    cantidadParticulas = 50
    tamanioVecindario = 16
    iteraciones = 2000
    dimensiones = 2
    cognitionLearningRate = 1.4944
    socialLearningRate = 1.4944
    for dim in range(4):
        for i in range(5):
            spo = SwarmParticleOptimization.SPO(iteraciones,
                                                cantidadParticulas,
                                                tamanioVecindario, dimensiones,
                                                cognitionLearningRate,
                                                socialLearningRate, problema,
                                                problema_nombre, i)
            spo.run()
        dimensiones = dimensiones * 2
Esempio n. 12
0
def main():
    ros = rosenbrock.Rosenbrock()
    sph = sphere.Sphere()
    qua = quartic.Quartic()
    ras = rastrigin.Rastrigin()

    aux = np.array([])
    graph = np.array([])
    ejecuciones = 1
    draw = drawer.Drawer()

    individuos = 32
    dimensiones = 16
    intervalos = 8
    a = 1
    Q = 20
    evaporacion = 0.9
    t0 = 0.00001
    generaciones = 100
    bestFitnessPos = 100

    graphName = "Quartic" + str(dimensiones) + "D"
    aco = ACO.ACO(individuos, dimensiones, intervalos, a, Q, evaporacion, t0,
                  ras, generaciones, bestFitnessPos)

    for i in range(ejecuciones):
        aux = aco.run()
        if i == 0:
            graph = aux
        else:  #Sumamos el resto de las ejecuciones.
            for a in range(len(aux)):
                graph[a] = graph[a] + aux[a]

    for x in range(len(graph)):
        graph[x] = graph[
            x] / ejecuciones  #Obtenemos el promedio de cada posicion

    draw.drawIndividual(graph, graphName)

    file = open(graphName + ".txt", "w")
    for y in range(len(graph)):
        file.write(str(graph[y]) + "\n")
    file.close()
Esempio n. 13
0
def main():
    sphere_problem = sphere.Sphere()
    rastrigin_problem = rastrigin.Rastrigin()
    quartic_problem = quartic.Quartic()
    rosenbrock_problem = rosenbrock.Rosenbrock()
    population_size = 16
    generations = 2000
    mutation_rate = 0.1
    for dimentions in [2, 4, 8]:
        raw_sets = []
        for i in range(5):
            ag = PSAlgorithm.ParticleSwarmAlgorithm(population_size, dimentions, generations, mutation_rate, quartic_problem)
            
            raw_sets.append(ag.run())
        print(zip_average(raw_sets), dimentions)
        plt.plot(range(100, generations+100, 100), zip_average(raw_sets), label = str(dimentions))
    # plt.legend(['2', '4', '8'])
    plt.legend()
    plt.show()
eyeX = 3.0
eyeY = 0.0
eyeZ = 0.0
# gluLookAt 'up' coordinates
upX = 0.0
upY = 0.0
upZ = 1.0

mousePosX = 0
mousePosY = 0
isPressedMouseLeft = 0
isPressedMouseRight = 0

rotation = 0

Sph = sphere.Sphere(1.0)
Cyl = cylinder.Cylinder(0.75, 1.25, 16)


def InitGL(Width, Height):
    # We call this right after our OpenGL window is created.
    global eyeX, eyeY, eyeZ, upX, upY, upZ

    # This Will Clear The Background Color To Black
    glClearColor(0.0, 0.0, 0.0, 0.0)

    glClearDepth(1.0)  # Enables Clearing Of The Depth Buffer
    glDepthFunc(GL_LESS)  # The Type Of Depth Test To Do
    glEnable(GL_DEPTH_TEST)  # Enables Depth Testing
    # glShadeModel(GL_SMOOTH)				# Enables Smooth Color Shading
    glShadeModel(GL_FLAT)  # Enables Flat Color Shading
Esempio n. 15
0
import transform
import light
import material

cam = camera.FreeCamera(bdgmath.Vector3(3, -7, 10), bdgmath.Vector3(0, 0, 4))

scene = scene.Scene()

scene.addLight(light.DirectionalLight(bdgmath.Vector3(-1, 0.5, -4), 0.8))
scene.addLight(light.AmbientLight(0.2))

floor = plane.ZPlane(0)
floor.squareSize = 2
scene.addObject(floor)

s = sphere.Sphere(bdgmath.Vector3(0, 0, 4), 2)
s.material = material.Reflect(
    (0.4, 0.4, 0.4),  # base color
    0.5,  # kR the amount of reflected light to use
    0.3,  # kD the amount of diffuse light to use
    0.2,  # kA the amount of ambient light to use
)
scene.addObject(s)
#repeatedSphere = repeated2d.Repeated2d(10, 10, s)
#scene.addObject(repeatedSphere)

plinth = box.Box(bdgmath.Vector3(1.5, 1.5, 1))
translatedPlinth = transform.Translate3d(bdgmath.Vector3(0, 0, 1), plinth)
scene.addObject(translatedPlinth)

#repeatedPlinth = repeated2d.Repeated2d(10, 10, translatedPlinth)
    def load(self):
        # 3D Model Loader
        # load_model = models.Models("CornellBox-Original.obj")
        # self.create_model(load_model, glm.vec3(0.0, 0.0, -2.0))

        # First Scene: FOUR SPHERE
        # self.primitives.append(sphere.Sphere(glm.vec3(0.0, 0.0, 0.0), 0.2))
        # self.primitives.append(sphere.Sphere(glm.vec3(-0.5, 0.0, -1.0), 0.2))
        # self.primitives.append(sphere.Sphere(glm.vec3(0.0, -0.5, -2.0), 0.2))
        # self.primitives.append(sphere.Sphere(glm.vec3(0.0, 0.5, -3.0), 0.2))

        # Second Scene: TRIFORCE
        # self.primitives.append(triangle.Triangle(glm.vec3(0.0, 0.6, -2.0), glm.vec3(-0.2, 0.3, -2.0), glm.vec3(0.2, 0.3, -2.0)))
        # self.primitives.append(triangle.Triangle(glm.vec3(-0.2, 0.3, -2.0), glm.vec3(-0.4, 0.0, -2.0), glm.vec3(0.0, 0.0, -2.0)))
        # self.primitives.append(triangle.Triangle(glm.vec3(0.2, 0.3, -2.0), glm.vec3(0.0, 0.0, -2.0), glm.vec3(0.4, 0.0, -2.0)))

        # Third Scene: THE WIZARD
        # self.primitives.append(sphere.Sphere(glm.vec3(0.0, 0.5, -3.0), 0.2))
        # self.primitives.append(triangle.Triangle(glm.vec3(0.0, 1.0, -0.5), glm.vec3(-1.0, -2.0, -3.0), glm.vec3(1.0, -2.0, -3.0)))

        # Forth Scene: TRIANGLES
        # self.primitives.append(triangle.Triangle(glm.vec3(-0.2, 0.3, -1.0), glm.vec3(-0.4, 0.0, -1.0), glm.vec3(0.0, 0.0, -1.0)))
        # self.primitives.append(triangle.Triangle(glm.vec3(-0.2, 0.3, -1.5), glm.vec3(-0.4, 0.0, -1.5), glm.vec3(0.0, 0.0, -1.5)))
        # self.primitives.append(triangle.Triangle(glm.vec3(-0.2, 0.3, -2.0), glm.vec3(-0.4, 0.0, -2.0), glm.vec3(0.0, 0.0, -2.0)))
        # self.primitives.append(triangle.Triangle(glm.vec3(-0.2, 0.3, -2.5), glm.vec3(-0.4, 0.0, -2.5), glm.vec3(0.0, 0.0, -2.5)))
        # self.primitives.append(triangle.Triangle(glm.vec3(-0.2, 0.3, -3.0), glm.vec3(-0.4, 0.0, -3.0), glm.vec3(0.0, 0.0, -3.0)))

        # Pathtracer Scene: CORNELL BOX WITH SPHERES
        # BACK
        self.primitives.append(
            triangle.Triangle(
                glm.vec3(1.2, -1.2, -2.5), glm.vec3(-1.2, 1.2, -2.5),
                glm.vec3(-1.2, -1.2, -2.5),
                diffuse.Diffuse(brdf=glm.vec3(0.725, 0.71, 0.68))))
        self.primitives.append(
            triangle.Triangle(
                glm.vec3(1.2, -1.2, -2.5), glm.vec3(1.2, 1.2, -2.5),
                glm.vec3(-1.2, 1.2, -2.5),
                diffuse.Diffuse(brdf=glm.vec3(0.725, 0.71, 0.68))))
        # FLOOR
        self.primitives.append(
            triangle.Triangle(
                glm.vec3(-1.2, -1.2, -2.5), glm.vec3(1.2, -1.2, -2.5),
                glm.vec3(-1.2, -1.0, -1.0),
                diffuse.Diffuse(brdf=glm.vec3(0.725, 0.71, 0.68))))
        self.primitives.append(
            triangle.Triangle(
                glm.vec3(-1.2, -1.0, -1.0), glm.vec3(1.2, -1.2, -2.5),
                glm.vec3(1.2, -1.0, -1.0),
                diffuse.Diffuse(brdf=glm.vec3(0.725, 0.71, 0.68))))
        # LEFT WALL
        self.primitives.append(
            triangle.Triangle(
                glm.vec3(-1.2, -1.2, -2.5), glm.vec3(-1.2, -1.0, -1.0),
                glm.vec3(-1.2, 1.2, -2.5),
                diffuse.Diffuse(brdf=glm.vec3(0.14, 0.45, 0.091))))
        self.primitives.append(
            triangle.Triangle(
                glm.vec3(-1.2, 1.2, -2.5), glm.vec3(-1.2, -1.0, -1.0),
                glm.vec3(-1.2, 1.2, -1.0),
                diffuse.Diffuse(brdf=glm.vec3(0.14, 0.45, 0.091))))
        # RIGHT WALL
        self.primitives.append(
            triangle.Triangle(
                glm.vec3(1.2, 1.2, -1.0), glm.vec3(1.2, -1.0, -1.0),
                glm.vec3(1.2, 1.2, -2.5),
                diffuse.Diffuse(brdf=glm.vec3(0.63, 0.065, 0.05))))
        self.primitives.append(
            triangle.Triangle(
                glm.vec3(1.2, 1.2, -2.5), glm.vec3(1.2, -1.0, -1.0),
                glm.vec3(1.2, -1.2, -2.5),
                diffuse.Diffuse(brdf=glm.vec3(0.63, 0.065, 0.05))))
        # CEILING
        self.primitives.append(
            triangle.Triangle(
                glm.vec3(-1.2, 1.2, -1.0), glm.vec3(-1.2, 1.2, -2.5),
                glm.vec3(1.2, 1.2, -2.5),
                diffuse.Diffuse(brdf=glm.vec3(0.725, 0.71, 0.68))))
        self.primitives.append(
            triangle.Triangle(
                glm.vec3(1.2, 1.2, -2.5), glm.vec3(1.2, 1.2, -1.0),
                glm.vec3(-1.2, 1.2, -1.0),
                diffuse.Diffuse(brdf=glm.vec3(0.725, 0.71, 0.68))))
        # LIGHT
        self.primitives.append(
            triangle.Triangle(
                glm.vec3(-0.5, 1.19, -1.5), glm.vec3(-0.5, 1.19, -2.0),
                glm.vec3(0.5, 1.19, -2.0),
                light.Light(emittance=glm.vec3(30.0, 30.0, 30.0))))
        self.primitives.append(
            triangle.Triangle(
                glm.vec3(0.5, 1.19, -2.0), glm.vec3(0.5, 1.19, -1.5),
                glm.vec3(-0.5, 1.19, -1.5),
                light.Light(emittance=glm.vec3(30.0, 30.0, 30.0))))
        # SPHERES
        self.primitives.append(
            sphere.Sphere(glm.vec3(-0.5, -0.65, -1.5), 0.4, mirror.Mirror()))
        self.primitives.append(
            sphere.Sphere(glm.vec3(0.6, -0.65, -1.8), 0.4,
                          diffuse.Diffuse(brdf=glm.vec3(0.725, 0.71, 0.68))))
Esempio n. 17
0
def sfvp():
    #-----------------------------------------------------------------------------------
    #
    #     purpose:  starting with analytically generated winds, calculate the stream
    #               function and velocity potential using Spherepack and compare with
    #               analytically generated stream function and velocity potential.
    #
    #     usage:    sfvp()
    #
    #     passed :  nothing
    #
    #     returned: nothing
    #
    #-----------------------------------------------------------------------------------
    sendmsg(
        '**************** calculate the stream function and velocity potential on gaussian grid  *****************'
    )
    sendmsg(' ')

    testError = 0
    comp = 'computed'
    nlon = 128
    nlat = 64
    lonvals, latvals, timevals, u, v, sfexact, vpexact = sphere_test(
        nlon, nlat, 'v', 'gaussian')

    nt = len(timevals)
    x = sphere.Sphere(lonvals,
                      latvals,
                      numberLevels=0,
                      numberTimes=nt,
                      computed_stored=comp)

    sfcal, vpcal = x.sfvp(u, v)

    scale = radius  # scale exact functions to radius for the earth
    sfexact = sphere.geoscale(scale, sfexact)
    vpexact = sphere.geoscale(scale, vpexact)

    sfexact = remove_offset(sfcal, sfexact)  # subtract the offset
    vpexact = remove_offset(vpcal, vpexact)

    sendmsg('******* compare results')
    rms = rmserror(sfcal, sfexact)  # stream function rms error
    sendmsg(
        'expected normalized rms error in stream function computation is less than 1.e-05'
    )
    sendmsg('calculated normalized rms error in stream function computation =',
            rms)
    sendmsg(' ')
    if rms > 1.e-05:
        testError = testError + 1

    rms = rmserror(vpcal, vpexact)  # velocity potential rms error
    sendmsg(
        'expected normalized rms error in velocity potential computation is less than 1.e-05'
    )
    sendmsg(
        'calculated normalized rms error in velocity potential computation =',
        rms)
    sendmsg(' ')
    if rms > 1.e-05:
        testError = testError + 1

    if writeTestcase == 'yes':
        sendmsg('******* write data')
        sendmsg('calculated stream function written to sfcal.nc'
                )  # write netcdf file
        writeField(lonvals, latvals, timevals, 'sfcal', sfcal)
        sendmsg('calculated velocity potential written to vpcal.nc')
        writeField(lonvals, latvals, timevals, 'vpcal', vpcal)
        sendmsg(' ')

        sendmsg(
            'exact stream function written to sfexact.nc')  # write netcdf file
        writeField(lonvals, latvals, timevals, 'sfexact', sfexact)
        sendmsg('exact velocity potential written to vpexact.nc')
        writeField(lonvals, latvals, timevals, 'vpexact', vpexact)
        sendmsg(' ')
        sendmsg(' ')

    return testError
def main():
    s = sphere.Sphere()
    ag = AGC.AGC(32, 2, 4000, 0.02, s)
    ag.run()
    for i in ag._individuos:
        print(i._cromosoma)
phi_basis = de.Fourier('phi', 2 * (L_max + 1), interval=(0, 2 * np.pi))
theta_basis = de.Fourier('theta', L_max + 1, interval=(0, np.pi))
domain = de.Domain([phi_basis, theta_basis], grid_dtype=np.float64)
phi = domain.grids(1)[0]

# set up fields
v_th = domain.new_field()
v_ph = domain.new_field()
p = domain.new_field()
om = domain.new_field()
psi = domain.new_field()
# set up sphere
p.require_coeff_space()
m_start = p.layout.start(1)[0]
m_len = p.layout.local_shape(1)[0]
S = sph.Sphere(L_max, S_max, m_min=m_start, m_max=m_start + m_len)

# Calculate theta grid
theta_slice = domain.distributor.layouts[-1].slices(1)[1]
theta_len = domain.local_grid_shape(1)[1]
theta = S.grid[theta_slice].reshape([1, theta_len])

figure, ax = plt.subplots(1, 1)
figure.set_size_inches(6, 6)
lon = np.linspace(0, 2 * np.pi, 2 * (L_max + 1))
lat = grid - np.pi / 2

meshed_grid = np.meshgrid(lon, lat)
lat_grid = meshed_grid[1]
lon_grid = meshed_grid[0]
Esempio n. 20
0
cam = camera.FreeCamera(bdgmath.Vector3(8, -12, 8), bdgmath.Vector3(0, 0, 5))

scene = scene.Scene()

scene.addLight(light.DirectionalLight(bdgmath.Vector3(-1, 0.5, -4), 0.8))
scene.addLight(light.AmbientLight(0.2))

floor = plane.ZPlane(0)
floor.squareSize = 2
scene.addObject(floor)

cube = box.Box(bdgmath.Vector3(5, 5, 5))
cube.color = (1.0, 0.75, 0.25)

negSphere = sphere.Sphere(bdgmath.Vector3(2.5, -2.5, 2.5), 4.5)

cubeMinusSphere = csg.Difference(cube, negSphere)

torus = donut.Donut(3.5, 1)
torus.color = torus.color1 = torus.color2 = (0, 0.8, 0)

rotTorus = transform.RotateZ(225, transform.RotateX(45, torus))

torusCube = csg.Union(cubeMinusSphere, rotTorus)

posTorusCube = transform.Translate3d(bdgmath.Vector3(0, 0, 5), torusCube)

scene.addObject(posTorusCube)

#cam.renderScene(scene, 640, 320, "raytest.png", 5)
Esempio n. 21
0
def can_use_sphere(longitude, latitude):
    """Test if can use sphere package.
   
    Calling Sequence:
        Result = can_use_sphere(longitude, latitude)

    Note that Result is a 3-element tuple, not a scalar.  See the
    description below for details.

    Test if the longitude-latitude domain and Python package configur-
    ation allows use of the NCAR SPHEREPACK 3.0 package.  Specifically 
    the function tests:

    (1) Can you import sphere?
    (2) Is the longitude vector evenly spaced?
    (3) Does the longitude vector entirely span the globe, but doesn't
        repeat?
    (4) Is the latitude vector gaussian?  If not, is it evenly spaced 
        and includes the poles?

    If the answer to (1) is no, then there's no use to go through the 
    other tests and the function return tuple element [0] is 0.  If (2) 
    or (3) is no, return tuple element [0] is 0.  If (4) is both not 
    gaussian and not evenly spaced with the poles, return tuple 
    element [0] is 0.  Otherwise, return tuple element [0] is 1.  Note 
    that (4) uses the latitude checker in the sphere package.


    Method Arguments:
    * longitude:  Vector of longitudes of the domain [deg].  Can be 
      in any order, and a Numeric array or regular list/tuple.

    * latitude:  Vector of latitudes of the domain [deg].  Can be in
      any order, and a Numeric array or regular list/tuple.


    Output Result:
    * A 3-element tuple:
      [0]:  1 if the longitude-latitude domain and Python package 
            configuration passes tests to allow use of the NCAR 
            SPHEREPACK 3.0 package.  0 if does not pass those tests.
      [1]:  String containing messages written to stdout by calls to 
            module sphere used for checking latitude (e.g. if it is
            gaussian, etc.).  If there are no messages or there were 
            no calls needed to sphere for checking latitude, value is 
            empty string.
      [2]:  Same as [1] except contains stderr messages.


    Examples:
    >>> from can_use_sphere import can_use_sphere
    >>> import numpy as np
    >>> lon = np.arange(36)*10
    >>> lat = [-90, -60, -30, 0, 30, 60, 90]
    >>> can_use_sphere(lon, lat)[0]
    1
    >>> lat = [-90, -60, -30, 0, 30, 60, 87]
    >>> can_use_sphere(lon, lat)[0]
    0
    >>> can_use_sphere(lon, lat)[1].splitlines()[1]
    'CANNOT PROCESS THE DATA - Latitude values are incorrect'
    """

    #- Test if the sphere package exists:

    try:
        import sphere
    except ImportError:
        return (0, '', '')

    #- Convert input to Numeric and sort:

    lon = np.sort(np.array(longitude))
    lat = np.sort(np.array(latitude))

    #- Check if either vector is less than 2 elements.  If so,
    #  return false:

    if (len(lon) < 2) or (len(lat) < 2): return (0, '', '')

    #- Is the longitude vector evenly spaced?  If not, return false:

    diff_lon = lon[1:] - lon[0:-1]
    if not np.allclose(diff_lon, diff_lon[0]): return (0, '', '')

    #- Does the longitude vector exactly spans the globe but without
    #  repeating?  If not, return false:

    if not np.allclose((lon[-1] + diff_lon[0] - lon[0]), 360.0):
        return (0, '', '')

    #- Check latitude (e.g. whether it is gaussian, whether it includes
    #  the pole points if they are evenly spaced) and any other bad
    #  conditions for sphere using the sphere package checker.  If
    #  sphere can't execute correctly, return 0.  Also return standard
    #  error and standard out:

    temp_out = sys.stdout
    temp_err = sys.stderr
    sys.stdout = io.StringIO()
    sys.stderr = io.StringIO()

    try:
        try:
            sph_obj = sphere.Sphere(lon, lat)
            sph_obj_exception = 0
        except:
            sph_obj_exception = 1
    finally:
        stdout = sys.stdout.getvalue()
        stderr = sys.stderr.getvalue()
        sys.stdout.close()
        sys.stderr.close()
        sys.stdout = temp_out
        sys.stderr = temp_err
        if sph_obj_exception == 1: return (0, stdout, stderr)

    #- Return true if haven't returned yet:

    return (1, stdout, stderr)
Esempio n. 22
0
#cam = camera.YCamera(0, -5, 3)
#cam.setViewDistance(2)
#cam.setViewWidth(2)

cam = camera.FreeCamera(bdgmath.Vector3(10, -8, 6), bdgmath.Vector3(0, 0, 5))

scene = scene.Scene()

scene.addLight(light.DirectionalLight(bdgmath.Vector3(-1, 1, -4), 0.8))
scene.addLight(light.AmbientLight(0.2))

scene.addObject(plane.ZPlane(0))
#scene.addObject(plane.ZPlane(-2))
#scene.addObject(sphere.Sphere(bdgmath.Vector3(-0.1, 0, 2.5), 2.5))

s2 = sphere.Sphere(bdgmath.Vector3(3.5, 2, 2), 2)
s2.color1 = (40, 200, 40)
#s2.color2 = (0, 250, 0)
s2.color2 = (40, 200, 40)
#scene.addObject(s2)

s3 = sphere.Sphere(bdgmath.Vector3(-4, 2, 2), 2)
s3.color1 = (40, 40, 200)
#s3.color2 = (0, 0, 250)
s3.color2 = s3.color1
#scene.addObject(s3)

#cyl = cylinder.ZCylinder(bdgmath.Vector2(1, 4), 1)
#scene.addObject(cyl)

donut = donut.Donut(2.5, 1)
Esempio n. 23
0
def main():
    s = sphere.Sphere()
    for i in range(5):
        ag = AGC.AGC(32, 16, 2000, 0.02, s, i)
        ag.run()