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 / 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)):
@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()