Commit 6503d8c5 authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

gap summary with different report levels is implemented

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 4553
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 35cbe0b3
......@@ -59,6 +59,7 @@
* - 30/01/2012 V1.16m implemented completeness time series
* - 13/02/2012 V1.17 gap and completeness series is implemented and
* tested
* - 14/02/2012 V1.18 provide gap summary
*
* TODO:
* * properly handle cases in which the output format can take only single
......@@ -71,7 +72,7 @@
*/
#define ANYEXTRACT_VERSION \
"ANYEXTRACT V1.17 extract data files, using index file"
"ANYEXTRACT V1.18 extract data files, using index file"
#define ANYEXTRACT_CVSID \
"$Id$"
......@@ -124,6 +125,7 @@ struct Options {
bool printgaps;
std::string gapoutputfile;
std::string binsize;
unsigned int summarizelevel;
}; // struct Options
/*----------------------------------------------------------------------*/
......@@ -362,7 +364,7 @@ int main(int iargc, char* argv[])
" [-RANGECHECK]\n"
"gap options are:\n"
" [-GAPFIND] [-Ggs f] [-Gcs f] [-Gprint[=file]]" "\n"
" [-Gbin s]" "\n"
" [-Gbin s] [-Gsummarize l]" "\n"
};
// define help text
......@@ -457,6 +459,12 @@ int main(int iargc, char* argv[])
" -Ggc f gap distribution will be written to file \"f\"\n"
" -Gprint[=f] print a list of gaps to stdout\n"
" if \"f\" is defined, write this list to file \"f\"\n"
" -Gsummarize l set summerize level for -Gprint to \"l\"\n"
" l=0: print complete report (default)\n"
" l=1: summarize results for each stream\n"
" l=2: summarize total results only\n"
" l=3: just output total number of gaps\n"
" l=4: just output total number of missing samples\n"
};
// define extended help text
......@@ -550,6 +558,8 @@ int main(int iargc, char* argv[])
{"Ggs",arg_yes,"-"},
// 28: write completeness time series to file
{"Gcs",arg_yes,"-"},
// 29: set summarize level
{"Gsummarize",arg_yes,"0"},
{NULL}
};
......@@ -626,6 +636,7 @@ int main(int iargc, char* argv[])
opt.gapseriesfile=cmdline.string_arg(27);
opt.writecompleteness=cmdline.optset(28);
opt.completenessseriesfile=cmdline.string_arg(28);
opt.summarizelevel=static_cast<unsigned int>(cmdline.int_arg(29));
// is any of the GAP analysis modes activated
bool doGAPanalysis=opt.findgapsonly
......@@ -666,8 +677,12 @@ int main(int iargc, char* argv[])
if (doGAPanalysis)
{
infiles.push_back(outfile);
cout << "SPECIAL MODE: find gaps in input data - do not extract data"
<< endl;
if (opt.verbose || (opt.summarizelevel < 3))
{
cout << "SPECIAL MODE: find gaps in input data - do not extract data"
<< endl;
}
}
else
{
......@@ -1443,6 +1458,11 @@ int main(int iargc, char* argv[])
libtime::TAbsoluteTime latesttime=opt.last;
TContiguouslist contiguouslist;
if (opt.verbose || (opt.summarizelevel < 3))
{
cout << "chunks of contiguous data:" << std::endl;
}
// cycle through traces
for (unsigned int itrace=0; itrace<trace.size(); ++itrace)
{
......@@ -1475,10 +1495,13 @@ int main(int iargc, char* argv[])
}
// report block
libtime::TAbsoluteTime lastdate=sff::wid2lastsample(tracewid2);
cout << tracewid2.station << " " << tracewid2.channel << " "
<< tracewid2.auxid << " "
<< tracewid2.date.timestring().substr(4,26) << " - "
<< lastdate.timestring().substr(4,26) << std::endl;
if (opt.verbose || (opt.summarizelevel < 3))
{
cout << tracewid2.station << " " << tracewid2.channel << " "
<< tracewid2.auxid << " "
<< tracewid2.date.timestring().substr(4,26) << " - "
<< lastdate.timestring().substr(4,26) << std::endl;
}
// finished reading, write now
if (opt.verbose)
{
......@@ -1538,12 +1561,12 @@ int main(int iargc, char* argv[])
datrw::abort_if_exists(opt.gapoutputfile);
}
std::ofstream os(opt.gapoutputfile.c_str());
printgaps(os, vecofgaps);
printgaps(os, vecofgaps, opt.summarizelevel);
}
else
{
std::cout << std::endl;
printgaps(std::cout, vecofgaps);
printgaps(std::cout, vecofgaps, opt.summarizelevel);
}
} // if (opt.printgaps)
......
......@@ -88,8 +88,8 @@ Tvecofgaps gaps(const libtime::TAbsoluteTime& earliest,
// initialize new stream if required and find time of last existing sample
if (firstofstream)
{
Gapsofstream newgaps;
newgaps.ID=currentid;
Gapsofstream newgaps(currentid, earliest, latest);
// newgaps.ID=currentid;
stream.push_back(newgaps);
istream=stream.size()-1;
lastexisting=earliest-currentid.dt;
......
......@@ -39,20 +39,59 @@
"$Id$"
#include "gapfunctions.h"
#include <tfxx/misc.h>
void printgaps(std::ostream& os, const Tvecofgaps& vog)
void printgaps(std::ostream& os, const Tvecofgaps& vog,
const unsigned int& lev)
{
os << "gaps present in input data:\n";
if (lev<3) { os << "gaps present in input data:\n"; }
unsigned int ntotalgaps=0;
unsigned int ntotalmissing=0;
unsigned int ntotalexpected=0;
libtime::TRelativeTime ttotalexpected(0);
libtime::TRelativeTime ttotalmissing(0);
for (Tvecofgaps::const_iterator I=vog.begin(); I!=vog.end(); ++I)
{
os << "stream: " << I->ID << std::endl;
for (std::vector<Gap>::const_iterator J=I->gap.begin();
if (lev<2) { os << "stream: " << I->ID << std::endl; }
for (Gapsofstream::Tvecofgap::const_iterator J=I->gap.begin();
J!=I->gap.end(); ++J)
{
os << *J << std::endl;
} // for (std::vector<Gap>::const_iterator J=I->gap.begin();
if (lev<1) { os << *J << std::endl; }
} // for (Gapsofstream::Tvecofgap::const_iterator J=I->gap.begin();
// J!=I->gap.end(); ++J)
Gapsummary summary=I->summarize();
ntotalgaps += summary.ngaps;
ntotalmissing += summary.nmissing;
ntotalexpected += summary.nexpected;
ttotalexpected += summary.tspan;
ttotalmissing += summary.tmissing;
if (lev<2)
{
os << " number of gaps / number of missing samples / completeness:\n";
os << " " << summary.ngaps << " / ";
os << summary.nmissing << " / ";
double tspan=libtime::time2double(summary.tspan);
double tmissing=libtime::time2double(summary.tmissing);
int completeness=nearbyint(1.e4*(1.-(tmissing/tspan)));
os << static_cast<double>(completeness)*1.e-2 << "%\n";
}
} // for (Tvecofgaps::const_iterator I=vog.begin(); I!=vog.end(); ++I)
double tspan=libtime::time2double(ttotalexpected);
double tmissing=libtime::time2double(ttotalmissing);
int completeness=nearbyint(1.e4*(1.-(tmissing/tspan)));
if (lev<3)
{
os << "summary of entire analysis:\n";
os << "number of gaps / number of missing samples / completeness:\n";
os << ntotalgaps << " / ";
os << ntotalmissing << " / ";
os << static_cast<double>(completeness)*1.e-2 << "%\n";
}
if (lev==3) { os << ntotalgaps << std::endl; }
if (lev==4) { os << ntotalmissing << std::endl; }
} // void printgaps(std::ostream& os, const Tvecofgaps& vog)
/* ----- END OF fnprintgaps.cc ----- */
......@@ -53,7 +53,8 @@ Tvecofgaps gaps(const libtime::TAbsoluteTime& earliest,
const TContiguouslist& cl,
const bool& debug=false);
void printgaps(std::ostream& os, const Tvecofgaps& vog);
void printgaps(std::ostream& os, const Tvecofgaps& vog,
const unsigned int& summarizelevel=0);
CompletenessSeries completeness(const GapSeries& gs,
const bool& debug=false);
......
......@@ -39,7 +39,25 @@
"$Id$"
#include "structgapanalysis.h"
/*----------------------------------------------------------------------*/
Gapsummary Gapsofstream::summarize() const
{
Gapsummary retval(this->Mearliest, this->Mlatest, this->ID.dt);
retval.ngaps=this->gap.size();
Tvecofgap::const_iterator I=gap.begin();
while (I!=gap.end())
{
retval.nmissing += I->nmissing();
retval.tmissing += I->tmissing();
++I;
}
return(retval);
} // Gapsummary Gapsofstream::summarize() const
/*----------------------------------------------------------------------*/
//! print stream ID
std::ostream& operator<<(std::ostream& os, const Gapid& id)
{
......@@ -47,6 +65,8 @@ std::ostream& operator<<(std::ostream& os, const Gapid& id)
return(os);
} // std::ostream& operator<<(std:ostream& os, const Gapid& id)
/*----------------------------------------------------------------------*/
//! print contiguous chunk definition
std::ostream& operator<<(std::ostream& os, const Contiguous& chunk)
{
......@@ -56,6 +76,8 @@ std::ostream& operator<<(std::ostream& os, const Contiguous& chunk)
return(os);
} // std::ostream& operator<<(std:ostream& os, const Contiguous& chunk)
/*----------------------------------------------------------------------*/
//! print gaps
std::ostream& operator<<(std::ostream& os, const Gap& gap)
{
......
......@@ -93,15 +93,49 @@ struct Gapid {
//! struct to hold one gap
struct Gap {
libtime::TRelativeTime tmissing() const { return(last-first+ID.dt); }
unsigned int nmissing() const { return(this->tmissing()/ID.dt); }
libtime::TAbsoluteTime first, last;
Gapid ID;
}; // struct Gap
//! struct to present a summary
struct Gapsummary {
Gapsummary(const libtime::TAbsoluteTime& earliest,
const libtime::TAbsoluteTime& latest,
const libtime::TRelativeTime& indt)
: ngaps(0), nmissing(0), nexpected(1+((latest-earliest)/indt)),
tspan(latest-earliest), tmissing(0), dt(indt)
{ }
//! total number of gaps
unsigned int ngaps;
//! number of missing samples
unsigned int nmissing;
//! number of expected samples
unsigned int nexpected;
//! time span of analysis
libtime::TRelativeTime tspan;
//! time span not covered with samples
libtime::TRelativeTime tmissing;
//! sampling interval
libtime::TRelativeTime dt;
}; // struct Gapsummary
//! struct to hold gaps of one stream
struct Gapsofstream {
typedef std::vector<Gap> Tvecofgap;
Gapsofstream(const Gapid& id,
const libtime::TAbsoluteTime& earliest,
const libtime::TAbsoluteTime& latest)
: ID(id), Mearliest(earliest), Mlatest(latest)
{ this->gap.clear(); }
//! \brief provide a summary for this stream
Gapsummary summarize() const;
Gapid ID;
Tvecofgap gap;
private:
libtime::TAbsoluteTime Mearliest;
libtime::TAbsoluteTime Mlatest;
}; // struct Gapsofstream
//! vector to hold all gaps
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment