source: trunk/FACT++/src/makedata.cc@ 14801

Last change on this file since 14801 was 14784, checked in by tbretz, 12 years ago
Added this tool to access the observation scheduling parameters of a single source for one night.
File size: 6.7 KB
Line 
1#include <libnova/solar.h>
2#include <libnova/lunar.h>
3#include <libnova/rise_set.h>
4#include <libnova/transform.h>
5
6#include "Database.h"
7
8#include "Time.h"
9#include "Configuration.h"
10
11using namespace std;
12
13// ------------------------------------------------------------------------
14
15double Angle(double ra, double dec, double r, double d)
16{
17 const double theta0 = M_PI/2-d*M_PI/180;
18 const double phi0 = r*M_PI/12;
19
20 const double theta1 = M_PI/2-dec*M_PI/180;
21 const double phi1 = ra*M_PI/12;
22
23 const double x0 = sin(theta0) * cos(phi0);
24 const double y0 = sin(theta0) * sin(phi0);
25 const double z0 = cos(theta0);
26
27 const double x1 = sin(theta1) * cos(phi1);
28 const double y1 = sin(theta1) * sin(phi1);
29 const double z1 = cos(theta1);
30
31 double arg = x0*x1 + y0*y1 + z0*z1;
32 if(arg > 1.0) arg = 1.0;
33 if(arg < -1.0) arg = -1.0;
34
35 return acos(arg) * 180/M_PI;
36}
37
38// ========================================================================
39// ========================================================================
40// ========================================================================
41
42void SetupConfiguration(Configuration &conf)
43{
44 po::options_description control("Smart FACT");
45 control.add_options()
46 ("source-name", var<string>(), "Source name")
47 ("date-time", var<string>(), "SQL time (UTC)")
48 ("source-database", var<string>(""), "Database link as in\n\tuser:password@server[:port]/database.")
49 ("max-current", var<double>(75), "Maximum current to display in other plots.")
50 ("max-zd", var<double>(75), "Maximum zenith distance to display in other plots")
51 ("no-limits", po_switch(), "Switch off limits in plots")
52 ;
53
54 po::positional_options_description p;
55 p.add("source-name", 1); // The 1st positional options
56 p.add("date-time", 2); // The 2nd positional options
57
58 conf.AddOptions(control);
59 conf.SetArgumentPositions(p);
60}
61
62void PrintUsage()
63{
64 cout <<
65 "makedata - The astronomy data listing\n"
66 "\n"
67// "Calculates several plots for the sources in the database\n"
68// "helpful or needed for scheduling. The Plot is always calculated\n"
69// "for the night which starts at the same so. So no matter if\n"
70// "you specify '1974-09-09 00:00:00' or '1974-09-09 21:56:00'\n"
71// "the plots will refer to the night 1974-09-09/1974-09-10.\n"
72// "The advantage is that specification of the date as in\n"
73// "1974-09-09 is enough. Time axis starts and ends at nautical\n"
74// "twilight which is 12deg below horizon.\n"
75// "\n"
76 "Usage: makedata sql-datetime [--ra={ra} --dec={dec}]\n";
77 cout << endl;
78}
79
80int main(int argc, const char* argv[])
81{
82 Configuration conf(argv[0]);
83 conf.SetPrintUsage(PrintUsage);
84 SetupConfiguration(conf);
85
86 if (!conf.DoParse(argc, argv))
87 return 127;
88
89 if (!conf.Has("source-name"))
90 {
91 cout << "ERROR - --source-name missing." << endl;
92 return 1;
93 }
94
95 // ------------------ Eval config ---------------------
96
97 const double lon = -(17.+53./60+26.525/3600);
98 const double lat = 28.+45./60+42.462/3600;
99
100 ln_lnlat_posn observer;
101 observer.lng = lon;
102 observer.lat = lat;
103
104 Time time;
105 if (conf.Has("date-time"))
106 time.SetFromStr(conf.Get<string>("date-time"));
107
108 const string source_name = conf.Get<string>("source-name");
109 const double max_current = conf.Get<double>("max-current");
110 const double max_zd = conf.Get<double>("max-zd");
111 const double no_limits = conf.Get<bool>("no-limits");
112
113 // -12: nautical
114 ln_rst_time sun_set; // Sun set with the same date than th provided date
115 ln_rst_time sun_rise; // Sun rise on the following day
116 ln_get_solar_rst_horizon(time.JD()-0.5, &observer, -12, &sun_set);
117 ln_get_solar_rst_horizon(time.JD()+0.5, &observer, -12, &sun_rise);
118
119 const double jd = floor(time.Mjd())+2400001;
120 const double mjd = floor(time.Mjd())+49718+0.5;
121
122
123 const double jd0 = fmod(sun_set.set, 1); // ~0.3
124 const double jd1 = fmod(sun_rise.rise, 1); // ~0.8
125
126 cout << Time::iso << time << ", " << mjd-49718 << ", ";
127 cout << jd0 << ", ";
128 cout << jd1 << "\n";
129
130 const string fDatabase = conf.Get<string>("source-database");
131
132 // ------------------ Precalc moon coord ---------------------
133
134 vector<pair<ln_equ_posn, double>> fMoonCoords;
135
136 for (double h=0; h<1; h+=1./(24*12))
137 {
138 ln_equ_posn moon;
139 ln_get_lunar_equ_coords_prec(jd+h, &moon, 0.01);
140
141 const double disk = ln_get_lunar_disk(jd+h);
142
143 fMoonCoords.push_back(make_pair(moon, disk));
144 }
145
146 // ------------- Get Sources from databasse ---------------------
147
148 const mysqlpp::StoreQueryResult res =
149 Database(fDatabase).query("SELECT fRightAscension, fDeclination FROM source WHERE fSourceName='"+source_name+"'").store();
150
151 // ------------- Create canvases and frames ---------------------
152
153 vector<mysqlpp::Row>::const_iterator row=res.begin();
154
155 ln_equ_posn pos;
156 pos.ra = double((*row)[0])*15;
157 pos.dec = double((*row)[1]);
158
159 // Loop over 24 hours
160 for (int i=0; i<24*12; i++)
161 {
162 const double h = double(i)/(24*12);
163
164 // check if it is betwene sun-rise and sun-set
165 if (h<jd0 || h>jd1)
166 continue;
167
168 // get local position of source
169 ln_hrz_posn hrz;
170 ln_get_hrz_from_equ(&pos, &observer, jd+h, &hrz);
171
172 // Get moon properties and
173 ln_equ_posn moon = fMoonCoords[i].first;
174 const double disk = fMoonCoords[i].second;
175
176 ln_hrz_posn hrzm;
177 ln_get_hrz_from_equ(&moon, &observer, jd+h, &hrzm);
178
179 // Distance between source and moon
180 const double angle = Angle(moon.ra, moon.dec, pos.ra, pos.dec);
181
182 // Current prediction
183 const double lc = angle*hrzm.alt*pow(disk, 6)/360/360;
184 const double cur = lc>0 ? 7.7+4942*lc : 7.7;
185
186 // Relative energy threshold prediction
187 const double cs = cos((90+hrz.alt)*M_PI/180);
188 const double ratio = (10.*sqrt(409600.*cs*cs+9009.) + 6400.*cs - 60.)/10.;
189
190 // Add points to curve
191 // const double axis = (mjd+h)*24*3600;
192
193 Time t(mjd-49718);
194 t += boost::posix_time::minutes(i*5);
195
196 cout << t << ", " << h << ", ";
197
198 if (no_limits || cur<max_current)
199 cout << hrz.alt;
200 cout << ", ";
201
202 if (no_limits || 90-hrz.alt<max_zd)
203 cout << cur;
204 cout << ", ";
205
206 if (no_limits || (cur<max_current && 90-hrz.alt<max_zd))
207 cout << ratio*cur/7.7;
208 cout << ", ";
209
210 if (no_limits || (cur<max_current && 90-hrz.alt<max_zd))
211 cout << angle;
212 cout << "\n";
213 }
214
215 cout << flush;
216
217 return 0;
218}
Note: See TracBrowser for help on using the repository browser.