-
Notifications
You must be signed in to change notification settings - Fork 4
/
Initializer.h
590 lines (490 loc) · 20.4 KB
/
Initializer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
/*
* VieSched++ Very Long Baseline Interferometry (VLBI) Scheduling Software
* Copyright (C) 2018 Matthias Schartner
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file Initializer.h
* @brief class Initializer
*
* @author Matthias Schartner
* @date 28.06.2017
*/
#ifndef INITIALIZER_H
#define INITIALIZER_H
#include <algorithm>
#include <boost/date_time.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <memory>
#include <numeric>
#include <thread>
#include <vector>
#include "Algorithm/FocusCorners.h"
#include "Input/SkdCatalogReader.h"
#include "Input/StpParser.h"
#include "Misc/AstrometricCalibratorBlock.h"
#include "Misc/AstronomicalParameters.h"
#include "Misc/AvoidSatellites.h"
#include "Misc/CalibratorBlock.h"
#include "Misc/Constants.h"
#include "Misc/DifferentialParallacticAngleBlock.h"
#include "Misc/HighImpactScanDescriptor.h"
#include "Misc/LookupTable.h"
#include "Misc/MultiScheduling.h"
#include "Misc/ParallacticAngleBlock.h"
#include "Misc/TimeSystem.h"
#include "Misc/WeightFactors.h"
#include "Misc/sofa.h"
#include "ObservingMode/ObservingMode.h"
#include "Scan/Scan.h"
#include "Source/Flux/Flux_B.h"
#include "Source/Flux/Flux_M.h"
#include "Source/Flux/Flux_constant.h"
#include "Source/SourceList.h"
#include "Station/Antenna/Antenna_AzEl.h"
#include "Station/Antenna/Antenna_GGAO.h"
#include "Station/Antenna/Antenna_HaDc.h"
#include "Station/Antenna/Antenna_ONSALA_VGOS.h"
#include "Station/Antenna/Antenna_XYew.h"
#include "Station/Baseline.h"
#include "Station/CableWrap/CableWrap_AzEl.h"
#include "Station/CableWrap/CableWrap_HaDc.h"
#include "Station/CableWrap/CableWrap_XYew.h"
#include "Station/Equip/Equipment_constant.h"
#include "Station/Equip/Equipment_elModel.h"
#include "Station/HorizonMask/HorizonMask_line.h"
#include "Station/HorizonMask/HorizonMask_step.h"
#include "Station/Network.h"
#include "XML/ParameterSettings.h"
#ifdef VIESCHEDPP_LOG
#include <boost/log/trivial.hpp>
#endif
namespace VieVS {
/**
* @class Initializer
* @brief this is the VLBI initializer that creats every objects and passes them to the VLBI_scheduler
*
* @author Matthias Schartner
* @date 28.06.2017
*/
class Initializer : public VieVS_Object {
friend class Scheduler;
friend class SkdParser;
public:
/**
* @brief possible member types
* @author Matthias Schartner
*/
enum class MemberType {
station, ///< stations wise group
source, ///< source wise group
satellite, ///< satellite wise group
spacecraft, ///< spacecraft wise group
baseline, ///< baseline wise group
};
/**
* @brief Parameters used in VLBI_initializer.
* @author Matthias Schartner
*
* Most of this parameters are than passed to other classes like VLBI_scheduler.
*/
struct Parameters {
bool subnetting = true; ///< if set to true subnetting is enabled
double subnettingMinAngle = 150 * deg2rad; ///< backup value for minimum angle of subnetting sources
double subnettingMinNStaPercent = 0.80; ///< backup value for minimum station percentage
double subnettingMinNStaAllBut = 1; ///< backup value for minimum station all but value
bool subnettingMinNStaPercent_otherwiseAllBut = false; ///< if set to true percentage value is used for
///< subnetting minimum number of station calculation
///< otherwise all but value
bool fillinmodeDuringScanSelection = true; ///< schedule fillin mode scans
bool fillinmodeInfluenceOnSchedule = true; ///< fillin modes scans influence schedule
bool fillinmodeAPosteriori = false; ///< schedule fillin mode a posteriori
boost::optional<int> fillinmodeAPosteriori_minSites =
boost::none; ///< fillin mode a posteriori min number of stations
boost::optional<int> fillinmodeAPosteriori_minRepeat =
boost::none; ///< fillin mode a posteriori min source repeat
bool idleToObservingTime = true; ///< transform idle time to additional observing time
std::string idleToObservingTimeGroup = "__all__ "; ///< idle time to additional observing time group
std::vector<std::string> selectedStations; ///< list of all selected station for this session from .xml file
unsigned int maxNumberOfIterations = 999; ///< backup value for max number of iterations
unsigned int numberOfGentleSourceReductions = 0; ///< backup value for gentle source reduction interations
unsigned int minNumberOfSourcesToReduce = 0; ///< backup value for minimum number of sources to reduce
double reduceFactor = .5; ///< number of sources which should be reduced during
///< gentle source reduction
bool ignoreSuccessiveScansSameSrc = true; ///< ignore successive scans to same source
bool doNotObserveSourcesWithinMinRepeat =
true; ///< consider scans (with reduced weight) if they are within min repeat time
bool andAsConditionCombination = true; ///< backup for condition combination. TRUE = and, FALSE = or
};
/**
* @brief pre calculated values
* @author Matthias Schartner
*/
struct PRECALC {
std::vector<std::vector<unsigned long>>
subnettingSrcIds; ///< list of all available second sources in subnetting
};
Initializer();
/**
* @brief constructor
* @author Matthias Schartner
*
* @param path path to VieSchedpp.xml file
*/
explicit Initializer( const std::string &path );
/**
* @brief constructor
* @author Matthias Schartner
*
* @param xml VieSchedpp.xml file
*/
explicit Initializer( const boost::property_tree::ptree &xml );
/**
* @brief getter for VieSchedpp.xml content
* @author Matthias Schartner
*
* @return VieSchedpp.xml content
*/
const boost::property_tree::ptree &getXml() const { return xml_; }
/**
* @brief pre calculates all possible second scans used for subnetting
* @author Matthias Schartner
*/
void precalcSubnettingSrcIds() noexcept;
/**
* @brief creates all selected stations from sked catalogs
* @author Matthias Schartner
*
* @param reader sked catalog reader
* @param of outstream to log file
*/
void createStations( const SkdCatalogReader &reader, std::ofstream &of ) noexcept;
/**
* @brief initializes all stations with settings from VieSchedpp.xml file
* @author Matthias Schartner
*/
void initializeStations() noexcept;
/**
* @brief precalc azimuth elevations for stations
* @author Matthias Schartner
*/
void precalcAzElStations() noexcept;
/**
* @brief initializes all baselines with settings from VieSchedpp.xml file
* @author Matthias Schartner
*/
void initializeBaselines() noexcept;
/**
* @brief creates all possible sources from sked catalogs
* @author Matthias Schartner
*
* @param reader sked catalogs
* @param of outstream to log file
*/
void createSources( const SkdCatalogReader &reader, std::ofstream &of ) noexcept;
/**
* @brief creates all possible satellites from TLE files
* @author Matthias Schartner
*
* @param reader sked catalogs
* @param of outstream to log file
*/
void createSatellites( const SkdCatalogReader &reader, std::ofstream &of ) noexcept;
/**
* @brief creates all possible satellites from TLE files
* @author Matthias Schartner
*
* @param reader sked catalogs
* @param of outstream to log file
*/
void createSatellitesToAvoid( std::ofstream &of ) noexcept;
/**
* @brief creates all possible spacecrafts
* @author Matthias Schartner
*
* @param reader sked catalogs
* @param of outstream to log file
*/
void createSpacecrafts( const SkdCatalogReader &reader, std::ofstream &of ) noexcept;
/**
* @brief initializes all sources with settings from VieSchedpp.xml file
* @author Matthias Schartner
*
* @param type source member type
*/
void initializeSources( MemberType type ) noexcept;
/**
* @brief initializes general block with settings from VieSchedpp.xml file
* @author Matthias Schartner
*
* @param of outstream to log file
*/
void initializeGeneral( std::ofstream &of ) noexcept;
/**
* @brief initializes astronomical parameters
* @author Matthias Schartner
*/
static void initializeAstronomicalParameteres() noexcept;
/**
* @brief initializes the weight factors
* @author Matthias Schartner
*/
void initializeWeightFactors() noexcept;
/**
* @brief inintializes the sky Coverage lookup table
* @author Matthias Schartner
*/
void initializeSkyCoverages() noexcept;
/**
* @brief inintializes the sky Coverage lookup table
* @author Matthias Schartner
*/
void initializeSites() noexcept;
/**
* @brief reads the observing mode information from VieSchedpp.xml file
* @author Matthias Schartner
*
* @param skdCatalogs sked catalogs
* @param of outstream to log file
*/
void initializeObservingMode( const SkdCatalogReader &skdCatalogs, std::ofstream &of ) noexcept;
/**
* @brief creates dummy observing modes file
* @author Matthias Schartner
*
* @param nsta number of stations
* @param samplerate sample rate
* @param bits sampling bits
* @param band2channel band name to number of channels
* @param band2wavelength band name to wavelength
* @param efficiencyFactor recording efficiency factor (use -1 for internal calculation)
*/
void initializeObservingMode( unsigned long nsta, double samplerate, unsigned int bits,
const std::unordered_map<std::string, unsigned int> &band2channel,
const std::unordered_map<std::string, double> &band2wavelength,
double efficiencyFactor = -1 ) noexcept;
/**
* @brief sets station names to observing mode and displays summary
* @author Matthias Schartner
*
* @param of outstream to log file
*/
void connectObservingMode( std::ofstream &of ) noexcept;
/**
* @brief initializes focus corner algorithm for intensives if there is one defined in the VieSchedpp.xml file
* @author Matthias Schartner
*/
void initializeFocusCornersAlgorithm() noexcept;
/**
* @brief initializes a custom source sequence if there is one defined in the VieSchedpp.xml file
* @author Matthias Schartner
*/
void initializeSourceSequence() noexcept;
/**
* @brief reads all groups specified in the root tree
* @author Matthias Schartner
*
* @param root tree start point
* @param type group type
* @return key is group name, value is list of group members
*/
std::unordered_map<std::string, std::vector<std::string>> readGroups( boost::property_tree::ptree root,
MemberType type ) noexcept;
/**
* @brief applies all multi scheduling parameters to the initializer
* @author Matthias Schartner
*
* @param version version number
* @param parameters multi scheduling parameters
*/
void applyMultiSchedParameters(const VieVS::MultiScheduling::Parameters ¶meters, int version);
/**
* @brief reads multiSched block from VieSchedpp.xml file
* @author Matthias Schartner
*
* @return vector of all possible multisched parameter combination
*/
std::vector<MultiScheduling::Parameters> readMultiSched( std::ostream &out );
/**
* @brief initializes astrometric calibration block with settings from VieSchedpp.xml file
* @author Matthias Schartner
*
* @param of outstream to log file
*/
void initializeAstrometricCalibrationBlocks( std::ofstream &of );
/**
* @brief initializes calibration block with settings from VieSchedpp.xml file
* @author Matthias Schartner
*/
void initializeCalibrationBlocks();
/**
* @brief writes statistics log header
* @author Matthias Schartner
*
* @param of outstream to statistics.csv file
* @param ms vector multi scheduling parameters
*/
void statisticsLogHeader( std::ofstream &of, const std::vector<VieVS::MultiScheduling::Parameters> &ms );
/**
* @brief initializes optimization conditions with settings from VieSchedpp.xml file
* @author Matthias Schartner
*
* @param of outstream to log file
*/
void initializeOptimization( std::ofstream &of );
/**
* @brief initializes high impact scan descriptors with settings from VieSchedpp.xml file
* @author Matthias Schartner
*
* @param of outstream to log file
*/
void initializeHighImpactScanDescriptor( std::ofstream &of );
/**
* @brief getter for session network
* @author Matthias Schartner
*
* This function should only be used for the GUI!
*
* @return network object
*/
const Network &getNetwork() { return network_; }
/**
* @brief getter for session network
* @author Matthias Schartner
*
* This function should only be used for the GUI!
*
* @return sourcelist object
*/
const SourceList &getSourceList() { return sourceList_; }
void initializeSatellitesToAvoid();
private:
static unsigned long nextId; ///< next id for this object type
int version_ = 0; ///< version
boost::property_tree::ptree xml_; ///< content of VieSchedpp.xml file
SourceList sourceList_; ///< session source list
Network network_; ///< station network
std::shared_ptr<ObservingMode> obsModes_ = nullptr; ///< observing mode
Parameters parameters_; ///< parameters
PRECALC preCalculated_; ///< pre calculated values
std::unordered_map<std::string, std::vector<std::string>> staGroups_; ///< station groups
std::unordered_map<std::string, std::vector<std::string>> srcGroups_; ///< source groups
std::unordered_map<std::string, std::vector<std::string>> satGroups_; ///< satellite groups
std::unordered_map<std::string, std::vector<std::string>> spacecraftGroups_; ///< spacecraft groups
std::unordered_map<std::string, std::vector<std::string>> blGroups_; ///< baseline groups
boost::optional<HighImpactScanDescriptor> himp_; ///< high impact scan descriptor
std::vector<CalibratorBlock> calib_; ///< fringeFinder impact scan descriptor
boost::optional<MultiScheduling::Parameters> multiSchedulingParameters_; ///< multi scheduling paramters
/**
* @brief station setup function
* @author Matthias Schartner
*
* As a start all parameter form parentPARA are used.
* If different parameter values are defined in the event these parameters are used instead of the parentPARA
* parameters.
*
* @param events list of all events for stations
* @param tree property tree that holds station setup information
* @param parameters all defined parameters
* @param groups all defined groups
* @param parentPARA previously used parameters which are are use as template
*/
void stationSetup( std::vector<std::vector<Station::Event>> &events, const boost::property_tree::ptree &tree,
const std::unordered_map<std::string, ParameterSettings::ParametersStations> ¶meters,
const std::unordered_map<std::string, std::vector<std::string>> &groups,
const Station::Parameters &parentPARA ) noexcept;
/**
* @brief source setup function
* @author Matthias Schartner
*
* As a start all parameter form parentPARA are used.
* If different parameter values are defined in the event these parameters are used instead of the parentPARA
* parameters.
*
* @param events list of all events for sources
* @param tree property tree that holds source setup information
* @param parameters all defined parameters
* @param groups all defined groups
* @param parentPARA previously used parameters which are are use as template
* @param type source member type
*/
void sourceSetup( std::vector<std::vector<AbstractSource::Event>> &events, const boost::property_tree::ptree &tree,
const std::unordered_map<std::string, ParameterSettings::ParametersSources> ¶meters,
const std::unordered_map<std::string, std::vector<std::string>> &groups,
const AbstractSource::Parameters &parentPARA, MemberType type ) noexcept;
/**
* @brief baseline setup function
* @author Matthias Schartner
*
* As a start all parameter form parentPARA are used.
* If different parameter values are defined in the event these parameters are used instead of the parentPARA
* parameters.
*
* @param events list of all events for baseline
* @param tree property tree that holds baseline setup information
* @param parameters all defined parameters
* @param groups all defined groups
* @param parentPARA previously used parameters which are are use as template
*/
void baselineSetup( std::vector<std::vector<Baseline::Event>> &events, const boost::property_tree::ptree &tree,
const std::unordered_map<std::string, ParameterSettings::ParametersBaselines> ¶meters,
const std::unordered_map<std::string, std::vector<std::string>> &groups,
const Baseline::Parameters &parentPARA ) noexcept;
/**
* @brief number of minutes where source is visible
* @author Matthias Schartner
*
* @param source target source
* @param parameters source parameters
* @param start start time
* @param end end time
* @return number of minutes where source was visible
*/
unsigned int minutesVisible( std::shared_ptr<const AbstractSource> source,
const AbstractSource::Parameters ¶meters, unsigned int start, unsigned int end );
/**
* @brief get members of station group
* @author Matthias Schartner
*
* @param name group name
* @param stations list of all available stations
* @return list of station ids
*/
std::vector<unsigned long> getMembers( const std::string &name, const std::vector<Station> &stations );
/**
* @brief get members of baseline group
* @author Matthias Schartner
*
* @param name group name
* @param baselines list of all available baselines
* @return list of baseline ids
*/
std::vector<unsigned long> getMembers( const std::string &name, const std::vector<Baseline> &baselines );
/**
* @brief get members of source group
* @author Matthias Schartner
*
* @param name group name
* @param sourceList list of all available sources
* @return list of source ids
*/
std::vector<unsigned long> getMembers( const std::string &name, const SourceList &sourceList );
std::unordered_map<std::string, std::unique_ptr<AbstractFlux>> generateFluxObject(
const std::string &name, const std::string &commonname,
const std::map<std::string, std::vector<std::string>> &fluxCatalog, bool fluxNecessary, std::ofstream &of );
}; // namespace VieVS
} // namespace VieVS
#endif /* INITIALIZER_H */