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 PhaseResult GetPhase(double[] pulseSequence) { var crestIndices = _finder.Find(pulseSequence); if (crestIndices.IsEmpty()) { return(PhaseResult.FromException(ProcessException.NoPeakFound)); } var sliceInfos = _slicer.Slice(pulseSequence, crestIndices); if (sliceInfos.IsEmpty()) { return(PhaseResult.FromException(ProcessException.NoSliceValid)); } var example = sliceInfos.First(); var pulse = _preprocessor.RetrievePulse(pulseSequence, example.StartIndex, example.CrestOffset, example.Length); _rotator.TrySymmetrize(pulse, example.CrestOffset); double[] phase; try { phase = _phaseExtractor.GetPhase(pulse, null); } catch (PhaseFitException) { return(PhaseResult.FromException(ProcessException.NoFlatPhaseIntervalFound)); } var unwrap = Functions.Unwrap(phase); return(PhaseResult.WithoutException(unwrap)); }
/// <summary> /// Find the crests in a pulse sequence. /// </summary> /// <param name="pulseSequence">A pulse sequence containing multiple pulses</param> /// <returns>Whether crests are found successfully</returns> public IList <int> Find(double[] pulseSequence) { while (_delegateFinder.VerticalThreshold > 0.055) // todo move, now recorded { var crestIndices = _delegateFinder.Find(pulseSequence); var cmp = CompareRepFreq(pulseSequence.Length, crestIndices); if (cmp > 0) { VerticalThreshold *= 1.2; } else if (cmp < 0) { VerticalThreshold *= 0.9; } else { return(crestIndices); } } return(_delegateFinder.Find(pulseSequence)); }
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)); }
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)); }