File: plotDegreeAmplitudes.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 (163 lines) | stat: -rw-r--r-- 7,791 bytes parent folder | download
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
/***********************************************/
/**
* @file plotDegreeAmplitudes.cpp
*
* @brief Plot Degree Amplitudes.
*
* @author Enrico Kurtenbach
* @author Torsten Mayer-Guerr
* @author Andreas Kvas
* @date 2015-10-26
*
*/
/***********************************************/

// Latex documentation
#define DOCSTRING docstring
static const char *docstring = R"(
Plot degree amplitudes of potential coefficients computed by \program{Gravityfield2DegreeAmplitudes}
or \program{PotentialCoefficients2DegreeAmplitudes} using the GMT Generic Mapping Tools
(\url{https://www.generic-mapping-tools.org}).
A variety of image file formats are supported (e.g. png, jpg, eps) determined by the extension of \config{outputfile}.
This is a convenience program with meaningful default values. The same plots can be generated with the more general \program{PlotGraph}.

\fig{!hb}{0.8}{plotDegreeAmplitudes}{fig:plotDegreeAmplitudes}{Comparison of GRACE solutions (2008-06) with GOCO06s.}
)";

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

#include "programs/program.h"
#include "inputOutput/file.h"
#include "plot/plotMisc.h"
#include "plot/plotGraphLayer.h"
#include "plot/plotLegend.h"

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

/** @brief Plot Degree Amplitudes.
* @ingroup programsGroup */
class PlotDegreeAmplitudes
{
public:
  void run(Config &config, Parallel::CommunicatorPtr comm);
};

GROOPS_REGISTER_PROGRAM(PlotDegreeAmplitudes, SINGLEPROCESS, "Plot Degree Amplitudes", Plot, Gravityfield, PotentialCoefficients)

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

void PlotDegreeAmplitudes::run(Config &config, Parallel::CommunicatorPtr /*comm*/)
{
  try
  {
    FileName          fileNamePlot;
    std::string       title;
    std::vector<PlotGraphLayerPtr> layer;
    Double            annotationX=NAN_EXPR, frameX=NAN_EXPR, gridX=NAN_EXPR;
    Double            annotationY=NAN_EXPR, frameY=NAN_EXPR, gridY=NAN_EXPR;
    UInt              minX=INFINITYDEGREE, maxX=INFINITYDEGREE;
    Double            minY=NAN_EXPR, maxY=NAN_EXPR;
    Bool              logX, logY;
    std::string       labelX, labelY, unitY;
    PlotLinePtr       gridLine;
    PlotLegendPtr     legend;
    PlotBasics        plotBasics;

    renameDeprecatedConfig(config, "annotationDegree", "majorTickSpacingDegree", date2time(2020, 4, 23));
    renameDeprecatedConfig(config, "frameDegree",      "minorTickSpacingDegree", date2time(2020, 4, 23));
    renameDeprecatedConfig(config, "gridDegree",       "gridLineSpacingDegree",  date2time(2020, 4, 23));
    renameDeprecatedConfig(config, "annotationY",      "majorTickSpacingY",      date2time(2020, 4, 23));
    renameDeprecatedConfig(config, "frameY",           "minorTickSpacingY",      date2time(2020, 4, 23));
    renameDeprecatedConfig(config, "gridY",            "gridLineSpacingY",       date2time(2020, 4, 23));

    readConfig(config, "outputfile",             fileNamePlot, Config::MUSTSET,  "",     "*.png, *.jpg, *.eps, ...");
    readConfig(config, "title",                  title,        Config::OPTIONAL, "",     "");
    readConfig(config, "layer",                  layer,        Config::MUSTSET,  "degreeAmplitudesSimple", "");
    readConfig(config, "minDegree",              minX,         Config::OPTIONAL, "0",    "");
    readConfig(config, "maxDegree",              maxX,         Config::OPTIONAL, "",     "");
    readConfig(config, "majorTickSpacingDegree", annotationX,  Config::OPTIONAL, "",     "boundary annotation");
    readConfig(config, "minorTickSpacingDegree", frameX,       Config::OPTIONAL, "",     "frame tick spacing");
    readConfig(config, "gridLineSpacingDegree",  gridX,        Config::OPTIONAL, "",     "gridline spacing");
    readConfig(config, "labelDegree",            labelX,       Config::OPTIONAL, "[degree]", "description of the x-axis");
    readConfig(config, "logarithmicDegree",      logX,         Config::DEFAULT,  "0",    "use logarithmic scale for the x-axis");
    readConfig(config, "minY",                   minY,         Config::OPTIONAL, "1e-6", "");
    readConfig(config, "maxY",                   maxY,         Config::OPTIONAL, "1",    "");
    readConfig(config, "majorTickSpacingY",      annotationY,  Config::OPTIONAL, "",     "boundary annotation");
    readConfig(config, "minorTickSpacingY",      frameY,       Config::OPTIONAL, "",     "frame tick spacing");
    readConfig(config, "gridLineSpacingY",       gridY,        Config::OPTIONAL, "",     "gridline spacing");
    readConfig(config, "unitY",                  unitY,        Config::OPTIONAL, "",     "appended to axis values");
    readConfig(config, "labelY",                 labelY,       Config::OPTIONAL, "geoid height [m]",  "description of the y-axis");
    readConfig(config, "logarithmicY",           logY,         Config::DEFAULT,  "1",    "use logarithmic scale for the y-axis");
    readConfig(config, "gridLine",               gridLine,     Config::OPTIONAL, R"({"solid": {"width":"0.25", "color":"gray"}})", "The style of the grid lines.");
    readConfig(config, "legend",                 legend,       Config::OPTIONAL, "1",    "");
    plotBasics.read(config, "PlotDegreeAmplitudes", fileNamePlot, title, "12", "10");
    if(isCreateSchema(config)) return;

    // ===========================================================

    // calculate min and max
    // ---------------------
    // x-axis
    Double minDegree  =  1e99;
    Double maxDegree  = -1e99;
    for(UInt k = 0; k<layer.size(); k++)
      layer.at(k)->getIntervalX(logX, minDegree, maxDegree);
    if(minX==INFINITYDEGREE) minX = static_cast<UInt>(minDegree);
    if(maxX==INFINITYDEGREE) maxX = static_cast<UInt>(maxDegree);

    // y-axis
    Double minSignal  =  1e99;
    Double maxSignal  = -1e99;
    for(UInt k = 0; k<layer.size(); k++)
      layer.at(k)->getIntervalY(logY, minX, maxX, minSignal, maxSignal);
    if(std::isnan(minY)) minY = minSignal;
    if(std::isnan(maxY)) maxY = maxSignal;

    // create data files
    // -----------------
    logStatus<<"create temporary data files"<<Log::endl;
    for(UInt i=0; i<layer.size(); i++)
      layer.at(i)->writeDataFile(plotBasics.workingDirectory, i, minX, maxX, minY, maxY);

    // create scriptfile
    // -----------------
    logStatus<<"create scriptfile"<<Log::endl;
    {
      OutFile file(plotBasics.fileNameScript());
      file<<plotBasics.scriptHeader();
      file<<PlotBasics::scriptSetVariable("range", minX%"%i/"s+maxX%"%i/"s+minY%"%g/"s+maxY%"%g"s)<<std::endl;
      file<<"gmt psbasemap -Y"<<-plotBasics.height-plotBasics.marginTitle<<"c -R"<<PlotBasics::scriptVariable("range");
      file<<" -JX"<<plotBasics.width<<"c"<<((logX) ? "l" : "")<<"/"<<plotBasics.height<<"c"<<((logY) ? "l" : "");
      file<<" -BWSne";
      file<<" -Bx"<<PlotBasics::axisTicks(logX, minX, maxX, annotationX, frameX, gridX, "",    labelX);
      file<<" -By"<<PlotBasics::axisTicks(logY, minY, maxY, annotationY, frameY, gridY, unitY, labelY);
      if(gridLine)
        file<<" --MAP_GRID_PEN_PRIMARY="<<gridLine->str();
      file<<" -O -K >> groopsPlot.ps"<<std::endl;
      for(UInt i=0; i<layer.size(); i++)
        file<<layer.at(i)->scriptEntry();
      if(legend)
      {
        std::vector<std::string> legendText;
        for(UInt i=0; i<layer.size(); i++)
          legendText.push_back(layer.at(i)->legendEntry());

        legend->writeDataFile(plotBasics.workingDirectory, legendText);
        file<<legend->scriptEntry();
        file<<std::endl;
      }
      file<<plotBasics.scriptTrailer();
    } // end scriptfile

    // run scriptfile
    // --------------
    logStatus<<"run scriptfile"<<Log::endl;
    plotBasics.runScript();
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

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