Skip to content

Instantly share code, notes, and snippets.

View mpilosov's full-sized avatar

Michael Pilosov mpilosov

View GitHub Profile
@mpilosov
mpilosov / plotting.py
Created August 25, 2017 03:07
Plotting example
import numpy as np
from matplotlib import pyplot as plt # imports plotting library, uses 'plt' as the handle. for help, google "matplotlib"
x = np.linspace(-1, 1, 100)
y = x.**2 + 2.*x + 1
plt.figure() # open a new figure (sometimes you see ax, fig = plt.figure() if people want to instantiate multiple figures.
plt.plot(x,y)
plt.xlabel("x axis")
plt.ylabel("y axis")
@mpilosov
mpilosov / writetexfiles.jl
Last active August 25, 2017 03:45
Write files to a grid of images in latex.
save_dir = "images/4D_2/"
QoI_list = [[12],[10], [7,16]]
std = 20
# image of the scatterplots.
portion = 0.32 # should be a hair less than 1/cols
cols = 3
rows = 2
# the following variable is how you want the row*cols images that will be in the figure to be ordered.
order = [ [1 3], [2 3], [1 4], [3 4], [1 2], [2 4] ] # part of the filenames (these are 2D scatterplots in 4D), serpentine column-dominant ordering. (top left to bot right)
for QoI_inds in QoI_list # loop through a list that differentiates the files from one another. each one of these is a different figure saved.
@mpilosov
mpilosov / image_example.py
Last active October 31, 2017 17:48
Images with Python
from matplotlib import pyplot as plt # the standard python plotting library
# installation instructions here: https://github.com/matplotlib/matplotlib
import numpy as np # math library for data-handling
# DEMO on random matrix to show how filtering based on pixel intensity works. How to make an image.
n = 20
I = np.random.random((n, n))
I[I>0.5] = 1 # highpass filter in two lines of code.
I[I<0.5] = 0

We'll be using nose for testing purposes.

The basic premise is simple. Write a file that imports solely the modules you want to test.

Writing your first nosetest

Write one test for each type-support that you want to be able to check. From this guide, we have the following example of ensuring that a user-defined function multiply operates the way it is intended to:

@mpilosov
mpilosov / kwd_fun_calls.py
Created January 27, 2018 06:36
keywording in python
import scipy.stats as sstats
def ev(*args, **kwds):
return sstats.norm(*args, **kwds)
kw = {'loc':2}
def kwrap(kwds):
return ev(**kwds)
print(kwrap(kw).rvs(3))

Manual Approach

Note: this procedure requires an .img file that you will be required to create from the .iso file you download.

Download the desired file. Convert the .iso file to .img using the convert option of hdiutil

hdiutil convert /path/to/ubuntu.iso -format UDRW -o /path/to/target.img  

Note: OS X tends to put the .dmg ending on the output file automatically.

@mpilosov
mpilosov / seaborn_marginal_example.py
Last active February 2, 2018 01:34
Quick marginal plots with Seaborn
# Here we utilize scipy to draw samples from two distributions and plot the result.
import seaborn as sns
import numpy as np
import scipy.stats as sstats
x_dist = sstats.norm(loc=0, scale=2)
y_dist = sstats.uniform(loc=0, scale=1)
N = 10000
x_data = x_dist.rvs(N)
@mpilosov
mpilosov / subplots.py
Created February 2, 2018 20:11 — forked from dyerrington/subplots.py
Plotting multiple figures with seaborn and matplotlib using subplots.
##
# Create a figure space matrix consisting of 3 columns and 2 rows
#
# Here is a useful template to use for working with subplots.
#
##################################################################
fig, ax = plt.subplots(figsize=(10,5), ncols=3, nrows=2)
left = 0.125 # the left side of the subplots of the figure
right = 0.9 # the right side of the subplots of the figure
@mpilosov
mpilosov / piecewise.py
Created February 11, 2018 23:51
piecewise function in python
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import numpy as np
def q1(lam):
L1 = lam[:,0] # local column-vectors.
L2 = lam[:,1]