예제 #1
0
    def __init__(self):
        super(ChopperDriver, self).__init__()
        self.choppers = [Chopper(1), Chopper(2), Chopper(3), Chopper(4)]

        self.monitor_lock = RLock()
        monitor_thread = Thread(target=self.update_monitors, args=())
        monitor_thread.daemon = True  # Daemonise thread
        monitor_thread.start()
예제 #2
0
 def prep_choppers(self):
     """Show how many choppers are left."""
     self.choppers = Group()
     for chopper_number in range(self.stats.choppers_left):
         chopper = Chopper(self.hr_game)
         chopper.rect.x = 10 + chopper_number * (chopper.rect.width / 2)
         chopper.rect.y = 10
         self.choppers.add(chopper)
예제 #3
0
 def valid(self):
     chopper = Chopper()
     params = eval(chopper.params)
     params["upper"] = False
     chopper.name = "sliding_full"
     params["step"] = 32
     params["scale"] = 128
     chopper.params = str(params)
     chop = chopper.get()
     x_valid, y_valid = self.prepare_data(chop, self.validation_tracks)
     x_valid = remove_track_boundaries(x_valid)
     y_valid = remove_track_boundaries(y_valid)
     return x_valid, y_valid
예제 #4
0
    def random(self):
        chopper = Chopper()

        # only one slices at a time is needed
        if chopper.params:
            chopparams = eval(chopper.params)
        else:
            chopparams = {}
        chopparams["slices"] = 1
        chopper.params = str(chopparams)

        # get full or partial depending on chopper
        if "full" in chopper.name:
            chopper.name = "random_full"
        else:
            chopper.name = "random"
        chop = chopper.get()

        def generator(features, labels, batch_size):
            shape = self._calculate_shape(features[0].shape)
            # Create empty arrays to contain batch of features and labels
            batch_features = np.zeros((batch_size, *shape))
            batch_labels = np.zeros((batch_size, *shape))
            n_tracks = len(features)
            while True:
                for i in range(batch_size):
                    # get random track
                    t = random.randrange(n_tracks)
                    x_track = features[t]
                    y_track = labels[t]

                    feature, label = chop(x_track, y_track)

                    batch_features[i] = feature[0]
                    batch_labels[i] = label[0]
                yield batch_features, batch_labels

        return generator
    def process_spectrogram(self, spectrogram, channels=1):
        chopper = Chopper()
        chopper.name = "infer"
        chopper.params = "{'scale': %d}" % self.config.inference_slice
        chop = chopper.get(both=False)

        slices = chop(spectrogram)

        normalizer = Normalizer()
        normalize = normalizer.get(both=False)
        denormalize = normalizer.get_reverse()

        new_spectrogram = np.zeros((spectrogram.shape[0], 0, channels))
        for slice in slices:
            # normalize
            slice, norm = normalize(slice)

            epanded_spectrogram = conversion.expand_to_grid(
                slice, self.peakDownscaleFactor, channels)
            epanded_spectrogram_with_batch_and_channels = \
                epanded_spectrogram[np.newaxis, :, :]

            predicted_spectrogram_with_batch_and_channels = self.model.predict(
                epanded_spectrogram_with_batch_and_channels)
            # o /// o
            predicted_spectrogram = \
                predicted_spectrogram_with_batch_and_channels[0, :, :, :]
            local_spectrogram = predicted_spectrogram[:slice.shape[0], :slice.
                                                      shape[1], :]

            # de-normalize
            local_spectrogram = denormalize(local_spectrogram, norm)

            new_spectrogram = np.concatenate(
                (new_spectrogram, local_spectrogram), axis=1)
        console.log("Processed spectrogram")
        return spectrogram, new_spectrogram
예제 #6
0
    def __init__(self):
        """Initialize the game and create game resources."""
        pygame.mixer.pre_init(frequency=22050, size=8, channels=1, buffer=256)
        pygame.init()
        self.clock = pygame.time.Clock()
        self.settings = Settings()

        self.screen = pygame.display.set_mode(
            (self.settings.screen_width, self.settings.screen_height))
        self.bg_surface = pygame.transform.scale(
            pygame.image.load(self.settings.bg_image),
            (self.settings.screen_width,
             self.settings.screen_height)).convert()
        pygame.display.set_caption("Heli Rescue")

        # Create game objects
        self.stats = GameStats(self)
        self.sb = Scoreboard(self)
        self.chopper = Chopper(self)
        self.cut_scene = CutScene('level clear', self)
        self.bullets = pygame.sprite.Group()
        self.asteroids = pygame.sprite.Group()
        self.aliens = pygame.sprite.Group()
        self.clouds = pygame.sprite.Group()
        self.shockwaves = pygame.sprite.Group()
        self.particles = pygame.sprite.Group()
        self.sparks = pygame.sprite.Group()
        self.smoke_puffs = pygame.sprite.Group()
        self.scene_x = 0  # used for enemy map to determine when enemies appear
        self._generate_alien_lists()

        # Tutorial Prompts.
        self.press_spacebar = Prompt(self, "Hold spacebar to fire bullets")

        # Make the 'play' button.
        self.play_button = Button(self, "Play Heli Rescue")
예제 #7
0
 def train(self):
     if self.config.batch_generator.startswith("random"):
         return self.prepare_random_data(self.train_tracks)
     else:
         chop = Chopper().get()
         return self.prepare_data(chop, self.train_tracks)
예제 #8
0
    def update_monitors(self):
        while True:
            with self.monitor_lock:
                for ch in self.choppers:
                    ch.update()
                    self.setParam("{}:SPD".format(ch.chopper_num), ch.speed)
                    self.setParam("{}:PHS".format(ch.chopper_num), ch.phase)
                    self.setParam("{}:PHS:SP".format(ch.chopper_num),
                                  ch.req_phase)
                self.updatePVs()
            time.sleep(1)


if __name__ == "__main__":
    print("Airbus Choppers to EPICS")
    print("Checking connection to database...")
    ans = Chopper(1)._get_data()
    if ans is not None and len(ans) > 0:
        print("...connection established")
    else:
        raise Exception("Could not connect to database")

    server = SimpleServer()
    server.createPV(prefix, pvdb)
    driver = ChopperDriver()

    # process CA transactions
    while True:
        server.process(0.1)