Skip to content

Instantly share code, notes, and snippets.

View briochemc's full-sized avatar

Benoît Pasquier briochemc

View GitHub Profile
@briochemc
briochemc / make_c_map_out_of_screenshot.m
Created June 12, 2018 20:40
make a colormap out of a screenshot
function [cbar] = make_c_map_out_of_screenshot(impath,crop,column)
% ------ Help for make_c_map_out_of_screenshot -------
%
% Creates a colorbar from a screenshot of another colorbar.
%
% How to use:
% 1) Make screenshot of the colorbar (Ideally, have the left most column of
% pixels right on the colormap)
% 2) Save as image file (png works, maybe other formats will not, try it out!)
% 3) Put path to file in some variable, e.g.:
@briochemc
briochemc / FastBackslash.jl
Created October 18, 2018 23:46
Testing factorisation in Julia
using LinearAlgebra, DualNumbers, BenchmarkTools, SparseArrays, SuiteSparse
n = 1000 # size of J and y
# make y
a, b = rand(n), rand(n)
y = a + b * ε
# make J
spA = sprandn(n, n, 10/n) + I
H \ sₖ
% The following takes a 3D matrix and averages across depths
% You want to see what the z depth are?
% I would suggest following Seth John's advice: use explcit names and capitals to show big 3d things
DEPTH = z ;
depth = squeeze(DEPTH(1,1,:)) ;
itoplayers = find(depth < 55) ; % this creates a range of the indices for depth less than (i.e., above) 55m
% Here this range is 0m–50m. Check the values before to make sure:
depths_top = depth(itoplayers) ; % These are the depth levels [0, 10, 20, 30, 40, 50]
NEIGHBORS_MAP = {
0: (0, 0, 0, 0, 1, 0, 1, 0, 0, 0),
1: (0, 0, 0, 0, 0, 0, 1, 0, 1, 0),
2: (0, 0, 0, 0, 0, 0, 0, 1, 0, 1),
3: (0, 0, 0, 0, 1, 0, 0, 0, 1, 0),
4: (1, 0, 0, 1, 0, 0, 0, 0, 0, 1),
5: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
6: (1, 1, 0, 0, 0, 0, 0, 1, 0, 0),
7: (0, 0, 1, 0, 0, 0, 1, 0, 0, 0),
8: (0, 1, 0, 1, 0, 0, 0, 0, 0 ,0),
[[AbstractFFTs]]
deps = ["Compat", "LinearAlgebra"]
git-tree-sha1 = "8d59c3b1463b5e0ad05a3698167f85fac90e184d"
uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c"
version = "0.3.2"
[[Arpack]]
deps = ["BinaryProvider", "Libdl", "LinearAlgebra", "Random", "SparseArrays", "Test"]
git-tree-sha1 = "1ce1ce9984683f0b6a587d5bdbc688ecb480096f"
uuid = "7d9fca2a-8960-54d3-9f78-7d1dccf2cb97"
# Here I store more data as I go,
# which I could use to plot figures comparing methods
# the convergence speed of different methods
# I use the Rosenbrock classic example and
# Optim.jl as an iterative process which will
# call f multiple times to find its minimum
# and I plot the convergence vs time
using Optim, Cassette
load Downloads/CTL.mat
T = output.TR ;
f1 = figure ;
spy(T, 'w') ;
darkBackground(f1, [0 0 0], [1 1 1])
f1(x) = x
f2(x) = 2x
f3(x) = 3x
list_methods = [
("method1", :f1)
("method2", :f2)
("method3", :f3)
]
# Example function to find the root of
f(x) = [(x[1] + x[2] + 1)^3, (x[1] - x[2] - 1)^3]
function f_Jac!(J, x)
J[1, 1] = 3(x[1] + x[2] + 1)^2
J[2, 1] = 3(x[1] - x[2] - 1)^2
J[1, 2] = 3(x[1] + x[2] + 1)^2
J[2, 2] = -3(x[1] - x[2] - 1)^2
return J
end