-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simplify script for creating artifact
- Loading branch information
1 parent
098e63f
commit f6055ec
Showing
3 changed files
with
36 additions
and
72 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
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 |
---|---|---|
@@ -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" |
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 |
---|---|---|
@@ -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 |