Skip to content

Instantly share code, notes, and snippets.

View dimitri-justeau's full-sized avatar

Dimitri Justeau-Allaire dimitri-justeau

View GitHub Profile
@dimitri-justeau
dimitri-justeau / niamoto_flatten_taxonomy.py
Created February 1, 2024 18:06
Convert a linked taxonomy csv file to a flattened taxonomy csv file.
"""
Convert a linked taxonomy csv file to a flattened taxonomy csv file.
"""
import pandas as pd
def get_flattened_taxonomy(linked_taxonomy, parent_col="id_parent", rank_names_or_prefix="rank", include_rank=True, drop_parent_col=True):
"""
Converts a linked taxonomy DataFrame (i.e. where nodes in the taxonomic tree are only linked through their parent) to a flattened
@dimitri-justeau
dimitri-justeau / niamoto_link_taxonomy.py
Created February 1, 2024 18:06
Convert a flattened taxonomy csv file to a linked taxonomy csv file.
@dimitri-justeau
dimitri-justeau / PathWithCost.java
Created October 11, 2018 01:07
Choco CP Model: Enumerating paths in a graph with a cost constraint (costs are on the arcs).
import org.chocosolver.solver.Model;
import org.chocosolver.solver.Solver;
import org.chocosolver.solver.variables.IntVar;
import java.util.stream.IntStream;
/**
* CP Model for enumerating paths in a graph from start_node to end_node, with a cost constraint.
* Costs are on the arcs.
*
@dimitri-justeau
dimitri-justeau / PropSizeCC.java
Last active July 30, 2018 14:26
sizeConnectedComponent propagator for Choco-graph (https://github.com/chocoteam/choco-graph). Ensure that every CC of a graph variable has his size (number of vertices) bounded by MinNCC and MaxNCC. **EDIT**: More advanced propagators had been implemented and merged into Choco-graph (https://github.com/chocoteam/choco-graph/blob/master/src/main/…
package org.chocosolver.graphsolver.cstrs.connectivity;
import org.chocosolver.graphsolver.util.ConnectivityFinder;
import org.chocosolver.graphsolver.variables.GraphEventType;
import org.chocosolver.graphsolver.variables.UndirectedGraphVar;
import org.chocosolver.solver.constraints.Propagator;
import org.chocosolver.solver.constraints.PropagatorPriority;
import org.chocosolver.solver.exception.ContradictionException;
import org.chocosolver.solver.variables.Variable;
@dimitri-justeau
dimitri-justeau / multiclass_vector_to_singleclass_rasters.py
Created May 24, 2018 19:31
Converting multi-class vector dataset to multiple single-class presence-absence raster datasets, with GeoPandas and Rasterio
# coding: utf-8
import os
import math
import geopandas as gpd
import rasterio
import rasterio.features
from affine import Affine