From e0bf111941912f246c8ac3bbc962ae7094f0d003 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Mon, 26 Jun 2023 09:58:10 +0200 Subject: [PATCH] JFJochReceiverClient: Generate dummy plots for radial_integration_profile --- grpc/JFJochReceiverClient.cpp | 51 +++++++++++++++++++++++++++++++++-- grpc/JFJochReceiverClient.h | 2 ++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/grpc/JFJochReceiverClient.cpp b/grpc/JFJochReceiverClient.cpp index 25c88f4e..0ef4eb90 100644 --- a/grpc/JFJochReceiverClient.cpp +++ b/grpc/JFJochReceiverClient.cpp @@ -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; -} \ No newline at end of file +} + +JFJochProtoBuf::Plot JFJochReceiverClient::GenerateGaussianPlot(uint64_t n_elements, float spacing, float mean, float std) { + + std::vector x(n_elements); + std::vector 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; +} + diff --git a/grpc/JFJochReceiverClient.h b/grpc/JFJochReceiverClient.h index cc939bfe..401a6f37 100644 --- a/grpc/JFJochReceiverClient.h +++ b/grpc/JFJochReceiverClient.h @@ -12,6 +12,8 @@ class JFJochReceiverClient { std::unique_ptr _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);