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