def __init__(self,
                 labels,
                 dataset,
                 ids,
                 rasters,
                 size_patch=64,
                 transform=None,
                 add_all=True,
                 limit=-1,
                 reset_extractor=False,
                 **kwargs):
        self.labels = labels
        self.ids = ids
        self.dataset = dataset

        self.limit = limit
        global ENVIRONMENTAL_DATASET_EXTRACTOR
        if ENVIRONMENTAL_DATASET_EXTRACTOR is None or reset_extractor:
            self.extractor = PatchExtractor(rasters,
                                            size=size_patch,
                                            verbose=True)
            if add_all:
                self.extractor.add_all()
            ENVIRONMENTAL_DATASET_EXTRACTOR = self.extractor
        else:
            self.extractor = ENVIRONMENTAL_DATASET_EXTRACTOR

        self.transform = transform
Ejemplo n.º 2
0
def pplot(latitude,
          longitude,
          source,
          resolution=1.,
          style=special_parameters.plt_style,
          nb_cols=5,
          alpha=1.):
    """
    patch plot
    :param style:
    :param latitude:
    :param longitude:
    :param source:
    :param resolution:
    :return:
    """
    r = check_source(source)
    rasters = r['rasters']
    extractor = PatchExtractor(rasters, resolution=resolution)
    extractor.add_all()
    extractor.plot(item=(latitude, longitude),
                   return_fig=True,
                   style=style,
                   nb_cols=nb_cols,
                   alpha=alpha)
 def __init__(self, root_dir, labels, dataset, ids, extractor=None):
     self.extractor = extractor
     self.labels = labels
     self.ids = ids
     self.dataset = dataset
     if extractor is None:
         self.extractor = PatchExtractor(root_dir, size=64, verbose=True)
         self.extractor.add_all()
     else:
         self.extractor = extractor
Ejemplo n.º 4
0
def raster_characteristics(source):
    """
    print infos about the rasters
    :param source:
    :return:
    """
    r = check_source(source)
    rasters = r['rasters']
    extractor = PatchExtractor(rasters)
    extractor.add_all()

    print_statistics(str(extractor))
    def __init__(self, labels, dataset, ids, rasters, patches, size_patch=64, extractor=None, transform=None,
                 add_all=True, limit=-1):
        self.extractor = extractor
        self.labels = labels
        self.ids = ids
        self.dataset = dataset
        self.patches = patches

        self.limit = limit

        if extractor is None:
            self.extractor = PatchExtractor(rasters, size=size_patch, verbose=True)
            if add_all:
                self.extractor.add_all()
        else:
            self.extractor = extractor

        self.transform = transform
    def __init__(self,
                 root_dir,
                 labels,
                 dataset,
                 ids,
                 n_neighbours=200,
                 extractor=None,
                 nb_labels=3336):
        self.labels = labels
        self.ids = ids
        self.dataset = dataset
        self.n_neighbours = n_neighbours
        self.nb_labels = nb_labels
        self.extractor = extractor

        self.kdtree = None
        self.train_dataset = None

        if extractor is None:
            self.extractor = PatchExtractor(root_dir, size=64, verbose=True)
            self.extractor.add_all()
        else:
            self.extractor = extractor
    def __init__(self,
                 root_dir,
                 labels,
                 dataset,
                 ids,
                 extractor=None,
                 nb_labels=3336,
                 second_neihbour=True):
        self.labels = labels
        self.ids = ids
        self.dataset = dataset
        self.nb_labels = nb_labels
        self.extractor = extractor

        self.pos_multipoints = None
        self.kdtree = None
        self.multipoints = None
        self.second_neihbour = second_neihbour

        if extractor is None:
            self.extractor = PatchExtractor(root_dir, size=64, verbose=True)
            self.extractor.add_all()
        else:
            self.extractor = extractor
def plot_raster(rasters,
                occurrences,
                dataset_class,
                validation_size=0,
                test_size=1,
                label_name='Label',
                id_name='id',
                splitter=train_test_split,
                filters=tuple(),
                online_filters=tuple(),
                postprocessing=tuple(),
                save_index=False,
                limit=None,
                raster="alti",
                **kwargs):
    _, _, grid_points = _occurrence_loader(rasters,
                                           occurrences,
                                           dataset_class,
                                           validation_size,
                                           test_size,
                                           label_name,
                                           id_name,
                                           splitter,
                                           filters,
                                           online_filters,
                                           postprocessing,
                                           save_index,
                                           limit,
                                           extractor=PatchExtractor(
                                               rasters, size=1, verbose=True),
                                           **kwargs)

    grid_points.extractor.append(raster)

    r = np.zeros((len(grid_points.dataset), 1), dtype=float)

    for i, data in enumerate(grid_points.dataset):
        value = grid_points[i][0].numpy()
        r[i, 0] = min(value[0], 2000)

    print(r)

    max_val = np.max(r)
    """

    viridis = matplotlib.cm.get_cmap('inferno', max_val)
    newcolors = viridis(np.linspace(0, 1, max_val))
    pink = np.array([248 / 256, 24 / 256, 148 / 256, 1])
    newcolors[1500:, :] = pink
    newcmp = ListedColormap(newcolors)
    newcmp.set_bad('grey', 1.)

    top = matplotlib.cm.get_cmap('inferno', 2000)
    bottom = matplotlib.cm.get_cmap('Blues', max_val-2000)

    newcolors = np.vstack((top(np.linspace(0, 1, 2000)),
                           bottom(np.linspace(0, 1, max_val-2000))))
    white = np.array([1, 1, 1, 1])
    newcolors[2000:, :] = white
    newcmp = ListedColormap(newcolors, name='OrangeBlue')
    newcmp.set_bad('grey', 1.)

    """

    plot_on_map(r,
                grid_points.ids,
                n_cols=1,
                n_rows=1,
                figsize=5,
                log_scale=False,
                mean_size=1,
                selected=(0, ),
                legend=(raster, ),
                output=raster)