Skip to content

Instantly share code, notes, and snippets.

@mstankie
mstankie / grid_indices_list.py
Last active September 5, 2022 10:52
List of 3D grid indices in NumPy
# Get i, j, k indices of grid nodes as a list to iterate over
import numpy as np
GRID_SHAPE = (2, 3, 4)
grid_indices: np.ndarray = np.indices(GRID_SHAPE).reshape(len(GRID_SHAPE), -1).T
grid_indices.shape # >> (24, 3)
# This way we can loop through the indices as array rows
for idx in grid_indices:
@mstankie
mstankie / point_grid.py
Created April 8, 2022 12:36
Generate (x,y,z) coordinates of N points arranged on 3D grid as Nx3 NumPy array
import numpy as np
x_coords = np.arange(3)
y_coords = np.linspace(-1, 1, 11)
z_coords = [0.0, 0.5, 1.0]
point_grid = np.hstack([c.reshape(-1, 1) for c in np.meshgrid(x_coords, y_coords, z_coords)])
@mstankie
mstankie / keybase.md
Created May 6, 2019 13:46
Keybase proof

Keybase proof

I hereby claim:

  • I am mstankie on github.
  • I am mstankie (https://keybase.io/mstankie) on keybase.
  • I have a public key ASDqlBvzYxBakNUkZJtg5gbJrQ4-SP4oL1-ItZrVqn3W2go

To claim this, I am signing this object:

@mstankie
mstankie / OpenCV_HighGUI_Fullscreen.cpp
Created January 29, 2018 11:38
HighGUI fullscren window
cv::namedWindow("Fullscreen", cv::WINDOW_NORMAL);
cv::setWindowProperty("Fullscreen", cv::WND_PROP_FULLSCREEN, cv::WINDOW_FULLSCREEN);
cv::imshow("Fullscreen", someImage);
cv::waitKey(10);
@mstankie
mstankie / build.sh
Last active October 3, 2017 10:56
Obtaining `git describe` directly from LaTeX document without any intermediate files.
#!/bin/bash
# obtaining the name of either the remote origin repo or the local directory if no origin defined
DIRNAME=${PWD##*/}
JOBNAME=$(git config --get remote.origin.url | xargs basename || echo $DIRNAME".loc")
# compiling
latexmk -pdf -pdflatex="pdflatex --enable-pipes --shell-escape --enable-write18 %O %S" -jobname=$JOBNAME -output-directory="./build/" document.tex
latexmk -c -jobname=$JOBNAME -output-directory="./build/"
@mstankie
mstankie / JupyterFileSelector.py
Last active June 2, 2017 11:18 — forked from tritemio/open file dialog
Open file dialog for default ipython notebook in Anaconda
def selectFile(startDir = '.', filter = "All files (*)", title = "Select a file..."):
from PyQt4 import QtGui
app = QtGui.QApplication([dir])
fname = QtGui.QFileDialog.getOpenFileName(None, title, startDir, filter=filter)
return str(fname)
@mstankie
mstankie / listings-customc.tex
Last active May 25, 2017 14:41
Styles for listings package -different languages listings in LaTeX.
\definecolor{mygreen}{rgb}{0,0.6,0}
\definecolor{mygray}{rgb}{0.5,0.5,0.5}
\definecolor{mymauve}{rgb}{0.58,0,0.82}
\lstdefinestyle{customc}{
belowcaptionskip=1\baselineskip,
breaklines=true,
frame=L,
xleftmargin=\parindent,
language=C,
showstringspaces=false,
def createLineIterator(P1, P2, img):
"""
Produces and array that consists of the coordinates and intensities of each pixel in a line between two points
Parameters:
-P1: a numpy array that consists of the coordinate of the first point (x,y)
-P2: a numpy array that consists of the coordinate of the second point (x,y)
-img: the image being processed
Returns:
@mstankie
mstankie / twoCurvesFit.py
Created November 11, 2016 15:00
Fitting two curves with some common parameters. From http://scipy-cookbook.readthedocs.io/items/FittingData.html
# Target function
fitfunc = lambda T, p, x: p[0]*np.cos(2*np.pi/T*x+p[1]) + p[2]*x
# Initial guess for the first set's parameters
p1 = r_[-15., 0., -1.]
# Initial guess for the second set's parameters
p2 = r_[-15., 0., -1.]
# Initial guess for the common period
T = 0.8
# Vector of the parameters to fit, it contains all the parameters of the problem, and the period of the oscillation is not there twice !
p = r_[T, p1, p2]
@mstankie
mstankie / import-plt.py
Created June 15, 2016 19:33
Two images side-by-side using matplotlib (pylab)
import matplotlib.pyplot as plt