-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a4b59a4
commit b63f917
Showing
7 changed files
with
344 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,6 @@ dependencies: | |
- pandas | ||
- seaborn | ||
- pip: | ||
- pmagpy==4.2.106 | ||
- pmagpy==4.2.106 | ||
# GUI interface for VSCode | ||
- PyQt5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,252 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Example of fir with two rotations" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/.julia/dev/SphereFit`\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"using Pkg; Pkg.activate(\"../.\")\n", | ||
"using Revise \n", | ||
"\n", | ||
"using LinearAlgebra, Statistics, Distributions \n", | ||
"using OrdinaryDiffEq\n", | ||
"using SciMLSensitivity\n", | ||
"using Optimization, OptimizationOptimisers, OptimizationOptimJL\n", | ||
"\n", | ||
"using SphereFit" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"200" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"using Random\n", | ||
"rng = Random.default_rng()\n", | ||
"Random.seed!(rng, 000666)\n", | ||
"# Fisher concentration parameter on observations (small = more dispersion)\n", | ||
"κ = 200 " | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Let's create a simple example consisting in two solid rotations around the globe with Fisher noise on top. " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"1.0e-7" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"# Total time simulation\n", | ||
"tspan = [0, 130.0]\n", | ||
"# Number of sample points\n", | ||
"N_samples = 50\n", | ||
"# Times where we sample points\n", | ||
"times_samples = sort(rand(sampler(Uniform(tspan[1], tspan[2])), N_samples))\n", | ||
"\n", | ||
"# Expected maximum angular deviation in one unit of time (degrees)\n", | ||
"Δω₀ = 1.0 \n", | ||
"# Angular velocity \n", | ||
"ω₀ = Δω₀ * π / 180.0\n", | ||
"# Change point\n", | ||
"τ₀ = 65.0\n", | ||
"# Angular momentum\n", | ||
"L0 = ω₀ .* [1.0, 0.0, 0.0]\n", | ||
"L1 = 0.5ω₀ .* [0.0, sqrt(2), sqrt(2)]\n", | ||
"\n", | ||
"# Solver tolerances \n", | ||
"reltol = 1e-7\n", | ||
"abstol = 1e-7" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"3×50 Matrix{Float64}:\n", | ||
" -0.0385817 -0.102203 0.0130063 … -0.801308 -0.804544 -0.777151\n", | ||
" 0.0229773 0.0624114 0.134454 0.593017 0.591397 0.625861\n", | ||
" -0.998991 -0.992804 -0.990834 -0.0789676 -0.0543948 0.065833" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"function true_rotation!(du, u, p, t)\n", | ||
" if t < τ₀\n", | ||
" L = p[1]\n", | ||
" else \n", | ||
" L = p[2]\n", | ||
" end\n", | ||
" du .= cross(L, u)\n", | ||
"end\n", | ||
"\n", | ||
"prob = ODEProblem(true_rotation!, [0.0, 0.0, -1.0], tspan, [L0, L1])\n", | ||
"true_sol = solve(prob, Tsit5(), reltol=reltol, abstol=abstol, saveat=times_samples)\n", | ||
"\n", | ||
"# Add Fisher noise to true solution \n", | ||
"X_noiseless = Array(true_sol)\n", | ||
"X_true = mapslices(x -> rand(sampler(VonMisesFisher(x/norm(x), κ)), 1), X_noiseless, dims=1)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Let's make a plot of this using `PyCall` to call `cartopy` and `matplotlib`. " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"3×50 Matrix{Float64}:\n", | ||
" -0.0385817 -0.102203 0.0130063 … -0.801308 -0.804544 -0.777151\n", | ||
" 0.0229773 0.0624114 0.134454 0.593017 0.591397 0.625861\n", | ||
" -0.998991 -0.992804 -0.990834 -0.0789676 -0.0543948 0.065833" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"X_true" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"2×50 Matrix{Float64}:\n", | ||
" 149.224 148.589 84.4747 104.938 … 143.496 143.681 141.155\n", | ||
" -87.4262 -83.1222 -82.2367 -78.8478 -4.52923 -3.11813 3.77468" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"X_true_sph = cart2sph(X_true, radians=false)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Python plots" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 26, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"using PyPlot, PyCall\n", | ||
"\n", | ||
"mpl_colors = pyimport(\"matplotlib.colors\")\n", | ||
"mpl_colormap = pyimport(\"matplotlib.cm\")\n", | ||
"sns = pyimport(\"seaborn\")\n", | ||
"ccrs = pyimport(\"cartopy.crs\")\n", | ||
"feature = pyimport(\"cartopy.feature\")\n", | ||
"\n", | ||
"plt.figure(figsize=(10,10))\n", | ||
"ax = plt.axes(projection=ccrs.Orthographic(central_latitude=-20, central_longitude=150))\n", | ||
"\n", | ||
"# ax.coastlines()\n", | ||
"ax.gridlines()\n", | ||
"ax.set_global()\n", | ||
"\n", | ||
"cmap = mpl_colormap.get_cmap(\"viridis\")\n", | ||
"\n", | ||
"sns.scatterplot(ax=ax, x = X_true_sph[:,1], y=X_true_sph[:,2], \n", | ||
" # hue = df_data['time'], s=50,\n", | ||
" # palette=\"viridis\",\n", | ||
" transform = ccrs.PlateCarree());\n", | ||
"\n", | ||
"plt.savefig(\"testing.pdf\", format=\"pdf\")\n", | ||
"# plt.show()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Julia 1.9.4", | ||
"language": "julia", | ||
"name": "julia-1.9" | ||
}, | ||
"language_info": { | ||
"file_extension": ".jl", | ||
"mimetype": "application/julia", | ||
"name": "julia", | ||
"version": "1.9.4" | ||
}, | ||
"orig_nbformat": 4 | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.