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

Last change on this file since 15211 was 15211, checked in by tbretz, 12 years ago
Removed obsoleete includes.
File size: 6.7 KB
Line 
1#include "externals/nova.h"
2
3#include "Database.h"
4
5#include "Time.h"
6#include "Configuration.h"
7
8using namespace std;
9
10// ------------------------------------------------------------------------
11
12double Angle(double ra, double dec, double r, double d)
13{
14 const double theta0 = M_PI/2-d*M_PI/180;
15 const double phi0 = r*M_PI/12;
16
17 const double theta1 = M_PI/2-dec*M_PI/180;
18 const double phi1 = ra*M_PI/12;
19
20 const double x0 = sin(theta0) * cos(phi0);
21 const double y0 = sin(theta0) * sin(phi0);
22 const double z0 = cos(theta0);
23
24 const double x1 = sin(theta1) * cos(phi1);
25 const double y1 = sin(theta1) * sin(phi1);
26 const double z1 = cos(theta1);
27
28 double arg = x0*x1 + y0*y1 + z0*z1;
29 if(arg > 1.0) arg = 1.0;
30 if(arg < -1.0) arg = -1.0;
31
32 return acos(arg) * 180/M_PI;
33}
34
35// ========================================================================
36// ========================================================================
37// ========================================================================
38
39void SetupConfiguration(Configuration &conf)
40{
41 po::options_description control("Smart FACT");
42 control.add_options()
43 ("source-name", var<string>(), "Source name")
44 ("date-time", var<string>(), "SQL time (UTC)")
45 ("source-database", var<string>(""), "Database link as in\n\tuser:password@server[:port]/database.")
46 ("max-current", var<double>(75), "Maximum current to display in other plots.")
47 ("max-zd", var<double>(75), "Maximum zenith distance to display in other plots")
48 ("no-limits", po_switch(), "Switch off limits in plots")
49 ;
50
51 po::positional_options_description p;
52 p.add("source-name", 1); // The 1st positional options
53 p.add("date-time", 2); // The 2nd positional options
54
55 conf.AddOptions(control);
56 conf.SetArgumentPositions(p);
57}
58
59void PrintUsage()
60{
61 cout <<
62 "makedata - The astronomy data listing\n"
63 "\n"
64// "Calculates several plots for the sources in the database\n"
65// "helpful or needed for scheduling. The Plot is always calculated\n"
66// "for the night which starts at the same so. So no matter if\n"
67// "you specify '1974-09-09 00:00:00' or '1974-09-09 21:56:00'\n"
68// "the plots will refer to the night 1974-09-09/1974-09-10.\n"
69// "The advantage is that specification of the date as in\n"
70// "1974-09-09 is enough. Time axis starts and ends at nautical\n"
71// "twilight which is 12deg below horizon.\n"
72// "\n"
73 "Usage: makedata sql-datetime [--ra={ra} --dec={dec}]\n";
74 cout << endl;
75}
76
77int main(int argc, const char* argv[])
78{
79 Configuration conf(argv[0]);
80 conf.SetPrintUsage(PrintUsage);
81 SetupConfiguration(conf);
82
83 if (!conf.DoParse(argc, argv))
84 return 127;
85/*
86 if (!conf.Has("source-name"))
87 {
88 cout << "ERROR - --source-name missing." << endl;
89 return 1;
90 }
91*/
92 // ------------------ Eval config ---------------------
93
94 const double lon = -(17.+53./60+26.525/3600);
95 const double lat = 28.+45./60+42.462/3600;
96
97 ln_lnlat_posn observer;
98 observer.lng = lon;
99 observer.lat = lat;
100
101 Time time;
102 if (conf.Has("date-time"))
103 time.SetFromStr(conf.Get<string>("date-time"));
104
105 const double max_current = conf.Get<double>("max-current");
106 const double max_zd = conf.Get<double>("max-zd");
107 const double no_limits = conf.Get<bool>("no-limits");
108
109 // -12: nautical
110 ln_rst_time sun_set; // Sun set with the same date than th provided date
111 ln_rst_time sun_rise; // Sun rise on the following day
112 ln_get_solar_rst_horizon(time.JD()-0.5, &observer, -12, &sun_set);
113 ln_get_solar_rst_horizon(time.JD()+0.5, &observer, -12, &sun_rise);
114
115 const double jd = floor(time.Mjd())+2400001;
116 const double mjd = floor(time.Mjd())+49718+0.5;
117
118
119 const double jd0 = fmod(sun_set.set, 1); // ~0.3
120 const double jd1 = fmod(sun_rise.rise, 1); // ~0.8
121
122 cout << Time::iso << time << ", " << mjd-49718 << ", ";
123 cout << jd0 << ", ";
124 cout << jd1 << "\n";
125
126 if (!conf.Has("source-name"))
127 return 1;
128
129 const string source_name = conf.Get<string>("source-name");
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 Nova::EquPosn 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 const Nova::HrzPosn hrz = Nova::GetHrzFromEqu(pos, jd+h);
170
171 // Get moon properties and
172 const Nova::EquPosn moon = fMoonCoords[i].first;
173 const double disk = fMoonCoords[i].second;
174
175 const Nova::HrzPosn hrzm = Nova::GetHrzFromEqu(moon, jd+h);
176
177 // Distance between source and moon
178 const double angle = Angle(moon.ra, moon.dec, pos.ra, pos.dec);
179
180 // Current prediction
181 const double cang = sin(angle *M_PI/180);
182 const double calt = sin(hrzm.alt*M_PI/180);
183
184 const double lc = cang==0 ? -1 : calt*pow(disk, 3)/sqrt(cang);
185 const double cur = lc>0 ? 8.1+94.6*lc : 8.1;
186
187 // Relative energy threshold prediction
188 const double cs = cos((90+hrz.alt)*M_PI/180);
189 const double ratio = (10.*sqrt(409600.*cs*cs+9009.) + 6400.*cs - 60.)/10.;
190
191 // Add points to curve
192 // const double axis = (mjd+h)*24*3600;
193
194 Time t(mjd-49718);
195 t += boost::posix_time::minutes(i*5);
196
197 cout << t << ", " << h << ", ";
198
199 if (no_limits || cur<max_current)
200 cout << hrz.alt;
201 cout << ", ";
202
203 if (no_limits || 90-hrz.alt<max_zd)
204 cout << cur;
205 cout << ", ";
206
207 if (no_limits || (cur<max_current && 90-hrz.alt<max_zd))
208 cout << ratio*cur/8.1;
209 cout << ", ";
210
211 if (no_limits || (cur<max_current && 90-hrz.alt<max_zd))
212 cout << angle;
213 cout << "\n";
214 }
215
216 cout << flush;
217
218 return 0;
219}
Note: See TracBrowser for help on using the repository browser.