File: instrumentRemoveEpochsThruster.cpp

package info (click to toggle)
groops 0%2Bgit20250907%2Bds-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 11,140 kB
  • sloc: cpp: 135,607; fortran: 1,603; makefile: 20
file content (107 lines) | stat: -rw-r--r-- 4,107 bytes parent folder | download | duplicates (2)
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
/***********************************************/
/**
* @file instrumentRemoveEpochsThruster.cpp
*
* @brief Remove epochs from instrument data.
*
* @author Torsten Mayer-Guerr
* @date 2022-07-30
*
*/
/***********************************************/

// Latex documentation
#define DOCSTRING docstring
static const char *docstring = R"(
This program remove epochs from an \file{instrument file}{instrument}.
The epochs are defined by a \file{thruster file}{instrument}
plus a defined margin before and after the thruster firings.
The arcs of the instrument file are concatenated to one arc.
The removed epochs can be saved in a separate instrument file.
)";

/***********************************************/

#include "programs/program.h"
#include "files/fileInstrument.h"
#include "classes/timeSeries/timeSeries.h"

/***** CLASS ***********************************/

/** @brief Remove epochs from instrument data.
* @ingroup programsGroup */
class InstrumentRemoveEpochsThruster
{
public:
  void run(Config &config, Parallel::CommunicatorPtr comm);
};

GROOPS_REGISTER_PROGRAM(InstrumentRemoveEpochsThruster, SINGLEPROCESS, "Remove epochs from instrument data", Instrument)

/***********************************************/

void InstrumentRemoveEpochsThruster::run(Config &config, Parallel::CommunicatorPtr /*comm*/)
{
  try
  {
    FileName fileNameOut, fileNameOutRemoved, fileNameIn, fileNameThruster;
    Double   marginBefore, marginAfter;

    readConfig(config, "outputfileInstrument",               fileNameOut,        Config::OPTIONAL, "",    "all epochs are concatenated in one arc");
    readConfig(config, "outputfileInstrumentRemovedEpochs",  fileNameOutRemoved, Config::OPTIONAL, "",    "all epochs are concatenated in one arc");
    readConfig(config, "inputfileInstrument",                fileNameIn,         Config::MUSTSET,  "",    "");
    readConfig(config, "inputfileThruster",                  fileNameThruster,   Config::MUSTSET,  "",    "THRUSTER");
    readConfig(config, "marginBefore",                       marginBefore,       Config::DEFAULT,  "0.1", "margin before start of firing [seconds]");
    readConfig(config, "marginAfter",                        marginAfter,        Config::DEFAULT,  "0.7", "margin after end of firing [seconds]");
    if(isCreateSchema(config)) return;

    // thruster time series
    // --------------------
    logStatus<<"read thruster data <"<<fileNameThruster<<">"<<Log::endl;
    ThrusterArc thruster = InstrumentFile::read(fileNameThruster);
    std::vector<Time> timesStart = thruster.times();
    std::vector<Time> timesEnd   = timesStart;
    for(UInt i=0; i<thruster.size(); i++)
      timesStart.at(i) -= seconds2time(marginBefore);
    for(UInt i=0; i<thruster.size(); i++)
      timesEnd.at(i) += seconds2time(1e-3*max(thruster.at(i).data()) + marginAfter);

    logStatus<<"read instrument data <"<<fileNameIn<<">"<<Log::endl;
    Arc arc = InstrumentFile::read(fileNameIn);

    logStatus<<"remove thruster epochs from instrument data"<<Log::endl;
    Arc arcNew, arcRemoved;
    UInt idxThruster = 0;
    Single::forEach(arc.size(), [&](UInt i)
    {
      while((idxThruster < timesEnd.size()) && ((arc.at(i).time-timesEnd.at(idxThruster)).seconds() >= 0)) // find next thruster epoch
        idxThruster++;
      if((idxThruster >= timesEnd.size()) || ((arc.at(i).time-timesStart.at(idxThruster)).seconds() < 0))
        arcNew.push_back(arc.at(i));
      else
        arcRemoved.push_back(arc.at(i));
    });

    // save instrument data
    // --------------------
    if(!fileNameOut.empty())
    {
      logStatus<<"write instrument data to file <"<<fileNameOut<<">"<<Log::endl;
      InstrumentFile::write(fileNameOut, arcNew);
      Arc::printStatistics(arcNew);
    }

    if(!fileNameOutRemoved.empty())
    {
      logStatus<<"write removed epochs to file <"<<fileNameOutRemoved<<">"<<Log::endl;
      InstrumentFile::write(fileNameOutRemoved, arcRemoved);
      Arc::printStatistics(arcRemoved);
    }
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

/***********************************************/