This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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``. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.