Skip to content

Commit fdb9ddf

Browse files
committed
Changes bayes plots to use mean reflectivity and SLD
1 parent 92c6d67 commit fdb9ddf

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

RATapi/utils/plotting.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Plots using the matplotlib library"""
22

3+
import copy
34
from functools import partial, wraps
45
from math import ceil, floor, sqrt
56
from statistics import stdev
@@ -241,10 +242,11 @@ def plot_ref_sld(
241242
"""
242243
data = PlotEventData()
243244

245+
# We need to take a copy of results and SLD in case the data to plot is modified later
244246
data.modelType = project.model
245-
data.reflectivity = results.reflectivity
247+
data.reflectivity = copy.deepcopy(results.reflectivity)
246248
data.shiftedData = results.shiftedData
247-
data.sldProfiles = results.sldProfiles
249+
data.sldProfiles = copy.deepcopy(results.sldProfiles)
248250
data.resampledLayers = results.resampledLayers
249251
data.dataPresent = RATapi.inputs.make_data_present(project)
250252
data.subRoughs = results.contrastParams.subRoughs
@@ -275,6 +277,12 @@ def plot_ref_sld(
275277
for sld in results.predictionIntervals.sld
276278
],
277279
}
280+
# For a shaded plot, use the mean values from predictionIntervals
281+
for reflectivity, mean_reflectivity in zip(data.reflectivity, results.predictionIntervals.reflectivity):
282+
reflectivity[:, 1] = mean_reflectivity[2]
283+
for sldProfile, mean_sld_profile in zip(data.sldProfiles, results.predictionIntervals.sld):
284+
for sld, mean_sld in zip(sldProfile, mean_sld_profile):
285+
sld[:, 1] = mean_sld[2]
278286
else:
279287
raise ValueError(
280288
"Shaded confidence intervals are only available for the results of Bayesian analysis (NS or DREAM)"

cpp/rat.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,18 @@ py::list pyList1DFromRatCellWrap2D(const T& values)
995995
return result;
996996
}
997997

998+
template <typename T>
999+
py::list pyList1DFromRatCellWrap1D(const T& values)
1000+
{
1001+
py::list result;
1002+
1003+
for (int32_T idx0{0}; idx0 < values.size(0); idx0++) {
1004+
result.append(pyArrayFromRatArray2d(values[idx0].f1));
1005+
}
1006+
1007+
return result;
1008+
}
1009+
9981010
template <typename T>
9991011
py::list pyList2dFromRatCellWrap(const T& values)
10001012
{
@@ -1234,7 +1246,7 @@ BayesResults bayesResultsFromStruct9T(const RAT::struct9_T results)
12341246

12351247
bayesResults.chain = pyArrayFromRatArray2d(results.chain);
12361248

1237-
bayesResults.predictionIntervals.reflectivity = pyList1DFromRatCellWrap2D<coder::array<RAT::cell_wrap_11, 1U>>(results.predictionIntervals.reflectivity);
1249+
bayesResults.predictionIntervals.reflectivity = pyList1DFromRatCellWrap1D<coder::array<RAT::cell_wrap_11, 1U>>(results.predictionIntervals.reflectivity);
12381250
bayesResults.predictionIntervals.sld = pyList2dFromRatCellWrap<coder::array<RAT::cell_wrap_11, 2U>>(results.predictionIntervals.sld);
12391251
bayesResults.predictionIntervals.sampleChi = pyArray1dFromBoundedArray<coder::bounded_array<real_T, 1000U, 1U>>(results.predictionIntervals.sampleChi);
12401252

0 commit comments

Comments
 (0)