예제 #1
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool AmplitudeProcessor::computeNoise(const DoubleArray &data, int i1, int i2, double *offset, double *amplitude) {
	// compute offset and rms within the time window
	if(i1<0) i1=0;
	if(i2<0) return false;
	if(i2>(int)data.size()) i2=(int)data.size();

	// If noise window is zero return an amplitude and offset of zero as well.
	if ( i2-i1 == 0 ) {
		*amplitude = 0;
		*offset = 0;
		return true;
	}

	DoubleArrayPtr d = static_cast<DoubleArray*>(data.slice(i1, i2));

	double ofs, amp;

	// compute pre-arrival offset
	ofs = d->median();
	// compute rms after removing offset
	amp = 2 * d->rms(ofs);

	if ( offset ) *offset = ofs;
	if ( amplitude ) *amplitude = amp;

	return true;
}
예제 #2
0
파일: Mjma.cpp 프로젝트: palminn/seiscomp3
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool AmplitudeProcessor_Mjma::deconvolveData(Response *resp,
                                             DoubleArray &data,
                                             int numberOfIntegrations) {
	Math::Restitution::FFT::TransferFunctionPtr tf =
		resp->getTransferFunction(numberOfIntegrations);

	if ( tf == NULL ) {
		setStatus(DeconvolutionFailed, 0);
		return false;
	}

	
	Math::SeismometerResponse::Seismometer5sec paz(Math::Velocity);
	Math::Restitution::FFT::PolesAndZeros seis5sec(paz);

	Math::Restitution::FFT::TransferFunctionPtr cascade =
		*tf / seis5sec;

	// Remove linear trend
	double m,n;
	Math::Statistics::computeLinearTrend(data.size(), data.typedData(), m, n);
	Math::Statistics::detrend(data.size(), data.typedData(), m, n);

	return Math::Restitution::transformFFT(data.size(), data.typedData(),
	                                         _stream.fsamp, cascade.get(),
	                                         _config.respTaper, _config.respMinFreq, _config.respMaxFreq);
}
예제 #3
0
/*!
	Updates the ImageView and the ParameterSelector associated
	with the given panel.
*/
void VideoParserWindow::UpdatePanel(VideoControlPanel* pPanel, int sel, 
		DoubleArray params, bool checkViewSync)
{
	// Get the potentially new parameter range from the component
	DoubleArray minVals, maxVals, steps;

	m_videoProcessor.GetParameterInfo(sel, &minVals, &maxVals, &steps);

	// Ensure that the current parameters are within the "new" ranges
	if (params.size() == minVals.size())
	{
		for (unsigned i = 0; i < params.size(); i++)
		{
			if (params[i] > maxVals[i])
				params[i] = maxVals[i];

			if (params[i] < minVals[i])
				params[i] = minVals[i];
		}
	}
	else
	{
		params = minVals;
	}

	// Update the selected view with the new image
	UpdateImageView(pPanel, sel, params, checkViewSync);

	// Update the displayed parameter value and range
	pPanel->GetParamSelector()->Update(params, minVals, maxVals, steps);

	pPanel->GetCommandSelector()->UpdateCommands(
		m_videoProcessor.GetUserCommands(sel));
}
예제 #4
0
파일: md.cpp 프로젝트: aemanov/seiscomp3
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool AmplitudeProcessor_Md::deconvolveData(Response* resp,
                                           DoubleArray& data,
                                           int numberOfIntegrations) {
	if ( numberOfIntegrations < -1 )
		return false;

	SEISCOMP_DEBUG("Inside deconvolve function");

	double m, n;
	Math::Restitution::FFT::TransferFunctionPtr tf =
		resp->getTransferFunction(numberOfIntegrations < 0 ? 0 : numberOfIntegrations);

	if ( !tf )
		return false;

	Math::GroundMotion gm;

	if ( numberOfIntegrations < 0 )
		gm = Math::Displacement;
	else
		gm = Math::Velocity;

	Math::Restitution::FFT::TransferFunctionPtr cascade;
	Math::SeismometerResponse::WoodAnderson woodAndersonResp(gm, _config.woodAndersonResponse);
	Math::SeismometerResponse::Seismometer5sec seis5sResp(gm);
	Math::SeismometerResponse::L4C_1Hz l4c1hzResp(gm);

	Math::Restitution::FFT::PolesAndZeros woodAnderson(woodAndersonResp);
	Math::Restitution::FFT::PolesAndZeros seis5sec(seis5sResp);
	Math::Restitution::FFT::PolesAndZeros l4c1hz(l4c1hzResp);

	SEISCOMP_DEBUG("SEISMO = %d", aFile.SEISMO);

	switch ( aFile.SEISMO ) {
		case 1:
			cascade = *tf / woodAnderson;
		break;
		case 2:
			cascade = *tf / seis5sec;
		break;
		case 9:
			SEISCOMP_INFO("%s Applying filter L4C 1Hz to data", AMPTAG);
			cascade = *tf / l4c1hz;
		break;
		default:
			cascade = tf;
			SEISCOMP_INFO("%s No seismometer specified, no signal reconvolution performed", AMPTAG);
			return false;
		break;
	}

	// Remove linear trend
	Math::Statistics::computeLinearTrend(data.size(), data.typedData(), m, n);
	Math::Statistics::detrend(data.size(), data.typedData(), m, n);

	return Math::Restitution::transformFFT(data.size(), data.typedData(),
	    _stream.fsamp, cascade.get(), _config.respTaper, _config.respMinFreq,
	    _config.respMaxFreq);
}
예제 #5
0
파일: msbb.cpp 프로젝트: Fran89/seiscomp3
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool AmplitudeProcessor_msbb::computeAmplitude(const DoubleArray &data,
                                               size_t i1, size_t i2,
                                               size_t si1, size_t si2, double offset,
                                               AmplitudeIndex *dt,
                                               AmplitudeValue *amplitude,
                                               double *period, double *snr) {
	/*
	* Low-level signal amplitude computation. This is magnitude specific.
	*
	* Input:
	*      f           double array of length n
	*      i1,i2       indices defining the measurement window,
	*                  0 <= i1 < i2 <= n
	*      offset      this is subtracted from the samples in f before
	*                  computation
	*
	* Output:
	*      dt          Point at which the measurement was mad/completed. May
	*                  be the peak time or end of integration.
	*      amplitude   amplitude. This may be a peak amplitude as well as a
	*                  sum or integral.
	*      period      dominant period of the signal. Optional. If the period
	*                  is not computed, set it to -1.
	*/

	size_t imax = find_absmax(data.size(), (const double*)data.data(), si1, si2, offset);
	double amax = fabs(data[imax] - offset);
	double pmax = -1;
	double pstd =  0; // standard error of period
	if ( !measure_period(data.size(), static_cast<const double*>(data.data()), imax, offset, &pmax, &pstd) )
		pmax = -1;

	if ( amax < *_noiseAmplitude * _config.snrMin ) {
		amplitude->value = amax / *_noiseAmplitude;
		setStatus(LowSNR, amplitude->value);
		return false;
	}

	dt->index = imax;
	*period = pmax;
	amplitude->value = amax;

	if ( _usedComponent <= SecondHorizontal ) {
		if ( _streamConfig[_usedComponent].gain != 0.0 )
			amplitude->value /= _streamConfig[_usedComponent].gain;
		else {
			setStatus(MissingGain, 0.0);
			return false;
		}
	}
	else
		return false;

	return true;
}
예제 #6
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool AmplitudeProcessor::deconvolveData(Response *resp, DoubleArray &data,
                                        int numberOfIntegrations) {
	// Remove linear trend
	double m,n;
	Math::Statistics::computeLinearTrend(data.size(), data.typedData(), m, n);
	Math::Statistics::detrend(data.size(), data.typedData(), m, n);

	return resp->deconvolveFFT(data, _stream.fsamp, _config.respTaper,
	                           _config.respMinFreq, _config.respMaxFreq,
	                           numberOfIntegrations);
}
예제 #7
0
	int Ardb::ZAdd(const DBID& db, const Slice& key, DoubleArray& scores,
			const SliceArray& svs)
	{
		KeyLockerGuard keyguard(m_key_locker, db, key);
		ZSetMetaValue meta;
		GetZSetMetaValue(db, key, meta);
		BatchWriteGuard guard(GetEngine());
		int count = 0;
		bool metachange = false;
		for (uint32 i = 0; i < scores.size(); i++)
		{
			int tryret = TryZAdd(db, key, meta, scores[i], svs[i]);
			if (tryret == 2)
			{
				count++;
			}
			if (!metachange && tryret > 0)
			{
				metachange = true;
			}
		}
		if (metachange)
		{
			SetZSetMetaValue(db, key, meta);
		}
		return count;
	}
예제 #8
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
TEST(ArrayTest, CopyData)
{
    DoubleArray a;

    a.resize(6);

    a[0] = 1.23;
    a[1] = 4.56;
    a[2] = 7.89;

    double data[] = { 3.2, 1.0, 0.0 };
    
    a.copyData(data, 3, 3);

    ASSERT_DOUBLE_EQ(3.2, a[3]);
    ASSERT_DOUBLE_EQ(1.0, a[4]);
    ASSERT_DOUBLE_EQ(0.0, a[5]);

    DoubleArray b;
    b.resize(3);
    b[0] = 10.0;
    b[1] = 20.0;
    b[2] = 30.0;

    a.copyData(b, b.size(), 2, 0);

    ASSERT_DOUBLE_EQ(1.23, a[0]);
    ASSERT_DOUBLE_EQ(4.56, a[1]);
    ASSERT_DOUBLE_EQ(10.0, a[2]);
    ASSERT_DOUBLE_EQ(20.0, a[3]);
    ASSERT_DOUBLE_EQ(30.0, a[4]);
    ASSERT_DOUBLE_EQ(0.0, a[5]);
}
예제 #9
0
파일: mask.C 프로젝트: anilkunwar/OOF2
/*
This has a funny way of dealing with edges. In case of a Gaussian blur, divides by the sum of all of the numbers in the mask by definition. Might prove harsh on edges. In all other cases, divides by 8 no matter what, so that can equalize at edges. Also, when one of the pixels needed in the mask calculation is off the bounds of the image, the center pixel value is substituted, so that there is less difference. This doesnt pick up as many stray lines on edges, but also proves to often not pick up enough lines. 
*/
DoubleArray Mask::applyMask(DoubleArray array){
	ICoord size = array.size();
	DoubleArray newarray = DoubleArray(size);
	width = (int)maskArray.size()(0)/2; /* in case the maskArray was edited */
	for (DoubleArray::iterator i = array.begin();i !=array.end(); ++i){
		ICoord curr = i.coord();
		double num = 0;
		double c = 0;
		int d = 1;
		for (int i = -width; i <= width; ++i){ // scans through the mask
			for (int j = -width; j <= width; ++j){
				ICoord a = ICoord(i,j);
				if (pixelInBounds(curr + a, size)){
					num = num + array[curr+a]*maskArray[ICoord(i + width, j + width)];
					c = c + maskArray[ICoord(i + width, j + width)];
				}
				else{
					num = num + array[curr]*maskArray[ICoord(i + width, j + width)]; /* if pixel needed for mask is out of the image, then substitute the center pixel */
					d = d + 1; /* count number of pixels out of bounds */
				}
			}
		}
		if (type == GAUSSIAN_MASK)
			newarray[curr] = num/159;
		else if (type == SMALL_GAUSSIAN_MASK)
			newarray[curr] = num/99;
		else
			newarray[curr] = num/8;
	}
	return newarray;
}
예제 #10
0
파일: masks.C 프로젝트: anilkunwar/OOF2
DoubleArray MASKS::applyMasks(const DoubleArray& image) {
//This applies the mask that is stored onto an array of doubles representing
//the image.
  DoubleArray newImage(image.size(),0.0);
  double tempSum=0;
  int startI,endI,startK,endK;
  int M=maskArrays.width(), N=maskArrays.height();

  for(int x=0;x<image.width();x++) {
    for(int y=0;y<image.height();y++) {
      startI=-M/2; endI=M/2;
      startK=-N/2; endK=N/2;
      if(x-M/2<0)
	startI=-x;
      if(y-N/2<0)
	startK=-y;
      if(x+M/2>=image.width())
	endI=image.width()-x-1;
      if(y+N/2>=image.height())
	endK=image.height()-y-1;
      for(int i=startI;i<=endI;i++) {
	for(int k=startK;k<=endK;k++) {
	  tempSum+=image[ICoord(x+i,y+k)]*maskArrays[ICoord(M/2+i,N/2+k)];
	  //If M and N aren't odd, will get segmentation fault
	}
      }
      newImage[ICoord(x,y)]=tempSum;
      //    if(tempSum<0)
      tempSum=0;
    }
  }
  return newImage;
}
예제 #11
0
void doClassifying(DoubleArray & gray) {
    ICoord size = gray.size();
    DoubleArray newgray = DoubleArray(size);
    ClassifyClass classif = ClassifyClass();
    newgray = classif.classifyRegions(gray);
    gray = newgray;

}
예제 #12
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void Detector::process(const Record *record, const DoubleArray &filteredData) {
	_amplProc.pickIndex = 0;

	SimpleDetector::process(record, filteredData);

	if ( _amplProc.isRunning() ) {
		calculateMaxAmplitude(record, _amplProc.pickIndex, filteredData.size(), filteredData);
		if ( _amplProc.isFinished() )
			sendMaxAmplitude(record);
	}
}
예제 #13
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool AmplitudeProcessor::deconvolveData(Response *resp, DoubleArray &data,
                                        int numberOfIntegrations) {
	// Remove linear trend
	double m,n;
	Math::Statistics::computeLinearTrend(data.size(), data.typedData(), m, n);
	Math::Statistics::detrend(data.size(), data.typedData(), m, n);

	bool ret = resp->deconvolveFFT(data, _stream.fsamp, _config.respTaper,
	                               _config.respMinFreq, _config.respMaxFreq,
	                               numberOfIntegrations < 0 ? 0 : numberOfIntegrations);

	if ( !ret )
		return false;

	// If number of integrations are negative, derive data
	while ( numberOfIntegrations < 0 ) {
		Math::Filtering::IIRDifferentiate<double> diff;
		diff.setSamplingFrequency(_stream.fsamp);
		diff.apply(data.size(), data.typedData());
		++numberOfIntegrations;
	}

	return true;
}
예제 #14
0
	int Ardb::ZAddLimit(const DBID& db, const Slice& key, DoubleArray& scores,
			const SliceArray& svs, int setlimit, ValueArray& pops)
	{
		ZSetMetaValue meta;
		GetZSetMetaValue(db, key, meta);
		if (setlimit <= 0)
		{
			setlimit = meta.size + scores.size();
		}
		ZAdd(db, key, scores, svs);
		GetZSetMetaValue(db, key, meta);
		if (meta.size > (uint32) setlimit)
		{
			ZPop(db, key, false, meta.size - setlimit, pops);
		}
		return 0;
	}
예제 #15
0
파일: Mjma.cpp 프로젝트: palminn/seiscomp3
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool AmplitudeProcessor_Mjma::computeAmplitude(
		const DoubleArray &data,
		size_t i1, size_t i2,
		size_t si1, size_t si2,
		double offset,AmplitudeIndex *dt,
		AmplitudeValue *amplitude,
		double *period, double *snr)
{
	double amax;

	size_t imax = find_absmax(data.size(), data.typedData(), si1, si2, offset);
	amax = fabs(data[imax] - offset);
	dt->index = imax;

	if ( *_noiseAmplitude == 0. )
		*snr = 1000000.0;
	else
		*snr = amax / *_noiseAmplitude;

	if ( *snr < _config.snrMin ) {
		setStatus(LowSNR, *snr);
		return false;
	}

	*period = -1;

	amplitude->value = amax;

	if ( _streamConfig[_usedComponent].gain != 0.0 )
		amplitude->value /= _streamConfig[_usedComponent].gain;
	else {
		setStatus(MissingGain, 0.0);
		return false;
	}

	// - convert to micrometer
	amplitude->value *= 1E06;

	// - estimate peak-to-peak from absmax amplitude
	amplitude->value *= 2.0;

	return true;
}
예제 #16
0
TEST(ArrayDeathTest, AddBeyondCapacity)
{
    DoubleArray a;
    EXPECT_DEATH(a.add(100), "Assertion");

    a.reserve(2);
    a.add(100);
    a.add(101);
    EXPECT_DEATH(a.add(102), "Assertion");

    a.reserve(4);
    a.add(102);
    a.add(103);
    EXPECT_DEATH(a.add(104), "Assertion");

    ASSERT_EQ(4u, a.size());
    EXPECT_DOUBLE_EQ(100, a[0]);
    EXPECT_DOUBLE_EQ(101, a[1]);
    EXPECT_DOUBLE_EQ(102, a[2]);
    EXPECT_DOUBLE_EQ(103, a[3]);
}
예제 #17
0
void TraceContours(
    /* 点 */
    const PointArray& pts,
    /* 边 */
    const EdgeArray& ea,
    /* 三角形 */
    const TriangleArray& ta,
    /* 要追踪的z值 */
    const DoubleArray& zValues,
    /* 所有的等值线上的点都放在一个数组 */
    PointArray& cnpts,
    /* 记录等值线信息 */
    ContourArray& cna )
{
    Contour cnt( pts, ea, ta );
    for( int i = 0; i < ( int )zValues.size(); i++ )
    {
        PointArray z_cnpts;
        IntArray z_cnpos;
        IntArray dirs;
        cnt.traceContour( zValues[i], z_cnpts, z_cnpos, dirs );

        if( z_cnpos.empty() )
        {
            DT_Contour z_contour = {i, 0, 1, 0};
            cna.push_back( z_contour );
        }
        else
        {
            for( int j = 0; j < ( int )z_cnpos.size(); j++ )
            {
                DT_Contour z_contour = {i, z_cnpos[j], dirs[j], 0};
                cna.push_back( z_contour );
            }
            // 复制计算得到的等值线数据
            std::copy( z_cnpts.begin(), z_cnpts.end(), std::back_inserter( cnpts ) );
        }
    }
}
예제 #18
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void Processor::process(const Record *rec, const DoubleArray &data) {
	// First record after reset?
	if ( !_stream.initialized ) {
		// Try to setup all internal variables
		if ( !init(rec) ) return;
	}
	// Mismatching sampling frequency: reset
	else if ( rec->samplingFrequency() != _stream.fsamp ) {
		SEISCOMP_INFO("%s: mismatching sampling frequency (%f != %f): reset",
		              rec->streamID().c_str(), _stream.fsamp,
		              rec->samplingFrequency());
		reset();
		// Try to setup all internal variables
		if ( !init(rec) ) return;
	}

	// Record time window is after the current time window -> flush
	// existing samples and setup the new interval
	if ( rec->startTime() >= _currentEndTime ) {
		flush();
		setupTimeWindow(rec->startTime());
	}

	Core::Time ts = rec->startTime();
	// Process all samples
	for ( int i = 0; i < data.size(); ++i ) {
		if ( ts >= _currentEndTime ) {
			// Flush existing pool
			flush();
			// Step to next time span
			_currentStartTime = _currentEndTime;
			_currentEndTime = _currentStartTime + Core::TimeSpan(1,0);
		}
		_samplePool.push(data[i]);
		ts += _dt;
	}
}
예제 #19
0
파일: mean.cpp 프로젝트: Fran89/seiscomp3
double mean(const DoubleArray &v)
{
	return mean(v.size(), (const double*)v.data());	
}
예제 #20
0
파일: mean.cpp 프로젝트: Fran89/seiscomp3
double
trimmedMean(const DoubleArray &v, double percent)
{
// XXX deprecated XXX
	return trimmedMean(v.size(), (const double*)v.data(), percent);	
}
예제 #21
0
파일: mean.cpp 프로젝트: Fran89/seiscomp3
double fractile(const DoubleArray &v, double x)
{
	return fractile(v.size(), (const double*)v.data(), x);
}
예제 #22
0
파일: md.cpp 프로젝트: Fran89/seiscomp3
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool AmplitudeProcessor_Md::computeAmplitude(const DoubleArray& data, size_t i1,
                                             size_t i2, size_t si1, size_t si2,
                                             double offset, AmplitudeIndex* dt,
                                             AmplitudeValue* amplitude,
                                             double* period, double* snr) {

	double amax, Imax, ofs_sig, amp_sig;
	DoubleArrayPtr d;

    if ( *snr < aFile.SNR_MIN )
        SEISCOMP_DEBUG("%s computed SNR is under configured SNR MIN", AMPTAG);

	if ( _computeAbsMax ) {
		size_t imax = find_absmax(data.size(), data.typedData(), si1, si2, offset);
		amax = fabs(data[imax] - offset);
		dt->index = imax;
	}
	else {
		int lmin, lmax;
		find_minmax(lmin, lmax, data.size(), data.typedData(), si1, si2, offset);
		amax = data[lmax] - data[lmin];
		dt->index = (lmin + lmax) * 0.5;
		dt->begin = lmin - dt->index;
		dt->end = lmax - dt->index;
	}

	Imax = dt->index;

	SEISCOMP_DEBUG("%s Amplitude max: %.2f", AMPTAG, amax);

	//! searching for Coda second by second through the end of the window
	//! if snrMin config is not 0 (config file or waveform review window)
	//! TODO: elevate accuracy by using a nanometers scale (maybe)
	if ( _config.snrMin != 0 ) {

		unsigned int i = si1;
		bool hasEndSignal = false;
		double calculatedSnr = -1;

		for (i = (int) Imax; i < i2; i = i + 1 * (int) _stream.fsamp) {

			int window_end = i + 1 * (int) _stream.fsamp;
			d = static_cast<DoubleArray*>(data.slice(i, window_end));

			//! computes pre-arrival offset
			ofs_sig = d->median();

			//! computes rms after removing offset
			amp_sig = 2 * d->rms(ofs_sig);

			if ( amp_sig / *_noiseAmplitude <= _config.snrMin ) {
				SEISCOMP_DEBUG("%s End of signal found! (%.2f <= %.2f)", AMPTAG,
				    (amp_sig / *_noiseAmplitude), _config.snrMin);
				hasEndSignal = true;
				calculatedSnr = amp_sig / *_noiseAmplitude;
				break;
			}
		}

		if ( !hasEndSignal ) {
			SEISCOMP_ERROR("%s SNR stayed over configured SNR_MIN! (%.2f > %.2f), "
				"skipping magnitude calculation for this station", AMPTAG,
			    calculatedSnr, _config.snrMin);
			return false;
		}

		dt->index = i;
	}
	else dt->index = Imax;

	//amplitude->value = 2 * amp_sig; //! actually it would have to be max. peak-to-peak
	amplitude->value = amp_sig;

	if ( _streamConfig[_usedComponent].gain != 0.0 )
		amplitude->value /= _streamConfig[_usedComponent].gain;
	else {
		setStatus(MissingGain, 0.0);
		return false;
	}

	// Convert m/s to nm/s
	amplitude->value *= 1.E09;

	*period = dt->index - i1 + (_config.signalBegin * _stream.fsamp);

	SEISCOMP_DEBUG("%s calculated event amplitude = %.2f", AMPTAG, amplitude->value);
	SEISCOMP_DEBUG("%s calculated signal end at %.2f ms from P phase", AMPTAG, *period);

	return true;
}
예제 #23
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void AmplitudeProcessor::prepareData(DoubleArray &data) {
	Sensor *sensor = _streamConfig[_usedComponent].sensor();

	// When using full responses then all information needs to be set up
	// correctly otherwise an error is set
	if ( _enableResponses ) {
		if ( !sensor ) {
			setStatus(MissingResponse, 1);
			return;
		}

		if ( !sensor->response() ) {
			setStatus(MissingResponse, 2);
			return;
		}

		// If the unit cannot be converted into the internal
		// enum (what basically means "unknown") then the deconvolution
		// cannot be correctly. We do not want to assume a unit here
		// to prevent computation errors in case of bad configuration.
		SignalUnit unit;
		if ( !unit.fromString(sensor->unit().c_str()) ) {
			// Invalid unit string
			setStatus(IncompatibleUnit, 2);
			return;
		}

		int intSteps = 0;
		switch ( unit ) {
			case Meter:
				intSteps = -1;
				break;
			case MeterPerSecond:
				break;
			case MeterPerSecondSquared:
				intSteps = 1;
				break;
			default:
				setStatus(IncompatibleUnit, 1);
				return;
		}

		if ( _responseApplied ) return;

		_responseApplied = true;

		if ( !deconvolveData(sensor->response(), _data, intSteps) ) {
			setStatus(DeconvolutionFailed, 0);
			return;
		}
	}
	else {
		// If the sensor is known then check the unit and skip
		// non velocity streams. Otherwise simply use the data
		// to be compatible to the old version. This will be
		// changed in the future and checked more strictly.
		if ( sensor ) {
			SignalUnit unit;
			if ( !unit.fromString(sensor->unit().c_str()) ) {
				// Invalid unit string
				setStatus(IncompatibleUnit, 4);
				return;
			}

			switch ( unit ) {
				case Meter:
					if ( _enableUpdates ) {
						// Updates with differentiation are not yet supported.
						setStatus(IncompatibleUnit, 5);
						return;
					}

					// Derive to m/s
					{
						Math::Filtering::IIRDifferentiate<double> diff;
						diff.setSamplingFrequency(_stream.fsamp);
						diff.apply(data.size(), data.typedData());
					}
					break;

				case MeterPerSecond:
					break;

				default:
					setStatus(IncompatibleUnit, 3);
					return;
			}
		}
	}
}
예제 #24
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void Detector::calculateMaxAmplitude(const Record *record, size_t i0, size_t i1, const DoubleArray &filteredData) {
	size_t i = i0;

	while ( i < i1 && _amplProc.processedSamples < _amplProc.neededSamples && i < (size_t)filteredData.size() ) {
		double amp = fabs(filteredData[i]);
		if ( !_amplProc.amplitude || amp > *_amplProc.amplitude ) {
			_amplProc.amplitude = amp;
			_amplProc.index = _amplProc.processedSamples;
		}
		++i;
		++_amplProc.processedSamples;
	}
}