Skip to content

Instantly share code, notes, and snippets.

View FilipDominec's full-sized avatar
🙂
Happy. Basically whenever I code, I am working on something I love

Filip Dominec FilipDominec

🙂
Happy. Basically whenever I code, I am working on something I love
View GitHub Profile
@FilipDominec
FilipDominec / labbook_xls_filter.py
Created January 1, 2019 22:25
Parses one or more XLS files, each containing arbitrary number of sheets, and filters all rows for a pattern
#!/usr/bin/python3
#-*- coding: utf-8 -*-
"""
Parses one or more XLS files, each containing arbitrary number of sheets, and filters all rows for a
pattern as determined by filter_lines=... below. Prints matching names.
Typical invocation
python3 ./xlsfilter.py *201{6,7,8}.{1,2}.xlsx | vi -
@FilipDominec
FilipDominec / file_splitter_by_search.py
Created December 14, 2018 10:00
File splitter based on (multiple) keyword searches (must be at line start!). Keeps 1st line as header.
#!/usr/bin/python3
#-*- coding: utf-8 -*-
import re, sys
with open(sys.argv[1]) as inputf:
c = 1
ls = inputf.readlines()
fromline = 1
for splitter in sys.argv[2:]:
@FilipDominec
FilipDominec / RPSDF.py
Created July 27, 2018 18:21
Evaluate the cathodoluminescence statistical features using Radial Power Spectral Density
#!/usr/bin/python3
#-*- 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, hbar, pi
from scipy.misc import imread
@FilipDominec
FilipDominec / calibration_curve.dat
Last active September 22, 2017 17:04
How to calibrate an UV spectrometer if you have separate UVB, UVA and visible sources
3.003903829999999857e+02 1.640232643851876337e-01
3.006813710000000128e+02 1.663268589412743859e-01
3.009723399999999742e+02 1.676764695268916916e-01
3.012632909999999811e+02 1.669212216194967402e-01
3.015542229999999790e+02 1.670782231063905887e-01
3.018451360000000250e+02 1.743939035195906928e-01
3.021360310000000027e+02 1.665717034735433866e-01
3.024269070000000283e+02 1.757442043184819225e-01
3.027177649999999858e+02 1.777328050331506148e-01
3.030086029999999937e+02 1.730466534811957724e-01
matplotlib.rc('font', size=12)
ys = np.array(ys)[:, :1024]
ys /= 5782000/.1517*0.02301 # np.max(ys) # fixed normalization for all samples
x = np.poly1d([4.64708212e-15, -1.65806129e-05, 5.20397778e-01, 3.53568373e+02])(range(1024))
for yy in ys:
yy[:] = np.convolve(yy, 2**(-np.linspace(-2,2,15)**2),mode='same')
@FilipDominec
FilipDominec / explore-object-tree.py
Created September 21, 2017 11:13
Recursively prints all attributes, lists, dicts etc. of a given object - here used for analysis of a parsed OPJ file
#!/usr/bin/python3
#-*- coding: utf-8 -*-
import liborigin
opj = liborigin.parseOriginFile('../test.opj')
coloured = True
if coloured:
normal = "\033[1;0m"
bold = "\033[1;1m"
@FilipDominec
FilipDominec / filter_outliers.py
Last active September 6, 2017 13:25
Clean up two-column ASCII file from "hot pixels" that differ by more than 3σ from their neighbours
#!/usr/bin/python3
#-*- coding: utf-8 -*-
"""
Do you have some "outlier" noise in your experimental data, e.g. due to "hot pixels" in spectrometer?
Run
python3 rm_outliers.py my_file.dat
and the new "my_file.dat_corrected.dat" will be free of these errors.
@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)):