Skip to content

Instantly share code, notes, and snippets.

View Datseris's full-sized avatar
🐻
I am a bear.

George Datseris Datseris

🐻
I am a bear.
View GitHub Profile
@Datseris
Datseris / fit_ellipse.jl
Created July 4, 2022 13:01
Simple Julia code that can fit ellipses to 2D data.
"""
fit_ellipse(x, y) → a, b, θ, x_0, y_0, p
Fit an ellipse into the 2D data defined by `(x, y)`.
Return: semi-major axis length, semi-minor axis length, ellipse rotation,
center coordinates and a parameter container for quadratic form of ellipse,
which is just `M = hcat(x.^2, x.*y, y.^2, x, y); M*p = 1`.
Code modified from:
https://www.matecdev.com/posts/julia-least-squares-qr.html
using a lot of stuff from:
@Datseris
Datseris / schelling.jl
Last active May 7, 2022 15:19
Gist of Agents.jl introductory workshop
### Step 1: decide space
using Agents
space = GridSpace((10, 10); periodic = false)
### Step 2: make agent type
mutable struct SchellingAgent <: AbstractAgent
id::Int
pos::NTuple{2, Int}
group::Int
@Datseris
Datseris / makie_tutorial.jl
Last active March 3, 2024 17:15
Making animated and interactive scientific visualizations in Makie.jl
# # Making animated and interactive scientific
# # visualizations in Makie.jl
# Alrighty, in this short tutorial I'll teach you how to make
# animated scientific such as this video, or this application.
# Prerequisitives:
# * Basic familiarity with Julia (obviously)
# * Basic familiarity with Makie.jl
@Datseris
Datseris / phase_interactive.jl
Created February 9, 2021 19:56
interactive r toggling for phase dependent induced transition
using GLMakie, InteractiveDynamics, DynamicalSystems, OrdinaryDiffEq, LinearAlgebra
diffeq = (alg = Tsit5(), dtmax = 0.02, abstol = 1e-6, reltol = 1e-6)
function hassan_alkhayuon(u, p, t) # From talk of Hassan Alkhayuon
r, c, μ, ν, α, β, χ, δ = p
N, P = u
common = α*N*P/(β+N)
dN = r*N*(1 - (c/r)*N)*((N-μ)/(N+ν)) - common
dP = χ*common - δ*P
return SVector(dN, dP)
@Datseris
Datseris / hassan_alkhayuon_statespace.jl
Last active February 9, 2021 17:36
Attempts at reproducing phase-tipping plots of https://arxiv.org/abs/2101.12107
using DynamicalSystems, PyPlot, LinearAlgebra, OrdinaryDiffEq
# ODE solver options:
diffeq = (alg = Vern9(), reltol = 1e-10, abstol = 1e-10)
# non-dimensionalized Rozenweig-MacArthur model
function rozenweig_macarthur(u, p, t)
k, m, c = p
x, y = u
common = m*x*y/(1+x)
xdot = x*(1-x/k) - common
@Datseris
Datseris / mutualinfo.jl
Created December 5, 2020 23:56
mutual information pure
function naivehist(x::AbstractVector, ε::Real)
mi, ma = extrema(x)
hs = zeros(Int((ma-mi)÷ε) + 1)
is = zeros(Int, length(x))
for (j, e) in enumerate(x)
xi = Int((e-mi)÷ε + 1)
hs[xi] += 1
is[j] = xi
end
return hs ./ length(x), is
@Datseris
Datseris / xarray_to_climarray.jl
Created October 27, 2020 13:04
xarray to ClimArray
using ClimateBase, Dates
# This needs to numpy, xarray and dask installed from Conda
using PyCall
xr = pyimport("xarray")
np = pyimport("numpy")
"""
climarray_from_xarray(xa, fieldname, name = Symbol(fieldname))
Load underlying field with given `fieldname` from the given xarray instance `xa`,
optionally providing a name for it. This `xa` can be loaded with commands like
@Datseris
Datseris / man.txt
Last active February 13, 2020 13:02
project manifest
############### in Juno version ####################################
(AlbedoProperties) pkg> st -m
Project AlbedoProperties v0.0.0
Status `C:\Users\m300808\ownCloud\Projects\AlbedoProperties\Manifest.toml`
[621f4979] AbstractFFTs v0.5.0
[85c772de] AbstractNumbers v0.2.1
[537997a7] AbstractPlotting v0.9.17 #master (https://github.com/JuliaPlots/AbstractPlotting.jl.git)
[27a7e980] Animations v0.3.1
[7d9fca2a] Arpack v0.4.0
@Datseris
Datseris / TraceCalls.jl
Created February 12, 2020 14:26 — forked from pfitzseb/TraceCalls.jl
TraceCalls.jl with Cassette
module TraceCalls
using Cassette
mutable struct Trace
level::Int
cutoff::Int
end
Cassette.@context TraceCtx
*.css