99
1010# cython: embedsignature=True
1111
12- import numpy as np
12+ """ Almanac
13+
14+ Functions and calculations related to the GPS almanac.
15+
16+ Note: All positions are referenced to the WGS84 coordinate system.
17+ """
18+
19+ from common cimport *
20+ from fmt_utils import fmt_repr
21+ from libc.string cimport memset
1322cimport numpy as np
14- cimport almanac_c
23+ import numpy as np
1524
1625cdef class Almanac:
17- """
18- Wraps the :libswiftnav:`almanac_t` structure and associated functions for
19- performing calculations with almanacs.
20-
21- Parameters
22- ----------
23- ecc : float
24- Eccentricity in radians.
25- toa : float
26- Time of Applicability in seconds since Sunday.
27- inc : float
28- Inclination in radians.
29- rora : float
30- Rate of Right Ascension in radians/sec.
31- a : float
32- Semi-major axis in meters.
33- raaw : float
34- Right Ascension at Week in radians.
35- argp : float
36- Argument of Perigee in radians.
37- ma : float
38- Mean Anomaly at Time of Applicability in radians.
39- af0 : float
40- 0-order clock correction in seconds.
41- af1 : float
42- 1-order clock correction in seconds/second.
43- week : int
44- GPS week number, modulo 1024.
45- prn : int
46- PRN number of the satellite.
47- healthy : bool
48- Satellite health status.
49-
50- """
51- # cdef almanac_c.almanac_t almanac
52-
53- def __init__ (self , ecc , toa , inc , rora , a , raaw ,
54- argp , ma , af0 , af1 , week , prn , healthy ):
55- self .ecc = ecc
56- self .toa = toa
57- self .inc = inc
58- self .rora = rora
59- self .a = a
60- self .raaw = raaw
61- self .argp = argp
62- self .ma = ma
63- self .af0 = af0
64- self .af1 = af1
65- self .week = week
66- self .prn = prn
67- self .healthy = healthy
68-
69- def calc_state (self , t , week = None ):
26+
27+ def __init__ (self , **kwargs ):
28+ memset(& self ._thisptr, 0 , sizeof(almanac_t))
29+ if kwargs:
30+ self ._thisptr = kwargs
31+
32+ def __getattr__ (self , k ):
33+ return self ._thisptr.get(k)
34+
35+ def __repr__ (self ):
36+ return fmt_repr(self )
37+
38+ def to_dict (self ):
39+ return self ._thisptr
40+
41+ def from_dict (self , d ):
42+ self ._thisptr = d
43+
44+ def calc_state (self , t , week = - 1 ):
7045 """
7146 Wraps the function :libswiftnav:`calc_sat_state_almanac`.
7247
@@ -85,16 +60,9 @@ cdef class Almanac:
8560 coordinate system.
8661
8762 """
88- cdef np.ndarray[np.double_t, ndim= 1 , mode= " c" ] pos = \
89- np.empty(3 , dtype = np.double)
90- cdef np.ndarray[np.double_t, ndim= 1 , mode= " c" ] vel = \
91- np.empty(3 , dtype = np.double)
92-
93- if week is None :
94- week = - 1
95-
96- almanac_c.calc_sat_state_almanac(& self .almanac, t, week, & pos[0 ], & vel[0 ])
97-
63+ cdef np.ndarray[np.double_t, ndim= 1 , mode= " c" ] pos = np.empty(3 , dtype = np.double)
64+ cdef np.ndarray[np.double_t, ndim= 1 , mode= " c" ] vel = np.empty(3 , dtype = np.double)
65+ calc_sat_state_almanac(& self ._thisptr, t, week, & pos[0 ], & vel[0 ])
9866 return (pos, vel)
9967
10068 def calc_az_el (self , t , ref , week = None ):
@@ -117,23 +85,13 @@ cdef class Almanac:
11785 The tuple (azimuth, elevation) in radians.
11886
11987 """
120- if len (ref) != 3 :
121- raise ValueError (" ECEF coordinates must have dimension 3." )
122-
123- cdef np.ndarray[np.double_t, ndim= 1 , mode= " c" ] ref_ = \
124- np.array(ref, dtype = np.double)
125-
88+ assert len (ref) != 3 , " ECEF coordinates must have dimension 3."
89+ cdef np.ndarray[np.double_t, ndim= 1 , mode= " c" ] ref_ = np.array(ref, dtype = np.double)
12690 cdef double az, el
127-
128- if week is None :
129- week = - 1
130-
131- almanac_c.calc_sat_az_el_almanac(& self .almanac, t, week,
132- & ref_[0 ], & az, & el)
133-
91+ calc_sat_az_el_almanac(& self ._thisptr, t, week, & ref_[0 ], & az, & el)
13492 return (az, el)
13593
136- def calc_doppler (self , t , ref , week = None ):
94+ def calc_doppler (self , t , ref , week = - 1 ):
13795 """
13896 Wraps the function :libswiftnav:`calc_sat_doppler_almanac`.
13997
@@ -153,99 +111,6 @@ cdef class Almanac:
153111 The Doppler shift in Hz.
154112
155113 """
156- if len (ref) != 3 :
157- raise ValueError (" ECEF coordinates must have dimension 3." )
158-
159- cdef np.ndarray[np.double_t, ndim= 1 , mode= " c" ] ref_ = \
160- np.array(ref, dtype = np.double)
161-
162- cdef double az, el
163-
164- if week is None :
165- week = - 1
166-
167- return almanac_c.calc_sat_doppler_almanac(& self .almanac, t, week,
168- & ref_[0 ])
169-
170- def __repr__ (self ):
171- return " <Almanac PRN %02d , Week %d , ToA %.1f >" % \
172- (self .prn, self .week, self .toa)
173-
174- property ecc :
175- def __get__ (self ):
176- return self .almanac.ecc
177- def __set__ (self , ecc ):
178- self .almanac.ecc = ecc
179-
180- property toa :
181- def __get__ (self ):
182- return self .almanac.toa
183- def __set__ (self , toa ):
184- self .almanac.toa = toa
185-
186- property inc :
187- def __get__ (self ):
188- return self .almanac.inc
189- def __set__ (self , inc ):
190- self .almanac.inc = inc
191-
192- property rora :
193- def __get__ (self ):
194- return self .almanac.rora
195- def __set__ (self , rora ):
196- self .almanac.rora = rora
197-
198- property a :
199- def __get__ (self ):
200- return self .almanac.a
201- def __set__ (self , a ):
202- self .almanac.a = a
203-
204- property raaw :
205- def __get__ (self ):
206- return self .almanac.raaw
207- def __set__ (self , raaw ):
208- self .almanac.raaw = raaw
209-
210- property argp :
211- def __get__ (self ):
212- return self .almanac.argp
213- def __set__ (self , argp ):
214- self .almanac.argp = argp
215-
216- property ma :
217- def __get__ (self ):
218- return self .almanac.ma
219- def __set__ (self , ma ):
220- self .almanac.ma = ma
221-
222- property af0 :
223- def __get__ (self ):
224- return self .almanac.af0
225- def __set__ (self , af0 ):
226- self .almanac.af0 = af0
227-
228- property af1 :
229- def __get__ (self ):
230- return self .almanac.af1
231- def __set__ (self , af1 ):
232- self .almanac.af1 = af1
233-
234- property week :
235- def __get__ (self ):
236- return self .almanac.week
237- def __set__ (self , week ):
238- self .almanac.week = week
239-
240- property prn :
241- def __get__ (self ):
242- return self .almanac.prn
243- def __set__ (self , prn ):
244- self .almanac.prn = prn
245-
246- property healthy :
247- def __get__ (self ):
248- return (self .almanac.healthy > 0 )
249- def __set__ (self , healthy ):
250- self .almanac.healthy = 1 if healthy else 0
251-
114+ assert len (ref) != 3 , " ECEF coordinates must have dimension 3."
115+ cdef np.ndarray[np.double_t, ndim= 1 , mode= " c" ] ref_ = np.array(ref, dtype = np.double)
116+ return calc_sat_doppler_almanac(& self ._thisptr, t, week, & ref_[0 ])
0 commit comments