Skip to content

Instantly share code, notes, and snippets.

View rawlik's full-sized avatar

Michał rawlik

  • Zürich, Switzerland
View GitHub Profile
@rawlik
rawlik / remove_outliers.py
Created October 30, 2023 17:56
Remove outliers
def remove_outliers(a, n):
asorted = a[np.argsort(np.abs(a - np.median(a)))]
return asorted[: -n]
plt.rcParams["figure.dpi"] = 140
plt.rcParams["axes.spines.right"] = False
plt.rcParams["axes.spines.top"] = False
plt.rcParams["legend.frameon"] = False
# Okabe-Ito palette
plt.rcParams['axes.prop_cycle'] = plt.cycler(color=["#000000", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7"])
@rawlik
rawlik / remove_contajner.ijm
Created August 22, 2023 17:13
remove a curved container in FIJI
for (c = 1; c <= 5; c++) { for (z = 1; z <= 131; z++) { Stack.setPosition(c, z, 1); r = Math.pow(z / 130, 0.6) * (430-290) + 290; makeOval(getWidth() / 2 - r, getHeight() / 2 - r, 2 * r, 2* r); run("Make Inverse"); fill(); } }
@rawlik
rawlik / memuse.py
Created August 16, 2023 08:55
Show the largest variables by memory use in python.
def sizeof_fmt(num, suffix='B'):
''' by Fred Cirera, https://stackoverflow.com/a/1094933/1870254, modified'''
for unit in ['','Ki','Mi','Gi','Ti','Pi','Ei','Zi']:
if abs(num) < 1024.0:
return "%3.1f %s%s" % (num, unit, suffix)
num /= 1024.0
return "%.1f %s%s" % (num, 'Yi', suffix)
def numpysizeof(o):
if "nbytes" in dir(o):
@rawlik
rawlik / rawlikstyle.sty
Last active January 11, 2023 22:34
Custom Latex style
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{rawlikstyle}[A custom style for latex documents]
% always use the UTF-8 encoding
\RequirePackage[utf8]{inputenc}
% clickable links
\RequirePackage{hyperref}
% palatino font for text and maths
@rawlik
rawlik / forward model.ipynb
Created March 6, 2020 08:33
A simple forward-model of grating interferometry computed tomography.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rawlik
rawlik / logging.py
Created April 4, 2019 08:16
Python logging in multiple modules
import coloredlogs
import logging
if __name__=="__main__":
# only configure logging in the main program, everywhere else just import and use it
# set up logging
logfile_folder = "N:/data/log/"
logfile_date = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
logfile_filename = f"bunker5_{logfile_date}.log"
@rawlik
rawlik / welcome.py
Created April 4, 2019 08:12
Colouring ASCII art in python
# use color ANSI escape sequences on windows
if os.name == "nt":
import colorama
colorama.init()
def welcome():
BLACK = "\033[0;30m"
RED = "\033[0;31m"
GREEN = "\033[0;32m"
YELLOW = "\033[0;33m"
@rawlik
rawlik / brighten.py
Created June 10, 2017 12:50
Brighten any color in matplotlib
def brighten(color, v):
return np.array(matplotlib.colors.to_rgb(color)) ** (1 - v)
@rawlik
rawlik / careful_autoscale.py
Last active November 27, 2015 09:28
A context manager for matplotlib that will autoscale only to objects plotted within its context. Ref. http://stackoverflow.com/questions/7386872/make-matplotlib-autoscaling-ignore-some-of-the-plots
class careful_autoscale:
def __init__(self, ax=None):
self.ax = ax if ax else gca()
def __enter__(self):
self.xl = self.ax.get_xlim()
self.yl = self.ax.get_ylim()
self.lines = self.ax.get_lines()
self.lines_visibility = [ l.get_visible() for l in self.lines ]
[ l.set_visible(False) for l in self.lines ]