-
Notifications
You must be signed in to change notification settings - Fork 0
/
gala.jl
78 lines (62 loc) · 1.98 KB
/
gala.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
#
# This script bootstraps GalacticPotentials.jl through the "gala" Python package!
# An attempt is made to convert all potentials in the package to SymPy expressions,
# and then to LaTeX expressions. The results are printed to an ImmutableDict within
# GalacticPotentials.jl. Thank you Gala!
#
if haskey(ENV, "CLEAN") || !isdir("venv")
run(`rm -rf $(joinpath(@__DIR__, "venv"))`)
run(`python3 -m venv $(joinpath(@__DIR__, "venv"))`)
end
run(`$(joinpath(@__DIR__, "venv", "bin", "pip")) install -U gala -U sympy`)
ENV["PYTHON"] = joinpath(@__DIR__, "venv", "bin", "python")
import Pkg
Pkg.build()
using Dates
using PyCall, SymPy, LaTeXStrings
gala = pyimport("gala.potential")
expressions = Dict{String, LaTeXString}()
function latex!(collection::AbstractDict, name::AbstractString)
try
collection[name] = getproperty(gala.potential, name).to_latex()
catch
@warn "Unable to get expression for $name."
end
end
for potential in gala.potential.__dir__()
if occursin("Potential", potential)
latex!(expressions, potential)
end
end
open(joinpath(@__DIR__, "..", "src", "gen", "expressions.jl"), "w") do file
write(
file,
"""
#
# This is an autogenerated file! It was created on $(today()).
#
const LATEX_EXPRESSIONS = Base.ImmutableDict(
"""
)
for potential in sort(collect(keys(expressions)))
write(file, """\t"$potential" => L"\\Phi = $(expressions[potential])",\n""")
end
write(file, ")\n")
end
open(joinpath(@__DIR__, "..", "test", "gen", "potentials.jl"), "w") do file
write(
file,
"""
#
# This is an autogenerated file! It was created on $(today()).
#
"""
)
for potential in sort(collect(keys(expressions)))
help = py"help(gala.potential.$potential)"
for line in readlines(IOBuffer(help))
write(file, "# $potential Initializer\n # $line\n")
end
end
write(file, ")\n")
end