Skip to content

Instantly share code, notes, and snippets.

View stefanv's full-sized avatar

Stefan van der Walt stefanv

View GitHub Profile
@stefanv
stefanv / dotemacs-zenburn.el
Created May 15, 2020 14:27
Customizing zenburn for org-mode to highlight all headings
(use-package zenburn-theme
:config
(setq org-fontify-whole-heading-line t
org-fontify-quote-and-verse-blocks t)
(load-theme 'zenburn t)
(zenburn-with-color-variables
(custom-theme-set-faces
'zenburn
`(org-level-1 ((t (:inherit ,z-variable-pitch
:foreground ,zenburn-orange
@stefanv
stefanv / fetch_prs
Last active December 5, 2019 07:35
NumPy: nr of PRs per contributor
#!/bin/bash
curl "https://api.github.com/repos/numpy/numpy/pulls?page=1&per_page=100" > prs0.json
curl "https://api.github.com/repos/numpy/numpy/pulls?page=2&per_page=100" > prs1.json
curl "https://api.github.com/repos/numpy/numpy/pulls?page=3&per_page=100" > prs2.json
@stefanv
stefanv / autocropjpg.py
Created December 4, 2019 23:54
Auto-crop jpeg image without recompressing (requires Python 3 with scikit-image, and jpegtran)
#!/usr/bin/env python
import subprocess
import sys
from skimage import io, filters
import numpy as np
filename = sys.argv[1]
base, ext = filename.rsplit('.', 1)
outfile = f'{base} cropped.{ext}'
import numpy as np
xs = np.linspace(2, 5, 10000) # 10000 samples of x between 2 and 5
ys = np.linspace(1, 2, 10000) # 10000 samples of y between 1 and 2
ix = np.random.randint(0, 10000, size=(10000, 2)) # random index, 2 parameters
def my_model(x, y):
... # do some magic
return 42 # spit out your evaluation of the model for a given x, y
$ PYTHONPATH=. pytest --doctest-modules networkx/generators/spectral_graph_forge.py
================================================================================ test session starts ================================================================================
platform linux -- Python 3.7.4+, pytest-4.3.1, py-1.8.0, pluggy-0.12.0
Using --randomly-seed=1570776077
rootdir: /home/stefan/src/networkx, inifile:
plugins: randomly-2.1.1
collected 1 item
networkx/generators/spectral_graph_forge.py s [100%]
@stefanv
stefanv / cell-segmentation-visualized-with-napari.ipynb
Created August 7, 2019 07:08
Cell segmentation visualized with Napari
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
function workon {
ENVS=${HOME}/envs
TARGET=$ENVS/${1}
if [[ -z ${1} || ! -d $TARGET ]]; then
echo "Invalid environment. Choose from:"
ls $ENVS
else
unset PYTHONPATH
source $TARGET/bin/activate
fi
@stefanv
stefanv / pangeo.bib
Last active February 21, 2019 18:29
@article{Abernathey2017,
author = "Abernathey, Ryan and Paul, Kevin and Hamman, Joe and Rocklin, Matthew and Lepore, Chiara and Tippett, Michael and Henderson, Naomi and Seager, Richard and May, Ryan and Del Vento, Davide",
title = "{Pangeo NSF Earthcube Proposal}",
year = "2017",
month = "8",
url = "https://figshare.com/articles/Pangeo_NSF_Earthcube_Proposal/5361094",
doi = "10.6084/m9.figshare.5361094.v1"
}
===================================================================================== FAILURES ======================================================================================
______________________________________________________________________________ test_minor_axis_length _______________________________________________________________________________
def test_minor_axis_length():
length = regionprops(SAMPLE)[0].minor_axis_length
# MATLAB has different interpretation of ellipse than found in literature,
# here implemented as found in literature
> assert_almost_equal(length, 9.739302807263)
E AssertionError:
E Arrays are not almost equal to 7 decimals
_________________________________________________________________________________ test_convex_image _________________________________________________________________________________
def test_convex_image():
img = regionprops(SAMPLE)[0].convex_image
# determined with MATLAB
ref = np.array(
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0],