Loading INAF.Apps.Uwp.SLabDataManager/Constants/Constants.cs +25 −9 Original line number Diff line number Diff line Loading @@ -31,14 +31,30 @@ public static readonly string CURRENT_PAGE = "currentpage"; public static readonly string LAST_PAGE = "lastpage"; public static readonly string NUM_OF_POINTS_FOR_MISSING_POINTS = "numofpointsformissingpoints"; public static readonly string XML_ELEMENTS = "elements"; public static readonly string XML_ELEMENT = "element"; public static readonly string XML_RAW_FILENAME = "rawfilename"; public static readonly string XML_INFO = "info"; public static readonly string XML_SPECTRUM = "spectrum"; public static readonly string XML_TYPE = "type"; public static readonly string XML_WAVELENGTH = "wavelength"; public static readonly string NUM_OF_POINTS_FOR_MISSING_POINTS = "NumOfPointsForMissingPoints"; public static readonly string XML_ALIGNMENT_SETTINGS = "AlignmentSettings"; public static readonly string XML_ALIGNMENT_SETTINGS_SEGMENT_BOUNDARIES = "SegmentBoundaries"; public static readonly string XML_CONTINUUM_REMOVAL_SETTINGS = "ContinuumRemovalSettings"; public static readonly string XML_CONTINUUM_REMOVAL_SETTINGS_SEGMENT_FIT_METHOD_NAME = "FitMethodName"; public static readonly string XML_CONTINUUM_REMOVAL_SETTINGS_SEGMENT_PARAMETER_VALUE = "ParameterValue"; public static readonly string XML_CONTINUUM_REMOVAL_SETTINGS_SEGMENT = "Segment"; public static readonly string XML_CONTINUUM_REMOVAL_SETTINGS_SEGMENTS = "Segments"; public static readonly string XML_ELEMENTS = "Elements"; public static readonly string XML_ELEMENT = "Element"; public static readonly string XML_FILE_IDS = "FileIds"; public static readonly string XML_MAX = "Max"; public static readonly string XML_MIN = "Min"; public static readonly string XML_NUM_OF_POINTS = "NumOfPoints"; public static readonly string XML_RAW_FILENAME = "RawFilename"; public static readonly string XML_INFO = "Info"; public static readonly string XML_RAW_FILE_ID = "RawFileId"; public static readonly string XML_REF_FILE_ID = "RefFileId"; public static readonly string XML_REF_WHITE_FILE_ID = "RefWiteFileId"; public static readonly string XML_SEGMENT_END = "SegmentEnd"; public static readonly string XML_SEGMENT_START = "SegmentStart"; public static readonly string XML_SPECTRUM = "Spectrum"; public static readonly string XML_TYPE = "Type"; public static readonly string XML_WAVELENGTH = "Wavelength"; } } INAF.Apps.Uwp.SLabDataManager/Extensions/Extensions.cs +116 −3 Original line number Diff line number Diff line Loading @@ -6,13 +6,16 @@ using INAF.Libraries.NetStandard.Math.Stats; using INAF.Libraries.NetStandard.ScienceModels.Spectra; using INAF.Libraries.NetStandard.SLabCommonModels.Models.Files; using INAF.Libraries.NetStandard.SLabCommonModels.Models.Spectrum; using INAF.Libraries.NetStandard.SLabCommonModels.Models.Spectrum.ProcessedSpectraInfo.Alignment; using INAF.Libraries.NetStandard.SLabCommonModels.Models.Spectrum.ProcessedSpectraInfo.ContinuumRemoval; using INAF.Libraries.NetStandard.SLabCommonModels.Models.Spectrum.ProcessedSpectraInfo.Smoothing; using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Linq; using System.Text; using System.Xml.Serialization; using Telerik.UI.Xaml.Controls.Chart; using Windows.Data.Xml.Dom; using Windows.UI; Loading Loading @@ -203,7 +206,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.Extensions } } public static FileSpectrumModel ToSpectrumFile(this ISpectrumModel model) public static FileSpectrumModel ToSpectrumFile(this IChartSpectrumModel model) { return new FileSpectrumModel() { Loading Loading @@ -262,7 +265,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.Extensions } } public static string ToTxt(this IMathSpectrumModel spectrum) public static string ToTxt(this ISpectrumModel spectrum) { if (spectrum == null || spectrum.Elements == null || spectrum.Elements.Count == 0) return null; Loading @@ -276,7 +279,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.Extensions return sb.ToString(); } public static XmlDocument ToXml(this ISpectrumModel spectrum) public static XmlDocument ToXml(this IChartSpectrumModel spectrum) { if (spectrum == null || spectrum.Elements == null || spectrum.Elements.Count == 0) return null; Loading @@ -299,6 +302,20 @@ namespace INAF.Apps.Uwp.SLabDataManager.Extensions xmlspectrum.AppendChild(xmlinfo); /* type specific actions */ if (spectrum.GetType() == typeof(ChartSpectrumOfTypeAlignedModel)) { xmlspectrum.AppendChild(GetAlignmentSettingsXml(dom, ((ChartSpectrumOfTypeAlignedModel)spectrum).AlignmentSettings)); } else if (spectrum.GetType() == typeof(ChartSpectrumOfTypeContinuumRemovedModel)) { xmlspectrum.AppendChild(GetSegmentsFitSettingsXml(dom, ((ChartSpectrumOfTypeContinuumRemovedModel)spectrum).ContinuumRemovalSettings)); } else if (spectrum.GetType() == typeof(ChartSpectrumOfTypeSmoothedModel)) { } /* append spectrum data (wavelength, value) */ var xmlelements = dom.CreateElement(Constants.Constants.XML_ELEMENTS); foreach (var element in spectrum.Elements) Loading Loading @@ -366,6 +383,102 @@ namespace INAF.Apps.Uwp.SLabDataManager.Extensions return elements; } #endregion #region aligned private static XmlElement GetAlignmentSettingsXml(XmlDocument dom, AlignmentSettingsModel alignmentSettings) { var xmlalignmentsettings = dom.CreateElement(Constants.Constants.XML_ALIGNMENT_SETTINGS); /* num of points */ var xmlnumofpoints = dom.CreateElement(Constants.Constants.XML_NUM_OF_POINTS); xmlnumofpoints.InnerText = alignmentSettings.NumOfPoints.ToString(); xmlalignmentsettings.AppendChild(xmlnumofpoints); /* segment boundaries */ var xmlsegmentboundaries = dom.CreateElement(Constants.Constants.XML_ALIGNMENT_SETTINGS_SEGMENT_BOUNDARIES); /* min */ var xmlsegmentboundariesmin = dom.CreateElement(Constants.Constants.XML_MIN); xmlsegmentboundariesmin.InnerText = alignmentSettings.AlignmentSegmentBoundaries.Min.ToString(); xmlsegmentboundaries.AppendChild(xmlsegmentboundariesmin); /* max */ var xmlsegmentboundariesmax = dom.CreateElement(Constants.Constants.XML_MAX); xmlsegmentboundariesmax.InnerText = alignmentSettings.AlignmentSegmentBoundaries.Max.ToString(); xmlsegmentboundaries.AppendChild(xmlsegmentboundariesmax); xmlalignmentsettings.AppendChild(xmlsegmentboundaries); /* file ids */ var xmlfileids = dom.CreateElement(Constants.Constants.XML_FILE_IDS); /* raw file id */ var xmlrawfileid = dom.CreateElement(Constants.Constants.XML_RAW_FILE_ID); xmlrawfileid.InnerText = alignmentSettings.RawFile.Id.ToString(); xmlfileids.AppendChild(xmlrawfileid); /* ref file id */ var xmlreffileid = dom.CreateElement(Constants.Constants.XML_REF_FILE_ID); xmlreffileid.InnerText = alignmentSettings.RefFile.Id.ToString(); xmlfileids.AppendChild(xmlreffileid); /* raw file id */ var xmlrefwhitefileid = dom.CreateElement(Constants.Constants.XML_REF_WHITE_FILE_ID); xmlrefwhitefileid.InnerText = alignmentSettings.RefWhiteFile.Id.ToString(); xmlfileids.AppendChild(xmlrefwhitefileid); xmlalignmentsettings.AppendChild(xmlfileids); xmlalignmentsettings.AppendChild(xmlsegmentboundaries); return xmlalignmentsettings; } #endregion #region segments fit private static XmlElement GetSegmentsFitSettingsXml(XmlDocument dom, ContinuumRemovalSettingsModel continuumRemovalSettings) { var xmlcontinuumremovalsettings = dom.CreateElement(Constants.Constants.XML_CONTINUUM_REMOVAL_SETTINGS); /* num of points */ var xmlnumofpoints = dom.CreateElement(Constants.Constants.XML_NUM_OF_POINTS); xmlnumofpoints.InnerText = continuumRemovalSettings.NumOfPointsForAveragingMissingPointX.ToString(); xmlcontinuumremovalsettings.AppendChild(xmlnumofpoints); /* segments */ var xmlsegments = dom.CreateElement(Constants.Constants.XML_CONTINUUM_REMOVAL_SETTINGS_SEGMENTS); foreach (var segment in continuumRemovalSettings.Segments) { var xmlsegment = dom.CreateElement(Constants.Constants.XML_CONTINUUM_REMOVAL_SETTINGS_SEGMENT); /* fit method name */ var xmlfitmethodname = dom.CreateElement(Constants.Constants.XML_CONTINUUM_REMOVAL_SETTINGS_SEGMENT_FIT_METHOD_NAME); xmlfitmethodname.InnerText = segment.FitMethodName; xmlsegment.AppendChild(xmlfitmethodname); var xmlsegmentstart = dom.CreateElement(Constants.Constants.XML_SEGMENT_START); xmlsegmentstart.InnerText = segment.XStart.ToDoubleInvariantString(); xmlsegment.AppendChild(xmlsegmentstart); var xmlsegmentend = dom.CreateElement(Constants.Constants.XML_SEGMENT_END); xmlsegmentend.InnerText = segment.XEnd.ToDoubleInvariantString(); xmlsegment.AppendChild(xmlsegmentend); /* fit param value */ if (segment.FitParamValue.HasValue) { var xmlfitparamvalue = dom.CreateElement(Constants.Constants.XML_CONTINUUM_REMOVAL_SETTINGS_SEGMENT_PARAMETER_VALUE); xmlfitmethodname.InnerText = segment.FitParamValue.Value.ToDoubleInvariantString(); xmlsegment.AppendChild(xmlfitparamvalue); } } xmlcontinuumremovalsettings.AppendChild(xmlsegments); return xmlcontinuumremovalsettings; } #endregion #endregion public static string GetDescription(this Enum enumValue) Loading INAF.Apps.Uwp.SLabDataManager/Helpers/UI/Chart/ProcessingHelpers/SpectrumProcessingHelper.cs +18 −10 Original line number Diff line number Diff line using CommunityToolkit.Mvvm.ComponentModel; using INAF.Apps.Uwp.SLabDataManager.Charts; using INAF.Apps.Uwp.SLabDataManager.Charts.Containers; using INAF.Apps.Uwp.SLabDataManager.Extensions; using INAF.Apps.Uwp.SLabDataManager.Models; using INAF.Apps.Uwp.SLabDataManager.Models.Chart; using INAF.Apps.Uwp.SLabDataManager.Models.Fit; using INAF.Apps.Uwp.SLabDataManager.Models.Processing; Loading @@ -9,6 +9,7 @@ using INAF.Apps.Uwp.SLabDataManager.ViewModels.UserControlViewModels; using INAF.Libraries.NetStandard.Math.Fit.Linear; using INAF.Libraries.NetStandard.Math.Fit.Spline; using INAF.Libraries.NetStandard.ScienceModels.Spectra; using INAF.Libraries.NetStandard.SLabCommonModels.Models.Spectrum.ProcessedSpectraInfo.Alignment; using INAF.Libraries.Uwp.Logging; using Microsoft.Extensions.DependencyInjection; using System; Loading @@ -24,19 +25,19 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart.ProcessingHelpers private readonly LinearFitHelper linearFitHelper; private readonly AlignmentViewModel alignmentViewModel; private readonly SelectedRefBand selectedRefBand; private readonly WorkingItemsModel workingItems; private readonly SpectraContainer spectraContainer; private readonly Logger logger; public SpectrumProcessingHelper(IServiceProvider serviceProvider, SpectraContainer spectraContainer, LinearFitHelper linearFitHelper, WorkingItemsModel workingItems, AlignmentViewModel alignmentViewModel, SelectedRefBand selectedRefBand, Logger logger) { this.serviceProvider = serviceProvider; this.spectraContainer = spectraContainer; this.linearFitHelper = linearFitHelper; this.workingItems = workingItems; this.alignmentViewModel = alignmentViewModel; this.selectedRefBand = selectedRefBand; this.logger = logger; Loading @@ -59,10 +60,9 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart.ProcessingHelpers #region alignment methods private IChartSpectrumModel cloneSpectrumForAlignment() { var aligningSpectrum = (IChartSpectrumModel)workingItems.SpectraContainer.tryGetSpectrumOfType(SpectrumType.Raw).Clone(); aligningSpectrum.setType(SpectrumType.Aligned); aligningSpectrum.updateTitle(); return aligningSpectrum; var spectraFactory = serviceProvider.GetRequiredService<SpectraFactory>(); return spectraFactory.cloneSpectrum<ChartSpectrumOfTypeAlignedModel>(SpectrumType.Raw, SpectrumType.Aligned); } public async Task<ProcessingResult> alignRawSpectrumAsync() Loading @@ -76,14 +76,14 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart.ProcessingHelpers /* 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); var refWhiteSpectrum = spectraContainer.tryGetSpectrumOfType(SpectrumType.RefWhite); if (refWhiteSpectrum == null) 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); var refSpectrum = spectraContainer.tryGetSpectrumOfType(SpectrumType.Ref); if (refSpectrum == null) return new ProcessingResult("NoNormalizationAvailableMessage".GetText(), DialogMessageType.Warning); Loading Loading @@ -123,6 +123,14 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart.ProcessingHelpers alignRightSide(ref alignedSpectrum, refHighSeparator, refSegmentRightMean); /* save parameters used for alignment */ ((ChartSpectrumOfTypeAlignedModel)alignedSpectrum).AlignmentSettings.NumOfPoints = alignmentViewModel.NumOfPointsForAlignment; ((ChartSpectrumOfTypeAlignedModel)alignedSpectrum).AlignmentSettings.AlignmentSegmentBoundaries = new AlignmentSegmentBoundariesModel() { Min = refLowSeparator.CurrentValue, Max = refHighSeparator.CurrentValue }; } catch (Exception ex) { Loading INAF.Apps.Uwp.SLabDataManager/Models/Chart/ChartSpectrumModel.cs +18 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Xml.Serialization; using Windows.UI.Xaml; using Windows.UI.Xaml.Media; using static INAF.Libraries.NetStandard.SLabCommonModels.Enums.Enums; Loading Loading @@ -53,6 +54,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.Models.Chart } private SolidColorBrush color; [XmlIgnore] public SolidColorBrush Color { get { return color; } Loading Loading @@ -97,5 +99,21 @@ namespace INAF.Apps.Uwp.SLabDataManager.Models.Chart { return new ChartSpectrumModel(spectrumType, points); } public new object Clone() { IChartSpectrumModel clonedSpectrum = new ChartSpectrumModel(serviceProvider, Type) { Id = Id, Filename = Filename, Filepath = Filepath, Title = Title, ParentId = ParentId }; foreach (var element in Elements) clonedSpectrum.add((ElementModel)element.Clone()); return clonedSpectrum; } } } INAF.Apps.Uwp.SLabDataManager/Models/Chart/ChartSpectrumOfTypeAlignedModel.cs +15 −0 Original line number Diff line number Diff line using INAF.Libraries.NetStandard.SLabCommonModels.Models.Spectrum.ProcessedSpectraInfo.Alignment; using System; using static INAF.Libraries.NetStandard.SLabCommonModels.Enums.Enums; namespace INAF.Apps.Uwp.SLabDataManager.Models.Chart { public class ChartSpectrumOfTypeAlignedModel : ChartSpectrumModel { public ChartSpectrumOfTypeAlignedModel() { AlignmentSettings = new AlignmentSettingsModel(); } public ChartSpectrumOfTypeAlignedModel(IServiceProvider serviceProvider, SpectrumType spectrumType, string fileName, string filepath) : base(serviceProvider, spectrumType, fileName, filepath) { AlignmentSettings = new AlignmentSettingsModel(); } public AlignmentSettingsModel AlignmentSettings { get; set; } } } Loading
INAF.Apps.Uwp.SLabDataManager/Constants/Constants.cs +25 −9 Original line number Diff line number Diff line Loading @@ -31,14 +31,30 @@ public static readonly string CURRENT_PAGE = "currentpage"; public static readonly string LAST_PAGE = "lastpage"; public static readonly string NUM_OF_POINTS_FOR_MISSING_POINTS = "numofpointsformissingpoints"; public static readonly string XML_ELEMENTS = "elements"; public static readonly string XML_ELEMENT = "element"; public static readonly string XML_RAW_FILENAME = "rawfilename"; public static readonly string XML_INFO = "info"; public static readonly string XML_SPECTRUM = "spectrum"; public static readonly string XML_TYPE = "type"; public static readonly string XML_WAVELENGTH = "wavelength"; public static readonly string NUM_OF_POINTS_FOR_MISSING_POINTS = "NumOfPointsForMissingPoints"; public static readonly string XML_ALIGNMENT_SETTINGS = "AlignmentSettings"; public static readonly string XML_ALIGNMENT_SETTINGS_SEGMENT_BOUNDARIES = "SegmentBoundaries"; public static readonly string XML_CONTINUUM_REMOVAL_SETTINGS = "ContinuumRemovalSettings"; public static readonly string XML_CONTINUUM_REMOVAL_SETTINGS_SEGMENT_FIT_METHOD_NAME = "FitMethodName"; public static readonly string XML_CONTINUUM_REMOVAL_SETTINGS_SEGMENT_PARAMETER_VALUE = "ParameterValue"; public static readonly string XML_CONTINUUM_REMOVAL_SETTINGS_SEGMENT = "Segment"; public static readonly string XML_CONTINUUM_REMOVAL_SETTINGS_SEGMENTS = "Segments"; public static readonly string XML_ELEMENTS = "Elements"; public static readonly string XML_ELEMENT = "Element"; public static readonly string XML_FILE_IDS = "FileIds"; public static readonly string XML_MAX = "Max"; public static readonly string XML_MIN = "Min"; public static readonly string XML_NUM_OF_POINTS = "NumOfPoints"; public static readonly string XML_RAW_FILENAME = "RawFilename"; public static readonly string XML_INFO = "Info"; public static readonly string XML_RAW_FILE_ID = "RawFileId"; public static readonly string XML_REF_FILE_ID = "RefFileId"; public static readonly string XML_REF_WHITE_FILE_ID = "RefWiteFileId"; public static readonly string XML_SEGMENT_END = "SegmentEnd"; public static readonly string XML_SEGMENT_START = "SegmentStart"; public static readonly string XML_SPECTRUM = "Spectrum"; public static readonly string XML_TYPE = "Type"; public static readonly string XML_WAVELENGTH = "Wavelength"; } }
INAF.Apps.Uwp.SLabDataManager/Extensions/Extensions.cs +116 −3 Original line number Diff line number Diff line Loading @@ -6,13 +6,16 @@ using INAF.Libraries.NetStandard.Math.Stats; using INAF.Libraries.NetStandard.ScienceModels.Spectra; using INAF.Libraries.NetStandard.SLabCommonModels.Models.Files; using INAF.Libraries.NetStandard.SLabCommonModels.Models.Spectrum; using INAF.Libraries.NetStandard.SLabCommonModels.Models.Spectrum.ProcessedSpectraInfo.Alignment; using INAF.Libraries.NetStandard.SLabCommonModels.Models.Spectrum.ProcessedSpectraInfo.ContinuumRemoval; using INAF.Libraries.NetStandard.SLabCommonModels.Models.Spectrum.ProcessedSpectraInfo.Smoothing; using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Linq; using System.Text; using System.Xml.Serialization; using Telerik.UI.Xaml.Controls.Chart; using Windows.Data.Xml.Dom; using Windows.UI; Loading Loading @@ -203,7 +206,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.Extensions } } public static FileSpectrumModel ToSpectrumFile(this ISpectrumModel model) public static FileSpectrumModel ToSpectrumFile(this IChartSpectrumModel model) { return new FileSpectrumModel() { Loading Loading @@ -262,7 +265,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.Extensions } } public static string ToTxt(this IMathSpectrumModel spectrum) public static string ToTxt(this ISpectrumModel spectrum) { if (spectrum == null || spectrum.Elements == null || spectrum.Elements.Count == 0) return null; Loading @@ -276,7 +279,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.Extensions return sb.ToString(); } public static XmlDocument ToXml(this ISpectrumModel spectrum) public static XmlDocument ToXml(this IChartSpectrumModel spectrum) { if (spectrum == null || spectrum.Elements == null || spectrum.Elements.Count == 0) return null; Loading @@ -299,6 +302,20 @@ namespace INAF.Apps.Uwp.SLabDataManager.Extensions xmlspectrum.AppendChild(xmlinfo); /* type specific actions */ if (spectrum.GetType() == typeof(ChartSpectrumOfTypeAlignedModel)) { xmlspectrum.AppendChild(GetAlignmentSettingsXml(dom, ((ChartSpectrumOfTypeAlignedModel)spectrum).AlignmentSettings)); } else if (spectrum.GetType() == typeof(ChartSpectrumOfTypeContinuumRemovedModel)) { xmlspectrum.AppendChild(GetSegmentsFitSettingsXml(dom, ((ChartSpectrumOfTypeContinuumRemovedModel)spectrum).ContinuumRemovalSettings)); } else if (spectrum.GetType() == typeof(ChartSpectrumOfTypeSmoothedModel)) { } /* append spectrum data (wavelength, value) */ var xmlelements = dom.CreateElement(Constants.Constants.XML_ELEMENTS); foreach (var element in spectrum.Elements) Loading Loading @@ -366,6 +383,102 @@ namespace INAF.Apps.Uwp.SLabDataManager.Extensions return elements; } #endregion #region aligned private static XmlElement GetAlignmentSettingsXml(XmlDocument dom, AlignmentSettingsModel alignmentSettings) { var xmlalignmentsettings = dom.CreateElement(Constants.Constants.XML_ALIGNMENT_SETTINGS); /* num of points */ var xmlnumofpoints = dom.CreateElement(Constants.Constants.XML_NUM_OF_POINTS); xmlnumofpoints.InnerText = alignmentSettings.NumOfPoints.ToString(); xmlalignmentsettings.AppendChild(xmlnumofpoints); /* segment boundaries */ var xmlsegmentboundaries = dom.CreateElement(Constants.Constants.XML_ALIGNMENT_SETTINGS_SEGMENT_BOUNDARIES); /* min */ var xmlsegmentboundariesmin = dom.CreateElement(Constants.Constants.XML_MIN); xmlsegmentboundariesmin.InnerText = alignmentSettings.AlignmentSegmentBoundaries.Min.ToString(); xmlsegmentboundaries.AppendChild(xmlsegmentboundariesmin); /* max */ var xmlsegmentboundariesmax = dom.CreateElement(Constants.Constants.XML_MAX); xmlsegmentboundariesmax.InnerText = alignmentSettings.AlignmentSegmentBoundaries.Max.ToString(); xmlsegmentboundaries.AppendChild(xmlsegmentboundariesmax); xmlalignmentsettings.AppendChild(xmlsegmentboundaries); /* file ids */ var xmlfileids = dom.CreateElement(Constants.Constants.XML_FILE_IDS); /* raw file id */ var xmlrawfileid = dom.CreateElement(Constants.Constants.XML_RAW_FILE_ID); xmlrawfileid.InnerText = alignmentSettings.RawFile.Id.ToString(); xmlfileids.AppendChild(xmlrawfileid); /* ref file id */ var xmlreffileid = dom.CreateElement(Constants.Constants.XML_REF_FILE_ID); xmlreffileid.InnerText = alignmentSettings.RefFile.Id.ToString(); xmlfileids.AppendChild(xmlreffileid); /* raw file id */ var xmlrefwhitefileid = dom.CreateElement(Constants.Constants.XML_REF_WHITE_FILE_ID); xmlrefwhitefileid.InnerText = alignmentSettings.RefWhiteFile.Id.ToString(); xmlfileids.AppendChild(xmlrefwhitefileid); xmlalignmentsettings.AppendChild(xmlfileids); xmlalignmentsettings.AppendChild(xmlsegmentboundaries); return xmlalignmentsettings; } #endregion #region segments fit private static XmlElement GetSegmentsFitSettingsXml(XmlDocument dom, ContinuumRemovalSettingsModel continuumRemovalSettings) { var xmlcontinuumremovalsettings = dom.CreateElement(Constants.Constants.XML_CONTINUUM_REMOVAL_SETTINGS); /* num of points */ var xmlnumofpoints = dom.CreateElement(Constants.Constants.XML_NUM_OF_POINTS); xmlnumofpoints.InnerText = continuumRemovalSettings.NumOfPointsForAveragingMissingPointX.ToString(); xmlcontinuumremovalsettings.AppendChild(xmlnumofpoints); /* segments */ var xmlsegments = dom.CreateElement(Constants.Constants.XML_CONTINUUM_REMOVAL_SETTINGS_SEGMENTS); foreach (var segment in continuumRemovalSettings.Segments) { var xmlsegment = dom.CreateElement(Constants.Constants.XML_CONTINUUM_REMOVAL_SETTINGS_SEGMENT); /* fit method name */ var xmlfitmethodname = dom.CreateElement(Constants.Constants.XML_CONTINUUM_REMOVAL_SETTINGS_SEGMENT_FIT_METHOD_NAME); xmlfitmethodname.InnerText = segment.FitMethodName; xmlsegment.AppendChild(xmlfitmethodname); var xmlsegmentstart = dom.CreateElement(Constants.Constants.XML_SEGMENT_START); xmlsegmentstart.InnerText = segment.XStart.ToDoubleInvariantString(); xmlsegment.AppendChild(xmlsegmentstart); var xmlsegmentend = dom.CreateElement(Constants.Constants.XML_SEGMENT_END); xmlsegmentend.InnerText = segment.XEnd.ToDoubleInvariantString(); xmlsegment.AppendChild(xmlsegmentend); /* fit param value */ if (segment.FitParamValue.HasValue) { var xmlfitparamvalue = dom.CreateElement(Constants.Constants.XML_CONTINUUM_REMOVAL_SETTINGS_SEGMENT_PARAMETER_VALUE); xmlfitmethodname.InnerText = segment.FitParamValue.Value.ToDoubleInvariantString(); xmlsegment.AppendChild(xmlfitparamvalue); } } xmlcontinuumremovalsettings.AppendChild(xmlsegments); return xmlcontinuumremovalsettings; } #endregion #endregion public static string GetDescription(this Enum enumValue) Loading
INAF.Apps.Uwp.SLabDataManager/Helpers/UI/Chart/ProcessingHelpers/SpectrumProcessingHelper.cs +18 −10 Original line number Diff line number Diff line using CommunityToolkit.Mvvm.ComponentModel; using INAF.Apps.Uwp.SLabDataManager.Charts; using INAF.Apps.Uwp.SLabDataManager.Charts.Containers; using INAF.Apps.Uwp.SLabDataManager.Extensions; using INAF.Apps.Uwp.SLabDataManager.Models; using INAF.Apps.Uwp.SLabDataManager.Models.Chart; using INAF.Apps.Uwp.SLabDataManager.Models.Fit; using INAF.Apps.Uwp.SLabDataManager.Models.Processing; Loading @@ -9,6 +9,7 @@ using INAF.Apps.Uwp.SLabDataManager.ViewModels.UserControlViewModels; using INAF.Libraries.NetStandard.Math.Fit.Linear; using INAF.Libraries.NetStandard.Math.Fit.Spline; using INAF.Libraries.NetStandard.ScienceModels.Spectra; using INAF.Libraries.NetStandard.SLabCommonModels.Models.Spectrum.ProcessedSpectraInfo.Alignment; using INAF.Libraries.Uwp.Logging; using Microsoft.Extensions.DependencyInjection; using System; Loading @@ -24,19 +25,19 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart.ProcessingHelpers private readonly LinearFitHelper linearFitHelper; private readonly AlignmentViewModel alignmentViewModel; private readonly SelectedRefBand selectedRefBand; private readonly WorkingItemsModel workingItems; private readonly SpectraContainer spectraContainer; private readonly Logger logger; public SpectrumProcessingHelper(IServiceProvider serviceProvider, SpectraContainer spectraContainer, LinearFitHelper linearFitHelper, WorkingItemsModel workingItems, AlignmentViewModel alignmentViewModel, SelectedRefBand selectedRefBand, Logger logger) { this.serviceProvider = serviceProvider; this.spectraContainer = spectraContainer; this.linearFitHelper = linearFitHelper; this.workingItems = workingItems; this.alignmentViewModel = alignmentViewModel; this.selectedRefBand = selectedRefBand; this.logger = logger; Loading @@ -59,10 +60,9 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart.ProcessingHelpers #region alignment methods private IChartSpectrumModel cloneSpectrumForAlignment() { var aligningSpectrum = (IChartSpectrumModel)workingItems.SpectraContainer.tryGetSpectrumOfType(SpectrumType.Raw).Clone(); aligningSpectrum.setType(SpectrumType.Aligned); aligningSpectrum.updateTitle(); return aligningSpectrum; var spectraFactory = serviceProvider.GetRequiredService<SpectraFactory>(); return spectraFactory.cloneSpectrum<ChartSpectrumOfTypeAlignedModel>(SpectrumType.Raw, SpectrumType.Aligned); } public async Task<ProcessingResult> alignRawSpectrumAsync() Loading @@ -76,14 +76,14 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart.ProcessingHelpers /* 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); var refWhiteSpectrum = spectraContainer.tryGetSpectrumOfType(SpectrumType.RefWhite); if (refWhiteSpectrum == null) 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); var refSpectrum = spectraContainer.tryGetSpectrumOfType(SpectrumType.Ref); if (refSpectrum == null) return new ProcessingResult("NoNormalizationAvailableMessage".GetText(), DialogMessageType.Warning); Loading Loading @@ -123,6 +123,14 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart.ProcessingHelpers alignRightSide(ref alignedSpectrum, refHighSeparator, refSegmentRightMean); /* save parameters used for alignment */ ((ChartSpectrumOfTypeAlignedModel)alignedSpectrum).AlignmentSettings.NumOfPoints = alignmentViewModel.NumOfPointsForAlignment; ((ChartSpectrumOfTypeAlignedModel)alignedSpectrum).AlignmentSettings.AlignmentSegmentBoundaries = new AlignmentSegmentBoundariesModel() { Min = refLowSeparator.CurrentValue, Max = refHighSeparator.CurrentValue }; } catch (Exception ex) { Loading
INAF.Apps.Uwp.SLabDataManager/Models/Chart/ChartSpectrumModel.cs +18 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Xml.Serialization; using Windows.UI.Xaml; using Windows.UI.Xaml.Media; using static INAF.Libraries.NetStandard.SLabCommonModels.Enums.Enums; Loading Loading @@ -53,6 +54,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.Models.Chart } private SolidColorBrush color; [XmlIgnore] public SolidColorBrush Color { get { return color; } Loading Loading @@ -97,5 +99,21 @@ namespace INAF.Apps.Uwp.SLabDataManager.Models.Chart { return new ChartSpectrumModel(spectrumType, points); } public new object Clone() { IChartSpectrumModel clonedSpectrum = new ChartSpectrumModel(serviceProvider, Type) { Id = Id, Filename = Filename, Filepath = Filepath, Title = Title, ParentId = ParentId }; foreach (var element in Elements) clonedSpectrum.add((ElementModel)element.Clone()); return clonedSpectrum; } } }
INAF.Apps.Uwp.SLabDataManager/Models/Chart/ChartSpectrumOfTypeAlignedModel.cs +15 −0 Original line number Diff line number Diff line using INAF.Libraries.NetStandard.SLabCommonModels.Models.Spectrum.ProcessedSpectraInfo.Alignment; using System; using static INAF.Libraries.NetStandard.SLabCommonModels.Enums.Enums; namespace INAF.Apps.Uwp.SLabDataManager.Models.Chart { public class ChartSpectrumOfTypeAlignedModel : ChartSpectrumModel { public ChartSpectrumOfTypeAlignedModel() { AlignmentSettings = new AlignmentSettingsModel(); } public ChartSpectrumOfTypeAlignedModel(IServiceProvider serviceProvider, SpectrumType spectrumType, string fileName, string filepath) : base(serviceProvider, spectrumType, fileName, filepath) { AlignmentSettings = new AlignmentSettingsModel(); } public AlignmentSettingsModel AlignmentSettings { get; set; } } }