Loading INAF.Apps.Uwp.SLabDataManager/Charts/Containers/SpectraContainer.cs +26 −9 Original line number Diff line number Diff line Loading @@ -24,13 +24,6 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts.Containers public SpectrumAlignmentConfigModel SpectrumAlignmentConfig { get; protected set; } public async Task removeSpectrumOfTypeAsync(SpectrumType type) { var requestedSpectrum = tryGetSpectrumOfType(type); Spectra.Remove(requestedSpectrum); await updateBoundariesAsync(); } #region spectra public override async Task addOrUpdateSpectrumAsync(SpectrumModel spectrum) { Loading Loading @@ -81,10 +74,10 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts.Containers return Spectra.Any(x => x.Type == spectrumType); } /* wrapper of 'tryRemoveSpectrumOfTypeAsync' method for aligned spectrum */ public void removeAlignedSpectrum() { removeSpectrumOfTypeAsync(SpectrumType.Aligned); IsSpectrumAligned = false; tryRemoveSpectrumOfTypeAsync(SpectrumType.Aligned); IsAlignedSpectrumSaved = false; } Loading @@ -97,6 +90,30 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts.Containers { return Spectra.FirstOrDefault(x => x.Type == spectrumType); } public async Task tryRemoveSpectrumOfTypeAsync(SpectrumType type) { var requestedSpectrum = tryGetSpectrumOfType(type); if (requestedSpectrum != null) { int index = -1; int spectraNum = spectra.Count; for (int i = 0; i < spectraNum; i++) { if (spectra[i].Type == requestedSpectrum.Type) { index = i; break; } } if (index != -1) { Spectra.RemoveAt(index); await updateBoundariesAsync(); } } } #endregion public void clear() Loading INAF.Apps.Uwp.SLabDataManager/Charts/Containers/SpectraContainerBase.cs +0 −8 Original line number Diff line number Diff line Loading @@ -75,13 +75,6 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts.Containers } } protected bool isSpectrumAligned; public bool IsSpectrumAligned { get { return isSpectrumAligned; } set { SetProperty(ref isSpectrumAligned, value); } } protected bool isSpectrumContinuumRemoved; public bool IsSpectrumContinuumRemoved { Loading Loading @@ -193,7 +186,6 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts.Containers { IsAlignedSpectrumSaved = false; IsAnySpectrumLoaded = false; IsSpectrumAligned = false; IsChartUpdateLayoutRequired = false; XAxisMajorStepValues = new List<double>(2); Loading INAF.Apps.Uwp.SLabDataManager/Converters/SpectrumConverter.cs→INAF.Apps.Uwp.SLabDataManager/Converters/SpectraConverters.cs +7 −6 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ using SpectrumModel = INAF.Apps.Uwp.SLabDataManager.Models.Spectrum.SpectrumMode namespace INAF.Apps.Uwp.SLabDataManager.Converters { public sealed class IsSpectrumLoadedConverter : IValueConverter public sealed class IsAnySpectrumOfTypeConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, string language) { Loading @@ -19,11 +19,12 @@ namespace INAF.Apps.Uwp.SLabDataManager.Converters SpectrumType spectrumType = _spectrumType.ToSpectrumType(); SpectraContainer spectraContainer = Ioc.Default.GetService<WorkingItemsModel>().SpectraContainer; SpectrumModel spectrum = spectraContainer.tryGetSpectrumOfType(spectrumType); if (spectrum != null) return true; else return false; return spectraContainer.isAnySpectrumOfType(spectrumType); //SpectrumModel spectrum = spectraContainer.tryGetSpectrumOfType(spectrumType); //if (spectrum != null) // return true; //else // return false; } catch (Exception) { Loading INAF.Apps.Uwp.SLabDataManager/Extensions/Extensions.cs +58 −4 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ using INAF.Libraries.NetStandard.Math.Models; using INAF.Libraries.NetStandard.ScienceModels.Spectra; using INAF.Libraries.NetStandard.SLabCommonModels.Models.Files; using MathNet.Numerics.Statistics; using System; using System.Collections.Generic; using System.ComponentModel; Loading @@ -17,10 +18,63 @@ namespace INAF.Apps.Uwp.SLabDataManager.Extensions public static class Extensions { #region spectrum model public static IEnumerable<ElementModel> GetCenterSegmentElements(this SpectrumModel spectrum, public static IEnumerable<ElementModel> GetRefSegmentElements(this SpectrumModel spectrum, double xMin, double xMax) bool isXMinLowestBoundary, double xMax, bool isXMaxHighestBoundary) { /* if the selected left-separator is NOT the leftmost one, then check which segment the XMIN boundary point belongs to */ if (!isXMinLowestBoundary) { var xMinBoundaryElem = spectrum.Elements.FirstOrDefault(x => x.X == xMin); /* take points at the left of the boundary point and calculate mean+stddev */ var leftSegment = spectrum.Elements .Where(x => x.X < xMinBoundaryElem.X) .OrderByDescending(x => x.X) .Take(10); var leftMeanStdDev = leftSegment.Select(x => x.Y).MeanStandardDeviation(); /* take points at the right of the boundary point and calculate mean+stddev */ var rightSegment = spectrum.Elements .Where(x => x.X > xMinBoundaryElem.X) .Take(10); var rightMeanStdDev = rightSegment.Select(x => x.Y).MeanStandardDeviation(); bool testLeft = xMinBoundaryElem.Y >= leftMeanStdDev.Mean && xMinBoundaryElem.Y <= (leftMeanStdDev.Mean + (3d * leftMeanStdDev.StandardDeviation)); bool testRight = xMinBoundaryElem.Y <= rightMeanStdDev.Mean && xMinBoundaryElem.Y >= (rightMeanStdDev.Mean - (3d * rightMeanStdDev.StandardDeviation)); /* if testright is true, then the point belongs to the right segment and it's ok, no action required */ if (!testRight) { if (testLeft) { /* the boundary point belongs to the left segment, so the xMin for the current segment is the 1st after the current xMin */ var element = spectrum.Elements.FirstOrDefault(x => x.X > xMin); xMin = element.X; } else { /* the boundary point doesn't belong to any segment...let's detect in a different way */ double distLeft = Math.Abs(xMinBoundaryElem.Y - leftMeanStdDev.Mean); double distRight = Math.Abs(xMinBoundaryElem.Y - rightMeanStdDev.Mean); if (distLeft < distRight) { /* the boundary point belongs to the left segment, so the xMin for the current segment is the 1st after the current xMin */ var element = spectrum.Elements.FirstOrDefault(x => x.X > xMin); xMin = element.X; } } } } return spectrum.Elements.Where(x => x.X >= xMin && x.X <= xMax); } Loading INAF.Apps.Uwp.SLabDataManager/Helpers/UI/Chart/ProcessingHelpers/SpectrumProcessingHelper.cs +56 −68 Original line number Diff line number Diff line Loading @@ -58,27 +58,27 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart.ProcessingHelpers } #endregion private void raiseIsDialogRequired() { IsDialogRequired = true; isDialogRequired = false; } //private void raiseIsDialogRequired() //{ // IsDialogRequired = true; // isDialogRequired = false; //} #region alignment public async Task alignSpectrumProcedureAsync() { string exMsg = await alignRawSpectrumAsync(); if (!string.IsNullOrEmpty(exMsg)) { UpdateUIHelper.UpdateUIAsync(() => { DialogMessageType = DialogMessageType.Warning; DialogMessage = exMsg; raiseIsDialogRequired(); }); return; } } //public async Task alignSpectrumProcedureAsync() //{ // string exMsg = await alignRawSpectrumAsync(); // if (!string.IsNullOrEmpty(exMsg)) // { // UpdateUIHelper.UpdateUIAsync(() => // { // DialogMessageType = DialogMessageType.Warning; // DialogMessage = exMsg; // raiseIsDialogRequired(); // }); // return; // } //} public void removeAlignedSpectrum() { Loading @@ -94,7 +94,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart.ProcessingHelpers return aligningSpectrum; } private async Task<string> alignRawSpectrumAsync() public async Task<ProcessingResult> alignRawSpectrumAsync() { IsDialogRequired = false; DialogMessage = string.Empty; Loading @@ -102,52 +102,42 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart.ProcessingHelpers SpectrumModel alignedSpectrum = null; string exMsg = string.Empty; await Task.Run(() => { try { alignedSpectrum = cloneSpectrumForAlignment(); /* try to retrieve the ref white max value for normalizing raw spectrum during alignment process */ double refWhiteMaxY = 1d; var refWhiteSpectrum = workingItems.SpectraContainer.tryGetSpectrumOfType(SpectrumType.RefWhite); if (refWhiteSpectrum == null) { UpdateUIHelper.UpdateUIAsync(() => { DialogMessageType = DialogMessageType.Warning; DialogMessage = "RefWhiteSpectrumNotAvailable".GetText(); raiseIsDialogRequired(); }); } return new ProcessingResult("RefWhiteSpectrumNotAvailable".GetText(), DialogMessageType.Warning); else refWhiteMaxY = refWhiteSpectrum.Elements.Max(x => x.Y); /* try to retrieve ref spectrum for normalizing raw spectrum during alignment process */ var refSpectrum = workingItems.SpectraContainer.tryGetSpectrumOfType(SpectrumType.Ref); if (refSpectrum == null) return new ProcessingResult("NoNormalizationAvailableMessage".GetText(), DialogMessageType.Warning); await Task.Run(() => { UpdateUIHelper.UpdateUIAsync(() => try { DialogMessageType = DialogMessageType.Warning; DialogMessage = "NoNormalizationAvailableMessage".GetText(); raiseIsDialogRequired(); }); } alignedSpectrum = cloneSpectrumForAlignment(); /* normalize spectrum, if possible */ if (refWhiteSpectrum != null && refSpectrum != null) { multiplyByRef(ref alignedSpectrum, refWhiteMaxY, refSpectrum); } //if (refWhiteSpectrum != null && refSpectrum != null) //{ // multiplyByRef(ref alignedSpectrum, // refWhiteMaxY, // refSpectrum); //} /* retrieve the reference segment and calculate the mean values at the borders of the segment for aligning other segments */ var refLowSeparator = spectrumAlignmentConfig.WavelengthSeparators.FirstOrDefault(x => x.CurrentValue >= selectedRefBand.XMin && x.CurrentValue <= selectedRefBand.XMax); var refHighSeparator = spectrumAlignmentConfig.WavelengthSeparators.FirstOrDefault(x => x.CurrentValue > refLowSeparator.CurrentValue); var refSegment = alignedSpectrum.GetCenterSegmentElements(refLowSeparator.CurrentValue, refHighSeparator.CurrentValue); var refSegment = alignedSpectrum.GetRefSegmentElements(refLowSeparator.CurrentValue, refLowSeparator.CurrentValue == spectrumAlignmentConfig.WavelengthSeparators.FirstOrDefault().CurrentValue, refHighSeparator.CurrentValue, refHighSeparator.CurrentValue == spectrumAlignmentConfig.WavelengthSeparators.LastOrDefault().CurrentValue); double refSegmentLeftMean = refSegment.GetSegmentLeftMeanValue(spectrumAlignmentConfig.NumOfPointsForAlignment); double refSegmentRightMean = refSegment.GetSegmentRightMeanValue(spectrumAlignmentConfig.NumOfPointsForAlignment); Loading @@ -170,18 +160,12 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart.ProcessingHelpers } }); if (string.IsNullOrEmpty(exMsg)) { workingItems.SpectraContainer.IsSpectrumAligned = true; await workingItems.SpectraContainer.addOrUpdateSpectrumAsync(alignedSpectrum); } if (!string.IsNullOrEmpty(exMsg)) return new ProcessingResult(exMsg); else { DialogMessage = exMsg; raiseIsDialogRequired(); } await workingItems.SpectraContainer.addOrUpdateSpectrumAsync(alignedSpectrum); return exMsg; return new ProcessingResult(); } private void alignLeftSide(ref SpectrumModel aligningSpectrum, Loading @@ -191,16 +175,17 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart.ProcessingHelpers var leftSeparators = spectrumAlignmentConfig.WavelengthSeparators .Where(x => x.MinValue < refLowSeparator.MinValue) .OrderByDescending(x => x.MinValue); double rightSeparatorCurrentValue = refLowSeparator.CurrentValue; double refLeftValue = refSegmentLeftMean; foreach (var leftSeparator in leftSeparators) { var elements = aligningSpectrum .GetLeftSegmentElements(leftSeparator.CurrentValue, rightSeparatorCurrentValue) .FixLeftSegment(refLeftValue, spectrumAlignmentConfig.NumOfPointsForAlignment); aligningSpectrum.UpdateElements(elements); //aligningSpectrum.UpdateElements(elements); //inutile rightSeparatorCurrentValue = leftSeparator.CurrentValue; refLeftValue = elements.GetSegmentLeftMeanValue(spectrumAlignmentConfig.NumOfPointsForAlignment); Loading @@ -211,16 +196,19 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart.ProcessingHelpers WavelengthModel refHighSeparator, double refSegmentRightMean) { var rightSeparators = spectrumAlignmentConfig.WavelengthSeparators.Where(x => x.MinValue > refHighSeparator.MinValue); var rightSeparators = spectrumAlignmentConfig.WavelengthSeparators .Where(x => x.MinValue > refHighSeparator.MinValue); double leftSeparatorCurrentValue = refHighSeparator.CurrentValue; double refRightValue = refSegmentRightMean; foreach (var rightSeparator in rightSeparators) { var elements = aligningSpectrum .GetRightSegmentElements(leftSeparatorCurrentValue, rightSeparator.CurrentValue) .FixRightSegment(refRightValue, spectrumAlignmentConfig.NumOfPointsForAlignment); aligningSpectrum.UpdateElements(elements); //aligningSpectrum.UpdateElements(elements); //inutile leftSeparatorCurrentValue = rightSeparator.CurrentValue; refRightValue = elements.GetSegmentRightMeanValue(spectrumAlignmentConfig.NumOfPointsForAlignment); Loading Loading
INAF.Apps.Uwp.SLabDataManager/Charts/Containers/SpectraContainer.cs +26 −9 Original line number Diff line number Diff line Loading @@ -24,13 +24,6 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts.Containers public SpectrumAlignmentConfigModel SpectrumAlignmentConfig { get; protected set; } public async Task removeSpectrumOfTypeAsync(SpectrumType type) { var requestedSpectrum = tryGetSpectrumOfType(type); Spectra.Remove(requestedSpectrum); await updateBoundariesAsync(); } #region spectra public override async Task addOrUpdateSpectrumAsync(SpectrumModel spectrum) { Loading Loading @@ -81,10 +74,10 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts.Containers return Spectra.Any(x => x.Type == spectrumType); } /* wrapper of 'tryRemoveSpectrumOfTypeAsync' method for aligned spectrum */ public void removeAlignedSpectrum() { removeSpectrumOfTypeAsync(SpectrumType.Aligned); IsSpectrumAligned = false; tryRemoveSpectrumOfTypeAsync(SpectrumType.Aligned); IsAlignedSpectrumSaved = false; } Loading @@ -97,6 +90,30 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts.Containers { return Spectra.FirstOrDefault(x => x.Type == spectrumType); } public async Task tryRemoveSpectrumOfTypeAsync(SpectrumType type) { var requestedSpectrum = tryGetSpectrumOfType(type); if (requestedSpectrum != null) { int index = -1; int spectraNum = spectra.Count; for (int i = 0; i < spectraNum; i++) { if (spectra[i].Type == requestedSpectrum.Type) { index = i; break; } } if (index != -1) { Spectra.RemoveAt(index); await updateBoundariesAsync(); } } } #endregion public void clear() Loading
INAF.Apps.Uwp.SLabDataManager/Charts/Containers/SpectraContainerBase.cs +0 −8 Original line number Diff line number Diff line Loading @@ -75,13 +75,6 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts.Containers } } protected bool isSpectrumAligned; public bool IsSpectrumAligned { get { return isSpectrumAligned; } set { SetProperty(ref isSpectrumAligned, value); } } protected bool isSpectrumContinuumRemoved; public bool IsSpectrumContinuumRemoved { Loading Loading @@ -193,7 +186,6 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts.Containers { IsAlignedSpectrumSaved = false; IsAnySpectrumLoaded = false; IsSpectrumAligned = false; IsChartUpdateLayoutRequired = false; XAxisMajorStepValues = new List<double>(2); Loading
INAF.Apps.Uwp.SLabDataManager/Converters/SpectrumConverter.cs→INAF.Apps.Uwp.SLabDataManager/Converters/SpectraConverters.cs +7 −6 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ using SpectrumModel = INAF.Apps.Uwp.SLabDataManager.Models.Spectrum.SpectrumMode namespace INAF.Apps.Uwp.SLabDataManager.Converters { public sealed class IsSpectrumLoadedConverter : IValueConverter public sealed class IsAnySpectrumOfTypeConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, string language) { Loading @@ -19,11 +19,12 @@ namespace INAF.Apps.Uwp.SLabDataManager.Converters SpectrumType spectrumType = _spectrumType.ToSpectrumType(); SpectraContainer spectraContainer = Ioc.Default.GetService<WorkingItemsModel>().SpectraContainer; SpectrumModel spectrum = spectraContainer.tryGetSpectrumOfType(spectrumType); if (spectrum != null) return true; else return false; return spectraContainer.isAnySpectrumOfType(spectrumType); //SpectrumModel spectrum = spectraContainer.tryGetSpectrumOfType(spectrumType); //if (spectrum != null) // return true; //else // return false; } catch (Exception) { Loading
INAF.Apps.Uwp.SLabDataManager/Extensions/Extensions.cs +58 −4 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ using INAF.Libraries.NetStandard.Math.Models; using INAF.Libraries.NetStandard.ScienceModels.Spectra; using INAF.Libraries.NetStandard.SLabCommonModels.Models.Files; using MathNet.Numerics.Statistics; using System; using System.Collections.Generic; using System.ComponentModel; Loading @@ -17,10 +18,63 @@ namespace INAF.Apps.Uwp.SLabDataManager.Extensions public static class Extensions { #region spectrum model public static IEnumerable<ElementModel> GetCenterSegmentElements(this SpectrumModel spectrum, public static IEnumerable<ElementModel> GetRefSegmentElements(this SpectrumModel spectrum, double xMin, double xMax) bool isXMinLowestBoundary, double xMax, bool isXMaxHighestBoundary) { /* if the selected left-separator is NOT the leftmost one, then check which segment the XMIN boundary point belongs to */ if (!isXMinLowestBoundary) { var xMinBoundaryElem = spectrum.Elements.FirstOrDefault(x => x.X == xMin); /* take points at the left of the boundary point and calculate mean+stddev */ var leftSegment = spectrum.Elements .Where(x => x.X < xMinBoundaryElem.X) .OrderByDescending(x => x.X) .Take(10); var leftMeanStdDev = leftSegment.Select(x => x.Y).MeanStandardDeviation(); /* take points at the right of the boundary point and calculate mean+stddev */ var rightSegment = spectrum.Elements .Where(x => x.X > xMinBoundaryElem.X) .Take(10); var rightMeanStdDev = rightSegment.Select(x => x.Y).MeanStandardDeviation(); bool testLeft = xMinBoundaryElem.Y >= leftMeanStdDev.Mean && xMinBoundaryElem.Y <= (leftMeanStdDev.Mean + (3d * leftMeanStdDev.StandardDeviation)); bool testRight = xMinBoundaryElem.Y <= rightMeanStdDev.Mean && xMinBoundaryElem.Y >= (rightMeanStdDev.Mean - (3d * rightMeanStdDev.StandardDeviation)); /* if testright is true, then the point belongs to the right segment and it's ok, no action required */ if (!testRight) { if (testLeft) { /* the boundary point belongs to the left segment, so the xMin for the current segment is the 1st after the current xMin */ var element = spectrum.Elements.FirstOrDefault(x => x.X > xMin); xMin = element.X; } else { /* the boundary point doesn't belong to any segment...let's detect in a different way */ double distLeft = Math.Abs(xMinBoundaryElem.Y - leftMeanStdDev.Mean); double distRight = Math.Abs(xMinBoundaryElem.Y - rightMeanStdDev.Mean); if (distLeft < distRight) { /* the boundary point belongs to the left segment, so the xMin for the current segment is the 1st after the current xMin */ var element = spectrum.Elements.FirstOrDefault(x => x.X > xMin); xMin = element.X; } } } } return spectrum.Elements.Where(x => x.X >= xMin && x.X <= xMax); } Loading
INAF.Apps.Uwp.SLabDataManager/Helpers/UI/Chart/ProcessingHelpers/SpectrumProcessingHelper.cs +56 −68 Original line number Diff line number Diff line Loading @@ -58,27 +58,27 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart.ProcessingHelpers } #endregion private void raiseIsDialogRequired() { IsDialogRequired = true; isDialogRequired = false; } //private void raiseIsDialogRequired() //{ // IsDialogRequired = true; // isDialogRequired = false; //} #region alignment public async Task alignSpectrumProcedureAsync() { string exMsg = await alignRawSpectrumAsync(); if (!string.IsNullOrEmpty(exMsg)) { UpdateUIHelper.UpdateUIAsync(() => { DialogMessageType = DialogMessageType.Warning; DialogMessage = exMsg; raiseIsDialogRequired(); }); return; } } //public async Task alignSpectrumProcedureAsync() //{ // string exMsg = await alignRawSpectrumAsync(); // if (!string.IsNullOrEmpty(exMsg)) // { // UpdateUIHelper.UpdateUIAsync(() => // { // DialogMessageType = DialogMessageType.Warning; // DialogMessage = exMsg; // raiseIsDialogRequired(); // }); // return; // } //} public void removeAlignedSpectrum() { Loading @@ -94,7 +94,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart.ProcessingHelpers return aligningSpectrum; } private async Task<string> alignRawSpectrumAsync() public async Task<ProcessingResult> alignRawSpectrumAsync() { IsDialogRequired = false; DialogMessage = string.Empty; Loading @@ -102,52 +102,42 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart.ProcessingHelpers SpectrumModel alignedSpectrum = null; string exMsg = string.Empty; await Task.Run(() => { try { alignedSpectrum = cloneSpectrumForAlignment(); /* try to retrieve the ref white max value for normalizing raw spectrum during alignment process */ double refWhiteMaxY = 1d; var refWhiteSpectrum = workingItems.SpectraContainer.tryGetSpectrumOfType(SpectrumType.RefWhite); if (refWhiteSpectrum == null) { UpdateUIHelper.UpdateUIAsync(() => { DialogMessageType = DialogMessageType.Warning; DialogMessage = "RefWhiteSpectrumNotAvailable".GetText(); raiseIsDialogRequired(); }); } return new ProcessingResult("RefWhiteSpectrumNotAvailable".GetText(), DialogMessageType.Warning); else refWhiteMaxY = refWhiteSpectrum.Elements.Max(x => x.Y); /* try to retrieve ref spectrum for normalizing raw spectrum during alignment process */ var refSpectrum = workingItems.SpectraContainer.tryGetSpectrumOfType(SpectrumType.Ref); if (refSpectrum == null) return new ProcessingResult("NoNormalizationAvailableMessage".GetText(), DialogMessageType.Warning); await Task.Run(() => { UpdateUIHelper.UpdateUIAsync(() => try { DialogMessageType = DialogMessageType.Warning; DialogMessage = "NoNormalizationAvailableMessage".GetText(); raiseIsDialogRequired(); }); } alignedSpectrum = cloneSpectrumForAlignment(); /* normalize spectrum, if possible */ if (refWhiteSpectrum != null && refSpectrum != null) { multiplyByRef(ref alignedSpectrum, refWhiteMaxY, refSpectrum); } //if (refWhiteSpectrum != null && refSpectrum != null) //{ // multiplyByRef(ref alignedSpectrum, // refWhiteMaxY, // refSpectrum); //} /* retrieve the reference segment and calculate the mean values at the borders of the segment for aligning other segments */ var refLowSeparator = spectrumAlignmentConfig.WavelengthSeparators.FirstOrDefault(x => x.CurrentValue >= selectedRefBand.XMin && x.CurrentValue <= selectedRefBand.XMax); var refHighSeparator = spectrumAlignmentConfig.WavelengthSeparators.FirstOrDefault(x => x.CurrentValue > refLowSeparator.CurrentValue); var refSegment = alignedSpectrum.GetCenterSegmentElements(refLowSeparator.CurrentValue, refHighSeparator.CurrentValue); var refSegment = alignedSpectrum.GetRefSegmentElements(refLowSeparator.CurrentValue, refLowSeparator.CurrentValue == spectrumAlignmentConfig.WavelengthSeparators.FirstOrDefault().CurrentValue, refHighSeparator.CurrentValue, refHighSeparator.CurrentValue == spectrumAlignmentConfig.WavelengthSeparators.LastOrDefault().CurrentValue); double refSegmentLeftMean = refSegment.GetSegmentLeftMeanValue(spectrumAlignmentConfig.NumOfPointsForAlignment); double refSegmentRightMean = refSegment.GetSegmentRightMeanValue(spectrumAlignmentConfig.NumOfPointsForAlignment); Loading @@ -170,18 +160,12 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart.ProcessingHelpers } }); if (string.IsNullOrEmpty(exMsg)) { workingItems.SpectraContainer.IsSpectrumAligned = true; await workingItems.SpectraContainer.addOrUpdateSpectrumAsync(alignedSpectrum); } if (!string.IsNullOrEmpty(exMsg)) return new ProcessingResult(exMsg); else { DialogMessage = exMsg; raiseIsDialogRequired(); } await workingItems.SpectraContainer.addOrUpdateSpectrumAsync(alignedSpectrum); return exMsg; return new ProcessingResult(); } private void alignLeftSide(ref SpectrumModel aligningSpectrum, Loading @@ -191,16 +175,17 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart.ProcessingHelpers var leftSeparators = spectrumAlignmentConfig.WavelengthSeparators .Where(x => x.MinValue < refLowSeparator.MinValue) .OrderByDescending(x => x.MinValue); double rightSeparatorCurrentValue = refLowSeparator.CurrentValue; double refLeftValue = refSegmentLeftMean; foreach (var leftSeparator in leftSeparators) { var elements = aligningSpectrum .GetLeftSegmentElements(leftSeparator.CurrentValue, rightSeparatorCurrentValue) .FixLeftSegment(refLeftValue, spectrumAlignmentConfig.NumOfPointsForAlignment); aligningSpectrum.UpdateElements(elements); //aligningSpectrum.UpdateElements(elements); //inutile rightSeparatorCurrentValue = leftSeparator.CurrentValue; refLeftValue = elements.GetSegmentLeftMeanValue(spectrumAlignmentConfig.NumOfPointsForAlignment); Loading @@ -211,16 +196,19 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart.ProcessingHelpers WavelengthModel refHighSeparator, double refSegmentRightMean) { var rightSeparators = spectrumAlignmentConfig.WavelengthSeparators.Where(x => x.MinValue > refHighSeparator.MinValue); var rightSeparators = spectrumAlignmentConfig.WavelengthSeparators .Where(x => x.MinValue > refHighSeparator.MinValue); double leftSeparatorCurrentValue = refHighSeparator.CurrentValue; double refRightValue = refSegmentRightMean; foreach (var rightSeparator in rightSeparators) { var elements = aligningSpectrum .GetRightSegmentElements(leftSeparatorCurrentValue, rightSeparator.CurrentValue) .FixRightSegment(refRightValue, spectrumAlignmentConfig.NumOfPointsForAlignment); aligningSpectrum.UpdateElements(elements); //aligningSpectrum.UpdateElements(elements); //inutile leftSeparatorCurrentValue = rightSeparator.CurrentValue; refRightValue = elements.GetSegmentRightMeanValue(spectrumAlignmentConfig.NumOfPointsForAlignment); Loading