-
Notifications
You must be signed in to change notification settings - Fork 0
/
bc-approx-xyz.pl
executable file
·103 lines (72 loc) · 2.46 KB
/
bc-approx-xyz.pl
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/perl
# use "hermione" interpolation for XYZ values of planets, omitting as
# many data as possible while still preserving some accuracy
# based on bc-approx-ra-dec.pl, but simpler since we're storing raw values
require "bclib.pl";
# not in GIT, sorry
open(A,"bzcat /home/barrycarter/20110916/final-pos-500-0-301.txt.bz2|");
# $n = fraction of observations we want to preserve
$n = 10;
$count = -1;
while (<A>) {
$count++;
if ($count%10000==0) {debug("COUNT: $count");}
chomp($_);
# the first line is useless
if (/planet/) {next;}
# nuke brackets
s/[{}]//g;
# E+
s/\*10\^/E/isg;
# $w = data we don't want
# TODO: this is a bizarre way of converting "1e+3" to "1000"
my($w, $time, $x, $y, $z) = map($_=1.*$_, split(/\,\s*/, $_));
# avoid dupes
if ($x{$time} || $y{$time} || $z{$time}) {$count--; next;}
# store actual ra and dec
($x{$time}, $y{$time}, $z{$time}) = ($x, $y, $z);
# skip most data for interpolation
if ($count%$n) {next;}
# print "PUSHING TO XVALS: $x, TIME: $time\n";
push(@xvals, $x);
push(@yvals, $y);
push(@zvals, $z);
}
close(A);
@times = sort {$a <=> $b} keys %x;
# now, to compare the approx to the actual values
# we don't claim accuracy on the first $n and last 2*$n entries
for $i ($n..$#times-2*$n) {
my($time) = $times[$i];
# where in interval?
$intloc = ($i%$n)/$n;
$intv = int($i/$n);
# local interpolation faster than hermione()
$intx = hermm1($intloc)*$xvals[$intv-1] +
herm0($intloc)*$xvals[$intv] +
hermp1($intloc)*$xvals[$intv+1] +
hermp2($intloc)*$xvals[$intv+2];
$inty = hermm1($intloc)*$yvals[$intv-1] +
herm0($intloc)*$yvals[$intv] +
hermp1($intloc)*$yvals[$intv+1] +
hermp2($intloc)*$yvals[$intv+2];
$intz = hermm1($intloc)*$zvals[$intv-1] +
herm0($intloc)*$zvals[$intv] +
hermp1($intloc)*$zvals[$intv+1] +
hermp2($intloc)*$zvals[$intv+2];
my($diffx) = $intx-$x{$times[$i]};
my($diffy) = $inty-$y{$times[$i]};
my($diffz) = $intz-$z{$times[$i]};
# print "INTLOC: $intloc, INTV: $intv, XATINTV: $xvals[$intv]\n";
# print "$intx vs $x{$time} at $time\n";
$maxx = max($maxx,abs($diffx));
$maxy = max($maxy,abs($diffy));
$maxz = max($maxz,abs($diffz));
$truemaxx = max($truemaxx, abs($x{$times[$i]}));
$truemaxy = max($truemaxy, abs($y{$times[$i]}));
$truemaxz = max($truemaxz, abs($z{$times[$i]}));
if ($i%10000==0) {
debug("MAXSOFAR: $maxx/$maxy/$maxz vs $truemaxx/$truemaxy/$truemaxz");
}
}
debug("FINAL: $maxx/$maxy/$maxz");