Skip to content

Instantly share code, notes, and snippets.

View loganbvh's full-sized avatar

Logan Bishop-Van Horn loganbvh

View GitHub Profile
import h5py
import numpy as np
def set_h5_attrs(grp, data):
"""Sets attributes of h5py group or File `grp` according to dict `data`.
Args:
grp (h5py group or File): Group or file you would like to update.
data (dict): Dict of data with which to update `grp`.
"""
@loganbvh
loganbvh / mutual_inductance.py
Created January 11, 2023 21:31
Maxwell's analytical formula for the mutual inductance of two coaxial circular loops
from numpy import sqrt
from scipy.special import ellipe, ellipk
import pint
ureg = pint.UnitRegistry()
def mutual_inductance(r1: float, r2: float, h: float, length_units: str = "m") -> pint.Quantity:
"""Calculates the mutual inductance between two coaxial circular loops.
All lengths, ``r1``, ``r2``, and ``h`` are assumed to be given in ``length_units``.
@loganbvh
loganbvh / zenodo_upload_progress.py
Last active November 10, 2024 02:15
Zenodo Python upload with progress bar
import os
import requests # pip install requests
from tqdm import tqdm # pip install tqdm
from tqdm.utils import CallbackIOWrapper
# See: https://gist.github.com/slint/92e4d38eb49dd177f46b02e1fe9761e1
# See: https://gist.github.com/tyhoff/b757e6af83c1fd2b7b83057adf02c139
def get_bucket_url(deposit_id: str, access_token: str) -> str:
@loganbvh
loganbvh / numba_fast_matmul.py
Last active May 17, 2023 19:08
Fast matmul with numba
import numba
import numpy as np
@numba.njit(fastmath=True, parallel=True)
def fast_matmul(A: np.ndarray, B: np.ndarray) -> np.ndarray:
"""Performs ``A @ B`` for 2D matrices efficiently using numba."""
# I have found that pre-allocating ``out`` and passing it in as an argument does
# not speed things up very much.
# On my M1 MacBook with 10 cores, this function is faster and has lower CPU
# utilization than A @ B using numpy/BLAS. It is also slightly faster than
@loganbvh
loganbvh / superscreen-demo.ipynb
Created October 14, 2023 05:20
superscreen-demo.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@loganbvh
loganbvh / supercreen-field-from-solution.py
Created April 11, 2024 18:33
supercreen-field-from-solution.py
import numpy as np
import superscreen as sc
def field_from_solution(
x: np.ndarray,
y: np.ndarray,
z: np.ndarray,
*,
solution: sc.Solution,
dr: tuple[float, float, float] = (0.0, 0.0, 0.0),
@loganbvh
loganbvh / superscreen_susceptometry.py
Created April 11, 2024 18:39
superscreen_susceptometry.py
import os
import sys
import numpy as np
import pint
from scipy.spatial.transform import Rotation
import superscreen as sc
from superscreen.geometry import box
sys.path.insert(0, os.path.expanduser("~/GitHub/superscreen-squids"))
@loganbvh
loganbvh / simple-squid-figures.ipynb
Created July 2, 2024 19:35
pyTDGL simulation of a nano-SQUID
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.