Skip to content
Snippets Groups Projects
Commit 31381d37 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

Datafield::crop[2] no longer delete error bars

parent 1ecbef26
No related branches found
No related tags found
1 merge request!1974Pt fit example now loading data the ba way
......@@ -273,14 +273,20 @@ Datafield* Datafield::crop(double xmin, double xmax) const
{
const auto xclipped = std::make_unique<Scale>(xAxis().clipped(xmin, xmax));
std::vector<double> out(size());
const size_t N = size();
std::vector<double> out(N);
std::vector<double> errout(hasErrorSigmas() ? N : 0);
size_t iout = 0;
for (size_t i = 0; i < size(); ++i) {
for (size_t i = 0; i < N; ++i) {
const double x = frame().projectedCoord(i, 0);
if (xclipped->rangeComprises(x))
out[iout++] = m_values[i];
if (xclipped->rangeComprises(x)) {
out[iout] = m_values[i];
if (hasErrorSigmas())
errout[iout] = m_errSigmas[i];
++iout;
}
}
return new Datafield(frame().clone(), out);
return new Datafield(frame().clone(), out, errout);
}
#ifdef BORNAGAIN_PYTHON
......
......@@ -104,7 +104,7 @@ if __name__ == '__main__':
}
startPnB = {
"intensity": (1., 0.7, 1.3),
"intensity": (1., 0.8, 1.2),
"q_offset": (0.01, -0.02, 0.02),
"q_res/q": (0.01, 0, 0.02),
"t_pt/nm": (50, 45, 55),
......@@ -125,9 +125,15 @@ if __name__ == '__main__':
flags = ba.ImportSettings1D("q (1/angstrom)", "#", "", 1, 2, 3, 4)
data = ba.readData1D(fpath, ba.csv1D, flags)
# Initial plot
r = get_simulation(qzs, initialP | fixedP).simulate().npArray()
plot(qzs, r, data, initialP)
# Restrict data to given q range
data = data.crop(qmin, qmax)
# Fit:
fit_objective = ba.FitObjective()
......
......@@ -104,7 +104,7 @@ if __name__ == '__main__':
}
startPnB = {
"intensity": (1., 0.7, 1.3),
"intensity": (1., 0.8, 1.2),
"q_offset": (0.01, -0.02, 0.02),
"q_res/q": (0.01, 0, 0.02),
"t_pt/nm": (50, 45, 55),
......@@ -125,9 +125,15 @@ if __name__ == '__main__':
flags = ba.ImportSettings1D("q (1/angstrom)", "#", "", 1, 2, 3, 4)
data = ba.readData1D(fpath, ba.csv1D, flags)
# Initial plot
r = get_simulation(qzs, initialP | fixedP).simulate().npArray()
plot(qzs, r, data, initialP)
# Restrict data to given q range
data = data.crop(qmin, qmax)
# Fit:
fit_objective = ba.FitObjective()
......
......@@ -125,9 +125,15 @@ if __name__ == '__main__':
flags = ba.ImportSettings1D("q (1/angstrom)", "#", "", 1, 2, 3, 4)
data = ba.readData1D(fpath, ba.csv1D, flags)
# Initial plot
r = get_simulation(qzs, initialP | fixedP).simulate().npArray()
plot(qzs, r, data, initialP)
# Restrict data to given q range
data = data.crop(qmin, qmax)
# Fit:
fit_objective = ba.FitObjective()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment