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

revision of gap analysis:

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.
breaks in contiguous data without missing samples are now correctly
handled as a sperate conidtion
still to be resolved: gap analysis now always produces at least one
break


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 4677
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent c461ce09
......@@ -64,6 +64,7 @@
* - 02/03/2012 V1.20 include auxid when distinguishing streams
* - 26/03/2012 V1.21 ilist -> iinlist (used the same name twice)
* - 24/04/2012 V1.22 removed misleading help line
* - 25/04/2012 V1.23 correctly set latesttime
*
* TODO:
* * properly handle cases in which the output format can take only single
......@@ -76,7 +77,7 @@
*/
#define ANYEXTRACT_VERSION \
"ANYEXTRACT V1.21 extract data files, using index file"
"ANYEXTRACT V1.23 extract data files, using index file"
#define ANYEXTRACT_CVSID \
"$Id$"
......@@ -87,13 +88,13 @@
#include <string>
#include <sstream>
#include <aff/seriesoperators.h>
#include <tfxx/misc.h>
#include <tfxx/commandline.h>
#include <tfxx/stringfunc.h>
#include <tfxx/error.h>
#include <datrwxx/tracereader.h>
#include <libtime++.h>
#include <tfxx/regexx.h>
#include <tfxx/misc.h>
#include <datrwxx/formats.h>
#include <datrwxx/error.h>
#include <datrwxx/writeany.h>
......@@ -1585,7 +1586,7 @@ int main(int iargc, char* argv[])
if (itrace==0)
{
if (!opt.firstset) { earliesttime=tracewid2.date; }
if (!opt.lastset) { latesttime=tracewid2.date; }
if (!opt.lastset) { latesttime=lastdate; }
}
else
{
......
......@@ -30,11 +30,12 @@
*
* REVISIONS and CHANGES
* - 12/02/2012 V1.0 Thomas Forbriger
* - 25/04/2012 V1.1 collect breaks too
*
* ============================================================================
*/
#define TF_FNGAPS_CC_VERSION \
"TF_FNGAPS_CC V1.0 "
"TF_FNGAPS_CC V1.1"
#define TF_FNGAPS_CC_CVSID \
"$Id$"
......@@ -49,6 +50,10 @@ Tvecofgaps gaps(const libtime::TAbsoluteTime& earliest,
const TContiguouslist& cl,
const bool& debug)
{
TFXX_debug(debug, "gaps()", "received values: " <<
TFXX_value(earliest.timestring()));
TFXX_debug(debug, "gaps()", "received values: " <<
TFXX_value(latest.timestring()));
/*
* The word "stream" here refers to a "data stream" i.e. data comming from
* the same source as indicated by parameters like channel, station, auxid,
......@@ -107,12 +112,10 @@ Tvecofgaps gaps(const libtime::TAbsoluteTime& earliest,
TFXX_debug(debug, "gaps()", "new gap (not yet adjusted): "
<< TFXX_value(newgap));
if (newgap.last>=newgap.first)
{
stream[istream].gap.push_back(newgap);
TFXX_debug(debug, "gaps()", "pushed back gap of finite size "
<< TFXX_value(newgap));
}
stream[istream].gap.push_back(newgap);
TFXX_debug(debug, "gaps()", "pushed back gap of finite size "
<< TFXX_value(newgap));
// check if this is the last entry for this stream
bool lastofstream=false;
......
......@@ -30,11 +30,12 @@
*
* REVISIONS and CHANGES
* - 12/02/2012 V1.0 Thomas Forbriger
* - 25/04/2012 V1.1 properly distinguish between gaps and breaks
*
* ============================================================================
*/
#define TF_FNPRINTGAPS_CC_VERSION \
"TF_FNPRINTGAPS_CC V1.0 "
"TF_FNPRINTGAPS_CC V1.1"
#define TF_FNPRINTGAPS_CC_CVSID \
"$Id$"
......@@ -46,6 +47,7 @@ void printgaps(std::ostream& os, const Tvecofgaps& vog,
{
if (lev<3) { os << "gaps present in input data:\n"; }
unsigned int ntotalgaps=0;
unsigned int ntotalbreaks=0;
unsigned int ntotalmissing=0;
unsigned int ntotalexpected=0;
libtime::TRelativeTime ttotalexpected(0);
......@@ -61,15 +63,19 @@ void printgaps(std::ostream& os, const Tvecofgaps& vog,
// J!=I->gap.end(); ++J)
Gapsummary summary=I->summarize();
// os << "DEBUG: I->mearliest.timestring(): " << I->Mearliest.timestring() << std::endl;
// os << "DEBUG: I->mlatest.timestring(): " << I->Mlatest.timestring() << std::endl;
ntotalgaps += summary.ngaps;
ntotalbreaks += summary.nbreaks;
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 << " number of breaks / number of gaps / number of missing samples / completeness:\n";
os << " " << summary.nbreaks << " / ";
os << summary.ngaps << " / ";
os << summary.nmissing << " / ";
double tspan=libtime::time2double(summary.tspan);
double tmissing=libtime::time2double(summary.tmissing);
......@@ -84,7 +90,8 @@ void printgaps(std::ostream& os, const Tvecofgaps& vog,
if (lev<3)
{
os << "summary of entire analysis:\n";
os << "number of gaps / number of missing samples / completeness:\n";
os << "number of breaks / number of gaps / number of missing samples / completeness:\n";
os << ntotalbreaks << " / ";
os << ntotalgaps << " / ";
os << ntotalmissing << " / ";
os << static_cast<double>(completeness)*1.e-2 << "%\n";
......
......@@ -30,11 +30,12 @@
*
* REVISIONS and CHANGES
* - 12/02/2012 V1.0 Thomas Forbriger
* - 25/04/2012 V1.1 do not process breaks in contiguous data
*
* ============================================================================
*/
#define TF_FNSERIESOFMISSINGSAMPLES_CC_VERSION \
"TF_FNSERIESOFMISSINGSAMPLES_CC V1.0 "
"TF_FNSERIESOFMISSINGSAMPLES_CC V1.1"
#define TF_FNSERIESOFMISSINGSAMPLES_CC_CVSID \
"$Id$"
......@@ -62,65 +63,69 @@ GapSeries seriesofmissingsamples(const Gapsofstream& gos,
const libtime::TAbsoluteTime& first=G->first;
const libtime::TAbsoluteTime& last=G->last;
libtime::TAbsoluteTime current=first;
for (unsigned int i=0; i<cb.nbins(); ++i)
// do not process if this gaps actually is a break
if (!G->isbreak())
{
TFXX_debug(debug, "seriesofmissingsamples",
"bin #" << i << ": "
<< cb.bin(i).timestring() << " - "
<< cb.nextbin(i).timestring());
TFXX_debug(debug, "seriesofmissingsamples",
" current: " << current.timestring());
if (cb.isinbin(current, i))
for (unsigned int i=0; i<cb.nbins(); ++i)
{
TFXX_debug(debug, "seriesofmissingsamples",
"is in bin " << i << ": " << current.timestring());
libtime::TAbsoluteTime nextbin=cb.nextbin(i);
"bin #" << i << ": "
<< cb.bin(i).timestring() << " - "
<< cb.nextbin(i).timestring());
TFXX_debug(debug, "seriesofmissingsamples",
TFXX_value(nextbin.timestring()) << " " <<
TFXX_value(last.timestring()));
if (nextbin<=last)
" current: " << current.timestring());
if (cb.isinbin(current, i))
{
unsigned int n=(nextbin-current)/dt;
while ((current+n*dt)<nextbin)
{
TFXX_debug(debug, "seriesofmissingsamples",
"is in bin " << i << ": " << current.timestring());
libtime::TAbsoluteTime nextbin=cb.nextbin(i);
TFXX_debug(debug, "seriesofmissingsamples",
TFXX_value(nextbin.timestring()) << " " <<
TFXX_value(last.timestring()));
if (nextbin<=last)
{
unsigned int n=(nextbin-current)/dt;
while ((current+n*dt)<nextbin)
{
TFXX_debug(debug, "seriesofmissingsamples",
"n: " << n <<
" (current+n*dt): " <<
libtime::TAbsoluteTime(current+n*dt).timestring() <<
" nextbin: " << nextbin.timestring());
++n;
}
TFXX_debug(debug, "seriesofmissingsamples",
"n: " << n <<
" (current+n*dt): " <<
libtime::TAbsoluteTime(current+n*dt).timestring() <<
" nextbin: " << nextbin.timestring());
++n;
retseries.gapseries(i) += n;
current += n*dt;
}
TFXX_debug(debug, "seriesofmissingsamples",
"n: " << n <<
" (current+n*dt): " <<
libtime::TAbsoluteTime(current+n*dt).timestring() <<
" nextbin: " << nextbin.timestring());
retseries.gapseries(i) += n;
current += n*dt;
}
else
{
unsigned int n=(last-current)/dt;
while ((current+n*dt)<=last)
{
else
{
unsigned int n=(last-current)/dt;
while ((current+n*dt)<=last)
{
TFXX_debug(debug, "seriesofmissingsamples",
"n: " << n <<
" (current+n*dt): " <<
libtime::TAbsoluteTime(current+n*dt).timestring() <<
" last: " << last.timestring());
++n;
}
TFXX_debug(debug, "seriesofmissingsamples",
"n: " << n <<
" (current+n*dt): " <<
libtime::TAbsoluteTime(current+n*dt).timestring() <<
" last: " << last.timestring());
++n;
retseries.gapseries(i) += n;
// no need to cycle further
i=cb.nbins();
}
TFXX_debug(debug, "seriesofmissingsamples",
"n: " << n <<
" (current+n*dt): " <<
libtime::TAbsoluteTime(current+n*dt).timestring() <<
" last: " << last.timestring());
retseries.gapseries(i) += n;
// no need to cycle further
i=cb.nbins();
}
} // if (cb.isinbin(current, i))
} // end of loop over bins
} // if (cb.isinbin(current, i))
} // end of loop over bins
} // if (last >= first)
} // end of loop over gaps in gos
if (debug)
{
......
......@@ -30,11 +30,12 @@
*
* REVISIONS and CHANGES
* - 12/02/2012 V1.0 Thomas Forbriger
* - 25/04/2012 V1.1 properly distinguish between braeks and gaps
*
* ============================================================================
*/
#define TF_STRUCTGAPANALYSIS_CC_VERSION \
"TF_STRUCTGAPANALYSIS_CC V1.0 "
"TF_STRUCTGAPANALYSIS_CC V1.1"
#define TF_STRUCTGAPANALYSIS_CC_CVSID \
"$Id$"
......@@ -45,10 +46,10 @@
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())
{
if (I->isbreak()) { ++retval.nbreaks; } else { ++retval.ngaps; }
retval.nmissing += I->nmissing();
retval.tmissing += I->tmissing();
++I;
......@@ -81,13 +82,20 @@ std::ostream& operator<<(std::ostream& os, const Contiguous& chunk)
//! print gaps
std::ostream& operator<<(std::ostream& os, const Gap& gap)
{
os << " " << gap.first.timestring()
<< " - " << gap.last.timestring() << "\n";
os << " " << gap.first.timestring();
if (gap.isbreak())
{
os << ": break in contiguous data\n";
}
else
{
os << " - " << gap.last.timestring() << "\n";
}
unsigned int nmissing=(gap.ID.dt+gap.last-gap.first)/gap.ID.dt;
os << " "
<< ": " << nmissing
<< " sample";
if (nmissing>1) { os << "s are"; } else { os << " is"; }
if (nmissing!=1) { os << "s are"; } else { os << " is"; }
os << " missing";
return(os);
} // std::ostream& operator<<(std::ostream& os, const Gap& gap)^
......
......@@ -30,6 +30,7 @@
*
* REVISIONS and CHANGES
* - 12/02/2012 V1.0 Thomas Forbriger
* - 25/04/2012 V1.1 distinguish between breaks and gaps
*
* ============================================================================
*/
......@@ -38,7 +39,7 @@
#ifndef TF_STRUCTGAPANALYSIS_H_VERSION
#define TF_STRUCTGAPANALYSIS_H_VERSION \
"TF_STRUCTGAPANALYSIS_H V1.0 "
"TF_STRUCTGAPANALYSIS_H V1.1"
#define TF_STRUCTGAPANALYSIS_H_CVSID \
"$Id$"
......@@ -91,24 +92,46 @@ struct Gapid {
std::string Mstation, Mchannel, Mauxid;
}; // 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); }
// true, if no sample is missing (just a break in contiguous data)
bool isbreak() const { return (last<=(first+ID.dt)); }
// time span from first missing sample to last missing sample + one sample
// interval (represents gaps size in terms of missing sample intervals)
libtime::TRelativeTime tmissing() const
{
libtime::TRelativeTime retval(0);
if (!this->isbreak()) { retval=last-first+ID.dt; }
return(retval);
}
// number of missing samples, taking irregular sampling into account
unsigned int nmissing() const
{
unsigned int retval=0;
if (!this->isbreak()) { retval=(this->tmissing()+(ID.dt/2))/ID.dt; }
return retval;
}
// data
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)),
: ngaps(0), nbreaks(0), nmissing(0), nexpected(1+((latest-earliest)/indt)),
tspan(latest-earliest), tmissing(0), dt(indt)
{ }
//! total number of gaps
unsigned int ngaps;
//! total number of breaks
unsigned int nbreaks;
//! number of missing samples
unsigned int nmissing;
//! number of expected samples
......@@ -121,6 +144,8 @@ struct Gapsummary {
libtime::TRelativeTime dt;
}; // struct Gapsummary
/*----------------------------------------------------------------------*/
//! struct to hold gaps of one stream
struct Gapsofstream {
typedef std::vector<Gap> Tvecofgap;
......@@ -128,7 +153,9 @@ struct Gapsofstream {
const libtime::TAbsoluteTime& earliest,
const libtime::TAbsoluteTime& latest)
: ID(id), Mearliest(earliest), Mlatest(latest)
{ this->gap.clear(); }
{
this->gap.clear();
}
//! \brief provide a summary for this stream
Gapsummary summarize() const;
Gapid ID;
......@@ -138,6 +165,8 @@ struct Gapsofstream {
libtime::TAbsoluteTime Mlatest;
}; // struct Gapsofstream
/*----------------------------------------------------------------------*/
//! vector to hold all gaps
typedef std::vector<Gapsofstream> Tvecofgaps;
......
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