Skip to content

Commit c398ea4

Browse files
committed
Improves handling of excluded data points during minimization
1 parent b158bcf commit c398ea4

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/easydiffraction/analysis/minimization.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,24 @@ def _residual_function(self,
144144
residuals: List[float] = []
145145

146146
for (expt_id, experiment), weight in zip(experiments._items.items(), _weights):
147+
148+
# Calculate the difference between measured and calculated patterns
147149
y_calc: np.ndarray = calculator.calculate_pattern(sample_models,
148150
experiment,
149-
called_by_minimizer=True) # True False
151+
called_by_minimizer=True)
150152
y_meas: np.ndarray = experiment.datastore.pattern.meas
151153
y_meas_su: np.ndarray = experiment.datastore.pattern.meas_su
152-
excluded: np.ndarray = experiment.datastore.pattern.excluded
153-
diff = ((y_meas - y_calc) / y_meas_su)[~excluded] # Exclude points that are marked as excluded
154-
diff *= np.sqrt(weight) # Residuals are squared before going into reduced chi-squared
154+
diff = ((y_meas - y_calc) / y_meas_su)
155+
156+
# Exclude points that are marked as excluded
157+
excluded = experiment.datastore.pattern.excluded
158+
if excluded is not None:
159+
diff = diff[~excluded]
160+
161+
# Residuals are squared before going into reduced chi-squared
162+
diff *= np.sqrt(weight)
163+
164+
# Append the residuals for this experiment
155165
residuals.extend(diff)
156166

157167
return self.minimizer.tracker.track(np.array(residuals), parameters)

0 commit comments

Comments
 (0)