Skip to content

Instantly share code, notes, and snippets.

@alisterburt
alisterburt / josh.py
Last active March 13, 2024 01:05
recentering/reorienting RELION particles for Josh Hutchings
"""Recenter and reorient RELION particles
This shows the gist of how to manually move/reorient RELION particles in 3D.
You define a set of shifts and orientations in the coordinate system of the
reference for all 'subparticles' you want to generate from each existing particle.
"""
import pandas as pd
import starfile
import numpy as np
from scipy.spatial.transform import Rotation as R
@alisterburt
alisterburt / jules.py
Created February 23, 2024 16:37
jules
import napari
import numpy as np
from skimage import data
from napari_threedee.manipulators.base_manipulator import BaseManipulator
class FullManipulator(BaseManipulator):
def __init__(self, viewer, layer=None):
@alisterburt
alisterburt / molmap.py
Created February 22, 2024 01:30
molmap - slow
import numpy as np
import torch
import einops
import mmdf
from libtilt.grids._patch_grid_utils import patch_grid_centers
from libtilt.grids import coordinate_grid
RESOLUTION_ANGSTROMS = 3.4
VOLUME_SIZE = (512, 512, 512)
@alisterburt
alisterburt / 3d_sliding_window.py
Created February 14, 2024 19:09
torch sliding window view on 3D image
import torch
import einops
def sliding_window_3d(tensor, window_size):
d, h, w = tensor.shape
window_depth, window_height, window_width = window_size
# Calculate the number of windows in each dimension
new_d = d - window_depth + 1
new_h = h - window_height + 1
@alisterburt
alisterburt / h3_utils.py
Created December 6, 2023 22:11
h3 utils
import h3
import torch
import einops
from scipy.spatial.transform import Rotation as R
def get_h3_grid_at_resolution(resolution: int) -> list[str]:
"""Get h3 cells (their h3 index) at a given resolution.
@alisterburt
alisterburt / katherine.ipynb
Created August 28, 2023 12:15
katherine inpainting
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@alisterburt
alisterburt / tom_picker.py
Last active October 3, 2023 12:44
interactively delete dynamo particles - for Tom D, super hacky
from enum import Enum
from pathlib import Path
from glob import glob
import dynamotable
import mrcfile
import pandas as pd
import napari
import numpy as np
@alisterburt
alisterburt / jason.py
Last active June 21, 2023 19:40
basic file selector napari for Jason Kaelber
from pathlib import Path
import imageio
import numpy as np
import napari
from napari.utils.notifications import show_info
IMAGE_FILE_PATTERN = 'images/*'
DIRECTORY_FOR_GOOD_IMAGES = 'good_images'
from pathlib import Path
import numpy as np
import pandas as pd
import starfile
# generate fake data
a = np.random.uniform(0, 200, size=(100, 3))
@alisterburt
alisterburt / maddie_script.py
Created May 11, 2023 08:13
typer CLI example for maddie
from pathlib import Path
import typer
cli = typer.Typer()
@cli.command(no_args_is_help=True)
def my_command_line_interface(
pixel_size: float = 1.0,