Skip to content

Commit

Permalink
simplify script for creating artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbyrne committed Jan 8, 2024
1 parent 098e63f commit f6055ec
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 72 deletions.
29 changes: 1 addition & 28 deletions artifacts/laskar2004/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

julia_version = "1.10.0"
manifest_format = "2.0"
project_hash = "b9ce7e2b2ba966a9d962c19f15fc32c0b4b43bd5"
project_hash = "81673b72d56065f44d5a3b342a3de7eb32003bbc"

[[deps.ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
Expand All @@ -11,12 +11,6 @@ version = "1.1.1"
[[deps.Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"

[[deps.CodecZlib]]
deps = ["TranscodingStreams", "Zlib_jll"]
git-tree-sha1 = "cd67fc487743b2f0fd4380d4cbd3a24660d0eec8"
uuid = "944b1d66-785c-5afd-91f1-9de20f533193"
version = "0.7.3"

[[deps.Downloads]]
deps = ["ArgTools", "FileWatching", "LibCURL", "NetworkOptions"]
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
Expand Down Expand Up @@ -60,27 +54,6 @@ version = "1.2.0"
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[[deps.SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
version = "0.7.0"

[[deps.Tar]]
deps = ["ArgTools", "SHA"]
uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"
version = "1.10.0"

[[deps.TranscodingStreams]]
git-tree-sha1 = "1fbeaaca45801b4ba17c251dd8603ef24801dd84"
uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"
version = "0.10.2"

[deps.TranscodingStreams.extensions]
TestExt = ["Test", "Random"]

[deps.TranscodingStreams.weakdeps]
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[deps.Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

Expand Down
3 changes: 0 additions & 3 deletions artifacts/laskar2004/Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[deps]
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
Tar = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"
76 changes: 35 additions & 41 deletions artifacts/laskar2004/create_artifact.jl
Original file line number Diff line number Diff line change
@@ -1,49 +1,43 @@
using Downloads, Printf, Tar, CodecZlib, SHA, Pkg
using Downloads, Pkg.Artifacts
using Printf

insoln_file = Downloads.download("http://vo.imcce.fr/insola/earth/online/earth/La2004/INSOLN.LA2004.BTL.ASC")
insolp_file = Downloads.download("http://vo.imcce.fr/insola/earth/online/earth/La2004/INSOLP.LA2004.BTL.ASC")

insoln_lines = reverse(readlines(insoln_file)) # stored in reverse order
insolp_lines = readlines(insolp_file)[2:end] # 0 is duplicated in both files

out_dir = mktempdir()

out_csv = joinpath(out_dir, "INSOL.LA2004.BTL.csv")
open(out_csv; write=true) do f
println(f, "# t (kyr from J2000), ecc, obliq (rad), varpi (rad)")
varpi_offset = Float64(pi)
varpi_rad_prev = 1.0 + varpi_offset
for line in vcat(insoln_lines, insolp_lines)
kyr_s, ecc_s, obliq_rad_s, varpi_rad_s = split(line)
kyr = parse(Float64, kyr_s)
ecc = parse(Float64, replace(ecc_s, 'D' => 'e'))
obliq_rad = parse(Float64, replace(obliq_rad_s, 'D' => 'e'))
varpi_rad = parse(Float64, replace(varpi_rad_s, 'D' => 'e'))

# keep continuous so it can be interpolated
if varpi_rad + varpi_offset < varpi_rad_prev - pi
varpi_offset += 2pi
elseif varpi_rad + varpi_offset > varpi_rad_prev + pi
varpi_offset -= 2pi
end
varpi_rad += varpi_offset
varpi_rad_prev = varpi_rad
@printf(f, "%.3f,%.16e,%.16e,%.16e\n", kyr, ecc, obliq_rad, varpi_rad)
end
artifact_tree_sha1 = create_artifact() do dir

insoln_lines = reverse(readlines(insoln_file)) # stored in reverse order
insolp_lines = readlines(insolp_file)[2:end] # 0 is duplicated in both files

open(joinpath(dir, "INSOL.LA2004.BTL.csv"); write=true) do f
println(f, "# t (kyr from J2000), ecc, obliq (rad), varpi (rad)")
varpi_offset = Float64(pi)
varpi_rad_prev = 1.0 + varpi_offset
for line in vcat(insoln_lines, insolp_lines)
kyr_s, ecc_s, obliq_rad_s, varpi_rad_s = split(line)
kyr = parse(Float64, kyr_s)
ecc = parse(Float64, replace(ecc_s, 'D' => 'e'))
obliq_rad = parse(Float64, replace(obliq_rad_s, 'D' => 'e'))
varpi_rad = parse(Float64, replace(varpi_rad_s, 'D' => 'e'))

# keep continuous so it can be interpolated
if varpi_rad + varpi_offset < varpi_rad_prev - pi
varpi_offset += 2pi
elseif varpi_rad + varpi_offset > varpi_rad_prev + pi
varpi_offset -= 2pi
end
varpi_rad += varpi_offset
varpi_rad_prev = varpi_rad
@printf(f, "%.3f,%.16e,%.16e,%.16e\n", kyr, ecc, obliq_rad, varpi_rad)
end
end

# add README
cp(joinpath(@__DIR__, "README.md"), joinpath(dir, "README.md"))
end

# add README
cp(joinpath(@__DIR__, "README.md"), joinpath(out_dir, "README.md"))
artifact_path = joinpath(@__DIR__, "laskar2004.tar.gz")

git_tree_sha1 = bytes2hex(Pkg.GitTools.tree_hash(SHA1_CTX, out_dir))
artifact_archive_sha256 = archive_artifact(artifact_tree_sha1, artifact_path)

out_tar = joinpath(@__DIR__, "laskar2004.tar.gz")
open(out_tar, write=true) do f
gzf = GzipCompressorStream(f)
Tar.create(out_dir, gzf)
close(gzf)
end

archive_sha256 = bytes2hex(open(sha256, out_tar))

@info "Created artifact" file=out_tar git_tree_sha1 archive_sha256
@info "Created artifact" artifact_path artifact_tree_sha1 artifact_archive_sha256

0 comments on commit f6055ec

Please sign in to comment.