Skip to content

Commit

Permalink
Use minimum required kernels in test/TPM_Ryugu.jl (#46)
Browse files Browse the repository at this point in the history
* use minimum required kernels in test/TPM_Ryugu.jl

* enable TPM_Ryugu.jl test for Windows

* fix SPICE.furnsh

* remove joinpath for url

* organize directory for Ryugu test

* minor fixes in TPM_Ryugu.jl

* organize directory for Didymos test

* update gitignore for Didymos
  • Loading branch information
hyrodium committed Mar 11, 2023
1 parent 5c0063a commit 86a0438
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 90 deletions.
17 changes: 2 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,5 @@
/docs/Manifest.toml
.ipynb_checkpoints

# TPM_Ryugu
/test/spice_kernels
/test/hyb2_v03.tm
/test/SHAPE_SFM_49k_v20180804.obj
/test/SHAPE_SFM_49k_v20180804.jld2
/test/TPM_Ryugu.jld2

# TPM_Didymos
/test/hera
/test/hera_study_PO_EMA_2024.tm
/test/g_06650mm_rad_obj_didb_0000n00000_v001.obj
/test/g_50677mm_rad_obj_dida_0000n00000_v001.obj
/test/g_06650mm_rad_obj_didb_0000n00000_v001.jld2
/test/g_50677mm_rad_obj_dida_0000n00000_v001.jld2
/test/TPM_Didymos.jld2
/test/Ryugu
/test/Didymos
60 changes: 25 additions & 35 deletions test/TPM_Didymos.jl
Original file line number Diff line number Diff line change
@@ -1,37 +1,30 @@
# See https://github.com/Astroshaper/Astroshaper-examples/tree/main/TPM_Didymos for more information.
@testset "TPM_Didymos" begin
##= Download Files =##
path_meta_new = "hera_study_PO_EMA_2024.tm"
if !isfile(path_meta_new)
# Dowonload files for SPICE
run(Git.git(["clone", "https://s2e2.cosmos.esa.int/bitbucket/scm/spice_kernels/hera.git"]))
path_kernels = [
"fk/hera_v07.tf",
"lsk/naif0012.tls",
"pck/hera_didymos_v05.tpc",
"spk/de432s.bsp",
"spk/didymos_hor_000101_500101_v01.bsp",
"spk/didymos_gmv_260901_311001_v01.bsp",
"dsk/g_50677mm_rad_obj_dida_0000n00000_v001.obj",
"dsk/g_06650mm_rad_obj_didb_0000n00000_v001.obj",
]

# Update path
path_meta_old = "hera/kernels/mk/hera_study_PO_EMA_2024.tm"
cp(path_meta_old, path_meta_new, force=true)
script = read(path_meta_new, String)
max_length = 79
subpaths = String[]
path_kernel = abspath(joinpath("hera", "kernels"))
i = firstindex(path_kernel)
for _ in 1:(255 ÷ max_length)
if i + max_length < lastindex(path_kernel)
j = prevind(path_kernel, i + max_length)
else
j = lastindex(path_kernel)
end
push!(subpaths, path_kernel[i:j])
i = nextind(path_kernel, j)
if lastindex(path_kernel) < i
break
end
end
script = replace(script, "PATH_VALUES = ( '..' )"=>"PATH_VALUES = ('$(join(subpaths, "+'\n'"))')")
write(path_meta_new, script)
for path_kernel in path_kernels
url_kernel = "https://s2e2.cosmos.esa.int/bitbucket/projects/SPICE_KERNELS/repos/hera/raw/kernels/$(path_kernel)"
file_kernel = joinpath("Didymos", "kernels", path_kernel)
mkpath(dirname(file_kernel))
isfile(file_kernel) || Downloads.download(url_kernel, file_kernel)
end

##= Load data with SPICE =##
SPICE.furnsh(path_meta_new)
for path_kernel in path_kernels
file_kernel = joinpath("Didymos", "kernels", path_kernel)
@show file_kernel, isfile(file_kernel)
SPICE.furnsh(file_kernel)
end
et_start = SPICE.utc2et("2027-02-18T00:00:00")
et_end = SPICE.utc2et("2027-02-18T01:00:00")
step = 300
Expand Down Expand Up @@ -59,13 +52,10 @@
SPICE.kclear()

##= Load obj file =##
path_shape1_obj = "g_50677mm_rad_obj_dida_0000n00000_v001.obj"
path_shape2_obj = "g_06650mm_rad_obj_didb_0000n00000_v001.obj"
path_shape1_jld = "g_50677mm_rad_obj_dida_0000n00000_v001.jld2"
path_shape2_jld = "g_06650mm_rad_obj_didb_0000n00000_v001.jld2"

cp(joinpath("hera", "kernels", "dsk", "g_50677mm_rad_obj_dida_0000n00000_v001.obj"), path_shape1_obj, force=true)
cp(joinpath("hera", "kernels", "dsk", "g_06650mm_rad_obj_didb_0000n00000_v001.obj"), path_shape2_obj, force=true)
path_shape1_obj = joinpath("Didymos", "kernels", "dsk", "g_50677mm_rad_obj_dida_0000n00000_v001.obj")
path_shape2_obj = joinpath("Didymos", "kernels", "dsk", "g_06650mm_rad_obj_didb_0000n00000_v001.obj")
path_shape1_jld = joinpath("Didymos", "kernels", "dsk", "g_50677mm_rad_obj_dida_0000n00000_v001.jld2")
path_shape2_jld = joinpath("Didymos", "kernels", "dsk", "g_06650mm_rad_obj_didb_0000n00000_v001.jld2")

if isfile(path_shape1_jld)
shape1 = ThermoPhysicalModeling.ShapeModel(path_shape1_jld; scale=1000, find_visible_facets=true, save_shape=true)
Expand Down Expand Up @@ -98,7 +88,7 @@
ThermoPhysicalModeling.init_temps_zero!(shape2, thermo_params)

# Run TPM and save the result
savepath = "TPM_Didymos.jld2"
savepath = joinpath("Didymos", "TPM_Didymos.jld2")
shapes = (shape1, shape2)
suns = (sun_d1, sun_d2)
ThermoPhysicalModeling.run_TPM!(shapes, et_range, suns, D2_TO_D1, d2_d1, thermo_params, savepath, [:surf_temps, :forces, :torques])
Expand Down
54 changes: 20 additions & 34 deletions test/TPM_Ryugu.jl
Original file line number Diff line number Diff line change
@@ -1,45 +1,31 @@
# See https://github.com/Astroshaper/Astroshaper-examples/tree/main/TPM_Ryugu for more information.
@testset "TPM_Ryugu" begin
##= Download Files =##
path_meta_new = "hyb2_v03.tm"
if !isfile(path_meta_new)
# Dowonload files for SPICE
cmd = `wget -nv -m -np -nH --cut-dirs=3 -R "index.html*" --execute robots=off --wait=1 https://data.darts.isas.jaxa.jp/pub/hayabusa2/spice_bundle/spice_kernels/`
run(cmd)

# Update path
path_meta_old = "spice_kernels/mk/hyb2_v03.tm"
path_meta_new = "hyb2_v03.tm"
cp(path_meta_old, path_meta_new, force=true)
script = read(path_meta_new, String)
max_length = 79
subpaths = String[]
path_kernel = abspath("spice_kernels")
i = firstindex(path_kernel)
for _ in 1:(255 ÷ max_length)
if i + max_length < lastindex(path_kernel)
j = prevind(path_kernel, i + max_length)
else
j = lastindex(path_kernel)
end
push!(subpaths, path_kernel[i:j])
i = nextind(path_kernel, j)
if lastindex(path_kernel) < i
break
end
end
script = replace(script, "PATH_VALUES = ( '..' )"=>"PATH_VALUES = ('$(join(subpaths, "+'\n'"))')")
write(path_meta_new, script)
path_kernels = [
"lsk/naif0012.tls",
"pck/hyb2_ryugu_shape_v20190328.tpc",
"fk/hyb2_ryugu_v01.tf",
"spk/2162173_Ryugu.bsp",
]

for path_kernel in path_kernels
url_kernel = "https://data.darts.isas.jaxa.jp/pub/hayabusa2/spice_bundle/spice_kernels/$(path_kernel)"
file_kernel = joinpath("Ryugu", "kernels", path_kernel)
mkpath(dirname(file_kernel))
isfile(file_kernel) || Downloads.download(url_kernel, file_kernel)
end
path_obj = "SHAPE_SFM_49k_v20180804.obj"

path_obj = joinpath("Ryugu", "kernels", "SHAPE_SFM_49k_v20180804.obj")
if !isfile(path_obj)
url_obj = "https://data.darts.isas.jaxa.jp/pub/hayabusa2/paper/Watanabe_2019/SHAPE_SFM_49k_v20180804.obj"
Downloads.download(url_obj, path_obj)
end

##= Load data with SPICE =##
SPICE.furnsh(path_meta_new)
for path_kernel in path_kernels
file_kernel = joinpath("Ryugu", "kernels", path_kernel)
SPICE.furnsh(file_kernel)
end
et_start = SPICE.utc2et("2018-07-01T00:00:00")
et_end = SPICE.utc2et("2018-07-01T01:00:00")
step = 76.3262 # Rotation of 1 deg
Expand Down Expand Up @@ -84,9 +70,9 @@
P = 7.63262 * 3600,
)
# Run TPM and save the result
savepath = "TPM_Ryugu.jld2"
savepath = joinpath("Ryugu", "TPM_Ryugu.jld2")
ThermoPhysicalModeling.run_TPM!(shape, et_range, sun_ryugu, thermo_params, savepath, save_range)
JLD2.jldopen(savepath, "r+") do file
file["RYUGU_TO_J2000"] = RYUGU_TO_J2000[save_range]
end
end
end
8 changes: 2 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ using LinearAlgebra

Aqua.test_all(ThermoPhysicalModeling, ambiguities=false)

if !Sys.iswindows()
# TODO: add test for Windows
# `wget` command does not work for Windows, so the testset is disabled for now.
include("TPM_Ryugu.jl")
end
include("TPM_Ryugu.jl")
include("TPM_Didymos.jl")
include("Keplerian_motion.jl")
include("Keplerian_motion.jl")

0 comments on commit 86a0438

Please sign in to comment.