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 / continuous arccosine notes
Created August 21, 2014 08:37
continuous arccosine
TODO: copy from my codes and add a test:
http://comments.gmane.org/gmane.comp.python.scientific.devel/17439
@FilipDominec
FilipDominec / Lagrangian points - force plot
Created January 25, 2015 05:15
there are 5 points in the Sun-Earth system where gravitational and centrifugal forces cancel
#!/usr/bin/env python
#coding:utf8
import numpy as np
#Mearth, Msun = 5.97e24, 1.98e30 ## <-- these are realistic
Mearth, Msun = 1.97e29, 1.98e30 ## <-- unrealistic, but better for visualisation
earth_sun_dist = 149e9
Xsun = - earth_sun_dist * (Mearth/Msun) ## Sun center distance to the center-of-mass
Xearth = earth_sun_dist * (1 - Mearth/Msun) ## Earth center distance to the center-of-mass
kappa = 6.67e-11 ## Gravitational constant
@FilipDominec
FilipDominec / Testing Padé approximants
Last active August 29, 2015 14:15
- or, how eˣ can be approximated by fractions having small degrees of numerator/denominator
#!/usr/bin/env python
#-*- coding: utf-8 -*-
## Import common moduli
from __future__ import division
import matplotlib, sys, os, time
import matplotlib.pyplot as plt
import numpy as np
from scipy.constants import c, hbar, pi
@FilipDominec
FilipDominec / FFT of frequency-modulated sinewave
Created February 18, 2015 14:59
How does the spectrum of a frequency modulated wave differ from the well known amplitude-modulated one?
#!/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, hbar, pi
## Use LaTeX
#!/usr/bin/env python
#-*- coding: utf-8 -*-
## Import common moduli
import matplotlib, sys, os, time, re
import matplotlib.pyplot as plt
import numpy as np
from scipy.constants import c, hbar, pi
matplotlib.rc('text', usetex=True)
matplotlib.rc('font', size=10)
@FilipDominec
FilipDominec / Mayavi scripting
Created February 20, 2015 20:08
Instantly display a vector VTK file in Mayavi
#!/usr/bin/env python2.7
#-*- coding: utf-8 -*-
import os,sys
import numpy as np
try: from enthought.mayavi import mlab
except: from mayavi import mlab
mlab.options.offscreen = True ## XXX
def symmetric_colors(lut_manager):
@FilipDominec
FilipDominec / Square root of a matrix
Created February 20, 2015 20:27
Most scalar functions can be generalized to square matrices, which requires to apply the function to the eigenvalues
#!/usr/bin/env python
#coding:utf8
import numpy as np
import scipy.linalg as la
size = 3
A = np.random.random([size, size])
print "\n== Random square matrix can be subject to virtually any function =="
@FilipDominec
FilipDominec / useful_functions.py
Created February 25, 2015 11:45
Snippets for scipy
#!/usr/bin/env python
#-*- coding: utf-8 -*-
## . S C SM
## F1 PREAMB Import UseLatex StartFig
## F2 GET Load1D Gen1D Get2D
## F3
## F4
## F5 PLOT Plot1D Contours
## F6
@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
@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'