Skip to content

Instantly share code, notes, and snippets.

View nicoguaro's full-sized avatar

Nicolás Guarín-Zapata nicoguaro

View GitHub Profile
@nicoguaro
nicoguaro / rainbow_desaturated.txt
Last active July 12, 2024 01:59
Tecplot utilities.
# Rainbow Desaturated colormap
0 0.278431 0.278431 0.858824
0.143 0 0 0.360784
0.285 0 1 1
0.429 0 0.501961 0
0.571 1 1 0
0.714 1 0.380392 0
0.857 0.419608 0 0
1 0.878431 0.301961 0.301961
@nicoguaro
nicoguaro / viridis.xml
Created August 6, 2015 21:33
Viridis colormap in XML format.
<ColorMaps>
<ColorMap space="RGB" indexedLookup="false" name="Viridis">
<Point x="0" r="0.267004" g="0.004874" b="0.329415"/>
<Point x="0.003922" r="0.26851" g="0.009605" b="0.335427"/>
<Point x="0.007843" r="0.269944" g="0.014625" b="0.341379"/>
<Point x="0.011765" r="0.271305" g="0.019942" b="0.347269"/>
<Point x="0.015686" r="0.272594" g="0.025563" b="0.353093"/>
<Point x="0.019608" r="0.273809" g="0.031497" b="0.358853"/>
<Point x="0.023529" r="0.274952" g="0.037752" b="0.364543"/>
<Point x="0.027451" r="0.276022" g="0.044167" b="0.370164"/>
@nicoguaro
nicoguaro / shading_surf3d.py
Created July 22, 2015 20:27
3D surface with light shading using matplotlib.
"""
Example showing shaded 3d plots. It is based on the [shading example](
http://matplotlib.org/examples/pylab_examples/shading_example.html).
The surface used is the Matlab `peaks()`.
"""
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
@nicoguaro
nicoguaro / FDM_dirichlet.py
Last active August 29, 2015 14:24
Method of Manufactured Solutions for FDM in 1D
from __future__ import division
import numpy as np
from numpy import cos, sin, exp, zeros
from numpy.linalg import solve, norm
import matplotlib.pyplot as plt
from matplotlib import rcParams
rcParams['font.family'] = 'serif'
rcParams['font.size'] = 16
@nicoguaro
nicoguaro / hull_plot.py
Created June 8, 2015 14:55
Plot the convex hull around a set of points as a shaded polygon.
# -*- coding: utf-8 -*-
"""
Plot the convex hull around a set of points as a
shaded polygon.
@author: Nicolas Guarin Zapata
@date: October 15, 2014
"""
import numpy as np
from scipy.spatial import ConvexHull
@nicoguaro
nicoguaro / beam_eigs_FD.py
Last active November 29, 2016 21:30
Eigenvalues of beams and plates using Finite Differences.
# -*- coding: utf-8 -*-
"""
Eigenmodes of an Euler-Bernoulli beam with fixed ends [1]_. The stencil
used is a central finite difference of second order [2]_.
References
----------
.. [1] Euler–Bernoulli beam theory. (2015, June 2). In Wikipedia,
The Free Encyclopedia. Retrieved 20:11, June 3, 2015, from
@nicoguaro
nicoguaro / plot_mesh.py
Created May 11, 2015 22:00
Plot a (finite element) mesh formed by 8 node (serendipity) elements.
from numpy import array
from matplotlib import pyplot as plt
def plot_msh(pts, els, shw_pts=True, shw_els=True,
pts_text=False, els_text=False):
"""
Plot a mesh of 8 nodes (serendipity) elements.
Parameters
----------
@nicoguaro
nicoguaro / eval_fun.py
Created May 11, 2015 21:48
Evaluate a function with variable number of parameters.
def eval_fun(f, **args):
""" (str, dict) -> object
f: Function as string.
args: dictionary with arbitrary variables.
Use arbitrary args in **args to eval general functions.
Examples:
>> eval_fun('x**2',x=5)
25
>> eval_fun('x*y', x=3, y=2)
6
@nicoguaro
nicoguaro / parallel_proj.py
Last active August 29, 2015 14:20
Snippets relted to Paraview
"""
Set projection to parallel in Paraview
In Paraview 4.3 the default is perspective projection.
"""
camera = GetActiveCamera ()
camera. SetParallelProjection (True)
@nicoguaro
nicoguaro / hausdorff.py
Last active August 29, 2015 14:19
Calculate two-side Hausdorff distance between two sets using a brute force approach.
# -*- coding: utf-8 -*-
"""
Calculate two-side Hausdorff distance between two sets using a brute
force approach.
References
[1] http://en.wikipedia.org/wiki/Hausdorff_distance
@author: Nicolas Guarin-Zapata
"""