Skip to content

Commit 3bf410a

Browse files
committed
Now more carefully nulling out null inputs in epoch_prop.
This is so we do not invent values for pm, parallax, or rv. We are actually a bit over-cautious and invalidate both PMs even if only one is missing. This is because PMs mix, and hence there are traces of the invented 0 in the other component of the PM. Similarly, when the parallax is missing, the RV would be heavily contaminated and hence is nulled out. (sorry about the whitespace diffs introduced by killing trailing whitespace in sql/epochprop.sql; if they are too confusing, I'll take them into a commit of their own).
1 parent daa9478 commit 3bf410a

File tree

4 files changed

+58
-53
lines changed

4 files changed

+58
-53
lines changed

doc/functions.sgm

+6-3
Original file line numberDiff line numberDiff line change
@@ -867,9 +867,12 @@
867867
<para>
868868
It is an error to have either pos or delta_t NULL. For all
869869
other arguments, NULLs are turned into 0s, except for parallax,
870-
where some very small default is put in. In that case,
871-
both parallax and radial_velocity will be NULL in the output
872-
array.
870+
where some very small default is put in. Whatever is NULL
871+
on the input is NULL on the output. In addition, we null
872+
out a non-NULL input on one component of the proper motion
873+
if the other component is NULL, and we null out the radial
874+
velocity if the parallax is missing, as it would be horribly
875+
off with the propagation algorithm we use here.
873876
</para>
874877

875878
<para>

expected/epochprop.out

+27-28
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
SET extra_float_digits = 2;
2-
SELECT
1+
SELECT
32
to_char(DEGREES(tp[1]), '999D9999999999'),
43
to_char(DEGREES(tp[2]), '999D9999999999'),
54
to_char(tp[3], '999D999'),
65
to_char(DEGREES(tp[4])*3.6e6, '999D999'),
76
to_char(DEGREES(tp[5])*3.6e6, '99999D999'),
87
to_char(tp[6], '999D999')
98
FROM (
10-
SELECT epoch_prop(spoint(radians(269.45207695), radians(4.693364966)),
9+
SELECT epoch_prop(spoint(radians(269.45207695), radians(4.693364966)),
1110
546.9759,
1211
RADIANS(-801.551/3.6e6), RADIANS(10362/3.6e6), -110,
1312
-100) AS tp) AS q;
@@ -16,32 +15,32 @@ FROM (
1615
269.4742714391 | 4.4072939987 | 543.624 | -791.442 | 10235.412 | -110.450
1716
(1 row)
1817

19-
SELECT
18+
SELECT
2019
to_char(DEGREES(tp[1]), '999D9999999999'),
2120
to_char(DEGREES(tp[2]), '999D9999999999'),
2221
to_char(tp[3], '999D999'),
2322
to_char(DEGREES(tp[4])*3.6e6, '999D999'),
2423
to_char(DEGREES(tp[5])*3.6e6, '99999D999'),
2524
to_char(tp[6], '999D999')
2625
FROM (
27-
SELECT epoch_prop(spoint(radians(269.45207695), radians(4.693364966)),
26+
SELECT epoch_prop(spoint(radians(269.45207695), radians(4.693364966)),
2827
0,
2928
RADIANS(-801.551/3.6e6), RADIANS(10362/3.6e6), -110,
3029
-100) AS tp) AS q;
31-
to_char | to_char | to_char | to_char | to_char | to_char
32-
-----------------+-----------------+---------+----------+------------+---------
33-
269.4744079540 | 4.4055337210 | | -801.210 | 10361.762 |
30+
to_char | to_char | to_char | to_char | to_char | to_char
31+
-----------------+-----------------+----------+----------+------------+----------
32+
269.4744079540 | 4.4055337210 | .000 | -801.210 | 10361.762 | -###.###
3433
(1 row)
3534

36-
SELECT
35+
SELECT
3736
to_char(DEGREES(tp[1]), '999D9999999999'),
3837
to_char(DEGREES(tp[2]), '999D9999999999'),
3938
to_char(tp[3], '999D999'),
4039
to_char(DEGREES(tp[4])*3.6e6, '999D999'),
4140
to_char(DEGREES(tp[5])*3.6e6, '99999D999'),
4241
to_char(tp[6], '999D999')
4342
FROM (
44-
SELECT epoch_prop(spoint(radians(269.45207695), radians(4.693364966)),
43+
SELECT epoch_prop(spoint(radians(269.45207695), radians(4.693364966)),
4544
NULL,
4645
RADIANS(-801.551/3.6e6), RADIANS(10362/3.6e6), -110,
4746
-100) AS tp) AS q;
@@ -50,59 +49,59 @@ FROM (
5049
269.4744079540 | 4.4055337210 | | -801.210 | 10361.762 |
5150
(1 row)
5251

53-
SELECT
52+
SELECT
5453
to_char(DEGREES(tp[1]), '999D9999999999'),
5554
to_char(DEGREES(tp[2]), '999D9999999999'),
5655
to_char(tp[3], '999D999'),
5756
to_char(DEGREES(tp[4])*3.6e6, '999D999'),
5857
to_char(DEGREES(tp[5])*3.6e6, '99999D999'),
5958
to_char(tp[6], '999D999')
6059
FROM (
61-
SELECT epoch_prop(spoint(radians(269.45207695), radians(4.693364966)),
60+
SELECT epoch_prop(spoint(radians(269.45207695), radians(4.693364966)),
6261
23,
6362
RADIANS(-801.551/3.6e6), RADIANS(10362/3.6e6), NULL,
6463
20) AS tp) AS q;
65-
to_char | to_char | to_char | to_char | to_char | to_char
66-
-----------------+-----------------+----------+----------+------------+----------
67-
269.4476085384 | 4.7509315989 | 23.000 | -801.617 | 10361.984 | 2.159
64+
to_char | to_char | to_char | to_char | to_char | to_char
65+
-----------------+-----------------+----------+----------+------------+---------
66+
269.4476085384 | 4.7509315989 | 23.000 | -801.617 | 10361.984 |
6867
(1 row)
6968

70-
SELECT
69+
SELECT
7170
to_char(DEGREES(tp[1]), '999D9999999999'),
7271
to_char(DEGREES(tp[2]), '999D9999999999'),
7372
to_char(tp[3], '999D999'),
7473
to_char(DEGREES(tp[4])*3.6e6, '999D999'),
7574
to_char(DEGREES(tp[5])*3.6e6, '99999D999'),
7675
to_char(tp[6], '999D999')
7776
FROM (
78-
SELECT epoch_prop(spoint(radians(269.45207695), radians(4.693364966)),
77+
SELECT epoch_prop(spoint(radians(269.45207695), radians(4.693364966)),
7978
23,
8079
NULL, RADIANS(10362/3.6e6), -110,
8180
120) AS tp) AS q;
82-
to_char | to_char | to_char | to_char | to_char | to_char
83-
-----------------+-----------------+----------+----------+------------+----------
84-
269.4520769500 | 5.0388680565 | 23.007 | -.000 | 10368.061 | -97.120
81+
to_char | to_char | to_char | to_char | to_char | to_char
82+
-----------------+-----------------+----------+---------+---------+----------
83+
269.4520769500 | 5.0388680565 | 23.007 | | | -97.120
8584
(1 row)
8685

8786
SELECT epoch_prop(NULL,
8887
23,
8988
0.01 , RADIANS(10362/3.6e6), -110,
9089
120);
9190
ERROR: NULL position not supported in epoch propagation
92-
SELECT epoch_prop_pos(spoint(radians(269.45207695), radians(4.693364966)),
91+
SELECT epoch_prop_pos(spoint(radians(269.45207695), radians(4.693364966)),
9392
23,
9493
RADIANS(-801.551/3.6e6), RADIANS(10362/3.6e6), -110,
9594
20) AS tp;
96-
tp
97-
---------------------------------------------
98-
(4.7027479265831289 , 0.082919450934599334)
95+
tp
96+
-------------------------------------------
97+
(4.702747926583129 , 0.08291945093459933)
9998
(1 row)
10099

101-
SELECT epoch_prop_pos(spoint(radians(269.45207695), radians(4.693364966)),
100+
SELECT epoch_prop_pos(spoint(radians(269.45207695), radians(4.693364966)),
102101
RADIANS(-801.551/3.6e6), RADIANS(10362/3.6e6),
103102
20) AS tp;
104-
tp
105-
---------------------------------------------
106-
(4.7027479306195161 , 0.082919398938087627)
103+
tp
104+
-------------------------------------------
105+
(4.702747930619516 , 0.08291939893808763)
107106
(1 row)
108107

sql/epochprop.sql

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,64 @@
1-
SET extra_float_digits = 2;
2-
3-
SELECT
1+
SELECT
42
to_char(DEGREES(tp[1]), '999D9999999999'),
53
to_char(DEGREES(tp[2]), '999D9999999999'),
64
to_char(tp[3], '999D999'),
75
to_char(DEGREES(tp[4])*3.6e6, '999D999'),
86
to_char(DEGREES(tp[5])*3.6e6, '99999D999'),
97
to_char(tp[6], '999D999')
108
FROM (
11-
SELECT epoch_prop(spoint(radians(269.45207695), radians(4.693364966)),
9+
SELECT epoch_prop(spoint(radians(269.45207695), radians(4.693364966)),
1210
546.9759,
1311
RADIANS(-801.551/3.6e6), RADIANS(10362/3.6e6), -110,
1412
-100) AS tp) AS q;
1513

16-
SELECT
14+
SELECT
1715
to_char(DEGREES(tp[1]), '999D9999999999'),
1816
to_char(DEGREES(tp[2]), '999D9999999999'),
1917
to_char(tp[3], '999D999'),
2018
to_char(DEGREES(tp[4])*3.6e6, '999D999'),
2119
to_char(DEGREES(tp[5])*3.6e6, '99999D999'),
2220
to_char(tp[6], '999D999')
2321
FROM (
24-
SELECT epoch_prop(spoint(radians(269.45207695), radians(4.693364966)),
22+
SELECT epoch_prop(spoint(radians(269.45207695), radians(4.693364966)),
2523
0,
2624
RADIANS(-801.551/3.6e6), RADIANS(10362/3.6e6), -110,
2725
-100) AS tp) AS q;
2826

29-
SELECT
27+
SELECT
3028
to_char(DEGREES(tp[1]), '999D9999999999'),
3129
to_char(DEGREES(tp[2]), '999D9999999999'),
3230
to_char(tp[3], '999D999'),
3331
to_char(DEGREES(tp[4])*3.6e6, '999D999'),
3432
to_char(DEGREES(tp[5])*3.6e6, '99999D999'),
3533
to_char(tp[6], '999D999')
3634
FROM (
37-
SELECT epoch_prop(spoint(radians(269.45207695), radians(4.693364966)),
35+
SELECT epoch_prop(spoint(radians(269.45207695), radians(4.693364966)),
3836
NULL,
3937
RADIANS(-801.551/3.6e6), RADIANS(10362/3.6e6), -110,
4038
-100) AS tp) AS q;
4139

42-
SELECT
40+
SELECT
4341
to_char(DEGREES(tp[1]), '999D9999999999'),
4442
to_char(DEGREES(tp[2]), '999D9999999999'),
4543
to_char(tp[3], '999D999'),
4644
to_char(DEGREES(tp[4])*3.6e6, '999D999'),
4745
to_char(DEGREES(tp[5])*3.6e6, '99999D999'),
4846
to_char(tp[6], '999D999')
4947
FROM (
50-
SELECT epoch_prop(spoint(radians(269.45207695), radians(4.693364966)),
48+
SELECT epoch_prop(spoint(radians(269.45207695), radians(4.693364966)),
5149
23,
5250
RADIANS(-801.551/3.6e6), RADIANS(10362/3.6e6), NULL,
5351
20) AS tp) AS q;
5452

55-
SELECT
53+
SELECT
5654
to_char(DEGREES(tp[1]), '999D9999999999'),
5755
to_char(DEGREES(tp[2]), '999D9999999999'),
5856
to_char(tp[3], '999D999'),
5957
to_char(DEGREES(tp[4])*3.6e6, '999D999'),
6058
to_char(DEGREES(tp[5])*3.6e6, '99999D999'),
6159
to_char(tp[6], '999D999')
6260
FROM (
63-
SELECT epoch_prop(spoint(radians(269.45207695), radians(4.693364966)),
61+
SELECT epoch_prop(spoint(radians(269.45207695), radians(4.693364966)),
6462
23,
6563
NULL, RADIANS(10362/3.6e6), -110,
6664
120) AS tp) AS q;
@@ -70,11 +68,11 @@ SELECT epoch_prop(NULL,
7068
0.01 , RADIANS(10362/3.6e6), -110,
7169
120);
7270

73-
SELECT epoch_prop_pos(spoint(radians(269.45207695), radians(4.693364966)),
71+
SELECT epoch_prop_pos(spoint(radians(269.45207695), radians(4.693364966)),
7472
23,
7573
RADIANS(-801.551/3.6e6), RADIANS(10362/3.6e6), -110,
7674
20) AS tp;
7775

78-
SELECT epoch_prop_pos(spoint(radians(269.45207695), radians(4.693364966)),
76+
SELECT epoch_prop_pos(spoint(radians(269.45207695), radians(4.693364966)),
7977
RADIANS(-801.551/3.6e6), RADIANS(10362/3.6e6),
8078
20) AS tp;

src/epochprop.c

+13-8
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ epoch_prop(PG_FUNCTION_ARGS) {
133133
phasevec input, output;
134134
ArrayType *result;
135135
Datum retvals[6];
136+
bool output_null[6] = {0, 0, 0, 0, 0, 0};
136137

137138
if (PG_ARGISNULL(0)) {
138139
ereport(ERROR,
@@ -141,25 +142,36 @@ epoch_prop(PG_FUNCTION_ARGS) {
141142
memcpy(&(input.pos), (void*)PG_GETARG_POINTER(0), sizeof(SPoint));
142143
if (PG_ARGISNULL(1)) {
143144
input.parallax = 0;
145+
output_null[2] = 1;
146+
/* The way we do our computation, with a bad parallax the RV
147+
will be horribly off, too, so null this out, too */
148+
output_null[5] = 1;
144149
} else {
145150
input.parallax = PG_GETARG_FLOAT8(1);
146151
}
147152
input.parallax_valid = fabs(input.parallax) > PX_MIN;
148153

149154
if (PG_ARGISNULL(2)) {
150155
input.pm[0] = 0;
156+
input.pm[1] = 0;
157+
output_null[3] = 1;
158+
output_null[4] = 1;
151159
} else {
152160
input.pm[0] = PG_GETARG_FLOAT8(2);
153161
}
154162

155163
if (PG_ARGISNULL(3)) {
164+
input.pm[0] = 0;
156165
input.pm[1] = 0;
166+
output_null[3] = 1;
167+
output_null[4] = 1;
157168
} else {
158169
input.pm[1] = PG_GETARG_FLOAT8(3);
159170
}
160171

161172
if (PG_ARGISNULL(4)) {
162173
input.rv = 0;
174+
output_null[5] = 1;
163175
} else {
164176
input.rv = PG_GETARG_FLOAT8(4);
165177
}
@@ -181,7 +193,6 @@ epoch_prop(PG_FUNCTION_ARGS) {
181193
retvals[5] = Float8GetDatum(output.rv);
182194

183195
{
184-
bool isnull[6] = {0, 0, 0, 0, 0, 0};
185196
int lower_bounds[1] = {1};
186197
int dims[1] = {6};
187198
#ifdef USE_FLOAT8_BYVAL
@@ -190,13 +201,7 @@ epoch_prop(PG_FUNCTION_ARGS) {
190201
bool embyval = false;
191202
#endif
192203

193-
if (! output.parallax_valid) {
194-
/* invalidate parallax and rv */
195-
isnull[2] = 1;
196-
isnull[5] = 1;
197-
}
198-
199-
result = construct_md_array(retvals, isnull, 1, dims, lower_bounds,
204+
result = construct_md_array(retvals, output_null, 1, dims, lower_bounds,
200205
FLOAT8OID, sizeof(float8), embyval, 'd');
201206
}
202207
PG_RETURN_ARRAYTYPE_P(result);

0 commit comments

Comments
 (0)