Skip to content

Instantly share code, notes, and snippets.

View thomasaarholt's full-sized avatar

Thomas Aarholt thomasaarholt

View GitHub Profile
$ pip install pytetgen
Collecting pytetgen
Using cached pytetgen-0.1.4.tar.gz (392 kB)
Building wheels for collected packages: pytetgen
Building wheel for pytetgen (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: 'C:\Users\thomasaar\Miniconda3\envs\py38\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\thomasaar\\AppData\\Local\\Temp\\pip-install-xphrb4j7\\pytetgen_dc8134ee876b4f18b1a1373353bd0c09\\setup.py'"'"'; __file__='"'"'C:\\Users\\thomasaar\\AppData\\Local\\Temp\\pip-install-xphrb4j7\\pytetgen_dc8134ee876b4f18b1a1373353bd0c09\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\thomasaar\AppData\Local\Temp\pip-wheel-igdis3c8'
cwd: C:\Users\thomasaar\AppData\Local\Temp\pip-install-xphrb4j7\pytetgen_dc8134ee876b4f18b1a1373353bd0c09\
Complete output (339 lines):
running bdist_whee
@thomasaarholt
thomasaarholt / plot_arc.py
Last active January 19, 2025 00:17
Create a matplotlib Arc patch to show the angle between two lines
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
Arc = matplotlib.patches.Arc
def halfangle(a, b):
"Gets the middle angle between a and b, when increasing from a to b"
if b < a:
b += 360
return (a + b)/2 % 360
@thomasaarholt
thomasaarholt / rowroll.py
Created January 12, 2021 11:20
Row roll of an ndarray with optional fill_value=np.nan
def row_roll(arr, shifts, axis=1, fill=np.nan):
"""Apply an independent roll for each dimensions of a single axis.
Parameters
----------
arr : np.ndarray
Array of any shape.
shifts : np.ndarray, dtype int. Shape: `(arr.shape[:axis],)`.
Amount to roll each row by. Positive shifts row right.
@thomasaarholt
thomasaarholt / SympyGaussians.py
Created December 14, 2020 19:05
Example of using IndexedBase in order to do for loops in Sympy for memory conservation
import sympy as sp
import matplotlib.pyplot as plt
import numpy as np
def Gaussian(x, a, xc, sigma):
return a*sp.exp(-((x-xc)**2)/(2*sigma**2))
x, i, n = sp.symbols('x i n') # x is our main independent variable. i and n are indices
a, xc, sigma = sp.symbols('A xc sigma', cls=sp.IndexedBase) # parameters that are held in arrays
symbols = (x, a, xc, sigma, n)
@thomasaarholt
thomasaarholt / gist:94ce3653cefdf0fc3f209645e9304786
Created December 13, 2020 15:50
Bash PS1 Prompt code to show conda environment, last two directories and nothing more, in colour
export PROMPT_DIRTRIM=2
export PS1="\[\e[0m\](\[\e[32;40m\]\$CONDA_DEFAULT_ENV\[\e[0m\]) \[\e[36;40m\]\w: \[\e[0m\]"
@thomasaarholt
thomasaarholt / aoc2020_01_rust.rs
Created December 2, 2020 12:06
Beginner-rust solution to Advent of Code 2020 Day 01 - Feedback very welcome!
// Uses the cargo-aoc crate to help take care of inputs and benchmarks
use aoc_runner_derive::{aoc, aoc_generator};
use std::num::ParseIntError;
#[aoc_generator(day1)]
fn parse_input_day1(input: &str) -> Result<Vec<i32>, ParseIntError> {
input.lines().map(|l| l.parse()).collect()
}
#[aoc(day1, part1)]
@thomasaarholt
thomasaarholt / aoc_2020_01.py
Created December 2, 2020 08:55
Python Solution to Advent of Code Day 01
import numpy as np
with open("input01.txt") as f:
a = f.read()
data = np.array([int(n) for n in a.split("\n")[:-1]])
def first(data):
for i, number in enumerate(data):
for number2 in data[i:]:
if number + number2 == 2020:
@thomasaarholt
thomasaarholt / 2D_explorer.py
Last active November 20, 2020 12:26
Matplotlib Navigator and Signal plot with draggable marker
%matplotlib qt
import numpy as np
import matplotlib.pyplot as plt
fig, ax1 = plt.subplots(ncols=1)
fig2, ax2 = plt.subplots(ncols=1)
imdata = np.random.random((20,20))
im = ax1.imshow(imdata, animated=True)
@thomasaarholt
thomasaarholt / ffmpeg_script.sh
Created September 15, 2020 15:50
ffmpeg image -> movie
ffmpeg -r 20 -i img_%03d.png -c:v libx264 -pix_fmt yuv420p -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -y out.mp4
import numpy as np
from scipy.constants import electron_mass, elementary_charge, c, hbar, h
def relativistic_wavelength(kV=300):
"Returns relativistic wavelength in meters"
V = 1e3 * kV
top = h * c
bottom = np.sqrt(
elementary_charge * V * (2 * electron_mass * c ** 2 + elementary_charge * V)
)