示例#1
0
    def test_run_each_simulator(self):
        path = os.getcwd()
        # get all models in the models directory, skip penicilin
        model_names = [
            o for o in sorted(os.listdir(os.path.join('models')))
            if os.path.isdir(os.path.join('models', o))
        ]
        model_names.remove('penicillin_goldrick_2017')
        model_path = lambda model_name: os.path.join(path, 'models', model_name
                                                     )

        for m in model_names:
            try:
                mysim = Simulator(model=Model(model_path(m)))
                mysim.set_inputs()
                data = mysim.run()
                mymvars = mysim.model.reset()

                ok = True
                er = 'all good'
            except Exception as e:
                print(m)
                ok = False
                er = e
            self.assertTrue(ok, er)
示例#2
0
    def test_handle_load_each_model(self):
        path = os.getcwd()
        model_names = [
            o for o in sorted(os.listdir(os.path.join('models')))
            if os.path.isdir(os.path.join('models', o))
        ]
        model_path = lambda model_name: os.path.join(path, 'models', model_name
                                                     )

        for m in [*model_names, 'dummy']:
            try:
                Model(model_path(m)).get_model()
                ok = True
                er = 'all good'
            except Exception as e:
                if isinstance(e, ModelDefinitionError
                              ) and m == 'penicillin_goldrick_2017':
                    ok = True
                    er = 'hadled ok'
                elif isinstance(e, FileNotFoundError) and m == 'dummy':
                    ok = True
                    er = 'hadled ok'
                else:
                    ok = False
                    er = e

            self.assertTrue(ok, er)
示例#3
0
def make_prediction():
    price_data = dataset("price_data")
    blockchain_data = dataset("blockchain_data")

    processed_data = (price_data.pipe(
        transformer("calculate_indicators")).pipe(
            transformer("merge_datasets"), other_sets=[blockchain_data]).pipe(
                transformer("fix_null_vals")).pipe(
                    transformer("add_lag_vars")).pipe(
                        transformer("power_transform")).pipe(
                            transformer("binarize_labels")).drop("Date",
                                                                 axis=1))

    feature_vector = processed_data.drop("Trend", axis=1).iloc[0]
    model = Model(processed_data.drop(processed_data.index[0]), hyperopt=False)

    return model.predict(feature_vector.values)[0]
示例#4
0
    def test_load_each_model(self):
        path = os.getcwd()
        # get all models in the models directory, skip penicilin
        model_names = [
            o for o in sorted(os.listdir(os.path.join('models')))
            if os.path.isdir(os.path.join('models', o))
        ]
        model_names.remove('penicillin_goldrick_2017')
        model_path = lambda model_name: os.path.join(path, 'models', model_name
                                                     )

        for m in model_names:
            try:
                Model(model_path(m)).get_model()
                ok = True
                er = 'all good'
            except Exception as e:
                ok = False
                er = e
            self.assertTrue(ok, model_path(m))
示例#5
0
def sim(model_name):
    """
    Generates simulator object based on model name

    Arguments
    ---------
        model_name
    """
    global mysim, mymvars, mycvars, mymparams, mysparams, data
    mysim = Simulator(model = Model(model_path(model_name)))
    mymvars = mysim.model.mvars.default
    try:
        mycvars = mysim.subroutines.subrvars.default
    except Exception as e:
        print(e)
        mycvars = None

    mymparams = mysim.model.params.default
    mysparams = mysim.simvars.default

    mysim.set_inputs()
    data = mysim.run()
    mymvars = mysim.model.reset()
    return 
示例#6
0
def main():
    c = Context("pygame", (800, 400), "Renderer")
    init_engine()
    clock = Clock()
    obj0 = Obj(r"./assets/objects/tetrahedron.obj")
    obj1 = Obj(r"./assets/objects/halfcube.obj")
    obj2 = Obj(r"./assets/objects/octahedron.obj")
    obj3 = Obj(r"./assets/objects/dodecahedron.obj")
    obj4 = Obj(r"./assets/objects/teapot.obj")
    obj5 = Obj(r"./assets/objects/pointer.obj")
    tex0 = Tex(r"./assets/textures/_default.png")
    tex1 = Tex(r"./assets/textures/metal.jpg")
    tex2 = Tex(r"./assets/textures/abstract.jpg")
    tex3 = Tex(r"./assets/textures/white.png")
    model0 = Model(obj0, tex0, pos=Point(0.0, 0.0, 0.0), scale=0.8)
    model1 = Model(obj1, tex2, pos=Point(-1.5, 0.0, 0.0), scale=0.8)
    model2 = Model(obj2, tex0, pos=Point(0.0, 0.0, 0.0), scale=0.8)
    model3 = Model(obj3, tex0, pos=Point(0.0, 0.0, 0.0), scale=0.8)
    model4 = Model(obj4, tex3, pos=Point(10, 10, 10), scale=0.8)
    model5 = Model(obj5, tex1, pos=Point(0.0, 0.0, 0.0), scale=2.0)
    camera = Camera(pos=Point(0.0, 0.0, 3.0), rot=Rot(0.0, 0.0, 0.0), fovy=90)
    scene = Scene({model1, model4, model5})

    camera_rotdeltas = {
        pygame.K_LEFT: Rot(0.0, -0.04, 0.0),
        pygame.K_RIGHT: Rot(0.0, 0.04, 0.0),
        pygame.K_DOWN: Rot(-0.04, 0.0, 0.0),
        pygame.K_UP: Rot(0.04, 0.0, 0.0),
        pygame.K_COMMA: Rot(0.0, 0.0, -0.04),
        pygame.K_PERIOD: Rot(0.0, 0.0, 0.04)
    }

    camera_posdeltas = {
        pygame.K_a: Point(-0.1, 0.0, 0.0),
        pygame.K_d: Point(0.1, 0.0, 0.0),
        pygame.K_s: Point(0.0, 0.0, 0.1),
        pygame.K_w: Point(0.0, 0.0, -0.1),
        pygame.K_f: Point(0.0, -0.1, 0.0),
        pygame.K_r: Point(0.0, 0.1, 0.0)
    }

    while True:
        clock.tick(60)
        c.idle()
        model0.rot += Rot(0.01, 0.02, 0.03)
        model1.rot += Rot(0.02, 0.03, 0.01)
        model2.rot += Rot(0.03, 0.01, 0.02)
        model3.rot += Rot(0.03, 0.02, 0.01)
        ##    model4.rot += Rot(0.01, 0.03, 0.02)
        model5.rot += Rot(0.02, 0.01, 0.03)
        # rotate camera from keyboard inputs
        pygame.event.pump()
        pressed_keys = pygame.key.get_pressed()
        for k in camera_rotdeltas:
            if pressed_keys[k]:
                camera.rot += camera_rotdeltas[k]
        rx, ry, rz = camera.rot
        defacto_rot = Rot(rx, -ry, -rz)
        for k in camera_posdeltas:
            if pressed_keys[k]:
                camera.pos += defacto_rot.get_transmat() * camera_posdeltas[k]
        X, Y = c.getres()
        glViewport(0, 0, X, Y)
        scene.render(camera, aspect=X / Y, mode="full")
        c.dispbuffer()
示例#7
0
文件: saver.py 项目: Lax125/renderer
  def load_appdata(self, setGlobals=True):
    meshes = [self.defaultMesh]
    textures = [self.defaultTexture]
    bulbs = [self.defaultBulb]
    directories = [None] # MainApp.add(app, rend, None) adds rend as toplevel item to the scene
    dirStack = [engine.monoselected]
    for line in dataopen("tmp/blueprint.dat", "r"):
##      print(line, end="")
      words = shlex.split(line)
      if not words:
        continue
      command, *args = words
      
      if command == "#":
        pass

      elif command == "AMBIENT" and setGlobals:
        R,G,B, power = castList([*[float]*3, float], args)
        self.UE.scene.ambientColor = R,G,B
        self.UE.scene.ambientPower = power
      
      elif command == "m": # mesh
        name, ID, cullbackface = castList([str, int, int], args)
        if ID == 0:
          meshes.append(self.defaultMesh)
        else:
          new_mesh = Mesh(datapath("tmp/assets/meshes/%d.obj"%ID), name=name, cullbackface=cullbackface)
          self.app.add(new_mesh)
          meshes.append(new_mesh)
          
      elif command == "t": # texture
        name, ID, diffuse, specular, fresnel, shininess = castList([str, int, *[float]*3, float], args)
        if ID == 0:
          textures.append(self.defaultTexture)
        else:
          new_tex = Tex(datapath("tmp/assets/textures/%d.png"%ID),
                        diffuse=diffuse, specular=specular, fresnel=fresnel,
                        name=name)
          self.app.add(new_tex)
          textures.append(new_tex)

      elif command == "b": # bulb
        name, ID, R,G,B, power = castList([str, int, *[float]*3, float], args)
        if ID == 0:
          bulbs.append(self.defaultBulb)
        else:
          new_bulb = Bulb(color=(R,G,B), power=power, name=name)
          self.app.add(new_bulb)
          bulbs.append(new_bulb)

      elif command == "model":
        name, meshIndex, texIndex, x,y,z,rx,ry,rz, scale, visible\
          = castList([str, int, int, *[float]*6, str, int], args)
        scale = deStrScale(scale)
        new_model = Model(meshes[meshIndex], textures[texIndex],
                          pos=Point(x,y,z), rot=Rot(rx,ry,rz),
                          scale=scale, visible=visible,
                          name=name)
        self.app.add(new_model)

      elif command == "lamp":
        name, bulbIndex, x,y,z,rx,ry,rz, scale, visible\
          = castList([str, int, *[float]*6, str, int], args)
        scale = deStrScale(scale)
        new_lamp = Lamp(bulbs[bulbIndex],
                        pos=Point(x,y,z), rot=Rot(rx,ry,rz),
                        scale=scale, visible=visible,
                        name=name)
        self.app.add(new_lamp)

      elif command == "DIR":
        name, x,y,z,rx,ry,rz, scale, visible\
          = castList([str, *[float]*6, str, int], args)
        scale = deStrScale(scale)
        new_directory = Directory(pos=Point(x,y,z), rot=Rot(rx,ry,rz), scale=scale, visible=visible, name=name)
        self.app.add(new_directory)
        directories.append(new_directory)
        dirStack.append(new_directory)
        self.app.select(dirStack[-1])

      elif command == "END":
        dirStack.pop(-1)
        self.app.select(dirStack[-1])

      elif command == "SYMLINK":
        name, fromIndex, toIndex, x,y,z,rx,ry,rz, scale, visible\
          = castList([str, int, int, *[float]*6, str, int], args)
        scale = deStrScale(scale)
        new_symlink = Link(directories[toIndex], pos=Point(x,y,z), rot=Rot(rx,ry,rz), scale=scale, visible=visible, name=name)
        self.app.add(new_symlink, directory=directories[fromIndex])

      elif command == "cam" and setGlobals:
        x,y,z,rx,ry,rz, fovy, zoom = castList([*[float]*6, float, float], args)
        self.R.configCamera(Point(x,y,z), Rot(rx,ry,rz), fovy, zoom)