forked from JanisErdmanis/MDrop
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathread_and_plot.jl
83 lines (62 loc) · 2.11 KB
/
read_and_plot.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using Pkg
pkg"activate ."
pkg"resolve"
using Makie
using FileIO
using JLD2
using StatsBase
using Optim
#datadir = "/home/laigars/sim_data/star_8/"
datadir = "/home/laigars/mdrops/meshes/perturbed/starfish_2/"
#datadir = "/mnt/hpc/sim_data/perturbed_real_6_15/"
#datadir="/mnt/hpc/sim_data/rotation_lambd10.0_mu30.0_w1.5_Bm50.0"
datadir="/mnt/hpc/sim_data/perturbed_2_21_fastfield/"
last_file = readdir(datadir)[29] # end-3 if there are aux files (source, speeds); end if there aren't
#last_file = "ellipsoid_n_5_Bm_17.jld2"
println()
println(datadir)
println(last_file)
# fix hardcoding
global data
@load "$datadir/$last_file" data
#@load "$datadir/data00031.jld2" data
points, faces = data[1], data[2]
faces = Array{Int64,2}(faces)
mean_x, mean_y, mean_z = (StatsBase.mean(points[1,:]),
StatsBase.mean(points[2,:]),
StatsBase.mean(points[3,:]))
points = points .- [mean_x, mean_y, mean_z]
function f(ab::Array{Float64,1})
return sum((points[1,:].^2/ab[1]^2 .+ points[2,:].^2/ab[1]^2 .+
points[3,:].^2/ab[2]^2 .- 1).^2)
end
x0 = [0.99, 1.01]
res = Optim.optimize(f,x0)
b = Optim.minimizer(res)[1]
a = Optim.minimizer(res)[2]
println("a = $a, b = $b")
# @load "$datadir2/$last_file" data
# points3, faces3 = data[1], data[2]
# faces3 = Array{Int64,2}(faces3)
#
# println("plotting")
# println(size(points2))
# println(size(faces2))
n = 20
θ = [0;(0.5:n-0.5)/n;1]
φ = [(0:2n-2)*2/(2n-1);2]
x = [b*cospi(φ)*sinpi(θ) for θ in θ, φ in φ]
y = [b*sinpi(φ)*sinpi(θ) for θ in θ, φ in φ]
z = [a*cospi(θ) for θ in θ, φ in φ]
#Makie.surface(x, y, z, color=:black, shading=false, transparency=true)
scene = Makie.mesh(points', faces',color = :lightgray, shading = false, visible = true)
Makie.wireframe!(scene[end][1], color = :black, linewidth = 0.7,visible = true)#, limits=FRect3D((-5,-5,-5),(10,10,10)))
#text!("$(last_file[5:end-5])", position = (0, 0, 4), textsize = 0.6, rotation=2.)
#display(scene)
#cam = Makie.cameracontrols(scene)
#cam.upvector[] = (-1., -1., 1.)
#update_cam!(scene, cam)
# scene.center = false
# scene
# FileIO.save("plot.png", scene)
#readline(stdin)