All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes
GeopsyCore::StationSignals Class Reference

#include <StationSignals.h>

Inheritance diagram for GeopsyCore::StationSignals:
StructureStationSignals

List of all members.

Public Types

enum  Component {
  UndefinedComponent = 0, VerticalComponent = 1, HorizontalComponent = 2, AllComponent = 3,
  AnySingleComponent = 7
}

Public Member Functions

bool addSignal (Signal *sig, QString *log=0)
Signal::Components component () const
Components components () const
bool contains (Signal *sig) const
const Pointcoordinates () const
double deltaT () const
SignalfirstValidSignal () const
bool hasAllComponents (QString *log=0) const
SignallastValidSignal () const
double maxTime () const
double minTime () const
QString name () const
QString nameComponent () const
int nComponents () const
const SubSignalPooloriginals (int iComp) const
void setComponents (Components c)
void setKeep (SparseKeepSignal *keep, const WindowingParameters &param, int stationIndex) const
void setSampling (SparseKeepSignal *keep) const
const Pointsource () const
double sourceReceiverAzimuth () const
double sourceReceiverDistance () const
 StationSignals (Components c=UndefinedComponent)
double t0 () const
SparseTimeRange timeRange (const TimeRange &r) const
QDateTime timeReference () const
virtual ~StationSignals ()

Static Public Member Functions

static Signal::Components component (int index, Components c)
static int nComponents (Components c)
static void organizeSubPool (SubSignalPool *subPool)

Protected Attributes

SubSignalPool_signals

Member Enumeration Documentation

Enumerator:
UndefinedComponent 
VerticalComponent 
HorizontalComponent 
AllComponent 
AnySingleComponent 

Constructor & Destructor Documentation

References _signals, nComponents(), TRACE, and UndefinedComponent.

{
  TRACE;
  _components=c;
  if(_components==UndefinedComponent)
    _signals=0;
  else
    _signals=new SubSignalPool[nComponents()];
}

References _signals, and TRACE.

{
  TRACE;
  delete [] _signals;
}

Member Function Documentation

bool GeopsyCore::StationSignals::addSignal ( Signal sig,
QString *  log = 0 
)

Add signal sig to this station. If it is not compatible, it returns false. Compatibility criteria have been almost suppressed with sparse time range. Remains only errors for bad components: when validated, remove the bool (like returns always true).

References _signals, GeopsyCore::SubSignalPool::addSignal(), AllComponent, AnySingleComponent, GeopsyCore::Signal::component(), coordinates(), GeopsyCore::Signal::East, GeopsyCore::DoubleSignal::fastFourierTransform(), HorizontalComponent, GeopsyCore::Signal::id(), name(), GeopsyCore::Signal::North, SAFE_UNINITIALIZED, TRACE, UndefinedComponent, GeopsyCore::Signal::userName(), GeopsyCore::Signal::Vertical, VerticalComponent, and GeopsyCore::DoubleSignal::Waveform.

Referenced by GeopsyCore::StationList::addSignal().

{
  TRACE;
  // Check that deltaT and T0 are compatible, if no reference signal is available, the station
  // is still empty and may accept any signal
  // No longer a mandatory condition: still requires some testing
  /*Signal * refSig=firstValidSignal();
  if(refSig) {
    double refDeltaT=refSig->deltaT();
    if(refDeltaT!=sig->deltaT()) {
      if(log)
        (*log) += tr( "The sampling rate is not compatible (signal id %1).\n" ).arg(sig->id());
      else
        Message::warning(MSG_ID, tr("Adding station %1").arg(sig->name()),
                            tr( "The sampling rate is not compatible (signal id %1)." ).arg(sig->id()),
                            Message::cancel());
      return false;
    }
    double nDeltaT0=fabs(refSig->t0() - sig->t0())/refDeltaT;
    if(nDeltaT0 - round(nDeltaT0) > 0.01 * refDeltaT) {
      if(log)
        (*log) += tr( "The differences between t0s must be a multiple of "
                      "the sampling period (signal id %1).\n" ).arg(sig->id());
      else
        Message::warning(MSG_ID, tr("Adding station %1").arg(sig->name()),
                              tr( "The differences between t0s must be a multiple of "
                                  "the sampling period (signal id %1)." ).arg(sig->id()),
                              Message::cancel());
      return false;
    }
  }*/
  // Identify component index
  int iComp;
  SAFE_UNINITIALIZED(iComp,0);
  switch(_components) {
  case VerticalComponent:
    if(sig->component()!=Signal::Vertical) return false;
    iComp=0;
    break;
  case HorizontalComponent:
    switch(sig->component()) {
    case Signal::North:
      iComp=0;
      break;
    case Signal::East:
      iComp=1;
      break;
    default:
      return false;
    }
    break;
  case AllComponent:
    switch(sig->component()) {
    case Signal::Vertical:
      iComp=0;
      break;
    case Signal::North:
      iComp=1;
      break;
    case Signal::East:
      iComp=2;
      break;
    default:
      return false;
    }
    break;
  case AnySingleComponent:
    iComp=0;
    break;
  case UndefinedComponent:
    return false;
  }
  // Check for overlap in time and insert signal at correct place
  // Overlap is no longer a problem
  SubSignalPool& subPool=_signals[iComp];
  /*for(SubSignalPool::iterator it=subPool.begin(); it!= subPool.end(); it++ ) {
    Signal * sig0=*it;
    if(( sig->t0()<sig0->t0() && sig0->t0()<sig->endTime()) ||
         (sig0->t0()<sig->t0() && sig->t0()<sig0->endTime()) ) {
      if(log)
        ( *log) += tr( "Signals id %1 and id %2 overlap in time.\n" ).
                    arg(sig0->id()).arg(sig->id());
      else
        Message::warning(MSG_ID, tr("Add signal %1").arg(sig->nameComponent()).arg(sig->id()),
                              tr( "Signals id %1 and id %2 overlap in time." ).
                              arg(sig0->id()).arg(sig->id()), Message::cancel());
      return false;
    }
  }*/
  // Make sure signals are in time (needed for signal composition)
  sig->fastFourierTransform(Signal::Waveform);
  subPool.addSignal(sig);
  if(log)
    ( *log) += QString( "Add signal id %1 to component %2 of station %3 at %4\n" )
                .arg(sig->id())
                .arg(Signal::userName(sig->component()) )
                .arg(name())
                .arg(coordinates().toString());
  return true;
}
Signal::Components GeopsyCore::StationSignals::component ( int  index,
Components  c 
) [static]

References AllComponent, AnySingleComponent, GeopsyCore::Signal::East, HorizontalComponent, GeopsyCore::Signal::North, UndefinedComponent, GeopsyCore::Signal::Vertical, and VerticalComponent.

Referenced by GeopsyCore::StationList::addSignal().

{
  switch (c) {
  case VerticalComponent:
    return Signal::Vertical;
  case HorizontalComponent:
    switch (index) {
    case 0: return Signal::North;
    default: return Signal::East;
    }
    break;
  case AllComponent:
    switch (index) {
    case 0: return Signal::Vertical;
    case 1: return Signal::North;
    default: return Signal::East;
    }
    break;
  case AnySingleComponent:
  case UndefinedComponent:
    break;
  }
  return Signal::UndefinedComponent;
}
Components GeopsyCore::StationSignals::components ( ) const [inline]
{return _components;}

Return true if signal sig is one of the original signals of this station

References _signals, nComponents(), and TRACE.

Referenced by MonoStation::AbstractTool::refreshSignal().

{
  TRACE;
  int nComp=nComponents();
  for(int iComp=0; iComp<nComp; iComp++) {
    if(_signals[iComp].contains(sig)) {
      return true;
    }
  }
  return false;
}
const Point & GeopsyCore::StationSignals::coordinates ( ) const [inline]
double GeopsyCore::StationSignals::deltaT ( ) const [inline]
bool GeopsyCore::StationSignals::hasAllComponents ( QString *  log = 0) const

Check that all components are available

References _signals, component(), name(), nComponents(), QGpCoreTools::tr(), TRACE, and GeopsyCore::Signal::userName().

{
  TRACE;
  int nComp=nComponents();
  for(int iComp=0; iComp<nComp; iComp++) {
    if(_signals[iComp].isEmpty()) {
      if(log)
        ( *log) += tr( "Missing %1 component for station %2.\n" )
                    .arg(Signal::userName(component( iComp, _components)) )
                    .arg(name());
      return false;
    }
  }
  return true;
}

References _signals, GeopsyCore::SubSignalPool::last(), nComponents(), and TRACE.

Referenced by GeopsyCore::TimeRangeParameters::absoluteRange().

{
  TRACE;
  int nComp=nComponents();
  for(int iComp=0; iComp<nComp; iComp++) {
    if(!_signals[iComp].isEmpty()) return _signals[iComp].last();
  }
  return 0;
}

Return maximum ending time for all components

References _signals, GeopsyCore::SubSignalPool::begin(), GeopsyCore::SubSignalPool::end(), GeopsyCore::Signal::endTime(), nComponents(), and TRACE.

Referenced by GeopsyGui::ChronogramLayer::boundingRect().

{
  TRACE;
  int nComp=nComponents();
  double t=-1e99;
  for(int iComp=0; iComp<nComp; iComp++) {
    SubSignalPool& subPool=_signals[iComp];
    for(SubSignalPool::iterator it=subPool.begin();it!=subPool.end();it++) {
      Signal * sig=*it;
      if(sig->endTime() > t) t=sig->endTime();
    }
  }
  return t;
}

Return minimum starting time for all components

References _signals, GeopsyCore::SubSignalPool::begin(), GeopsyCore::SubSignalPool::end(), nComponents(), GeopsyCore::Signal::t0(), and TRACE.

Referenced by GeopsyGui::ChronogramLayer::boundingRect().

{
  TRACE;
  int nComp=nComponents();
  double t=1e99;
  for(int iComp=0; iComp<nComp; iComp++) {
    SubSignalPool& subPool=_signals[iComp];
    for(SubSignalPool::iterator it=subPool.begin();it!=subPool.end();it++) {
      Signal * sig=*it;
      if(sig->t0() < t) t=sig->t0();
    }
  }
  return t;
}
QString GeopsyCore::StationSignals::name ( ) const [inline]
QString GeopsyCore::StationSignals::nameComponent ( ) const [inline]

References firstValidSignal(), GeopsyCore::Signal::nameComponent(), and TRACE.

Referenced by SpectrumStation::name(), SpectrumStation::SpectrumStation(), and StructureStation::StructureStation().

{
  TRACE;
  Signal * sig=firstValidSignal();
  return sig ? sig->nameComponent() : QString::null;
}
int GeopsyCore::StationSignals::nComponents ( Components  c) [static]

References AllComponent, AnySingleComponent, HorizontalComponent, TRACE, and VerticalComponent.

{
  TRACE;
  switch (c) {
  case VerticalComponent:
  case AnySingleComponent:
    return 1;
  case HorizontalComponent:
    return 2;
  case AllComponent:
    return 3;
  default:
    return 0;
  }
}
const SubSignalPool& GeopsyCore::StationSignals::originals ( int  iComp) const [inline]

Modify number of components. Never remove components. Always add if necessary.

References _signals, AllComponent, AnySingleComponent, HorizontalComponent, nComponents(), TRACE, UndefinedComponent, and VerticalComponent.

{
  TRACE;
  if(c==_components || c==UndefinedComponent) return;
  switch(_components) {
  case UndefinedComponent:
    _components=c;
    _signals=new SubSignalPool[nComponents()];
    break;
  case VerticalComponent:
    if(c==HorizontalComponent || c==AllComponent) {
      _components=AllComponent;
      SubSignalPool * s=new SubSignalPool[nComponents()];
      s[0]=_signals[0];
      delete [] _signals;
      _signals=s;
    }
    break;
  case HorizontalComponent:
    if(c==VerticalComponent || c==AllComponent) {
      _components=AllComponent;
      SubSignalPool * s=new SubSignalPool[nComponents()];
      s[1]=_signals[0];
      s[2]=_signals[1];
      delete [] _signals;
      _signals=s;
    }
    break;
  case AnySingleComponent:
  case AllComponent:
    break;
  }
}
void GeopsyCore::StationSignals::setKeep ( SparseKeepSignal keep,
const WindowingParameters param,
int  stationIndex 
) const

Values of keep are initially all to 1. This function toogles them to 0 if param conditions are not satisfied.

References GeopsyCore::DoubleSignal::abs(), GeopsyCore::WindowingParameters::badSampleThreshold(), GeopsyCore::SubSignalPool::begin(), GeopsyCore::DoubleSignal::clipMaxToKeep(), GeopsyCore::DoubleSignal::copySamplesFrom(), GeopsyCore::WindowingParameters::ShortLongTermAverage::enabled, GeopsyCore::SubSignalPool::end(), GeopsyCore::DoubleSignal::filter(), GeopsyCore::WindowingParameters::filter(), GeopsyCore::WindowingParameters::filterComponent(), GeopsyCore::WindowingParameters::filterSignalAntiTrigger(), GeopsyCore::WindowingParameters::filterStation(), GeopsyCore::SparseKeepSignal::keeps(), nComponents(), originals(), GeopsyCore::SparseTimeRange::range(), GeopsyCore::WindowingParameters::rawComponent(), GeopsyCore::WindowingParameters::rawSignalAntiTrigger(), GeopsyCore::WindowingParameters::rawStation(), GeopsyCore::DoubleSignal::staltaToKeep(), GeopsyCore::KeepSignal::t0(), GeopsyCore::Signal::t0(), GeopsyCore::Signal::timeRange(), and TRACE.

{
  TRACE;
  int nComp=nComponents();
  for(int iComp=0; iComp<nComp; iComp++) {
    const SubSignalPool& subPool=originals(iComp);
    for(SubSignalPool::const_iterator itSig=subPool.begin();itSig!=subPool.end(); ++itSig) {
      const Signal * sig=*itSig;
      QVector<KeepSignal *> keeps=keep->keeps(sig->timeRange().range());
      for(QVector<KeepSignal *>::iterator itKeep=keeps.begin(); itKeep!=keeps.end(); itKeep++) {
        KeepSignal * keepSig=*itKeep;
        double delay=sig->t0()-keepSig->t0();
          if(param.rawSignalAntiTrigger().enabled &&
             param.rawComponent(iComp) &&
             param.rawStation(stationIndex)) {
          DoubleSignal * tempsig=new DoubleSignal( *sig);
          tempsig->copySamplesFrom(sig);
          tempsig->abs();
          tempsig->staltaToKeep(param.rawSignalAntiTrigger(), keepSig, delay);
          delete tempsig;
        }
        if(param.filterSignalAntiTrigger().enabled &&
           param.filterComponent(iComp) &&
           param.filterStation(stationIndex)) {
          DoubleSignal * tempsig=new DoubleSignal( *sig);
          tempsig->copySamplesFrom(sig);
          tempsig->filter(param.filter());
          tempsig->abs();
          tempsig->staltaToKeep(param.filterSignalAntiTrigger(), keepSig, delay);
          delete tempsig;
        }
        if(param.badSampleThreshold()<100.0) {
          sig->clipMaxToKeep((double) param.badSampleThreshold(), keepSig, delay);
        }
      }
    }
  }
}

Check sampling in all sub-ranges. In case of incompatibilities, discard the sub-ranges.

References GeopsyCore::SubSignalPool::begin(), GeopsyCore::DoubleSignal::deltaT(), GeopsyCore::TimeRange::end(), GeopsyCore::SubSignalPool::end(), QGpCoreTools::endl(), name(), nComponents(), originals(), GeopsyCore::SparseTimeRange::range(), GeopsyCore::SparseKeepSignal::remove(), GeopsyCore::SparseKeepSignal::setSampling(), GeopsyCore::TimeRange::start(), GeopsyCore::Signal::timeRange(), QGpCoreTools::tr(), and TRACE.

{
  TRACE;
  int nComp=nComponents();
  for(int iComp=0; iComp<nComp; iComp++) {
    const SubSignalPool& subPool=originals(iComp);
    for(SubSignalPool::const_iterator itSig=subPool.begin();itSig!=subPool.end();++itSig) {
      const Signal * sig=*itSig;
      TimeRange r=sig->timeRange().range();
      if(!keep->setSampling(r, sig->deltaT())) {
        App::stream() << tr("Station '%1': incompatible sampling from %2 to %3 s, skipping range")
                     .arg(name()).arg(r.start()).arg(r.end()) << endl;
        keep->remove(r);
      }
    }
  }
}
const Point & GeopsyCore::StationSignals::source ( ) const [inline]

References firstValidSignal(), and GeopsyCore::Signal::source().

{
  static Point dummy;
  Signal * sig=firstValidSignal();
  return sig ? sig->source() : dummy;
}

References firstValidSignal(), GeopsyCore::Signal::sourceReceiverAzimuth(), and TRACE.

{
  TRACE;
  Signal * sig=firstValidSignal();
  return sig ? sig->sourceReceiverAzimuth() : 0.0;
}

References firstValidSignal(), GeopsyCore::Signal::sourceReceiverDistance(), and TRACE.

{
  TRACE;
  Signal * sig=firstValidSignal();
  return sig ? sig->sourceReceiverDistance() : 0.0;
}
double GeopsyCore::StationSignals::t0 ( ) const [inline]

References firstValidSignal(), GeopsyCore::Signal::t0(), and TRACE.

{
  TRACE;
  Signal * sig=firstValidSignal();
  return sig ? sig->t0() : 0.0;
}

Get the range where all components are available

References GeopsyCore::SparseTimeRange::add(), GeopsyCore::SubSignalPool::begin(), GeopsyCore::SubSignalPool::end(), GeopsyCore::SparseTimeRange::intersection(), nComponents(), originals(), and TRACE.

{
  TRACE;
  SparseTimeRange globalRange(r);
  int nComp=nComponents();
  for(int iComp=0; iComp<nComp; iComp++) {
    const SubSignalPool& subPool=originals(iComp);
    SparseTimeRange compRange;
    for(SubSignalPool::const_iterator itSig=subPool.begin();itSig!=subPool.end();++itSig) {
      compRange.add((*itSig)->timeRange(), false);
    }
    globalRange=globalRange.intersection(compRange);
  }
  return globalRange;
}
QDateTime GeopsyCore::StationSignals::timeReference ( ) const [inline]

References firstValidSignal(), GeopsyCore::Signal::timeReference(), and TRACE.

{
  TRACE;
  Signal * sig=firstValidSignal();
  return sig ? sig->timeReference() : QDateTime();
}

Member Data Documentation


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines