Skip to content

Instantly share code, notes, and snippets.

View benmaier's full-sized avatar

Benjamin F. Maier benmaier

View GitHub Profile
@benmaier
benmaier / int_label.py
Created November 16, 2023 13:33
Python class of a continuous label-to-integer mapping that converts labels to integer indices and automatically handles new labels
class IntLabel():
def __init__(self):
self.ints = {}
self.keys = []
super().__init__()
def __getitem__(self, key):
try:
return self.ints[key]
@benmaier
benmaier / drobox_ubuntu_stuck_in_syncing.md
Last active February 3, 2023 09:39
Dropbox stuck in 'Syncing' on Ubuntu: How to solve

Dropbox stuck in 'Syncing' on Ubuntu: How to solve

Got a new machine and put Ubuntu on. Installed Dropbox, which started syncing, eventually it stopped and just showed status Syncing both in the daemon $ dropbox status as well as in the toolbar status icon. Nothing got synced, even syncing-icons on folders were not shown. Running $ dropbox filestatus in the dropbox root directory yielded a list of directories that all showed status unwatched.

Problem: Dropbox has a default maximum number of files that can be 'watched'. This number is, at the time of writing 100,000, which is incredibly low. You have to update this setting to a higher number. I followed this thread.

dropbox stop

@benmaier
benmaier / matplotlib_widget_in_jupyter_nb.md
Created January 12, 2023 11:42
Enabling matplotlib widgets in jupyter notebook

How to enable interactive matplotlib widgets in jupyter notebooks

This is the minimal summary of this article for my archives.

Install jupyter notebooks locally (with --user flag to make the jupyter directory writable) and the ipympl lib, as well.

pip install jupyter --user 
pip install ipympl --user
@benmaier
benmaier / katz_sparse_rgg.py
Created November 2, 2022 17:31
Katz centrality scipy.sparse on RGG
import networkx as nx
import numpy as np
import scipy.sparse as sprs
from scipy.stats import rankdata
from scipy.spatial import KDTree
import matplotlib.pyplot as pl
from matplotlib.collections import CircleCollection, LineCollection
def get_RGG(N, k):
@benmaier
benmaier / install_fiona_for_geopandas_on_mac_os_big_sur.md
Last active December 13, 2020 14:06
Install Geopandas/Fiona on Mac OS Big Sur

Install Geopandas/Fiona on mac OS Big Sur

I just tried to set up geopandas on mac OS Big Sur and ran into several problems, specifically this one appeared constantly:

/usr/local/Cellar/[email protected]/3.8.6_2/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/__init__.py:127: in import_module
  1 #!/bin/bash
    return _bootstrap._gcd_import(name[level:], package, level)
  1 #!/bin/bash
<frozen importlib._bootstrap>:1014: in _gcd_import
@benmaier
benmaier / Newick2JSON.py
Last active June 4, 2020 11:50 — forked from grabear/Newick2JSON.py
Converts a newick file into JSON format for d3/TreeWidget javascript component
import sys
from ete3 import Tree
import random
def get_json(node):
# Read ETE tag for duplication or speciation events
if not hasattr(node, 'evoltype'):
dup = random.sample(['N','Y'], 1)[0]
elif node.evoltype == "S":
dup = "N"
@benmaier
benmaier / add_curve_label.py
Last active November 7, 2021 01:24
In a matplotlib-plot, add a label to a curve according to its displayed slope, independent of potential log-scales
import numpy as np
from matplotlib import pyplot as pl
def add_curve_label(ax,
curve_x,
curve_y,
label,
label_pos_abs=None,
label_pos_rel=None,
bbox_pad=1.0,
@benmaier
benmaier / cividis.py
Created August 17, 2018 15:48
Register cividis as a colormap in matplotlib
# Copyright (c) 2017, Battelle Memorial Institute
#
# 1. Battelle Memorial Institute (hereinafter Battelle) hereby grants
# permission to any person or entity lawfully obtaining a copy of this software
# and associated documentation files (hereinafter “the Software”) to
# redistribute and use the Software in source and binary forms, with or without
# modification. Such person or entity may use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and may permit
# others to do so, subject to the following conditions:
#
@benmaier
benmaier / tisean_workflow.md
Last active June 18, 2018 03:42
Some Tisean stuff

Let's do some Tisean

Generate data

... by integrating the Rössler equations for the following parameters. Then let's say you save the data in a file like.

0.123
0.435
@benmaier
benmaier / compile_tisean.md
Last active December 4, 2023 10:33
What I did to compile TISEAN on OS X High Sierra

Compile TISEAN on OS X High Sierra

Install relevant compilers

Follow the installation instructions on http://hpc.sourceforge.net/ to install the latest binaries of gcc and gfortran for Mac OS X.

The important part is, download the gcc-8.1 binary, then do, quote

cd to the download folder. Then gunzip gcc-8.1-bin.tar.gz (if your browser didn't do so already) and then sudo tar -xvf gcc-8.1-bin.tar -C /"