Instantly share code, notes, and snippets.

🎯
Focusing

# João Faria j-faria

🎯
Focusing
Created December 15, 2012 23:50
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 def HelloWorld: print 'Hello World, from Python'
Created October 10, 2013 23:33
Generate data with a particular correlation matrix - resultados da primeira geek meeting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 #!/usr/bin/env python # -*- coding: utf-8 -*- # Generate data with a particular correlation matrix # # A useful fact is that if you have a random vector x with covariance matrix Σ, # then the random vector Ax has mean AE(x) and covariance matrix Ω=AΣA^T. # So, if you start with data that has mean zero, multiplying by A will not # change that. #
Last active December 25, 2015 16:39
Shuffle an array in place using the Knuth-Fisher-Yates algorithm.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 #!/usr/bin/env python # -*- coding: utf-8 -*- # # Shuffle an array in place using the Knuth-Fisher-Yates algorithm. from random import randrange def shuffle(x): """ Shuffle x in place using the Knuth-Fisher-Yates algorithm """ for i in xrange(len(x)-1, 0, -1):
Created November 15, 2013 16:02
Calculate and show the covariance matrix for template noise.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 from numpy import * from pylab import * from glob import glob from scipy.stats import nanmean NN = '088' # change this fileglob = 'Residuals_NN' + NN + '_Index*'
Created December 14, 2013 16:35
Generate samples of power law noise.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 from math import floor from numpy import arange, exp, pi, flipud, append, conj, real from numpy.fft import ifft from numpy.random import randn def powernoise(alpha, N, randpower=False, normalize=False): """ Generate samples of power law noise. The power spectrum of the signal scales as f^(-alpha).
Created January 9, 2014 20:17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 # file configfile.py # create a custom INI file reader and read a file called 'test.ini' import ConfigParser class iniReader(ConfigParser.ConfigParser): def as_dict(self): d = dict(self._sections) for k in d: d[k] = dict(self._defaults, **d[k])
Created March 3, 2014 13:15
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import sys def fun(): print 'fun' def test(): print 'test' if __name__ == "__main__": if len(sys.argv) > 1 and sys.argv[1] == 'test':
Last active August 29, 2015 14:17
Fortran implementation of the Generalized Lomb-Scargle (GLS) periodogram
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 GLS periodogram
Created April 2, 2015 13:41
Calculate the Pearson correlation coefficient of two arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 real(kind=8) function pearsonr(x, y) result(r) ! given two arrays x and y, this function computes their Pearson correlation coefficient r implicit none real(kind=8), dimension(:) :: x, y real(kind=8), dimension(size(x)) :: xt, yt real(kind=8) :: ax, ay, df, sxx, sxy, syy integer :: n if (size(x) /= size(y)) STOP 'Dimension mismatch in pearsonr'
Last active August 29, 2015 14:21
Change parameter file, in place
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import fileinput import os # create a copy of the template parameter file os.system('cp template_file new_file') # for example, in the template you have # par1 = 10 # par2 = 'some path' # and you want to change to