public IList <SpecInfo> Process([NotNull] double[] pulseSequence)
        {
            var crestIndices = _finder.Find(pulseSequence);

            if (crestIndices.IsEmpty())
            {
                return(new List <SpecInfo>());
            }
            var sliceInfos = _slicer.Slice(pulseSequence, crestIndices);

            if (sliceInfos.IsEmpty())
            {
                return(new List <SpecInfo>());
            }

            return(sliceInfos.Select(
                       (sliceInfo, i) => {
                var pulse = _preprocessor.RetrievePulse(pulseSequence, sliceInfo.StartIndex,
                                                        sliceInfo.CrestOffset,
                                                        sliceInfo.Length);
                _rotator.TrySymmetrize(pulse, sliceInfo.CrestOffset);     // todo do it at preproposs
                var correctedSpectrum = _corrector.Correct(pulse);
                return
                new SpecInfo(
                    correctedSpectrum.Aggregate((complex, complex1) => complex + complex1) /
                    correctedSpectrum.Length, i);
            }
                       ).ToList());
        }
        public AccumulationResult Process([NotNull] double[] pulseSequence)
        {
            var crestIndices = _finder.Find(pulseSequence);

            if (crestIndices.IsEmpty())
            {
                return(AccumulationResult.FromException(ProcessException.NoPeakFound));
            }
            var sliceInfos = _slicer.Slice(pulseSequence, crestIndices);

            if (sliceInfos.IsEmpty())
            {
                return(AccumulationResult.FromException(ProcessException.NoSliceValid));
            }

            var cnt = 0;

            Complex[] accumulatedSpectrum = null;
            var       errorCnt            = 0;

            foreach (var sliceInfo in sliceInfos)
            {
                var pulse = _preprocessor.RetrievePulse(pulseSequence, sliceInfo.StartIndex,
                                                        sliceInfo.CrestOffset,
                                                        sliceInfo.Length);
                _rotator.TrySymmetrize(pulse, sliceInfo.CrestOffset); // todo do it at preproposs
                Complex[] correctedSpectrum;
                try {
                    correctedSpectrum = _corrector.Correct(pulse);
                } catch (CorrectFailException) {
                    errorCnt++;
                    continue;
                }
                accumulatedSpectrum = Accumulate(accumulatedSpectrum, correctedSpectrum);
                cnt++;
            }
            if (accumulatedSpectrum == null)
            {
                return(AccumulationResult.FromException(ProcessException.NoFlatPhaseIntervalFound, errorCnt));
            }
            var spectrum = new Spectrum(accumulatedSpectrum, cnt);

            if (errorCnt == 0)
            {
                return(AccumulationResult.WithoutException(spectrum));
            }
            return(new AccumulationResult(spectrum, ProcessException.NoFlatPhaseIntervalFound, errorCnt));
        }
Beispiel #3
0
        public Complex[] Correct(double[] symmetryPulse)
        {
            var    complexSpectrum = _delegate.Correct(symmetryPulse);
            var    length          = complexSpectrum.Length;
            double sum             = 0;

            for (var i = length / 4; i < length / 2; i++)
            {
                sum += complexSpectrum[i].Real;
            }
            if (sum < 0)
            {
                for (var i = 0; i < length; i++)
                {
                    complexSpectrum[i] = -complexSpectrum[i];
                }
            }
            return(complexSpectrum);
        }
Beispiel #4
0
        public SplitResult Process([NotNull] double[] pulseSequence)
        {
            var crestIndices = _finder.Find(pulseSequence);

            if (crestIndices.Count <= 1)
            {
                return(SplitResult.FromException(ProcessException.NoPeakFound));
            }
            Duo <List <SliceInfo> > sliceInfos;

            try {
                sliceInfos = _slicer.Slice(pulseSequence, crestIndices);
            } catch (Exception) {
                return(SplitResult.FromException(ProcessException.NoSliceValid));
            }
            var errorCnt = 0;
            var spectra  = new Spectrum[2];

            for (var i = 0; i < 2; i++)
            {
                var       list = sliceInfos[i];
                Complex[] accumulatedSpectrum = null;
                var       cnt = 0;

                foreach (var sliceInfo in list)
                {
                    var pulse = _preprocessor.RetrievePulse(pulseSequence, sliceInfo.StartIndex,
                                                            sliceInfo.CrestOffset,
                                                            sliceInfo.Length);
                    _rotator.TrySymmetrize(pulse, sliceInfo.CrestOffset); // todo do it at preproposs
                    Complex[] correctedSpectrum;
                    try {
                        correctedSpectrum = _corrector.Correct(pulse);
                    } catch (CorrectFailException) {
                        errorCnt++;
                        continue;
                    }
                    if (accumulatedSpectrum == null)
                    {
                        accumulatedSpectrum = correctedSpectrum.Clone() as Complex[];
                    }
                    else
                    {
                        accumulatedSpectrum.Increase(correctedSpectrum);
                    }
                    cnt++;
                }
                if (accumulatedSpectrum == null)
                {
                    return(SplitResult.FromException(ProcessException.NoFlatPhaseIntervalFound, errorCnt));
                }
                spectra[i] = new Spectrum(accumulatedSpectrum, cnt);
            }

            GasRefTuple tuple;

            if (Average(spectra[1]) > Average(spectra[0]))
            {
                tuple = GasRefTuple.SourceAndRef(spectra[1], spectra[0]);
            }
            else
            {
                tuple = GasRefTuple.SourceAndRef(spectra[0], spectra[1]);
            }
            if (errorCnt != 0)
            {
                return(new SplitResult(tuple, ProcessException.NoFlatPhaseIntervalFound, errorCnt));
            }
            return(SplitResult.WithoutException(tuple));
        }