Skip to content

Instantly share code, notes, and snippets.

View ChocopieKewpie's full-sized avatar

James Ardo ChocopieKewpie

  • Manaaki Whenua Landcare Research
  • New Zealand
View GitHub Profile
@ChocopieKewpie
ChocopieKewpie / DTW.py
Last active August 1, 2024 02:13
DTW- Python implementation
import rasterio
import numpy as np
from skimage.graph import MCP
""" Adopted from Schönauer, M., Maack, J., 2021. R-code for calculating depth-to-water (DTW) maps using GRASS GIS. Zenodo. doi: 10.5281/zenodo.5638517
adopted to Python by Ardo.J, 2024"""
# Setting Paths, Assuming that these layers are calculated outside of this code.
dem_path = "breached.tif"
slope_path = "slope.tif"
@ChocopieKewpie
ChocopieKewpie / h3_neighbourhood.py
Created May 28, 2024 03:29
H3 uber DGGS. Simple script to return a dataframe with neighbourhood values, k_ring= 1
"""
Simple script to return a dataframe with neighbourhood values, k_ring= 1
"""
import h3
import pandas as pd
import h3pandas
def get_h3_neighbour(h3_index):
# Get the 6 neighbors for the given H3 cell
@ChocopieKewpie
ChocopieKewpie / dggs_join.py
Created February 27, 2024 06:25
dggs_join (for benchmarking)
import os
import geopandas as gpd
import h3pandas
folder_path = 'E:/DGGS_Benchmark/vectors'
# Get a list of all GPKG files in the folder
v_files = [file for file in os.listdir(folder_path) if file.endswith('.gpkg')]
@ChocopieKewpie
ChocopieKewpie / vector_join.py
Created February 27, 2024 02:35
Joining vectors
import os
import geopandas as gpd
import numpy as np
import matplotlib.pyplot as plt
folder_path = 'E:/DGGS_Benchmark/vectors'
# Get a list of all GPKG files in the folder
v_files = [file for file in os.listdir(folder_path) if file.endswith('.gpkg')]
@ChocopieKewpie
ChocopieKewpie / majority_raster.py
Created February 22, 2024 21:31
Majority rules raster generation over a vector area
import geopandas as gpd
import rasterio
import numpy as np
from rasterio.transform import from_bounds
# Function to apply majority rule cellular automaton
def majority_rule(array):
# Create a copy of the array to store the updated values
new_array = np.zeros_like(array)
rows, cols = array.shape
@ChocopieKewpie
ChocopieKewpie / generate_polys.py
Last active February 22, 2024 21:26
Generating Voronoi in a Polygon
import geopandas as gpd
from shapely.ops import voronoi_diagram
from shapely.ops import unary_union
from shapely.geometry import shape
import random
def generate_voronoi_plot(df, n_points):
# Read GeoDataFrame from file
# Extract geometry for clipping
@ChocopieKewpie
ChocopieKewpie / 139_to_DC.py
Last active July 16, 2024 23:31
ISO19139 to Dublin Core (click)
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 6 15:28:29 2023
@author: ArdoJ
"""
import click
from lxml import etree
@ChocopieKewpie
ChocopieKewpie / mapextend_test.py
Last active July 9, 2024 08:29
map_extend geopandas
import numpy as np
from shapely.ops import unary_union, voronoi_diagram
from shapely.geometry import Polygon, MultiPolygon
import geopandas as gpd
import pandas as pd
def read_data(file_path):
return gpd.read_file(file_path)
def create_outline(df):