Skip to content

Instantly share code, notes, and snippets.

@alisterburt
alisterburt / equidistant_spline.py
Created October 7, 2022 12:07
equidistant sampling on a spline
import numpy as np
import napari
from scipy.interpolate import splprep, splev
n = 10
w = np.linspace(0, 8*np.pi, num=n)
x = [0, 1, 1, 1,]
y = [0, 0, 10, 10]
z = [0, 0, 0, 100]
xyz = np.stack((x, y, z), axis=-1)
@alisterburt
alisterburt / cryo-em-inpainting.py
Created October 4, 2022 20:30
cryo-EM inpainting
from typing import Tuple
import einops
import imageio
import numpy as np
from scipy.interpolate import LSQBivariateSpline
import napari
image = imageio.imread('image/EMPIAR-10164_TS_01_000_0.0.tif')
mask = imageio.imread('mask/EMPIAR-10164_TS_01_000_0.0.tif')
@alisterburt
alisterburt / torch-index-operations.ipynb
Created September 28, 2022 19:42
assignment into repeated indices in pytorch
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@alisterburt
alisterburt / cross_correlation.ipynb
Created September 14, 2022 16:46
cross correlation numpy
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@alisterburt
alisterburt / figure-it-out.ipynb
Created August 8, 2022 14:58
ribosome tilt-series simulation
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@alisterburt
alisterburt / extract_data.py
Created July 26, 2022 14:32
3DVA analysis
import os
import numpy as np
import pandas as pd
import mrcfile
from pathlib import Path
def components_from_cryosparc(cs_file):
data = np.load(cs_file)
@alisterburt
alisterburt / read_cif.py
Created July 17, 2022 19:14
Read PDB/mmCIF coords using gemmi
import gemmi
import numpy as np
pdb = '4v6x-ribo.cif'
structure = gemmi.read_structure(pdb)
model = structure[0] # assumes one model in the file
ca_coords = np.array([
[cra.atom.pos.x, cra.atom.pos.y, cra.atom.pos.z]
@alisterburt
alisterburt / for_jacob.py
Created July 14, 2022 13:42
generate relion matrices from IMOD metadata
import numpy as np
import einops
import starfile
from yet_another_imod_wrapper.utils.io import read_xf, read_tlt
XF_FILE = 'imod_TS_01/TS_01.xf'
TLT_FILE = 'imod_TS_01/TS_01.tlt'
TILT_IMAGE_DIMENSIONS = (3710, 3838) # (x, y)
@alisterburt
alisterburt / evented_model_demo.py
Created July 6, 2022 14:07
simple evented model demo in napari
from typing import Tuple
import napari
import scipy.ndimage as ndi
import numpy as np
from psygnal import EventedModel
viewer = napari.Viewer(ndisplay=3)
mask_layer = viewer.add_image(mask := np.zeros((128, 128, 128)))
@alisterburt
alisterburt / label_edge.py
Created June 23, 2022 16:02
find edge of a label in python
import napari
import numpy as np
import scipy.ndimage as ndi
SIZE = 42
# small circle
circle = np.linalg.norm(
np.indices(dimensions=(SIZE, SIZE)) - (SIZE / 2), axis=0