1 | #include "externals/nova.h"
|
---|
2 |
|
---|
3 | #include "Database.h"
|
---|
4 |
|
---|
5 | #include "Time.h"
|
---|
6 | #include "Configuration.h"
|
---|
7 |
|
---|
8 | using namespace std;
|
---|
9 | using namespace Nova;
|
---|
10 |
|
---|
11 | // ========================================================================
|
---|
12 | // ========================================================================
|
---|
13 | // ========================================================================
|
---|
14 |
|
---|
15 | void SetupConfiguration(Configuration &conf)
|
---|
16 | {
|
---|
17 | po::options_description control("Smart FACT");
|
---|
18 | control.add_options()
|
---|
19 | ("source-name", var<string>(), "Source name")
|
---|
20 | ("date-time", var<string>(), "SQL time (UTC)")
|
---|
21 | ("source-database", var<string>(""), "Database link as in\n\tuser:password@server[:port]/database.")
|
---|
22 | ("max-current", var<double>(75), "Maximum current to display in other plots.")
|
---|
23 | ("max-zd", var<double>(75), "Maximum zenith distance to display in other plots")
|
---|
24 | ("no-limits", po_switch(), "Switch off limits in plots")
|
---|
25 | ;
|
---|
26 |
|
---|
27 | po::positional_options_description p;
|
---|
28 | p.add("source-name", 1); // The 1st positional options
|
---|
29 | p.add("date-time", 2); // The 2nd positional options
|
---|
30 |
|
---|
31 | conf.AddOptions(control);
|
---|
32 | conf.SetArgumentPositions(p);
|
---|
33 | }
|
---|
34 |
|
---|
35 | void PrintUsage()
|
---|
36 | {
|
---|
37 | cout <<
|
---|
38 | "makedata - The astronomy data listing\n"
|
---|
39 | "\n"
|
---|
40 | // "Calculates several plots for the sources in the database\n"
|
---|
41 | // "helpful or needed for scheduling. The Plot is always calculated\n"
|
---|
42 | // "for the night which starts at the same so. So no matter if\n"
|
---|
43 | // "you specify '1974-09-09 00:00:00' or '1974-09-09 21:56:00'\n"
|
---|
44 | // "the plots will refer to the night 1974-09-09/1974-09-10.\n"
|
---|
45 | // "The advantage is that specification of the date as in\n"
|
---|
46 | // "1974-09-09 is enough. Time axis starts and ends at nautical\n"
|
---|
47 | // "twilight which is 12deg below horizon.\n"
|
---|
48 | // "\n"
|
---|
49 | "Usage: makedata sql-datetime [--ra={ra} --dec={dec}]\n";
|
---|
50 | cout << endl;
|
---|
51 | }
|
---|
52 |
|
---|
53 | int main(int argc, const char* argv[])
|
---|
54 | {
|
---|
55 | Configuration conf(argv[0]);
|
---|
56 | conf.SetPrintUsage(PrintUsage);
|
---|
57 | SetupConfiguration(conf);
|
---|
58 |
|
---|
59 | if (!conf.DoParse(argc, argv))
|
---|
60 | return 127;
|
---|
61 | /*
|
---|
62 | if (!conf.Has("source-name"))
|
---|
63 | {
|
---|
64 | cout << "ERROR - --source-name missing." << endl;
|
---|
65 | return 1;
|
---|
66 | }
|
---|
67 | */
|
---|
68 | // ------------------ Eval config ---------------------
|
---|
69 |
|
---|
70 | Time time;
|
---|
71 | if (conf.Has("date-time"))
|
---|
72 | time.SetFromStr(conf.Get<string>("date-time"));
|
---|
73 |
|
---|
74 | const double max_current = conf.Get<double>("max-current");
|
---|
75 | const double max_zd = conf.Get<double>("max-zd");
|
---|
76 | const double no_limits = conf.Get<bool>("no-limits");
|
---|
77 |
|
---|
78 | // -12: nautical
|
---|
79 | const RstTime sun_set = GetSolarRst(time.JD()-0.5, -12); // Sun set with the same date than th provided date
|
---|
80 | const RstTime sun_rise = GetSolarRst(time.JD()+0.5, -12); // Sun rise on the following day
|
---|
81 |
|
---|
82 | const double jd = floor(time.Mjd())+2400001;
|
---|
83 | const double mjd = floor(time.Mjd())+49718+0.5;
|
---|
84 |
|
---|
85 |
|
---|
86 | const double jd0 = fmod(sun_set.set, 1); // ~0.3
|
---|
87 | const double jd1 = fmod(sun_rise.rise, 1); // ~0.8
|
---|
88 |
|
---|
89 | cout << Time::iso << time << ", " << mjd-49718 << ", ";
|
---|
90 | cout << jd0 << ", ";
|
---|
91 | cout << jd1 << "\n";
|
---|
92 |
|
---|
93 | if (!conf.Has("source-name"))
|
---|
94 | return 1;
|
---|
95 |
|
---|
96 | const string source_name = conf.Get<string>("source-name");
|
---|
97 | const string fDatabase = conf.Get<string>("source-database");
|
---|
98 |
|
---|
99 | // ------------------ Precalc moon coord ---------------------
|
---|
100 |
|
---|
101 | vector<pair<EquPosn, double>> fMoonCoords;
|
---|
102 |
|
---|
103 | for (double h=0; h<1; h+=1./(24*12))
|
---|
104 | {
|
---|
105 | const EquPosn moon = GetLunarEquCoords(jd+h, 0.01);
|
---|
106 | const double disk = GetLunarDisk(jd+h);
|
---|
107 |
|
---|
108 | fMoonCoords.emplace_back(moon, disk);
|
---|
109 | }
|
---|
110 |
|
---|
111 | // ------------- Get Sources from databasse ---------------------
|
---|
112 |
|
---|
113 | const mysqlpp::StoreQueryResult res =
|
---|
114 | Database(fDatabase).query("SELECT fRightAscension, fDeclination FROM Source WHERE fSourceName='"+source_name+"'").store();
|
---|
115 |
|
---|
116 | // ------------- Create canvases and frames ---------------------
|
---|
117 |
|
---|
118 | vector<mysqlpp::Row>::const_iterator row=res.begin();
|
---|
119 | if (row==res.end())
|
---|
120 | return 1;
|
---|
121 |
|
---|
122 | EquPosn pos;
|
---|
123 | pos.ra = double((*row)[0])*15;
|
---|
124 | pos.dec = double((*row)[1]);
|
---|
125 |
|
---|
126 | // Loop over 24 hours
|
---|
127 | for (int i=0; i<24*12; i++)
|
---|
128 | {
|
---|
129 | const double h = double(i)/(24*12);
|
---|
130 |
|
---|
131 | // check if it is betwene sun-rise and sun-set
|
---|
132 | if (h<jd0 || h>jd1)
|
---|
133 | continue;
|
---|
134 |
|
---|
135 | // get local position of source
|
---|
136 | const HrzPosn hrz = GetHrzFromEqu(pos, jd+h);
|
---|
137 |
|
---|
138 | // Get moon properties and
|
---|
139 | const EquPosn moon = fMoonCoords[i].first;
|
---|
140 | const double disk = fMoonCoords[i].second;
|
---|
141 | const HrzPosn hrzm = GetHrzFromEqu(moon, jd+h);
|
---|
142 |
|
---|
143 | // Angular distance between source and moon
|
---|
144 | const double angle = GetAngularSeparation(moon, pos);
|
---|
145 |
|
---|
146 | // Distance between earth and moon relative to major semi-axis
|
---|
147 | const double dist = GetLunarEarthDist(jd+h)/384400;
|
---|
148 |
|
---|
149 | // Current prediction
|
---|
150 | const double calt = sin(hrzm.alt*M_PI/180);
|
---|
151 | const double cang = 1-sin(angle*M_PI/180);
|
---|
152 |
|
---|
153 | //const double lc = cang==0 ? -1 : calt*pow(disk, 2.2)*pow(dist, -2);
|
---|
154 | //const double cur = lc>0 ? 4+103*lc : 4;
|
---|
155 |
|
---|
156 | const double lc = sqrt(calt)*pow(disk, 2.3)*pow(cang+1, 1)*pow(dist, -2);
|
---|
157 | const double cur = lc>0 ? 7.2 + 69*lc : 7.2;
|
---|
158 |
|
---|
159 | // Relative energy threshold prediction
|
---|
160 | //const double cs = cos((90+hrz.alt)*M_PI/180);
|
---|
161 | //const double ratio = (10.*sqrt(409600.*cs*cs+9009.) + 6400.*cs - 60.)/10.;
|
---|
162 | const double ratio = pow(cos((90-hrz.alt)*M_PI/180), -2.664);
|
---|
163 |
|
---|
164 | // Add points to curve
|
---|
165 | // const double axis = (mjd+h)*24*3600;
|
---|
166 |
|
---|
167 | Time t(mjd-49718);
|
---|
168 | t += boost::posix_time::minutes(i*5);
|
---|
169 |
|
---|
170 | cout << t << ", " << h << ", ";
|
---|
171 |
|
---|
172 | if (no_limits || cur<max_current)
|
---|
173 | cout << hrz.alt;
|
---|
174 | cout << ", ";
|
---|
175 |
|
---|
176 | if (no_limits || 90-hrz.alt<max_zd)
|
---|
177 | cout << cur;
|
---|
178 | cout << ", ";
|
---|
179 |
|
---|
180 | if (no_limits || (cur<max_current && 90-hrz.alt<max_zd))
|
---|
181 | cout << ratio*cur/8.1;
|
---|
182 | cout << ", ";
|
---|
183 |
|
---|
184 | if (no_limits || (cur<max_current && 90-hrz.alt<max_zd))
|
---|
185 | cout << angle;
|
---|
186 | cout << "\n";
|
---|
187 | }
|
---|
188 |
|
---|
189 | cout << flush;
|
---|
190 |
|
---|
191 | return 0;
|
---|
192 | }
|
---|