source: trunk/Mars/mcore/nova.h@ 18823

Last change on this file since 18823 was 18820, checked in by tbretz, 8 years ago
Slightly modified the interface to access the observatory. This allows simpler calles than before if any other than the default observatory should be used.
File size: 5.4 KB
Line 
1#ifndef MARS_Nova
2#define MARS_Nova
3
4#include <map>
5#include <string>
6
7#include <libnova/solar.h>
8#include <libnova/lunar.h>
9#include <libnova/rise_set.h>
10#include <libnova/transform.h>
11#include <libnova/angular_separation.h>
12
13namespace Nova
14{
15 typedef ln_rst_time RstTime; // Note that times are in JD not Mjd
16
17 struct ZdAzPosn;
18 struct RaDecPosn;
19
20 const static ln_lnlat_posn kORM
21#ifndef __CINT__
22 = { -(17.+53./60+26.525/3600), 28.+45./60+42.462/3600 } // 2200m
23#endif
24 ;
25 const static ln_lnlat_posn kHAWC
26#ifndef __CINT__
27 = { -97.3084, 18.9947 } // 4100m;
28#endif
29 ;
30 const static ln_lnlat_posn kSPM
31#ifndef __CINT__
32 = { -115.4637, 31.0439 } // 2800m;
33#endif
34 ;
35
36 struct LnLatPosn : public ln_lnlat_posn
37 {
38 LnLatPosn() { }
39 LnLatPosn(const ln_lnlat_posn &pos) : ln_lnlat_posn(pos) { }
40 LnLatPosn(const std::string &obs)
41 {
42#ifndef __CINT__
43 static const std::map<std::string, ln_lnlat_posn> lut =
44 {
45 { "orm", kORM },
46 { "hawc", kHAWC },
47 { "spm", kSPM },
48 };
49
50 const auto it = lut.find(obs);
51 *this = it==lut.end() ? ln_lnlat_posn({0,0}) : it->second;
52#endif
53 }
54 };
55
56 // Warning: 0deg=South, 90deg=W
57 struct HrzPosn : public ln_hrz_posn
58 {
59 HrzPosn() { }
60 HrzPosn(const ZdAzPosn &);
61 };
62
63 struct ZdAzPosn
64 {
65 double zd; // [deg]
66 double az; // [deg]
67
68 ZdAzPosn(double z=0, double a=0) : zd(z), az(a) { }
69 ZdAzPosn(const HrzPosn &hrz) : zd(90-hrz.alt), az(hrz.az-180) { }
70
71 // This crahsed cint, but it could save up the dedicate structure HrzPosn :(
72 //operator HrzPosn() const { const HrzPosn p = { az-180, 90-zd}; return p; }
73 };
74
75 HrzPosn::HrzPosn(const ZdAzPosn &za) { alt = 90-za.zd; az = za.az-180; }
76
77
78 // Note that right ascension is stored in degree
79 struct EquPosn : public ln_equ_posn
80 {
81 EquPosn() { }
82 EquPosn(const RaDecPosn &);
83 };
84
85 struct RaDecPosn
86 {
87 double ra; // [h]
88 double dec; // [deg]
89
90 RaDecPosn(double r=0, double d=0) : ra(r), dec(d) { }
91 RaDecPosn(const EquPosn &equ) : ra(equ.ra/15), dec(equ.dec) { }
92
93 // This crahsed cint, but it could save up the dedicate structure HrzPosn :(
94 //operator HrzPosn() const { const HrzPosn p = { az-180, 90-zd}; return p; }
95 };
96
97 EquPosn::EquPosn(const RaDecPosn &rd) { ra = rd.ra*15; dec = rd.dec; }
98
99 HrzPosn GetHrzFromEqu(const EquPosn &equ, const LnLatPosn &obs, double jd)
100 {
101 HrzPosn hrz;
102 ln_get_hrz_from_equ(const_cast<EquPosn*>(&equ), const_cast<LnLatPosn*>(&obs), jd, &hrz);
103 return hrz;
104 }
105 HrzPosn GetHrzFromEqu(const EquPosn &equ, double jd)
106 {
107 return GetHrzFromEqu(equ, kORM, jd);
108 }
109
110 EquPosn GetEquFromHrz(const HrzPosn &hrz, const LnLatPosn &obs, double jd)
111 {
112 EquPosn equ;
113 ln_get_equ_from_hrz(const_cast<HrzPosn*>(&hrz), const_cast<LnLatPosn*>(&obs), jd, &equ);
114 return equ;
115 }
116 EquPosn GetEquFromHrz(const HrzPosn &hrz, double jd)
117 {
118 return GetEquFromHrz(hrz, kORM, jd);
119 }
120
121 RstTime GetSolarRst(double jd, const LnLatPosn &obs, double hrz=LN_SOLAR_STANDART_HORIZON)
122 {
123 RstTime rst;
124 ln_get_solar_rst_horizon(jd, const_cast<LnLatPosn*>(&obs), hrz, &rst);
125 return rst;
126 }
127 RstTime GetSolarRst(double jd, double hrz=LN_SOLAR_STANDART_HORIZON)
128 {
129 return GetSolarRst(jd, kORM, hrz);
130 }
131
132 RstTime GetLunarRst(double jd, const LnLatPosn &obs=kORM)
133 {
134 RstTime rst;
135 ln_get_lunar_rst(jd, const_cast<LnLatPosn*>(&obs), &rst);
136 return rst;
137 }
138 EquPosn GetSolarEquCoords(double jd)
139 {
140 EquPosn equ;
141 ln_get_solar_equ_coords(jd, &equ);
142 return equ;
143 }
144
145 double GetLunarDisk(double jd)
146 {
147 return ln_get_lunar_disk(jd);
148 }
149
150 double GetLunarSdiam(double jd)
151 {
152 return ln_get_lunar_sdiam(jd);
153 }
154
155 double GetLunarPhase(double jd)
156 {
157 return ln_get_lunar_phase(jd);
158 }
159
160 EquPosn GetLunarEquCoords(double jd, double precision=0)
161 {
162 EquPosn equ;
163 ln_get_lunar_equ_coords_prec(jd, &equ, precision);
164 return equ;
165 }
166
167 double GetLunarEarthDist(double jd)
168 {
169 return ln_get_lunar_earth_dist(jd);
170 }
171
172 double GetAngularSeparation(const EquPosn &p1, const EquPosn &p2)
173 {
174 return ln_get_angular_separation(const_cast<EquPosn*>(&p1), const_cast<EquPosn*>(&p2));
175 }
176
177 double GetAngularSeparation(const HrzPosn &h1, const HrzPosn &h2)
178 {
179 EquPosn p1; p1.ra=h1.az; p1.dec=h1.alt;
180 EquPosn p2; p2.ra=h2.az; p2.dec=h2.alt;
181 return ln_get_angular_separation(&p1, &p2);
182 }
183
184 struct SolarObjects
185 {
186 double fJD;
187
188 EquPosn fSunEqu;
189 HrzPosn fSunHrz;
190
191 EquPosn fMoonEqu;
192 HrzPosn fMoonHrz;
193 double fMoonDisk;
194
195 double fEarthDist;
196
197 SolarObjects(const double &jd, const LnLatPosn &obs=Nova::kORM)
198 {
199 fJD = jd;
200
201 // Sun properties
202 fSunEqu = GetSolarEquCoords(jd);
203 fSunHrz = GetHrzFromEqu(fSunEqu, obs, jd);
204
205 // Moon properties
206 fMoonEqu = GetLunarEquCoords(jd, 0.01);
207 fMoonHrz = GetHrzFromEqu(fMoonEqu, obs, jd);
208
209 fMoonDisk = GetLunarDisk(jd);
210 fEarthDist = GetLunarEarthDist(jd);
211 }
212 };
213
214}
215
216#endif
Note: See TracBrowser for help on using the repository browser.