Skip to content

Commit

Permalink
Updates outputs correctly (#32)
Browse files Browse the repository at this point in the history
* Updates outputs correctly

* Fixes expected output in plot function

* Addresses review comment
  • Loading branch information
StephenNneji authored May 9, 2024
1 parent d26e760 commit a708a2f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
2 changes: 1 addition & 1 deletion RAT/utils/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def plot_ref_sld(data: PlotEventData, fig: Figure = None, delay: bool = True):
data.sldProfiles,
data.resampledLayers)):

r, sd, sld, layer = map(lambda x: x[0], (r, sd, sld, layer))
sld, layer = map(lambda x: x[0], (sld, layer))

# Calculate the divisor
div = 1 if i == 0 else 2**(4*(i+1))
Expand Down
42 changes: 20 additions & 22 deletions cpp/rat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -916,36 +916,24 @@ OutputResult OutputResultFromStruct5T(const RAT::struct5_T result)
// Copy problem to output
OutputResult output_result;
for (int32_T idx0{0}; idx0 < result.reflectivity.size(0); idx0++) {
py::list inner_list;
for (int32_T idx1{0}; idx1 < result.reflectivity.size(1); idx1++) {
auto tmp = result.reflectivity[idx0 + result.reflectivity.size(0) * idx1];
auto array = py::array_t<real_T, py::array::f_style>({tmp.f1.size(0), tmp.f1.size(1)});
std::memcpy(array.request().ptr, tmp.f1.data(), array.nbytes());
inner_list.append(array);
}
output_result.reflectivity.append(inner_list);
auto tmp = result.reflectivity[idx0];
auto array = py::array_t<real_T, py::array::f_style>({tmp.f1.size(0), tmp.f1.size(1)});
std::memcpy(array.request().ptr, tmp.f1.data(), array.nbytes());
output_result.reflectivity.append(array);
}

for (int32_T idx0{0}; idx0 < result.simulation.size(0); idx0++) {
py::list inner_list;
for (int32_T idx1{0}; idx1 < result.simulation.size(1); idx1++) {
auto tmp = result.simulation[idx0 + result.simulation.size(0) * idx1];
auto tmp = result.simulation[idx0];
auto array = py::array_t<real_T, py::array::f_style>({tmp.f1.size(0), tmp.f1.size(1)});
std::memcpy(array.request().ptr, tmp.f1.data(), array.nbytes());
inner_list.append(array);
}
output_result.simulation.append(inner_list);
output_result.simulation.append(array);
}

for (int32_T idx0{0}; idx0 < result.shiftedData.size(0); idx0++) {
py::list inner_list;
for (int32_T idx1{0}; idx1 < result.shiftedData.size(1); idx1++) {
auto tmp = result.shiftedData[idx0 + result.shiftedData.size(0) * idx1];
auto tmp = result.shiftedData[idx0];
auto array = py::array_t<real_T, py::array::f_style>({tmp.f1.size(0), tmp.f1.size(1)});
std::memcpy(array.request().ptr, tmp.f1.data(), array.nbytes());
inner_list.append(array);
}
output_result.shiftedData.append(inner_list);
output_result.shiftedData.append(array);
}

for (int32_T idx0{0}; idx0 < result.layerSlds.size(0); idx0++) {
Expand Down Expand Up @@ -981,8 +969,18 @@ OutputResult OutputResultFromStruct5T(const RAT::struct5_T result)
output_result.resampledLayers.append(inner_list);
}

for (int32_T idx0{0}; idx0 < result.fitNames.size(0); idx0++) {
auto tmp = result.fitNames[idx0];
std::string str(tmp.f1.data(), tmp.f1.size(1));
output_result.fitNames.append(str);
}

output_result.fitParams = py::array_t<real_T>(result.fitParams.size(1));
auto buffer = output_result.fitParams.request();
std::memcpy(buffer.ptr, result.fitParams.data(), output_result.fitParams.size()*sizeof(real_T));

output_result.contrastParams.backgroundParams = py::array_t<real_T>(result.contrastParams.backgroundParams.size(0));
auto buffer = output_result.contrastParams.backgroundParams.request();
buffer = output_result.contrastParams.backgroundParams.request();
std::memcpy(buffer.ptr, result.contrastParams.backgroundParams.data(), output_result.contrastParams.backgroundParams.size()*sizeof(real_T));

output_result.contrastParams.scalefactors = py::array_t<real_T>(result.contrastParams.scalefactors.size(0));
Expand Down Expand Up @@ -1357,7 +1355,7 @@ PYBIND11_MODULE(rat_core, m) {
.def_readwrite("shiftedData", &OutputResult::shiftedData)
.def_readwrite("layerSlds", &OutputResult::layerSlds)
.def_readwrite("sldProfiles", &OutputResult::sldProfiles)
.def_readwrite("resampledLayers)", &OutputResult::resampledLayers)
.def_readwrite("resampledLayers", &OutputResult::resampledLayers)
.def_readwrite("calculationResults", &OutputResult::calculationResults)
.def_readwrite("contrastParams", &OutputResult::contrastParams)
.def_readwrite("bestFitParams", &OutputResult::fitParams)
Expand Down
Binary file modified tests/test_data/plotting_data.pickle
Binary file not shown.
2 changes: 0 additions & 2 deletions tests/test_plotting.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import os
import re
import csv
import pytest
import pickle
from unittest.mock import patch
from unittest.mock import MagicMock
import numpy as np
import matplotlib.pyplot as plt
from RAT.rat_core import PlotEventData
from RAT.utils.plotting import Figure, plot_ref_sld
Expand Down

0 comments on commit a708a2f

Please sign in to comment.