JFJochReceiverClient: Generate dummy plots for radial_integration_profile

This commit is contained in:
2023-06-26 09:58:10 +02:00
parent a43fa2a296
commit e0bf111941
2 changed files with 51 additions and 2 deletions
+49 -2
View File
@@ -154,8 +154,55 @@ JFJochProtoBuf::RadialIntegrationProfiles JFJochReceiverClient::GetRadialIntegra
if (!status.ok()) throw JFJochException(JFJochExceptionCategory::gRPCError,
"JFJochReceiver: " + status.error_message());
} else {
// TODO: Write some dummy plots
auto p = ret.add_profiles();
p->set_title("dataset");
*p->mutable_plot() = GenerateGaussianPlot(50, 0.1, 2.5, 0.2);
p = ret.add_profiles();
p->set_title("file0");
*p->mutable_plot() = GenerateGaussianPlot(50, 0.1, 3.0, 0.2);
p = ret.add_profiles();
p->set_title("file1");
*p->mutable_plot() = GenerateGaussianPlot(50, 0.1, 2.0, 0.2);
p = ret.add_profiles();
p->set_title("file2");
*p->mutable_plot() = GenerateGaussianPlot(50, 0.1, 2.5, 0.1);
p = ret.add_profiles();
p->set_title("file3");
*p->mutable_plot() = GenerateGaussianPlot(50, 0.1, 2.5, 0.5);
for (int i = 4; i < 16; i++) {
p = ret.add_profiles();
p->set_title("file" + std::to_string(i));
*p->mutable_plot() = GenerateGaussianPlot(50, 0.1, 2.3, 0.1 + 0.02 * i);
}
}
return ret;
}
}
JFJochProtoBuf::Plot JFJochReceiverClient::GenerateGaussianPlot(uint64_t n_elements, float spacing, float mean, float std) {
std::vector<float> x(n_elements);
std::vector<float> y(n_elements);
constexpr float inv_sqrt_2pi = 0.3989422804;
for (int i = 0; i < n_elements; i++) {
x[i] = spacing * i;
float a = (x[i] - mean) / std;
y[i] = inv_sqrt_2pi / std * expf(-0.5f * a * a);;
}
JFJochProtoBuf::Plot ret;
if (n_elements > 0) {
*ret.mutable_x() = {x.begin(), x.end()};
*ret.mutable_y() = {y.begin(), y.end()};
}
return ret;
}
+2
View File
@@ -12,6 +12,8 @@
class JFJochReceiverClient {
std::unique_ptr<JFJochProtoBuf::gRPC_JFJochReceiver::Stub> _stub;
static JFJochProtoBuf::Plot GenerateGaussianPlot(uint64_t n_elements, float spacing, float max, float std);
public:
void Connect(const std::string& addr);
void Start(const DiffractionExperiment &experiment, const JFCalibration *calibration);