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
@raacampbell
raacampbell / lastexport.py
Created February 21, 2016 10:20 — forked from bitmorse/lastexport.py
lastfm scrobble exporter (from https://gitorious.org/fmthings/lasttolibre/blobs/master/lastexport.py // changed the script to try more often on failure )
#!/usr/bin/env python
#-*- coding: utf-8 -*-
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@raacampbell
raacampbell / affineRotExample3D.m
Created October 23, 2017 14:22
Rotating points in 3D using affine transformation in MATLAB
function affineRotExample3D(thetaX, thetaY, thetaZ)
% Example of how to rotate an array of points in 3 using affine transformation
%
% function affineRotExample3D(thetaX, thetaY, thetaZ)
%
% Purpose
% Rotate a grid of points in three dimensions about its centre using affine transformation
%
%
% By default:
@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
@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 / 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 / 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 / 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 / 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 / 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 / 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.