File: instrumentCovarianceCheck.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 (86 lines) | stat: -rw-r--r-- 2,408 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
/***********************************************/
/**
* @file instrumentCovarianceCheck.cpp
*
* @brief Remove non invertible covriance matrices.
*
* @author Norbert Zehentner
* @date 2016-01-20
*/
/***********************************************/

// Latex documentation
#define DOCSTRING docstring
static const char *docstring = R"(
This program checks \configFile{inputfileCovariance3d}{instrument}
3x3 covariance matrices if they are invertible or not and removes the invalid epochs.
)";

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

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

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

/** @brief Remove non invertible covariance matrices.
* @ingroup programsGroup */
class InstrumentCovarianceCheck
{
public:
  void run(Config &config, Parallel::CommunicatorPtr comm);
};

GROOPS_REGISTER_PROGRAM(InstrumentCovarianceCheck, PARALLEL, "Remove non invertible covariance matrices", Instrument, Covariance)

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

void InstrumentCovarianceCheck::run(Config &config, Parallel::CommunicatorPtr comm)
{
  try
  {
    FileName fileNameOut, fileNameIn;

    readConfig(config, "outputfileCovariance3d", fileNameOut, Config::MUSTSET,  "",  "");
    readConfig(config, "inputfileCovariance3d",  fileNameIn,  Config::MUSTSET,  "",  "");
    if(isCreateSchema(config)) return;

    logStatus<<"read and check covariance <"<<fileNameIn<<">"<<Log::endl;
    InstrumentFile file(fileNameIn);
    std::vector<Covariance3dArc> arcCov(file.arcCount());
    UInt removed = 0;
    Parallel::forEach(arcCov, [&](UInt arcNo)
    {
      Covariance3dArc arc = file.readArc(arcNo);
      Covariance3dArc arcNew;
      for(UInt i=0; i<arc.size(); i++)
      {
        try
        {
          Matrix W = arc.at(i).covariance.matrix();
          cholesky(W);
          arcNew.push_back(arc.at(i));
        }
        catch(std::exception &/*e*/)
        {
          removed++;
        }
      }
      return arcNew;
    }, comm);
    Parallel::reduceSum(removed, 0, comm);
    logInfo<<"  "<<removed<<" epochs removed"<<Log::endl;

    if(Parallel::isMaster(comm))
    {
      logStatus<<"write covariance to file <"<<fileNameOut<<"> "<<Log::endl;
      InstrumentFile::write(fileNameOut, arcCov);
    }
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

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