Skip to content

Instantly share code, notes, and snippets.

@adamltyson
adamltyson / injection_view.py
Created March 6, 2025 15:52
Lewis - visualise injection site
import numpy as np
from brainrender import Scene
from brainrender.actors import Points
scene = Scene()
mos = scene.add_brain_region("MOs", alpha=0.15)
# coordinate from brainglobe_segmentation
@adamltyson
adamltyson / napari_brainreg.py
Last active November 26, 2024 15:08
Open napari with the brainreg plugin opened.
# /// script
# requires-python = "==3.12"
# dependencies = [
# "napari[all]",
# "brainreg[napari]",
# ]
# ///
import napari
@adamltyson
adamltyson / linkcheck.sh
Created September 12, 2024 09:00
Alias to run sphinx build with linkcheck
alias dblc='rm -rf docs/build && sphinx-build docs/source docs/build -b linkcheck'
@adamltyson
adamltyson / brainsaw_pad.py
Created August 16, 2024 09:46
Pad a series of 2D images
import numpy as np
import tifffile as tiff
from pathlib import Path
# Define the input and output directories
input_dir = Path('/home/adam/Desktop/blackcap/blackcap_stitched/2')
output_dir = Path('/home/adam/Desktop/blackcap/blackcap_stitched_padded/2')
# Ensure the output directory exists
output_dir.mkdir(parents=True, exist_ok=True)
@adamltyson
adamltyson / brainrender_barrel.py
Created August 2, 2024 10:01
Visualise barrels in brainrender
from pathlib import Path
from myterial import *
from rich import print
from brainrender import Scene
from brainrender import settings
settings.SHOW_AXES = False
@adamltyson
adamltyson / actions_billing_summary.py
Created June 16, 2023 10:58
Summarise github actions billing report
# To use, download GitHub usage report from the organisation
# billing tab then run e.g.:
# `python actions_billing_summary.py file.csv`
import sys
import pandas as pd
actions_csv = sys.argv[1]
df = pd.read_csv(actions_csv)
@adamltyson
adamltyson / NIU_Python_tooling.md
Created January 23, 2023 14:35
SWC/GCNU Neuroinformatics Unit Python tooling

SWC/GCNU Neuroinformatics Unit tooling

Python

Setting up a project

  • To set up a new Python project, use the SWC cookiecutter repository. This ensures that the required tooling is in place (e.g. CI) and also that we are all using a familiar project structure. Part of using this cookiecutter is keeping it updated (e.g. Python versions, best practices) and communicating those changes to all users (including those at SWC).

  • Whenever possible, we will use pyproject.toml as the main configuration file for the project. Support for setup.cfg and setup.py will be deprecated in future python versions. This will also be the default option for the SWC cookiecutter.

Virtual environments

@adamltyson
adamltyson / extract_timecourse_napari.py
Created January 16, 2023 18:49
Extract timecourse of one channel from a labels layer in napari
# import packages
import numpy as np
import pandas as pd
from skimage.measure import label
# assign arrays to simpler variables
labels = label(viewer.layers["Labels"].data[0])
red_data = viewer.layers["NAME_OF_RED_CHANNEL"].data
# intialise empty list
@adamltyson
adamltyson / brainglobe_xarray.py
Created September 21, 2022 18:05
Representing BrainGlobe datasets with xarray
import dask.array as da
import xarray as xr
import numpy as np
from imlib.IO.cells import cells_xml_to_df
from skimage.io import imread
from dask import delayed
from glob import glob
from pathlib import Path
@adamltyson
adamltyson / docker_install.txt
Last active June 13, 2024 08:23
Install docker on ubuntu
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
sudo usermod -aG docker $USER
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose