Skip to content

Commit

Permalink
Change (int) cast -> Convert.ToInt32 on key features (convert double …
Browse files Browse the repository at this point in the history
…channel to integer channel)
  • Loading branch information
Am6er committed Jun 11, 2024
1 parent 7ec2f8b commit b492f29
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions BecquerelMonitor/BecquerelMonitor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
<MinimumRequiredVersion>2022.07.08.7</MinimumRequiredVersion>
<CreateWebPageOnPublish>true</CreateWebPageOnPublish>
<WebPage>index.html</WebPage>
<ApplicationRevision>1</ApplicationRevision>
<ApplicationVersion>2024.06.11.1</ApplicationVersion>
<ApplicationRevision>2</ApplicationRevision>
<ApplicationVersion>2024.06.11.2</ApplicationVersion>
<UseApplicationTrust>true</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
Expand Down
4 changes: 2 additions & 2 deletions BecquerelMonitor/EnergySpectrumView.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions BecquerelMonitor/PeakDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ List<Peak> CollectPeaks(FWHMPeakDetector.PeakFinder finder, EnergySpectrum energ
double centroid = finder.centroids[i];
int snr = (int)finder.snrs[i];
double fwhm = finder.fwhms[i];
centroid = sa.FindCentroid(energySpectrum, (int)centroid, (int)(centroid - fwhm), (int)(centroid + fwhm));
centroid = sa.FindCentroid(energySpectrum, Convert.ToInt32(centroid), Convert.ToInt32(centroid - fwhm), Convert.ToInt32(centroid + fwhm));

NuclideDefinition bestNuclide = null;
double minDelta = -1;
Peak peak = new Peak();
peak.Channel = (int)centroid;
peak.Channel = Convert.ToInt32(centroid);
peak.Energy = energySpectrum.EnergyCalibration.ChannelToEnergy(peak.Channel);
peak.SNR = snr;
peak.FWHM = fwhm;
Expand Down Expand Up @@ -141,8 +141,8 @@ List<Peak> CollectPeaks(FWHMPeakDetector.PeakFinder finder, EnergySpectrum energ

FWHMPeakDetector.PeakFinder PeakFinder(EnergySpectrum energySpectrum, FWHMPeakDetectionMethodConfig fWHMPeakDetectionMethodConfig)
{
int min_range_ch = (int)energySpectrum.EnergyCalibration.EnergyToChannel(fWHMPeakDetectionMethodConfig.Min_Range, maxChannels: energySpectrum.NumberOfChannels);
int max_range_ch = (int)energySpectrum.EnergyCalibration.EnergyToChannel(fWHMPeakDetectionMethodConfig.Max_Range, maxChannels: energySpectrum.NumberOfChannels);
int min_range_ch = Convert.ToInt32(energySpectrum.EnergyCalibration.EnergyToChannel(fWHMPeakDetectionMethodConfig.Min_Range, maxChannels: energySpectrum.NumberOfChannels));
int max_range_ch = Convert.ToInt32(energySpectrum.EnergyCalibration.EnergyToChannel(fWHMPeakDetectionMethodConfig.Max_Range, maxChannels: energySpectrum.NumberOfChannels));

double fwhm_tol_min = ((double)fWHMPeakDetectionMethodConfig.Min_FWHM_Tol) / 100;
double fwhm_tol_max = ((double)fWHMPeakDetectionMethodConfig.Max_FWHM_Tol) / 100;
Expand Down
6 changes: 3 additions & 3 deletions BecquerelMonitor/PolynomialEnergyCalibration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ double EnrgToChannel(double enrg, int maxCh = 8192)
System.Windows.Forms.MessageBox.Show(Resources.CalibrationFunctionError);
return 0;
}
return -c / b;
return - c / b;
}
else
{
Expand All @@ -239,7 +239,7 @@ double EnrgToChannel(double enrg, int maxCh = 8192)
{
double roots = FindRoots.OfFunction(f1, 0, maxCh);
//System.Windows.Forms.MessageBox.Show("Calibration coefficients are incorrect channels for Energy: " + enrg + " roots = " + roots);
return Math.Round(roots, 2);
return roots;
}
catch
{
Expand All @@ -256,7 +256,7 @@ double EnrgToChannel(double enrg, int maxCh = 8192)
try
{
double roots = FindRoots.OfFunction(f1, 0, maxCh);
return Math.Round(roots, 2);
return roots;
}
catch
{
Expand Down
4 changes: 2 additions & 2 deletions BecquerelMonitor/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: AssemblyVersion("2024.06.11.1")]
[assembly: AssemblyVersion("2024.06.11.2")]
[assembly: AssemblyProduct("BecquerelMonitor")]
[assembly: AssemblyCopyright("free")]
[assembly: AssemblyTrademark("none")]
[assembly: AssemblyConfiguration("")]
[assembly: Guid("40110b38-4882-47c1-ad94-a71e58dcb5f8")]
[assembly: AssemblyFileVersion("2024.06.11.1")]
[assembly: AssemblyFileVersion("2024.06.11.2")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyCompany("free")]
[assembly: CompilationRelaxations(8)]
Expand Down
32 changes: 16 additions & 16 deletions BecquerelMonitor/Utils/SpectrumAriphmetics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public int FindCentroid(EnergySpectrum energySpectrum, int centroid, int low_bou
}
}
if (new_centroid > high_boundary || new_centroid < low_boundary) new_centroid = centroid;
return (int)Math.Round(new_centroid);
return Convert.ToInt32(new_centroid);
}

double Ln(double x)
Expand Down Expand Up @@ -191,8 +191,8 @@ public static EnergySpectrum NormalizeSpectrum(EnergySpectrum spectrum, ROIConfi
return normalizedSpectrum;
}

int minChannel = (int)spectrum.EnergyCalibration.EnergyToChannel(roiAriphmetics.MinEnergy, maxChannels: normalizedSpectrum.NumberOfChannels);
int maxChannel = (int)spectrum.EnergyCalibration.EnergyToChannel(roiAriphmetics.MaxEnergy, maxChannels: normalizedSpectrum.NumberOfChannels);
int minChannel = Convert.ToInt32(spectrum.EnergyCalibration.EnergyToChannel(roiAriphmetics.MinEnergy, maxChannels: normalizedSpectrum.NumberOfChannels));
int maxChannel = Convert.ToInt32(spectrum.EnergyCalibration.EnergyToChannel(roiAriphmetics.MaxEnergy, maxChannels: normalizedSpectrum.NumberOfChannels));
normalizedSpectrum.TotalPulseCount = 0;
Parallel.For(0, normalizedSpectrum.NumberOfChannels, i =>
{
Expand Down Expand Up @@ -280,7 +280,7 @@ public EnergySpectrum SubtractPeaks(List<Peak> peaks, EnergySpectrum energySpect
int gauss(double x, double amplitude, double fwhm, double median)
{
double sigma = fwhm / 2.35482;
return (int)(amplitude * Math.Exp(-0.5 * Math.Pow((x - median) / sigma,2)));
return Convert.ToInt32(amplitude * Math.Exp(-0.5 * Math.Pow((x - median) / sigma,2)));
}

public (int[], int, int, Color) GetPeak(Peak peak, EnergySpectrum continuum, bool smooth)
Expand All @@ -294,7 +294,7 @@ int gauss(double x, double amplitude, double fwhm, double median)
{
amplitude = this.EnergySpectrum.Spectrum[peak.Channel] - continuum.Spectrum[peak.Channel];
}
int fwhm = (int)peak.FWHM;
int fwhm = Convert.ToInt32(peak.FWHM);
int median = peak.Channel;
int interval = 3 * fwhm;
int min_ch = median - interval;
Expand Down Expand Up @@ -364,7 +364,7 @@ int[] SASNIP(int[] x, double coeff = 1.0, bool useLLS = false, bool decreasing =
double[] r = new double[x.Length];
r = r.Select((i, iter) => (baseline[iter] == 0) ? 0 : coeff * (FWHM(iter, this.FWHMPeakDetectionMethodConfig))).ToArray();

int n = (int)r.Max();
int n = Convert.ToInt32(r.Max());

int[] seq = new int[n];
if (decreasing)
Expand Down Expand Up @@ -401,7 +401,7 @@ int[] SASNIP(int[] x, double coeff = 1.0, bool useLLS = false, bool decreasing =
baseline = baseline.Select(i => iLLS(i)).ToArray();
}

int[] baseline_arr = baseline.Select(i => (int)i).ToArray();
int[] baseline_arr = baseline.Select(i => Convert.ToInt32(i)).ToArray();

int baseline_max = 0;
int baseline_max_i = 0;
Expand Down Expand Up @@ -464,7 +464,7 @@ public static EnergySpectrum CutoffSpectrumChannels(EnergySpectrum energySpectru
public static EnergySpectrum CutoffSpectrumEnergy(EnergySpectrum energySpectrum, double energyVal)
{
PolynomialEnergyCalibration calibration = (PolynomialEnergyCalibration)energySpectrum.EnergyCalibration;
int newChan = (int)calibration.EnergyToChannel(energyVal, maxCh: energySpectrum.NumberOfChannels);
int newChan = Convert.ToInt32(calibration.EnergyToChannel(energyVal, maxCh: energySpectrum.NumberOfChannels));
return CutoffSpectrumChannels(energySpectrum, newChan);
}

Expand Down Expand Up @@ -496,7 +496,7 @@ public static EnergySpectrum ConcatSpectrum(EnergySpectrum energySpectrum, int n
newSpectrum.MeasurementTime = energySpectrum.MeasurementTime;
newSpectrum.TotalPulseCount = newSpectrum.Spectrum.Sum();
double newValidPulseCount = (double)newSpectrum.TotalPulseCount * (double)energySpectrum.ValidPulseCount / (double)energySpectrum.TotalPulseCount;
newSpectrum.ValidPulseCount = (int)newValidPulseCount;
newSpectrum.ValidPulseCount = Convert.ToInt32(newValidPulseCount);
newSpectrum.NumberOfSamples = energySpectrum.NumberOfSamples;
return newSpectrum;
}
Expand All @@ -516,7 +516,7 @@ public static EnergySpectrum RestoreSpectrum(EnergySpectrum energySpectrum, int
newSpectrum.MeasurementTime = energySpectrum.MeasurementTime;
newSpectrum.TotalPulseCount = newSpectrum.Spectrum.Sum();
double newValidPulseCount = (double)newSpectrum.TotalPulseCount * (double)energySpectrum.ValidPulseCount / (double)energySpectrum.TotalPulseCount;
newSpectrum.ValidPulseCount = (int)newValidPulseCount;
newSpectrum.ValidPulseCount = Convert.ToInt32(newValidPulseCount);
newSpectrum.NumberOfSamples = energySpectrum.NumberOfSamples;
return newSpectrum;
}
Expand Down Expand Up @@ -552,7 +552,7 @@ public double[] WMA2(double[] spectrum, int numberOfWMADataPoints, int countlimi
int window_size = 1;
if (spectrum[i] <= countlimit)
{
window_size = (int)Math.Round((double)spectrum[i] * (1 - (double)numberOfWMADataPoints) / (double)countlimit + (double)numberOfWMADataPoints);
window_size = Convert.ToInt32((double)spectrum[i] * (1 - (double)numberOfWMADataPoints) / (double)countlimit + (double)numberOfWMADataPoints);
}
if (window_size == 1)
{
Expand Down Expand Up @@ -591,7 +591,7 @@ public int[] WMA(int[] spectrum, int numberOfWMADataPoints, int countlimit = 100
int window_size = 1;
if (spectrum[i] <= countlimit)
{
window_size = (int)Math.Round((double)spectrum[i] * (1 - (double)numberOfWMADataPoints) / (double)countlimit + (double)numberOfWMADataPoints);
window_size = Convert.ToInt32((double)spectrum[i] * (1 - (double)numberOfWMADataPoints) / (double)countlimit + (double)numberOfWMADataPoints);
}
if (window_size == 1)
{
Expand All @@ -616,7 +616,7 @@ public int[] WMA(int[] spectrum, int numberOfWMADataPoints, int countlimit = 100
part += (double)spectrum[ch] * weight;
total += weight;
}
result[i] = (int)(part / total);
result[i] = Convert.ToInt32(part / total);
}
});
return result;
Expand All @@ -631,7 +631,7 @@ public double[] SMA2(double[] spectrum, int numberOfSMADataPoints, int countlimi
int window_size = 1;
if (spectrum[i] <= countlimit)
{
window_size = (int)Math.Round((double)spectrum[i] * (1 - (double)numberOfSMADataPoints) / (double)countlimit + (double)numberOfSMADataPoints);
window_size = Convert.ToInt32((double)spectrum[i] * (1 - (double)numberOfSMADataPoints) / (double)countlimit + (double)numberOfSMADataPoints);
}
if (window_size == 1)
{
Expand Down Expand Up @@ -667,7 +667,7 @@ public int[] SMA(int[] spectrum, int numberOfSMADataPoints, int countlimit = 100
int window_size = 1;
if (spectrum[i] <= countlimit)
{
window_size = (int)Math.Round((double)spectrum[i] * (1 - (double)numberOfSMADataPoints) / (double)countlimit + (double)numberOfSMADataPoints);
window_size = Convert.ToInt32((double)spectrum[i] * (1 - (double)numberOfSMADataPoints) / (double)countlimit + (double)numberOfSMADataPoints);
}
if (window_size == 1)
{
Expand All @@ -688,7 +688,7 @@ public int[] SMA(int[] spectrum, int numberOfSMADataPoints, int countlimit = 100
}
new_count += (double)spectrum[ch];
}
result[i] = (int)(new_count / (double)window_size);
result[i] = Convert.ToInt32(new_count / (double)window_size);
}
});
return result;
Expand Down

0 comments on commit b492f29

Please sign in to comment.