Skip to content

Instantly share code, notes, and snippets.

View habi's full-sized avatar

David Haberthür habi

View GitHub Profile
@habi
habi / LogfileParser.py
Last active August 29, 2015 14:27
Logfile-Parser (reading log into a dictionary, easier for searching) and Logfile.
"""
Log file parser, based on http://stackoverflow.com/a/17776027/323100
"""
import re
def str2dict(filename='LogFile.log'):
results = {}
with open(filename, "r") as cache:
import time
import numpy # not really needed for the printing, but for nice percentage :)
import sys
print 'Ciao Fede'
print 'Here is a percentage, on the same line'
for i in numpy.arange(0, 100, 0.1):
print '\r', # Comma is needed.
print 'Doing something. I am now %s%% done' % i, # Comma is needed
time.sleep(0.01)
import numpy
from scipy.optimize import curve_fit
import matplotlib.pyplot as plt
# Define model function to be used to fit to the data above:
def gauss(x, *p):
A, mu, sigma = p
return A*numpy.exp(-(x-mu)**2/(2.*sigma**2))
xdata = numpy.linspace(-5,5,100)
\documentclass{article}
\usepackage{lipsum}
\usepackage{tabularx}
\usepackage{siunitx}
\usepackage{booktabs}
\renewcommand{\tabularxcolumn}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\begin{document}
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
GetCurrentImage.py | David Haberthür <david.haberthuer@psi.ch>
Minimal script to get current camera image from EPICS and display it
"""
# Import necessary modules
@habi
habi / iuutub.ipynb
Last active April 18, 2016 09:56
Testing nbviewer (on GitHub)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@habi
habi / EM-Tippspiel.py
Created June 9, 2016 09:07
So tippe ich im EM Tippspiel
# -*- coding: utf8 -*-
"""
Da ich keine Ahnung von Fussball habe, tippe ich bei unserem EM-Tippspiel so...
"""
import random
AnzahlTipps = 36
# Tipp 1
@habi
habi / shiftimage.py
Created July 27, 2016 12:39
Shift an image to its centroid
from scipy import ndimage
import numpy
def shiftimagetocentroid(image):
imagecenter = [l/2 for l in numpy.shape(image)]
centroid = ndimage.measurements.center_of_mass(image)
print(centroid)
shift = numpy.subtract(imagecenter, centroid)
print(shift)
image = scipy.ndimage.interpolation.shift(image, shift, mode='wrap')
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@habi
habi / Interaction.ipynb
Created March 22, 2017 15:19
Implementing a simple slice browser
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.