Exemplo n.º 1
0
 def trigger(self):
     common.gamestate['x'] = self.data['x']
     common.gamestate['y'] = self.data['y']
     common.gamestate['z'] = self.data['z']
     common.gamestate['level'] = self.data['level']
     common.gamestate['player']['direction'] = self.data['direction']
     common.load()
    def execute(self, args, config, study):
        # feature_cache = common.diskcache.DiskCache("cache_{}".format(common.dict_to_filename(config, ["images", ])))
        data = common.RDict(config=config)
        for image_set in self.logger.loop(
            data["config"]["images"], entry_message="Processing {count} image sets", item_prefix="image set"
        ):
            self.logger.log("Processing query image '{}'...".format(image_set["query_image"]))

            query_image = common.load(config["readers"]["query"]).execute(image_set["query_image"], data=data)
            query_coefficients = common.load(config["curvelets"]["transform"]).execute(query_image, data=data)
            # data["images"][image_set_key]["query_features"] =\
            query_features = common.load(config["features"]["extractor"]).execute(query_coefficients, data=data)

            for source_image_filename, features in self.logger.sync_loop(
                process_image,
                *common.augment_list(common.glob_list(image_set["source_images"]), data),
                entry_message="Processing {count} images...",
                item_prefix="image"
            ):
                self.logger.log("Processing image '{}'...".format(source_image_filename))

                # if not feature_cache.contains(source_image_filename):
                # image = common.load(data["config"]["readers"]["image"]).execute(source_image_filename, data=data)
                # coefficients = common.load(data["config"]["curvelets"]["transform"]).execute(image, data=data)
                ##data["images"][image_set_key]["source_images"][source_image_filename]["image_features"] =\
                # features = common.load(data["config"]["features"]["extractor"]).execute(coefficients, data=data)
                # feature_cache.set(source_image_filename, features)
                # else:
                # features = feature_cache.get(source_image_filename)
                data["distances"][image_set["query_image"]][source_image_filename] = common.load(
                    config["metric"]["metric"]
                ).execute(query_features, features, data=data)
        correlations, mean_correlation = self.correlate_to_study(data["distances"], study)
        # self.logger.log("Mean correlation: {}".format(mean_correlation))
        return (correlations, mean_correlation)
Exemplo n.º 3
0
 def _load_frames(self):
     self.frames = {
             'normal':   common.load("mouse.png", True, (int(config.WIDTH * 0.023), 0)),
             'over':     common.load("over.png", True, (int(config.WIDTH * 0.023), 0)),
             'dragging': common.load("dragging.png", True, (int(config.WIDTH * 0.023), 0)),
             'hide':     common.load("hide.png", True, (int(config.WIDTH * 0.023), 0)),
             }
Exemplo n.º 4
0
class Test(unittest.TestCase):
    path = 'data/country_admin_export_clean.xlsx - Admin_2013.csv'
    thresh = 50
    ts = umd.main(path, thresh, national=False)
    raw = common.load(path)

    ts_nat = umd.main(path, thresh, national=True)
    raw_nat = common.load(path)

    def test_loss(self):
        """Check that loss is calculated properly for a given threshold."""
        acre = self.ts.query("region == 'Acre'")

        df = self.raw[self.raw['name'] == 'Brazil_Acre']

        result = list(acre.query('year == 2003')['loss'])
        expected = list(df['loss_75_2003'] + df['loss_100_2003'])

        self.assertEqual(result, expected)

    def test_gain(self):
        """Check that gain field is properly generated."""
        acre = self.ts.query("region == 'Acre'")
        df = self.raw[self.raw['name'] == 'Brazil_Acre']

        result = list(acre[acre.year == 2003]['gain'])
        expected = list(df.gain0012 / 12.)

        self.assertEqual(result, expected)
Exemplo n.º 5
0
def process_image(source_image_filename, data):
    import common
    import common.diskcache

    cache_config = data["config"].get("cache", {})

    if cache_config.get("reader_enabled", False):
        reader_cache = common.diskcache.ReaderDiskCache.from_config(data["config"])
    else:
        reader_cache = common.diskcache.NullCache()

    if cache_config.get("feature_enabled", False):
        feature_cache = common.diskcache.FeatureDiskCache.from_config(data["config"])
    else:
        feature_cache = common.diskcache.NullCache()

    if feature_cache.contains(source_image_filename):
        features = feature_cache.get(source_image_filename)
    else:
        if reader_cache.contains(source_image_filename):
            image = reader_cache.get(source_image_filename)
        else:
            image = common.load(data["config"]["readers"]["image"]).execute(source_image_filename, data=data)
            reader_cache.set(source_image_filename, image)
        coefficients = common.load(data["config"]["curvelets"]["transform"]).execute(image, data=data)
        features = common.load(data["config"]["features"]["extractor"]).execute(coefficients, data=data)
        feature_cache.set(source_image_filename, features)

    return source_image_filename, features
Exemplo n.º 6
0
    def crear_barra_de_botones(self):
        anterior = common.load("anterior.png", True, (config.BLOCK_SIZE, config.BLOCK_SIZE))
        siguiente = common.load("siguiente.png", True, (config.BLOCK_SIZE, config.BLOCK_SIZE))
        crear = common.load("crear.png", True, (config.BLOCK_SIZE, config.BLOCK_SIZE))

        if self.editor.nivel > 1:
            item = ItemBoton(anterior, self.editor.imagen_bloque.convert_alpha(), 
                    self.editor.retroceder, config.WIDTH - config.BLOCK_SIZE * 2, 0)
            self.editor.sprites.add(item)
            self.items_creados.append(item)

        if self.editor.es_ultimo_nivel():
            item = ItemBoton(crear, self.editor.imagen_bloque.convert_alpha(), 
                    self.editor.avanzar_y_crear_ese_nivel, config.WIDTH - config.BLOCK_SIZE, 0)
        else:
            item = ItemBoton(siguiente, self.editor.imagen_bloque.convert_alpha(), 
                    self.editor.avanzar, config.WIDTH - config.BLOCK_SIZE, 0)

        self.editor.sprites.add(item)
        self.items_creados.append(item)

        alternar = common.load("alternar.png", True, (config.BLOCK_SIZE, config.BLOCK_SIZE))
        item = ItemBoton(alternar, self.editor.imagen_bloque.convert_alpha(), self.editor.alternar, 0, 0)
        self.editor.sprites.add(item)
        self.items_creados.append(item)

        probar = common.load("probar.png", True, (config.BLOCK_SIZE, config.BLOCK_SIZE))
        item = ItemBoton(probar, self.editor.imagen_bloque.convert_alpha(), self.editor.probar, config.BLOCK_SIZE, 0)
        self.editor.sprites.add(item)
        self.items_creados.append(item)
Exemplo n.º 7
0
    def agregar_boton_para_regresar_al_editor(self):
        from editor import ItemBoton

        regresar = common.load("regresar.png", True, (config.BLOCK_SIZE, config.BLOCK_SIZE))
        imagen_bloque = common.load("bloque.png", True, (config.BLOCK_SIZE, config.BLOCK_SIZE))
        item = ItemBoton(regresar, imagen_bloque.convert_alpha(), self.regresar_al_editor, 0, 0)
        self.sprites.add(item)
Exemplo n.º 8
0
 def _load_frames(self):
     self.frames = {
         'normal': common.load("mouse.png", True),
         'over': common.load("over.png", True),
         'dragging': common.load("dragging.png", True),
         'hide': common.load("hide.png", True),
     }
Exemplo n.º 9
0
    def crear_barra_de_botones(self):
        alternar = common.load("alternar.png", True, (config.BLOCK_SIZE, config.BLOCK_SIZE))
        item = ItemBoton(alternar, self.editor.imagen_bloque.convert_alpha(), self.editor.alternar, 0, 0)
        self.editor.sprites.add(item)
        self.items_creados.append(item)

        probar = common.load("probar.png", True, (config.BLOCK_SIZE, config.BLOCK_SIZE))
        item = ItemBoton(probar, self.editor.imagen_bloque.convert_alpha(), self.editor.probar, config.BLOCK_SIZE, 0)
        self.editor.sprites.add(item)
        self.items_creados.append(item)
Exemplo n.º 10
0
    def __init__(self, sprites):
        self.sprites = sprites
        self.nubes = []
        imagenes = [common.load("nubes/1.png", True, (config.WIDTH * 0.05, 0)),
                    common.load("nubes/2.png", True, (config.WIDTH * 0.11, 0)),
                    common.load("nubes/3.png", True, (config.WIDTH * 0.14, 0))]

        velocidades = [0.1, 0.2, 0.3, 0.4]

        for x in range(8):
            nube = Nube(random.choice(imagenes), random.choice(velocidades))
            self.nubes.append(nube)
            self.sprites.add(nube)
Exemplo n.º 11
0
    def execute(self, args, config, study):
        if args.codebook is not None:
            codebook = common.codebook.Codebook.load_from_path(args.codebook, size=config["codebook"]["codebook_size"])
        else:
            codebook = common.codebook.Codebook.load_from_config(config)

        data = common.RDict(config=config)
        data["codewords"] = codebook.codewords
        for image_set in self.logger.loop(
                data["config"]["images"],
                entry_message="Processing {count} image sets",
                item_prefix="image set"):
            if image_set.get("skip_benchmark", False):
                self.logger.log("Skipping distractor image set...")
            else:
                self.logger.log("Processing query image '{}'...".format(image_set["query_image"]))

                query_image = common.load(config["readers"]["query"]).execute(image_set["query_image"], data=data)
                query_coefficients = common.load(config["curvelets"]["transform"]).execute(query_image, data=data)
                query_features = common.load(config["features"]["extractor"]).execute(query_coefficients, data=data)
                query_signature = codebook.quantize(query_features,
                        use_stopwords=config["weights"]["use_stopwords"],
                        use_weights=config["weights"]["use_weights"],
                        )
                #self.logger.log(query_signature)

                for source_image_filename, signature in self.logger.sync_loop(
                        get_signature,
                        *common.augment_list(
                            common.glob_list(data["config"]["source_images"]),
                            data,
                            codebook,
                            ),
                        entry_message="Processing {count} images...",
                        item_prefix="image"):
                    self.logger.log("Processing image '{}'...".format(source_image_filename))

                    #self.logger.log(signature)
                    data["distances"][image_set["query_image"]][source_image_filename] =\
                            common.load(config["metric"]["metric"]).execute(query_signature, signature, data=data)
                self.logger.log("Calculating precisions for '{}'...".format(image_set["query_image"]))
                a = data["precisions"][image_set["query_image"]] = self.get_precision_recall(image_set["query_image"], data["distances"][image_set["query_image"]], study)
                self.logger.log("Precisions: {}".format(a))

        #correlations, mean_correlation = self.correlate_to_study(data["distances"], study)
        #precision_recall_stats, mean_stats = self.correlate_to_study(data["distances"], study)
        #self.logger.log("Mean correlation: {}".format(mean_correlation))
        return (data["precisions"], self.get_mean_average_precision(data["precisions"]))
Exemplo n.º 12
0
def main(path, thresh, national):
    '''Generate long-form datasets with year, thresh, gain, loss,
    treecover (and associated percentages).'''
    df = common.load(path)

    if national:
        df.drop('region', axis=1)
        df = df.groupby(['country', 'iso']).sum().reset_index()
    else:
        pass

    df = calc_extents(df, thresh)
    df = wide_to_long(df, thresh)
    df = calc_annual_gain(df)
    df = set_2000_0(df, 'loss')

    df = calc_perc(df, 'loss', thresh)
    df = calc_perc(df, 'gain', thresh)
    df = calc_perc(df, 'extent', thresh, denominator='land')
    df['thresh'] = thresh
    df = df.loc[:, OUTPUTFIELDS]

    df['year'] = df['year'].astype(int)
    df['id'] = df['id'].astype(int)

    return df
Exemplo n.º 13
0
    def __init__(self, type, x, y):
        Sprite.__init__(self)

        if config.SHOW_PLACEHOLDERS:
            self.image = common.load('placeholder.png', True, (config.BLOCK_SIZE, config.BLOCK_SIZE))
        else:
            self.image = common.load('hide.png', True, (config.BLOCK_SIZE, config.BLOCK_SIZE))

        self.rect = self.image.get_rect()
        self.rect.topleft = (x, y)
        self.are_used = False
        self.is_floor = False

        self.rect.width = config.BLOCK_SIZE
        self.rect.height = config.BLOCK_SIZE
        self.type = type
Exemplo n.º 14
0
def plotDeltas(i, t, range):
    # plt.subplot(4, 2, i)
    delta = common.load('tmp/' + t + '.p', [])
    label = 'Predictions for next {} to {} minutes'.format(range[0], range[1])
    ax = sns.distplot(delta, hist=False, label=label)
    # f.set_title('Predictions for next {} to {} minutes'.format(range[0], range[1]))
    ax.set_xlim([-1000, 1000])
Exemplo n.º 15
0
 def test_subtree_from_fragment(self):
     structure = load("branchy_glycan")
     fragment = Fragment(mass=1463.5284494, kind="1,5A0,3X", included_nodes=set([2, 3, 4, 5, 6, 7, 8, 9, 10]),
                         link_ids={}, name="0,3Xc4-1,5A4",
                         crossring_cleavages={2: ('1,5', 'A'), 7: ('0,3', 'X')})
     subtree = glycan.fragment_to_substructure(fragment, structure)
     self.assertAlmostEqual(subtree.mass(), fragment.mass)
Exemplo n.º 16
0
def cargar_imagen_por_codigo(codigo):
    referencias = {
        'o': "player/ico.png",
        '1': "pipes/1.png", 
        '2': "pipes/2.png", 
        '3': "pipes/3.png", 
        '4': "pipes/4.png", 
        '6': "pipes/6.png", 
        '7': "pipes/7.png", 
        '8': "pipes/8.png", 
        '9': "pipes/9.png", 
        'v': "pipes/v.png", 
        't': "pipes/t.png", 
        'n': "pipes/n.png", 
        'f': "pipes/f.png", 
        'r': "pipes/r.png", 
        'y': "pipes/y.png", 
        'z': "front_pipes/1.png", 
        'x': "front_pipes/2.png", 
        'c': "front_pipes/3.png", 
        'a': "front_pipes/4.png", 
        'q': "front_pipes/7.png", 
        'e': "front_pipes/9.png", 
    }

    return common.load(referencias[codigo], True, (config.BLOCK_SIZE, config.BLOCK_SIZE))
Exemplo n.º 17
0
 def crear_item(self, imagen, codigo, posicion):
     imagen_para_el_item = common.load(imagen, True, (config.BLOCK_SIZE, config.BLOCK_SIZE))
     dx = posicion % 14 + 1
     dy = posicion / 14 + 6
     item = Item(imagen_para_el_item, self.editor.imagen_bloque.convert_alpha(), codigo, dy, dx)
     self.editor.sprites.add(item)
     self.items_creados.append(item)
Exemplo n.º 18
0
    def test_fragments_preserve(self):
        structure = load("branchy_glycan")
        dup = structure.clone()
        self.assertEqual(structure, dup)
        list(dup.fragments('ABY', 2))

        self.assertEqual(structure, dup)
Exemplo n.º 19
0
    def __init__(self, type, x, y):
        Sprite.__init__(self)

        if config.SHOW_PLACEHOLDERS:
            self.image = common.load('placeholder.png', True)
        else:
            self.image = common.load('hide.png', True)

        self.rect = self.image.get_rect()
        self.rect.topleft = (x, y)
        self.are_used = False
        self.is_floor = False

        self.rect.width = 75
        self.rect.height = 75
        self.type = type
Exemplo n.º 20
0
    def __init__(self):
        Sprite.__init__(self)
        self.original_image = common.load('presents/gcoop.png', False)
        self.image = self.original_image
        self.alpha = 0
        self.rect = self.image.get_rect()
        self.rect.centerx = 1260 / 2
        self.center = self.rect.center
        self.y = 90
        w, h = self.image.get_width(), self.image.get_height()
        self.width = 0
        self.height = 0

        common.tweener.addTween(self,
                                width=w,
                                tweenTime=1700,
                                tweenType=pytweener.Easing.Elastic.easeInOut)
        common.tweener.addTween(self,
                                height=h,
                                tweenTime=1800,
                                tweenType=pytweener.Easing.Elastic.easeInOut)
        common.tweener.addTween(self,
                                alpha=255,
                                tweenTime=500,
                                tweenType=pytweener.Easing.Linear.easeNone)
        self.update()
Exemplo n.º 21
0
def plotDeltas(i, t, range):
    # plt.subplot(4, 2, i)
    delta = common.load('tmp/' + t + '.p', [])
    label = 'Predictions for next {} to {} minutes'.format(range[0], range[1])
    ax = sns.distplot(delta, hist=False, label=label)
    # f.set_title('Predictions for next {} to {} minutes'.format(range[0], range[1]))
    ax.set_xlim([-1000, 1000])
Exemplo n.º 22
0
 def reload(self):
     log("Clearing alerts")
     self.list.clear()
     log("Done")
     self.addpermanent()
     cnt = load(self, "config/alerts.txt", Alert)
     log("Loaded {:3d} alerts".format(cnt))
Exemplo n.º 23
0
    def __init__(self):
        self.params = {}
        load_config(self.params, "config/config.txt")

        self.list = []
        self.addpermanent()
        cnt = load(self, "config/alerts.txt", Alert)
        log("Loaded {:3d} alerts".format(cnt))
Exemplo n.º 24
0
 def __init__(self):
     Sprite.__init__(self)
     self.image = common.load('presents/presents.png', False, (config.WIDTH * 0.3, 0))
     self.rect = self.image.get_rect()
     self.rect.centerx = config.WIDTH / 2
     self.rect.y = config.HEIGHT * 0.8
     self.alpha = 0
     self.update()
Exemplo n.º 25
0
 def __init__(self):
     Sprite.__init__(self)
     self.image = common.load('title.png', True, (config.WIDTH * 0.3, 0))
     self.rect = self.image.get_rect()
     self.rect.right = config.WIDTH * 0.9
     self.y = config.HEIGHT
     common.tweener.addTween(self, y=self.y * 0.05, tweenTime=1700, 
             tweenType=pytweener.Easing.Elastic.easeInOut)
Exemplo n.º 26
0
 def __init__(self):
     Sprite.__init__(self)
     self.image = common.load('continue.png', True, (config.WIDTH * 0.7, 0))
     self.rect = self.image.get_rect()
     self.y = config.HEIGHT + self.rect.h
     self.rect.bottom = self.y
     self.rect.centerx = config.WIDTH / 2
     common.tweener.addTween(self, y=self.y * 0.8, tweenTime=1700)
Exemplo n.º 27
0
 def __init__(self):
     Sprite.__init__(self)
     self.image = common.load('presents/presents.png', False)
     self.rect = self.image.get_rect()
     self.rect.centerx = 1280 / 2
     self.rect.y = 600
     self.alpha = 0
     self.update()
Exemplo n.º 28
0
 def __init__(self, world):
     scene.Scene.__init__(self, world)
     self.sprites = group.Group()
     self.background = common.load("title_background.jpg", False)
     self.title = title_sprite.TitleSprite()
     self.sprites.add(self.title)
     self.draw_background()
     self.counter = 0
Exemplo n.º 29
0
    def _draw_background(self):
        "Imprime y actualiza el fondo de pantalla para usar dirtyrectagles mas adelante."
        self.background = common.load("background_menu.jpg", False, (config.WIDTH, config.HEIGHT))
        #self.map.draw_over(self.background)
        self.world.screen.blit(self.background, (0, 0))

        # actualiza toda la pantalla.
        pygame.display.flip()
Exemplo n.º 30
0
 def test_strip_derivatize(self):
     glycan = load("common_glycan")
     glycan.reducing_end = ReducedEnd()
     mass = glycan.mass()
     composition_transform.derivatize(glycan, 'methyl')
     self.assertNotEqual(mass, glycan.mass())
     composition_transform.strip_derivatization(glycan)
     self.assertAlmostEqual(glycan.mass(), mass, 3)
Exemplo n.º 31
0
 def __init__(self):
     Sprite.__init__(self)
     self.image = common.load('continue.png', True)
     self.rect = self.image.get_rect()
     self.y = 720 + self.rect.h
     self.rect.bottom = self.y
     self.rect.centerx = 1280 / 2
     common.tweener.addTween(self, y=710, tweenTime=1700)
Exemplo n.º 32
0
    def _draw_background_and_map(self):
        "Imprime y actualiza el fondo de pantalla para usar dirtyrectagles mas adelante."
        self.background = common.load("background.jpg", False)
        self.map.draw_over(self.background)
        self.world.screen.blit(self.background, (0, 0))

        # actualiza toda la pantalla.
        pygame.display.flip()
Exemplo n.º 33
0
    def __init__(self, world, actions):

        pygame.sprite.Sprite.__init__(self)
        self.image = common.load("cursor.png", True, (int(config.WIDTH * 0.8), int(config.HEIGHT * 0.09)))
        self.rect = self.image.get_rect()
        self.rect.centerx = config.WIDTH / 2
        self.posicion_actual = 0
        self.world = world
        self.actions = actions
Exemplo n.º 34
0
 def __init__(self, codigo):
     pygame.sprite.Sprite.__init__(self)
     imagen = common.load("elemento_actual.png", True, (config.BLOCK_SIZE * 2, config.BLOCK_SIZE))
     item = cargar_imagen_por_codigo(codigo)
     imagen.blit(item, (config.BLOCK_SIZE, 0))
     self.image = imagen
     self.rect = self.image.get_rect()
     self.rect.right = config.WIDTH
     self.z = 100
Exemplo n.º 35
0
 def __init__(self, rect):
     pygame.sprite.Sprite.__init__(self)
     self.original_image = common.load("particle_box.png", True)
     self.image = self.original_image.convert_alpha()
     self.rect = self.image.get_rect()
     self.rect.center = rect.center
     self.ttl = 40
     self.z = 300
     self.particles = []
Exemplo n.º 36
0
 def __init__(self):
     Sprite.__init__(self)
     self.image = common.load('level_complete.png', True, (config.WIDTH * 0.5, 0))
     self.rect = self.image.get_rect()
     self.rect.centerx = config.WIDTH / 2
     self.y = -self.rect.h * 2
     self.rect.y = self.y
     common.tweener.addTween(self, y=config.HEIGHT * 0.4, tweenTime=1700, 
             tweenType=pytweener.Easing.Elastic.easeInOut)
Exemplo n.º 37
0
 def test_leaves(self):
     structure = load("common_glycan")
     leaves = list(structure.leaves())
     for node in leaves:
         self.assertTrue(len(list(node.children())) == 0)
     leaves = list(structure.leaves(bidirectional=True))
     for node in leaves:
         self.assertTrue(
             len(list(node.children())) == 0 or node == structure.root)
Exemplo n.º 38
0
 def test_traversal(self):
     structure = load("common_glycan")
     structure[-
               1].add_monosaccharide(named_structures.monosaccharides['NeuGc'])
     structure.reindex(method='dfs')
     ref = structure.clone()
     self.assertEqual(structure[-1], ref[-1])
     structure.reindex(method='bfs')
     self.assertNotEqual(structure[-1], ref[-1])
 def __init__(self):
     Sprite.__init__(self)
     self.image = common.load('level_complete.png', True)
     self.rect = self.image.get_rect()
     self.rect.centerx = 1280 / 2
     self.y = -self.rect.h
     common.tweener.addTween(self,
                             y=300,
                             tweenTime=1700,
                             tweenType=pytweener.Easing.Elastic.easeInOut)
Exemplo n.º 40
0
 def test_indexing(self):
     structure = load("common_glycan")
     ref = structure.clone()
     for i, node in enumerate(structure.index):
         self.assertEqual(node.id, ref[i].id)
     structure.deindex()
     for i, node in enumerate(structure.index):
         self.assertNotEqual(node.id, ref[i].id)
     structure.index = None
     self.assertRaises(IndexError, lambda: structure[0])
Exemplo n.º 41
0
 def __init__(self):
     Sprite.__init__(self)
     self.image = common.load('title.png', True)
     self.rect = self.image.get_rect()
     self.rect.right = 1180
     self.y = 780
     common.tweener.addTween(self,
                             y=40,
                             tweenTime=1700,
                             tweenType=pytweener.Easing.Elastic.easeInOut)
Exemplo n.º 42
0
def createMitsubaVolume():
    density_path = r'D:\Dataset\round2\silk\silk_density.dat'
    orientation_path = r'D:\Dataset\round2\silk\silk_orientation.dat'
    density_path_mis = r'D:\Dataset\round2\silk\silk_density_mis_xy200-800.vol'
    orientation_path_mis = r'D:\Dataset\round2\silk\silk_orientation_mis_xy200-800.vol'

    print 'create density mitsuba volume ...'
    density = load(density_path)
    density = density[200:800, 200:800]
    print 'density shape: ', density.shape
    createMitsubaGridVolumeSimple(density, density_path_mis, 0.5)

    print 'create orientation mitsuba volume ...'
    orientation = load(orientation_path)
    orientation = orientation[200:800, 200:800]
    print 'orientation shape: ', orientation.shape
    createMitsubaGridVolumeSimple(orientation, orientation_path_mis, 0.5)

    print 'Done.'
Exemplo n.º 43
0
def createMitsubaVolume():
    density_path = r'D:\Dataset\round2\silk\silk_density.dat'
    orientation_path = r'D:\Dataset\round2\silk\silk_orientation.dat'
    density_path_mis = r'D:\Dataset\round2\silk\silk_density_mis_xy200-800.vol'
    orientation_path_mis = r'D:\Dataset\round2\silk\silk_orientation_mis_xy200-800.vol'

    print 'create density mitsuba volume ...'
    density = load(density_path)
    density = density[200:800, 200:800]
    print 'density shape: ', density.shape
    createMitsubaGridVolumeSimple(density, density_path_mis, 0.5)

    print 'create orientation mitsuba volume ...'
    orientation = load(orientation_path)
    orientation = orientation[200:800, 200:800]
    print 'orientation shape: ', orientation.shape
    createMitsubaGridVolumeSimple(orientation, orientation_path_mis, 0.5)

    print 'Done.'
Exemplo n.º 44
0
 def test_traversal_by_name(self):
     structure = load("common_glycan")
     structure[-
               1].add_monosaccharide(named_structures.monosaccharides['NeuGc'])
     structure.reindex(method='dfs')
     ref = structure.clone()
     self.assertEqual(structure, ref)
     structure.reindex(method='depth_first_traversal')
     self.assertEqual(structure, ref)
     self.assertRaises(
         AttributeError, lambda: structure.reindex(method='not_real_traversal'))
Exemplo n.º 45
0
    def _load_images(self):
        "Carga las imagenes de los pipes para pintar."

        self.images = {
            '1': common.load('pipes/1.png', True, (config.BLOCK_SIZE, config.BLOCK_SIZE)),
            '2': common.load('pipes/2.png', True, (config.BLOCK_SIZE, config.BLOCK_SIZE)),
            '3': common.load('pipes/3.png', True, (config.BLOCK_SIZE, config.BLOCK_SIZE)),
            '4': common.load('pipes/4.png', True, (config.BLOCK_SIZE, config.BLOCK_SIZE)),
            '6': common.load('pipes/6.png', True, (config.BLOCK_SIZE, config.BLOCK_SIZE)),
            '7': common.load('pipes/7.png', True, (config.BLOCK_SIZE, config.BLOCK_SIZE)),
            '8': common.load('pipes/8.png', True, (config.BLOCK_SIZE, config.BLOCK_SIZE)),
            '9': common.load('pipes/9.png', True, (config.BLOCK_SIZE, config.BLOCK_SIZE)),
        }
Exemplo n.º 46
0
def main(ds_name="a_example"):
    data = load(ds_name)
    best_points_per_startup_day = np.zeros(data["D"], dtype=np.float32)

    for lib in tqdm(data["libs"]):
        points_per_startup_day = get_points_per_startup_day(lib, data["D"], data["S"])
        best_points_per_startup_day = np.maximum(
            points_per_startup_day, best_points_per_startup_day
        )

    print(ds_name, best_points_per_startup_day.sum())
Exemplo n.º 47
0
 def test_subtree_from(self):
     structure = load("branchy_glycan")
     child = structure.root.children().next()[1]
     subtree = Glycan.subtree_from(structure, child)
     temp = structure.clone()
     temproot = temp.root.children().next()[1]
     for link in temp.root.links.values():
         link.break_link(refund=True)
     temp.root = temproot
     self.assertEqual(temp, subtree)
     self.assertEqual(Glycan.subtree_from(structure, 1), temp)
Exemplo n.º 48
0
def main():
    dlg_string = os.environ['DLG_UID']
    dlg_string = dlg_string[(dlg_string.rindex('_') + 1):len(dlg_string)]
    dlg_uid = dlg_string.split('/')
    Freq_Iteration = int(dlg_uid[1])  # derived from ID
    Facet_Iteration = int(dlg_uid[2])  # derived from ID
    vt = load(1)
    phasecentre_array = [[+15, -45], [+15.2, -45], [+15, -44], [+14.8, -45],
                         [+15, -46]]

    phasecentre = SkyCoord(ra=phasecentre_array[Facet_Iteration][0] * u.deg,
                           dec=phasecentre_array[Facet_Iteration][1] * u.deg,
                           frame='icrs',
                           equinox='J2000')

    model = create_image_from_visibility(vt,
                                         phasecentre=phasecentre,
                                         cellsize=0.001,
                                         npixel=256)
    dirty, sumwt = invert_function(vt, model)
    psf, sumwt = invert_function(vt, model, dopsf=True)

    #show_image(dirty)
    print("Max, min in dirty image = %.6f, %.6f, sumwt = %f" %
          (dirty.data.max(), dirty.data.min(), sumwt))

    print("Max, min in PSF         = %.6f, %.6f, sumwt = %f" %
          (psf.data.max(), psf.data.min(), sumwt))

    export_image_to_fits(
        dirty, '%s/imaging_dirty_%02d_%02d.fits' %
        (results_dir, Freq_Iteration, Facet_Iteration))
    export_image_to_fits(
        psf, '%s/imaging_psf_%02d_%02d.fits' %
        (results_dir, Freq_Iteration, Facet_Iteration))

    # Deconvolve using clean

    comp, residual = deconvolve_cube(dirty,
                                     psf,
                                     niter=1000,
                                     threshold=0.001,
                                     fracthresh=0.01,
                                     window_shape='quarter',
                                     gain=0.7,
                                     scales=[0, 3, 10, 30])

    restored = restore_cube(comp, psf, residual)

    export_image_to_fits(
        restored, '%s/imaging_clean%02d_%02d.fits' %
        (results_dir, Freq_Iteration, Facet_Iteration))
    dump(2, restored)
Exemplo n.º 49
0
 def __init__(self, game, type, x, y, map):
     Sprite.__init__(self)
     self.type = type
     self.image = common.load('front_pipes/%d.png' % (type), True)
     self.rect = self.image.get_rect()
     self.map = map
     self.can_be_clicked = True
     self.x = x - self.rect.w / 2
     self.y = y - self.rect.h
     self.are_in_a_placeholder = False
     self.z = -10
     self.game = game
Exemplo n.º 50
0
    def __init__(self, text_image, x, y):
        Sprite.__init__(self)
        self.image = common.load('balloon.png', True)
        self.rect = self.image.get_rect()
        self.rect.right = x + 70
        self.rect.bottom = y
        self.time_to_live = 150
        self.image.blit(text_image, (5, 5))

        # Evita que el cuadro de dialogo salga de la pantalla
        if self.rect.left < 2:
            self.rect.left = 2
        elif self.rect.right > 638:
            self.rect.right = 638
Exemplo n.º 51
0
 def __init__(self, world):
     pygame.mixer.init()
     pygame.mixer.music.load('data/presents/music.ogg')
     #music = pygame.mixer.Sound('presents/music.ogg')
     #music.play()
     pygame.mixer.music.play()
     scene.Scene.__init__(self, world)
     self.sprites = group.Group()
     self.background = common.load("presents/background.png", False)
     self.gcoop = GcoopLogo()
     self.presents = PresentsText()
     self.sprites.add(self.gcoop)
     self.draw_background()
     self.counter = 0
Exemplo n.º 52
0
def sync_folder(folder, rsync_file=f'{HOME}/.rsync/jobs.sh'):
    """
     rsync the given folder
     If the folder is already in sync just uploaded in the moment,
     avoiding repetitions in the rsync_file
   """
    S = common.load()
    ## Clean special characters
    folder = folder.replace(' ', '\ ')
    com = 'rsync -r --delete-before -a --relative %s' % (folder)
    com += f' {S.user}@{S.domain}:{S.folder}'
    os.system(com)
    ## Read all the currently syncing folders and files
    lines = open(rsync_file, 'r').read().splitlines()
    if com not in lines:
        with open(rsync_file, 'a') as f:
            f.write(com + '\n')
Exemplo n.º 53
0
def main(args):
    if len(args) < 2:
        Log.w("Arguments Error")
        return
    path = args[0]
    mfile = args[1]
    Log.i("Training file: %s" % path)
    Log.i("----------------")
    sentences = c.readconllfile(path)
    Log.i("Model file: %s" % mfile)
    Log.i("----------------")
    featdict, weights = c.load(mfile)
    output, score = parse(sentences, weights)
    for each in output:
        for token in each:
            print(token)
        print()
    Log.i("[DONE] accuracy: {:.2%}".format(score))
Exemplo n.º 54
0
def sync_file(abs_file, rsync_file=f'{HOME}/.rsync/jobs.sh'):
    """
     rsync the given (the abs path) file
     If the file is already in sync just uploaded in the moment,
     avoiding repetitions in the rsync_file
   """
    S = common.load()
    abs_file = abs_file.replace(' ', '\ ')
    #com = 'rsync -r  %s'%(abs_file)
    com = 'rsync -r --delete-before -a --relative %s' % (abs_file)
    #com += ' [email protected]:/media/BACKUP/%s'%(HOSTNAME)
    com += f' {S.user}@{S.domain}:{S.folder}'
    os.system(com)
    ## Read all the currently syncing folders and files
    lines = open(rsync_file, 'r').read().splitlines()
    if com not in lines:
        with open(rsync_file, 'a') as f:
            f.write(com + '\n')
Exemplo n.º 55
0
 def _load_frames(self):
     sheet_walk = animation.Sheet(common.load("player/walk.png", True), 4)
     sheet_stand = animation.Sheet(common.load("player/stand.png", True), 1)
     sheet_wait = animation.Sheet(common.load("player/wait.png", True), 2)
     sheet_working = animation.Sheet(common.load("player/working.png", True), 2)
     sheet_ok = animation.Sheet(common.load("player/ok.png", True), 1)
     sheet_stand_moving = animation.Sheet(common.load("player/stand_moving.png", True), 1)
     sheet_walk_moving = animation.Sheet(common.load("player/walk_moving.png", True), 4)
     self.animations = {
             "walk": animation.Animation(sheet_walk, 6, [0, 1, 2, 3]),
             "stand": animation.Animation(sheet_stand, 1, [0]),
             "working": animation.Animation(sheet_working, 6, [0, 1]),
             "ok": animation.Animation(sheet_ok, 1, [0]),
             "wait": animation.Animation(sheet_wait, 10, [0, 1]),
             "stand_moving": animation.Animation(sheet_stand_moving, 1, [0]),
             "walk_moving": animation.Animation(sheet_walk_moving, 6, [0, 1, 2, 3]),
         }
Exemplo n.º 56
0
def testFit():
    print 'load volume ...'
    v_path = r''
    v = load(v_path)    # float32, [0, 65535]
    print 'volume shape: ', v.shape

    # first, denoise using ed, and eJ?!
    print 'denoise using ed ...'
    bg = [v < 0.4 * 65535]
    v[bg] = 0.0

    # need binarize?
    print 'binarize ...'
    fiber = np.logical_not(bg)
    v[fiber] = 1.0
    
    m = poly2ndfitVolume(v)
    X, Y, Z = generatePoly2ndSurfaceSimple(m, v.shape[0], v.shape[1])
    plotSurface(X, Y, Z)
Exemplo n.º 57
0
def main(output_name, mode="points_div_opportunities", pick_rand_topn=1):
    for ds_name in dsets:
        if ds_name in output_name:
            break
    assert ds_name in output_name
    rest_name = osp.basename(output_name)[len(ds_name) + 1:-len(".out")]
    data = load(ds_name)
    prev_output = load_output(output_name)
    output = construct_empty_output(prev_output, data)
    lib_id_to_output_id = dict(
        zip([d["index"] for d in output], range(len(output))))

    if mode == "points_div_opportunities":
        book_score_func = books_by_points_div_opportunities
    else:
        assert mode == "opportunities"
        book_score_func = books_by_opportunities

    est_score = 0
    # books_left_data = init_books_left_data(
    #     output, scores=data["S"], lib_data=data["libs"]
    # )
    while True:
        books_left_data, nbr_empty_slots = get_books_left_data(
            output, data["S"], data["libs"])
        print(nbr_empty_slots, len(books_left_data))
        if books_left_data is None or len(books_left_data) == 0:
            break
        sel_books = sorted(books_left_data,
                           key=book_score_func)[-pick_rand_topn:]
        np.random.shuffle(sel_books)
        sel_book = sel_books[0]
        est_score += data["S"][sel_book["id"]]
        output[lib_id_to_output_id[sel_book["put_lib_idx"]]]["ids"].append(
            sel_book["id"])
    print(est_score)
    save(
        output,
        method_name="greedy_best_books_%s_pick_top_%d_from_%s" %
        (mode, pick_rand_topn, rest_name),
        ds_name=ds_name,
    )
    return est_score
Exemplo n.º 58
0
def main(args):
    # Set SIGCONF settings.
    sigconf_settings()

    # Load predictions.
    data = load(args.data)

    # Define labels.
    labels = [
        'Averaging',
        r'\textsc{SubSVD-Bernoulli}',
    ]

    # Define colors.
    colors = [
        'black',
        'C3',
    ]

    # Define line styles.
    linestyles = [
        '-',
        # '--',
        '-'
    ]

    # Set plot positions.
    positions = ['top', 'bottom']
    # Set titles.
    titles = ['Affordable Houses', 'Ban on Homophobia']

    fig, axes = plt.subplots(nrows=2, figsize=(3.6, 2.8))
    for vote, preds in data.items():
        if vote not in DATE2VOTES['2020-02-09']:
            continue
        i = VOTE2IDX[vote]
        plot(preds, axes[i], labels, colors, linestyles, titles[i],
             positions[i])

    fig.tight_layout()
    plt.savefig(args.fig)
    print(f'Figure saved to {args.fig}')
Exemplo n.º 59
0
def main(args) -> None:
    # Load Keras model
    model = common.create_cnn_model()

    # Load a subset of MNIST to simulate the local data partition
    (x_train, y_train), (x_test, y_test) = common.load(args.num_clients)[args.partition]

    # drop samples to form exact batches for dpsgd
    # this is necessary since dpsgd is sensitive to uneven batches
    # due to microbatching
    if args.dpsgd and x_train.shape[0] % args.batch_size != 0:
        drop_num = x_train.shape[0] % args.batch_size
        x_train = x_train[:-drop_num]
        y_train = y_train[:-drop_num]

    # Start Flower client
    client = MnistClient(model, x_train, y_train, x_test, y_test, args)
    fl.client.start_numpy_client("[::]:8080", client=client)
    if args.dpsgd:
        print("Privacy Loss: ", PRIVACY_LOSS)