Coverage Report

Created: 2026-05-16 06:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/sofars-0.6.1/src/astro/apcs.rs
Line
Count
Source
1
use super::IauAstrom;
2
use crate::consts::{AULT, DAU, DAYSEC, DJ00, DJY};
3
use crate::vm::{cp, ir, pn};
4
5
///  Prepare for ICRS <−> CIRS, space, special
6
///
7
///  For an observer whose geocentric position and velocity are known,
8
///  prepare star-independent astrometry parameters for transformations
9
///  between ICRS and GCRS.  The Earth ephemeris is supplied by the
10
///  caller.
11
///
12
///  The parameters produced by this function are required in the space
13
///  motion, parallax, light deflection and aberration parts of the
14
///  astrometric transformation chain.
15
///
16
///  This function is part of the International Astronomical Union's
17
///  SOFA (Standards of Fundamental Astronomy) software collection.
18
///
19
///  Status:  support function.
20
///
21
///  Given:
22
///  ```
23
///     date1  double       TDB as a 2-part...
24
///     date2  double       ...Julian Date (Note 1)
25
///     pv     double[2][3] observer's geocentric pos/vel (m, m/s)
26
///     ebpv   double[2][3] Earth barycentric PV (au, au/day)
27
///     ehp    double[3]    Earth heliocentric P (au)
28
///  ```
29
///  Returned:
30
///  ```
31
///     astrom iauASTROM*   star-independent astrometry parameters:
32
///      pmt    double       PM time interval (SSB, Julian years)
33
///      eb     double[3]    SSB to observer (vector, au)
34
///      eh     double[3]    Sun to observer (unit vector)
35
///      em     double       distance from Sun to observer (au)
36
///      v      double[3]    barycentric observer velocity (vector, c)
37
///      bm1    double       sqrt(1-|v|^2): reciprocal of Lorenz factor
38
///      bpn    double[3][3] bias-precession-nutation matrix
39
///      along  double       unchanged
40
///      xpl    double       unchanged
41
///      ypl    double       unchanged
42
///      sphi   double       unchanged
43
///      cphi   double       unchanged
44
///      diurab double       unchanged
45
///      eral   double       unchanged
46
///      refa   double       unchanged
47
///      refb   double       unchanged
48
///  ```
49
///  Notes:
50
///
51
///  1) The TDB date date1+date2 is a Julian Date, apportioned in any
52
///     convenient way between the two arguments.  For example,
53
///     JD(TDB)=2450123.7 could be expressed in any of these ways, among
54
///     others:
55
///  ```
56
///            date1          date2
57
///
58
///         2450123.7           0.0       (JD method)
59
///         2451545.0       -1421.3       (J2000 method)
60
///         2400000.5       50123.2       (MJD method)
61
///         2450123.5           0.2       (date & time method)
62
///  ```
63
///     The JD method is the most natural and convenient to use in cases
64
///     where the loss of several decimal digits of resolution is
65
///     acceptable.  The J2000 method is best matched to the way the
66
///     argument is handled internally and will deliver the optimum
67
///     resolution.  The MJD method and the date & time methods are both
68
///     good compromises between resolution and convenience.  For most
69
///     applications of this function the choice will not be at all
70
///     critical.
71
///
72
///     TT can be used instead of TDB without any significant impact on
73
///     accuracy.
74
///
75
///  2) All the vectors are with respect to BCRS axes.
76
///
77
///  3) Providing separate arguments for (i) the observer's geocentric
78
///     position and velocity and (ii) the Earth ephemeris is done for
79
///     convenience in the geocentric, terrestrial and Earth orbit cases.
80
///     For deep space applications it maybe more convenient to specify
81
///     zero geocentric position and velocity and to supply the
82
///     observer's position and velocity information directly instead of
83
///     with respect to the Earth.  However, note the different units:
84
///     m and m/s for the geocentric vectors, au and au/day for the
85
///     heliocentric and barycentric vectors.
86
///
87
///  4) In cases where the caller does not wish to provide the Earth
88
///     ephemeris, the function iauApcs13 can be used instead of the
89
///     present function.  This computes the Earth ephemeris using the
90
///     SOFA function iauEpv00.
91
///
92
///  5) This is one of several functions that inserts into the astrom
93
///     structure star-independent parameters needed for the chain of
94
///     astrometric transformations ICRS <-> GCRS <-> CIRS <-> observed.
95
///
96
///     The various functions support different classes of observer and
97
///     portions of the transformation chain:
98
///  ```
99
///          functions         observer        transformation
100
///
101
///       iauApcg iauApcg13    geocentric      ICRS <-> GCRS
102
///       iauApci iauApci13    terrestrial     ICRS <-> CIRS
103
///       iauApco iauApco13    terrestrial     ICRS <-> observed
104
///       iauApcs iauApcs13    space           ICRS <-> GCRS
105
///       iauAper iauAper13    terrestrial     update Earth rotation
106
///       iauApio iauApio13    terrestrial     CIRS <-> observed
107
///  ```
108
///     Those with names ending in "13" use contemporary SOFA models to
109
///     compute the various ephemerides.  The others accept ephemerides
110
///     supplied by the caller.
111
///
112
///     The transformation from ICRS to GCRS covers space motion,
113
///     parallax, light deflection, and aberration.  From GCRS to CIRS
114
///     comprises frame bias and precession-nutation.  From CIRS to
115
///     observed takes account of Earth rotation, polar motion, diurnal
116
///     aberration and parallax (unless subsumed into the ICRS <-> GCRS
117
///     transformation), and atmospheric refraction.
118
///
119
///  6) The context structure astrom produced by this function is used by
120
///     iauAtciq* and iauAticq*.
121
///
122
///  Called:
123
///  ```
124
///     iauCp        copy p-vector
125
///     iauPm        modulus of p-vector
126
///     iauPn        decompose p-vector into modulus and direction
127
///     iauIr        initialize r-matrix to identity
128
///  ```
129
0
pub fn apcs(
130
0
    date1: f64,
131
0
    date2: f64,
132
0
    pv: &[[f64; 3]; 2],
133
0
    ebpv: &[[f64; 3]; 2],
134
0
    ehp: &[f64; 3],
135
0
    astrom: &mut IauAstrom,
136
0
) {
137
    // au/d to m/s
138
0
    let audms = DAU / DAYSEC;
139
140
    // Light time for 1 au (day)
141
0
    let cr = AULT / DAYSEC;
142
143
0
    let mut pb = [0.0; 3];
144
0
    let mut vb = [0.0; 3];
145
0
    let mut ph = [0.0; 3];
146
147
    // Time since reference epoch, years (for proper motion calculation).
148
0
    astrom.pmt = ((date1 - DJ00) + date2) / DJY;
149
150
    // Adjust Earth ephemeris to observer.
151
0
    for i in 0..3 {
152
0
        let dp = pv[0][i] / DAU;
153
0
        let dv = pv[1][i] / audms;
154
0
        pb[i] = ebpv[0][i] + dp;
155
0
        vb[i] = ebpv[1][i] + dv;
156
0
        ph[i] = ehp[i] + dp;
157
0
    }
158
159
    // Barycentric position of observer (au).
160
0
    cp(&pb, &mut astrom.eb);
161
162
    // Heliocentric direction and distance (unit vector and au).
163
0
    (astrom.em, astrom.eh) = pn(&ph);
164
165
    // Barycentric vel. in units of c, and reciprocal of Lorenz factor.
166
0
    let mut v2 = 0.0;
167
0
    for i in 0..3 {
168
0
        let w = vb[i] * cr;
169
0
        astrom.v[i] = w;
170
0
        v2 += w * w;
171
0
    }
172
0
    astrom.bm1 = (1.0 - v2).sqrt();
173
174
    // Reset the NPB matrix.
175
0
    ir(&mut astrom.bpn);
176
0
}