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

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