Skip to content

Instantly share code, notes, and snippets.

View FilipDominec's full-sized avatar
🎯
Basically always busy, that's OK

Filip Dominec FilipDominec

🎯
Basically always busy, that's OK
View GitHub Profile
@FilipDominec
FilipDominec / pixel-covariance.py
Created August 17, 2017 14:20
Computes brightness covariance of two images and plots corresponding 2D histogram
#!/usr/bin/env python
#-*- coding: utf-8 -*-
"""
Program accepts two parameters: image1 image2
Both files have to have the same dimension. Any format accepted by scipy is possible.
They may be grayscale or RGB, in the latter case the R+G+B value is taken.
@FilipDominec
FilipDominec / num
Created July 11, 2017 21:47
Little command that returns 01, 02, 03... upon repeated calls. Good for automatic sequential numbering of simulations etc.
#!/usr/bin/python3
try:
with open('num.txt') as ff:
num = int(ff.read())+1
except FileNotFoundError:
num=1
numstr = '{:02d}'.format(num)
print(numstr)
with open('num.txt', 'w') as ff:
@FilipDominec
FilipDominec / SVD2Dmap_for_plotcommander.py
Last active July 3, 2017 15:56
similar to previous gist, but draws 2D maps for each SVD components - good for analysis of 2D spectral mapping of samples
#plotstyle = "basis"
plotstyle = "amplitude"
decimatex = 1
ncomponents = 6
a = ys[:, ::decimatex]
xs = xs[:, ::decimatex]
U, s, V = np.linalg.svd(a, full_matrices=False)
if plotstyle=="basis":
for x, y, label in zip(xs[:ncomponents], V[:ncomponents], range(ncomponents)):
@FilipDominec
FilipDominec / SVD_for_plotcommander.py
Created June 21, 2017 16:22
Example of singular value decomposition applied or real spectral data, ready to be copied&pasted into https://github.com/FilipDominec/plotcommander
plotstyle = "basis"
#plotstyle = "amplitude"
decimatex = 20
ncomponents = 5
a = ys[:, ::decimatex]
xs = xs[:, ::decimatex]
U, s, V = np.linalg.svd(a, full_matrices=True)
if plotstyle=="basis":
for x, y, label in zip(xs[:ncomponents], V[:ncomponents], range(ncomponents)):
@FilipDominec
FilipDominec / manualdetox.py
Created June 9, 2017 13:25
(not fully working) Manual character replacement in file names - if "chardet" and "convmv" fail
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
import os, sys
#import fileinput
AAA, BBB = u'‚¬…Ÿì¡ ýØç槣Ÿ§çç嬅Øý', u'éčůčýíář욊žÚčžššňČěřň'
filelist = [os.path.join(dp, f) for dp, dn, fn in os.walk('.') for f in fn]
filelist.sort()
@FilipDominec
FilipDominec / tb-update.py
Created November 2, 2016 12:35
Crystal band structure by R. Muller - update
#!/usr/bin/env python
# tb.py Richard P. Muller, 5/2000
# Updated for numpy.linalg and matplotlib by Filip Dominec, 2016
# This program is the tight-binding program for Diamond/Zincblende
# structures that is presented in Chadi and Cohen's paper
# "Tight-Binding Calculations of the Valence Bands of Diamond and
# Zincblende Crystals", Phys. Stat. Soli. (b) 68, 405 (1975). This
# program is written for diamond and zincblende structures only.
@FilipDominec
FilipDominec / passing variables with spaces.sh
Last active July 27, 2016 13:23
par=(so "me thin" g); command "${par[@]}" ... to run a bash command with multiple parameters possibly containing spaces, all stored in a single variable, you must write it as
#!/bin/bash
fn_bash() { for x in "$@"; do echo $x; done; }
echo '#!/usr/bin/env python' > printer.py
echo 'import sys ' >> printer.py
echo 'for a in sys.argv: print a' >> printer.py
chmod +x printer.py
fn() { ./printer.py "$@" ; }
echo 'Example 1 supplies the arguments at the line of function call and prints 3 lines, as we need'
@FilipDominec
FilipDominec / camera2slideshow.sh
Last active March 10, 2016 08:11
When a digital camera is connected to your computer, it automatically downloads and displays the last shot.
#!/bin/bash
cd /home/SLIDESHOW
sleep 60
gphoto2 --capture-tethered --keep &
# geeqie -f latest/slideshow.jpg &
geeqie -f -s &
while true ; do cp `ls *JPG -1tr | tail -n 1` latest/slideshow.jpg ; sleep 2 ; done
#!/usr/bin/env python
#-*- coding: utf-8 -*-
"""
Download and unpack the Hipparcos star catalog from www.astronexus.com/files/downloads/hygfull.csv.gz
Run in python to show interactive sky map with apparent star magnitude and approximate colour.
About 90000 stars are plotted within a second, you can pan and zoom the view.
Run with "--interactive no" to generate a big PDF file for printing. I could not find anything with this
@FilipDominec
FilipDominec / Planck_and_Stefan-Boltzmann_laws
Last active February 5, 2016 11:51
Show the luminosity by Planck law, numerically integrate to compute the S-B constant for different temperatures
#!/usr/bin/env python
#-*- coding: utf-8 -*-
## Import common moduli
import matplotlib, sys, os, time
import matplotlib.pyplot as plt
import numpy as np
from scipy.constants import c, h, hbar, pi, k, e
import scipy.integrate