diff --git a/Device/Data/Datafield.cpp b/Device/Data/Datafield.cpp index 08038dc68f1140db86514f46b4784b73a4334790..6ab5ce4a88b64390bc828646a61e3828ecd19bcc 100644 --- a/Device/Data/Datafield.cpp +++ b/Device/Data/Datafield.cpp @@ -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 diff --git a/auto/Examples/fit/specular/Pt_layer_fit.py b/auto/Examples/fit/specular/Pt_layer_fit.py index 81b1a746674cc331fa1571a9a2e6cb65d028ded9..bd4f17520fee49a59f810e4a594f716bd8b87d3c 100755 --- a/auto/Examples/fit/specular/Pt_layer_fit.py +++ b/auto/Examples/fit/specular/Pt_layer_fit.py @@ -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() diff --git a/auto/MiniExamples/fit/specular/Pt_layer_fit.py b/auto/MiniExamples/fit/specular/Pt_layer_fit.py index 4f3bba2f10402a0fe490a0c190b8120ce9c96405..3a32ac836a50139f3b1423030723776ae4ac5b99 100755 --- a/auto/MiniExamples/fit/specular/Pt_layer_fit.py +++ b/auto/MiniExamples/fit/specular/Pt_layer_fit.py @@ -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() diff --git a/rawEx/fit/specular/Pt_layer_fit.py b/rawEx/fit/specular/Pt_layer_fit.py index 70a25952906b654253c6b32196242c7bb7c2c5b1..bae2abf7f92edefe9b3e60190c1b177319a6c500 100755 --- a/rawEx/fit/specular/Pt_layer_fit.py +++ b/rawEx/fit/specular/Pt_layer_fit.py @@ -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()