Skip to content

Commit 13e082e

Browse files
committed
Copilot changes
1 parent 6d55a9b commit 13e082e

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

src/sas/sascalc/size_distribution/SizeDistribution.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323

2424
def add_gaussian_noise(x: npt.ArrayLike, dx: npt.ArrayLike, seed: int | None = None) -> npt.NDArray:
2525
"""
26-
Add Gaussian noise to data based on the sigma of the Guassian uncertainty
26+
Add Gaussian noise to data based on the sigma of the Gaussian uncertainty
2727
value associated with the data.
2828
29-
:param x: nput intensity values
30-
:param dx: sigma of Guassian uncertainties associated with the intensities
29+
:param x: input intensity values
30+
:param dx: sigma of Gaussian uncertainties associated with the intensities
3131
:param seed: random seed for reproducibility (default: None)
3232
:return: data with added Gaussian noise
3333
"""
@@ -190,8 +190,8 @@ def __init__(self, data: Data1D):
190190
self._binDiff: np.ndarray = np.array([])
191191
self._volumes: np.ndarray | None = None
192192

193-
# Return Values after the MaxEnt should
194-
self.BinMagnitude_maxEnt: np.ndarray = np.zeros_like(self.bins)
193+
# Return Values after the MaxEnt fit
194+
self.BinMagnitude_maxEnt: np.ndarray = np.array([], dtype=float)
195195
self.BinMagnitude_Errs: np.ndarray | None = None
196196
self.BinMag_numberDist: np.ndarray | None = None
197197
self.number_cdf: np.ndarray | None = None
@@ -534,7 +534,7 @@ def prep_maxEnt(
534534
1. Subtract intensities from the raw data.
535535
2. Trim the data to the correct q-range for maxEnt; Create new trimmed Data1D object to return after MaxEnt.
536536
3. Generate Model Data based of the trimmed data.
537-
4. Create a list of intensities for maxEnt, if full_fit == True , call add_gausisan_noise nreps times;
537+
4. Create a list of intensities for maxEnt, if full_fit == True , call add_gaussian_noise nreps times;
538538
pass just subtracted intensities.
539539
5. Calculate initial bin weights, sigma, and return.
540540
@@ -550,7 +550,8 @@ def prep_maxEnt(
550550
pars_keys = ["x", "y", "dx", "dy"]
551551
trim_data_pars = {}
552552

553-
assert len(sub_intensities.y) == len(self._data.y)
553+
if len(sub_intensities.y) != len(self._data.y):
554+
logger.error("The length of the subtracted intensities does not match the length of the data. ")
554555

555556
for pkey in pars_keys:
556557
check_data = pkey in list(self._data.__dict__.keys())
@@ -619,15 +620,15 @@ def run_maxEnt(
619620
ChiSq.append(chisq)
620621
BinMag.append(bin_magnitude)
621622
IMaxEnt.append(icalc)
622-
convergence.append([converged, conv_iter])
623+
convergence.append((converged, conv_iter))
623624
if not converged:
624625
logger.warning(
625626
"Maximum Entropy did not converge. Try increasing the weight factor "
626627
"to increase the weighting effect."
627628
)
628629
except ZeroDivisionError:
629630
logger.error(
630-
"Divide by Zero Error occured in maximum entropy fitting. "
631+
"Divide by Zero Error occurred in maximum entropy fitting. "
631632
"Try increasing the weight factor to increase the error weighting"
632633
)
633634

@@ -664,7 +665,14 @@ def run_maxEnt(
664665

665666
return convergence
666667

667-
def calculate_statistics(self, bin_mag: list) -> None:
668+
def calculate_statistics(self, bin_mag: npt.ArrayLike) -> None:
669+
"""
670+
Calculate statistics from the MaxEnt results, including volume fraction cumulative distribution function (CDF),
671+
number distribution, and related statistics such as mean, median, and mode.
672+
673+
:param bin_mag: list of bin magnitudes from the MaxEnt fits
674+
"""
675+
bin_mag = np.asarray(bin_mag)
668676
maxent_cdf_array = integrate.cumulative_trapezoid(bin_mag / (2 * self._binDiff), 2 * self.bins, axis=1)
669677
self.BinMag_numberDist = self.BinMagnitude_maxEnt / ellipse_volume(self.aspectRatio * self.bins, self.bins)
670678

0 commit comments

Comments
 (0)