Skip to content

Instantly share code, notes, and snippets.

View raacampbell's full-sized avatar
🌍

Rob Campbell raacampbell

🌍
  • Sainsbury Wellcome Centre, UCL
  • London
View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@raacampbell
raacampbell / mouse_rectangle.m
Created March 12, 2024 13:41
Rectangle whose free corner follows the mouse cursor
function mouse_rectangle
% Make a rectangle that is anchored at one corner at the axis origin but follows
% the mouse cursor at the other.
%
% Instructions
% Run "mouse_rectangle" then move mouse cursor over the axes.
%
% Inputs
% none
%
@raacampbell
raacampbell / bake.m
Last active February 15, 2024 10:42
bake with hack for re-acquiring slice with a different laser
function sectionInd = bake(obj,varargin)
% Runs an automated anatomy acquisition using the currently attached parameter file
%
% function BT.bake('Param1',val1,'Param2',val2,...)
%
%
% Inputs (optional param/val pairs)
% 'leaveLaserOn' - If true, the laser is not switched off when acquisition finishes.
% This setting can also be supplied by setting BT.leaveLaserOn. If
% not supplied, this built-in value is used.
@raacampbell
raacampbell / scanBeamPathDiagram
Created July 31, 2023 15:41
Path of laser beam over a scanned area showing blanking
function scanBeamPathDiagram
% Generate a figure showing a scanned beam with scan and image field
%
% The path of a resonant-scanned focused beam over a sample. The beam moves
% sinusoidally along the fast axis whilst being scanned up/down with a galvo.
% The area over which the beam moves is known as the “scan field”. On the left and
% right edges the beam slows and turns around. In these areas the potential for
% photodamage is greatest, as the beam is travelling more slowly over the sample.
% Thus the beam is “blanked” or disabled during these epochs. In a resonant scanning
% microscope the beam is blanked about 30% of the time. The image field (red lines
@raacampbell
raacampbell / basic_napari_example
Created May 9, 2022 13:58
Loading an image, adding layers, manipulating layers
import napari
import numpy as np
from skimage import data
from skimage.color import rgb2gray
# Convert the astronaut image to a grayscale
astro_im = rgb2gray(data.astronaut())
# Display the astronaut image and also display its negative in a new layer
@raacampbell
raacampbell / swipeTester.m
Last active February 28, 2022 20:01
Test swipe moves in BT
function swipeTester
% Test if BakingTray swipe moves are causing a failure
% How large the swipe size should be.
swipeSize = 4;
% Pull in BT object
evalin('base','clear ans') %Because it sometimes makes a copy of BT in ans when it fails
hBT=BakingTray.getObject(true);
@raacampbell
raacampbell / getGitInfo.m
Last active January 24, 2022 15:31 — forked from aleifer/getGitInfo.m
MATLAB getGitInfo: Get git repository hash, branch, and remote url in MATLAB
function gitInfo=getGitInfo()
% Get information about the Git repository in the current directory, including:
% - branch name of the current Git Repo
% -Git SHA1 HASH of the most recent commit
% -url of corresponding remote repository, if one exists
%
% The function first checks to see if a .git/ directory is present. If so it
% reads the .git/HEAD file to identify the branch name and then it looks up
% the corresponding commit.
%
@raacampbell
raacampbell / python_for_MATLABists.txt
Created June 20, 2019 07:40
Stuff in Python that's notable to people coming from a MATLAB background
## Multiple assignment
a=b=c=0 # all have the same value
a,b,c = 1,2,3 #a=1, b=2, c=3
a,*b,c = 1,11,22,33,44,2 #b contains all numbers >10
# Chaining comparison operators
@raacampbell
raacampbell / polyN3_line.py
Created June 14, 2019 15:42
Fit a curve to a line in 3D
#!/usr/local/bin/python3
import numpy as np
import scipy.linalg
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
# some 3-dim points
n=20
xx=np.linspace(-12,5,num=n)
@raacampbell
raacampbell / polyN3.py
Created June 14, 2019 12:36
3D polynomial surface fit
#!/usr/local/bin/python3
# Make a 3d point cloud and fit a surface to it
import numpy as np
import scipy.linalg
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt