/// <summary> /// Gets the peak inforamtion async /// </summary> /// <param name="peaks"></param> /// <returns></returns> public override async Task LoadDataAsync(DataTable peaks) { /**********get the data async******/ camfile.ReadFile(file); //time Task <DateTime> acqTask = Task.Run(() => camfile.GetAqusitionTime()); Task <DateTime> sampTask = Task.Run(() => camfile.GetSampleTime()); Task <double> liveTask = Task.Run(() => camfile.GetLiveTime()); //sepectrum Task <uint[]> specTask = Task.Run(() => camfile.GetSpectrum()); //peaks Task <Peak[]> peakTask = Task.Run(() => camfile.GetPeaks().ToArray()); //calibrations Task <double[]> ecalTask = Task.Run(() => camfile.GetEnergyCalibration()); Task <double[]> shapeCalTask = Task.Run(() => camfile.GetShapeCalibration()); Task <EfficiencyPoint[]> effCalTask = Task.Run(() => camfile.GetEfficiencyPoints().ToArray()); //assign variables collTime = await sampTask; acqTime = await acqTask; elapsedWait = collTime - acqTime; countTime = await liveTask; spectrum = await specTask; //assign the calibration info energyCoeff = await ecalTask; shapeCoeff = await shapeCalTask; EfficiencyPoint[] effpts = await effCalTask; //assign the efficiency points effMeas = new System.Collections.ObjectModel.ObservableCollection <EfficiencyMeasurement>(); for (int i = 0; i < effpts.Length; i++) { effMeas.Add(new EfficiencyMeasurement(effpts[i].Energy, effpts[i].Efficiency, effpts[i].EfficiencyUncertainty)); } effMeas.CollectionChanged += EffMeas_CollectionChanged; //assign the peaks Peak[] filePeaks = await peakTask; //add the peaks to the datatable foreach (Peak pk in filePeaks) { DataRow row = peaks.NewRow(); row["ENERGY"] = pk.Energy; row["FWHM"] = pk.FullWidthAtHalfMaximum; row["AREA"] = pk.Area; row["AREAUNC"] = pk.AreaUncertainty; row["CONTINUUM"] = pk.Continuum; row["CRITLEVEL"] = pk.CriticalLevel; peaks.Rows.Add(row); } order = effMeas.Count > 7 ? 5 : effMeas.Count > 2 ? effMeas.Count - 2 : 3; calParams = GetCalibrationParameters(); }
/// <summary> /// async load a library from file /// </summary> /// <param name="file">The path to the file</param> /// <returns></returns> public override async Task LoadLibraryAsync(string file) { //if the file dosen't exist if (!File.Exists(file)) { return; } if (lib == null) { InitilizeLib(); } //read the file camfile.ReadFile(file); //get the data from the file async Task <Nuclide[]> nucTask = Task.Run(() => camfile.GetNuclides().ToArray()); //parse the nuclides Nuclide[] nucs = await nucTask; foreach (Nuclide nuc in nucs) { DataRow nucRow = lib.Tables["MATCHEDNUCLIDES"].NewRow(); nucRow["ID"] = nuc.Index; nucRow["NAME"] = nuc.Name.Trim(); nucRow["HALF_LIFE"] = nuc.HalfLife; nucRow["HALF_LIFE_UNIT"] = nuc.HalfLifeUnit.Trim(); lib.Tables["MATCHEDNUCLIDES"].Rows.Add(nucRow); } //parse the lines Line[] lines = camfile.Lines.ToArray(); int ln = 0; foreach (Line line in lines) { DataRow nucRow = lib.Tables["MATCHEDLINES"].NewRow(); //check if the name has changed, if so reset the line number //check for bad lines Nuclide nuc = nucs.Where(r => r.Index == line.NuclideIndex).FirstOrDefault(); nucRow["NAME"] = nuc.Name; nucRow["LINENUMBER"] = ln; nucRow["ENERGY"] = line.Energy; nucRow["ENERGYUNC"] = line.EnergyUncertainty; nucRow["YIELD"] = line.Abundance; nucRow["YIELDUNC"] = line.AbundanceUncertainty; nucRow["ISKEY"] = line.IsKeyLine; lib.Tables["MATCHEDLINES"].Rows.Add(nucRow); ln++; } }
/// <summary> /// Gets the peak inforamtion async /// </summary> /// <param name="peaks"></param> /// <returns></returns> public override async Task LoadDataAsync(DataTable peaks) { /**********get the data async******/ camfile.ReadFile(file); //time Task <DateTime> acqTask = Task.Run(() => camfile.GetAqusitionTime()); Task <DateTime> sampTask = Task.Run(() => camfile.GetSampleTime()); Task <double> liveTask = Task.Run(() => camfile.GetLiveTime()); //sepectrum Task <uint[]> specTask = Task.Run(() => camfile.GetSpectrum()); //peaks Task <Peak[]> peakTask = Task.Run(() => camfile.GetPeaks().ToArray()); //calibrations Task <double[]> ecalTask = Task.Run(() => camfile.GetEnergyCalibration()); Task <double[]> shapeCalTask = Task.Run(() => camfile.GetShapeCalibration()); Task <EfficiencyPoint[]> effCalTask = Task.Run(() => camfile.GetEfficiencyPoints().ToArray()); //assign variables collTime = await sampTask; acqTime = await acqTask; elapsedWait = collTime - acqTime; countTime = await liveTask; spectrum = await specTask; //assign the calibration info energyCoeff = await ecalTask; shapeCoeff = await shapeCalTask; //efficiency is not necessary, if there isn't efficiency calibration add some defaults try { effMeas = new ObservableEntityCollection <EfficiencyMeasurement>(); EfficiencyPoint[] effpts = await effCalTask; if (effpts.Length < 2) { throw new FileFormatException("Not enough efficiency points to perfom calculations"); } for (int i = 0; i < effpts.Length; i++) { effMeas.Add(new EfficiencyMeasurement(effpts[i].Energy, effpts[i].Efficiency, effpts[i].EfficiencyUncertainty)); } } catch (FileFormatException) { double eff = 0.9999999999999; double effunc = 0.000000000005; effMeas.Add(new EfficiencyMeasurement(Properties.Settings.Default.LOWERELIMT, eff, effunc)); effMeas.Add(new EfficiencyMeasurement((Properties.Settings.Default.LOWERELIMT + Properties.Settings.Default.UPPERELIMIT) / 2, eff, effunc)); effMeas.Add(new EfficiencyMeasurement(Properties.Settings.Default.UPPERELIMIT, eff, effunc)); order = 2; } effMeas.CollectionChanged += EffMeas_CollectionChanged; //assign the peaks Peak[] filePeaks = await peakTask; //add the peaks to the datatable foreach (Peak pk in filePeaks) { DataRow row = peaks.NewRow(); row["ENERGY"] = pk.Energy; row["FWHM"] = pk.FullWidthAtHalfMaximum; row["AREA"] = pk.Area; row["AREAUNC"] = pk.AreaUncertainty; row["CONTINUUM"] = pk.Continuum; row["CRITLEVEL"] = pk.CriticalLevel; peaks.Rows.Add(row); } order = effMeas.Count > 7 ? 5 : effMeas.Count > 2 ? effMeas.Count - 2 : 3; calParams = GetCalibrationParameters(); }