Beispiel #1
0
    def call_and_reduce(self, *args, **kwargs):

        img = func(self, *args, **kwargs)

        if self.scale_factor > 1 and len(img.shape) == 3:
            img = np.array(
                [rescale(img_i, self.scale_factor) for img_i in img])
        elif self.scale_factor > 1 and len(img.shape) == 2:
            img = rescale(img, self.scale_factor)

        return np.swapaxes(img, len(img.shape) - 1, len(img.shape) - 2)
Beispiel #2
0
 def init_heights(self, height_resistance_path, min_h, max_h, scale_factor):
     # Load height resistance tif
     # TODO: change because corridors etc
     with rasterio.open(height_resistance_path, "r") as ds:
         height_rest = ds.read()[0]
         # for swiss instance artifacts:
         height_rest[height_rest < 0] = 200
     height_resistance = np.swapaxes(rescale(height_rest, scale_factor), 1,
                                     0)
     self.height_resistance = height_resistance
     self.min_h = min_h
     self.max_h = max_h
     self.resolution = 10 * scale_factor
Beispiel #3
0
    def generate_corridors_from_file(corr_path, nr_corrs=4, scale_param=1):
        with rasterio.open(corr_path, 'r') as ds:
            cost_img = ds.read()[0]
        print("read in corridor", cost_img.shape)
        actual_vals = cost_img[cost_img != 9999]

        corrs = []
        cut_val_prev = 0
        log_vals = np.logspace(np.log(0.03), np.log(1), 4, base=1.5)
        for i in range(4):
            cut_val = np.quantile(actual_vals, log_vals[i])  # (i+1)*0.24)
            copied = cost_img.copy()
            copied[copied < cut_val_prev] = 9999
            copied[copied > cut_val] = 9999
            corr_bool = (copied != 9999).astype(int)
            corrs.append(rescale(corr_bool, scale_param))
            cut_val_prev = cut_val
        return corrs
Beispiel #4
0
    def get_reduced_patches(
        instance, start_inds, dest_inds, factor, balance=[1, 1], quantile=0.1
    ):
        summed = np.sum(instance, axis=0)
        red = rescale(summed, factor)
        x_len, y_len = red.shape
        path_start_end = [
            [
                (start_inds / factor).astype(int).tolist(),
                (dest_inds / factor).astype(int).tolist()
            ]
        ]
        dist_corr = 1 - normalize(
            get_distance_surface(
                red.shape, path_start_end, n_dilate=min([x_len, y_len])
            )
        )
        surface_comb = balance[0] * dist_corr + balance[1] * red

        quantile_surface = np.quantile(surface_comb, quantile)
        patches = surface_comb < quantile_surface

        inds_x, inds_y = np.where(patches)
        return np.array([inds_x, inds_y])  # *factor
Beispiel #5
0
    if SAVE_PICKLE:
        data.data = (instance, instance_corr, start_inds, dest_inds)
        with open(IOPATH, "wb") as outfile:
            pickle.dump(data, outfile)
        print("successfully saved data")

# START PIPELINE
tic = time.time()
output_paths = []
plot_surfaces = []
time_infos = []

for (factor, dist) in PIPELINE:
    print("----------- PIPELINE", factor, dist, "---------------")
    # rescale
    inst_curr = np.array([rescale(img_i, factor) for img_i in instance])
    inst_corr_curr = rescale(instance_corr, factor)
    start_inds_curr = (start_inds / factor).astype(int)
    dest_inds_curr = (dest_inds / factor).astype(int)
    min_dist = cfg.PYLON_DIST_MIN / factor
    max_dist = cfg.PYLON_DIST_MAX / factor
    # DEFINE GRAPH AND ALGORITHM
    graph = GRAPH_TYPE(inst_curr,
                       inst_corr_curr,
                       graphtool=cfg.GTNX,
                       verbose=cfg.VERBOSE)

    graph.set_shift(min_dist,
                    max_dist,
                    dest_inds_curr - start_inds_curr,
                    cfg.MAX_ANGLE,