Improve plotting
This commit is contained in:
@@ -52,12 +52,17 @@ std::vector<float> AzimuthalIntegrationProfile::GetResult() const {
|
||||
return rad_int_profile;
|
||||
}
|
||||
|
||||
Plot AzimuthalIntegrationProfile::GetPlot() const {
|
||||
void AzimuthalIntegrationProfile::SetTitle(const std::string &input) {
|
||||
title = input;
|
||||
}
|
||||
|
||||
MultiLinePlot AzimuthalIntegrationProfile::GetPlot() const {
|
||||
std::unique_lock<std::mutex> ul(m);
|
||||
|
||||
Plot ret;
|
||||
ret.x = bin_to_q;
|
||||
ret.y = GetResult();
|
||||
MultiLinePlot ret(1);
|
||||
ret[0].x = bin_to_q;
|
||||
ret[0].y = GetResult();
|
||||
ret[0].title = title;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,16 +15,18 @@ class AzimuthalIntegrationProfile {
|
||||
std::vector<float> sum;
|
||||
std::vector<uint64_t> count;
|
||||
std::vector<float> bin_to_q;
|
||||
std::string title;
|
||||
public:
|
||||
explicit AzimuthalIntegrationProfile(const AzimuthalIntegrationMapping &mapping);
|
||||
AzimuthalIntegrationProfile(const AzimuthalIntegrationProfile& other); // Not thread safe
|
||||
AzimuthalIntegrationProfile(AzimuthalIntegrationProfile&& other) noexcept; // Not thread safe
|
||||
AzimuthalIntegrationProfile& operator=(const AzimuthalIntegrationProfile& other); //Not thread safe
|
||||
void SetTitle(const std::string& input);
|
||||
void Add(const DeviceOutput &result);
|
||||
void Add(const std::vector<float> &sum, const std::vector<uint32_t> &count);
|
||||
std::vector<float> GetResult() const;
|
||||
float GetMeanValueOfBins(uint16_t min_bin, uint16_t max_bin) const;
|
||||
Plot GetPlot() const;
|
||||
MultiLinePlot GetPlot() const;
|
||||
AzimuthalIntegrationProfile& operator+=(const AzimuthalIntegrationProfile& profile);
|
||||
};
|
||||
|
||||
|
||||
@@ -5,7 +5,11 @@ ADD_LIBRARY(JFJochImageAnalysis STATIC
|
||||
StrongPixelSet.cpp StrongPixelSet.h AzimuthalIntegrationProfile.cpp AzimuthalIntegrationProfile.h
|
||||
SpotFindingSettings.h
|
||||
AzimuthalIntegration.cpp
|
||||
AzimuthalIntegration.h)
|
||||
AzimuthalIntegration.h
|
||||
CPUSpotFinder.cpp
|
||||
CPUSpotFinder.h
|
||||
MXAnalyzer.cpp
|
||||
MXAnalyzer.h)
|
||||
|
||||
TARGET_LINK_LIBRARIES(JFJochImageAnalysis JFJochCommon)
|
||||
|
||||
|
||||
64
image_analysis/CPUSpotFinder.cpp
Normal file
64
image_analysis/CPUSpotFinder.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
// Copyright (2019-2024) Paul Scherrer Institute
|
||||
|
||||
#include "CPUSpotFinder.h"
|
||||
|
||||
template <int N>
|
||||
void FindSpots(StrongPixelSet& set,
|
||||
int big_column, int big_row,
|
||||
const SpotFindingSettings& settings,
|
||||
const int16_t* image) {
|
||||
uint64_t sum = 0;
|
||||
uint64_t sum2 = 0;
|
||||
uint64_t valid_count = 0;
|
||||
|
||||
for (int y = 0; y < N; y++) {
|
||||
for (int x = 0; x < N; x++) {
|
||||
size_t coord = (big_row * N + y) * RAW_MODULE_COLS + big_column * N + x;
|
||||
if ((image[coord] != INT16_MIN) || (image[coord] != INT16_MAX)) {
|
||||
sum += image[coord];
|
||||
sum2 += image[coord] * image[coord];
|
||||
valid_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int64_t variance = valid_count * sum2 - sum * sum;
|
||||
float threshold = variance * settings.signal_to_noise_threshold * settings.signal_to_noise_threshold;
|
||||
|
||||
for (int y = 0; y < N; y++) {
|
||||
for (int x = 0; x < N; x++) {
|
||||
size_t coord = (big_row * N + y) * RAW_MODULE_COLS + big_column * N + x;
|
||||
|
||||
bool strong_pixel = true;
|
||||
|
||||
if ((settings.photon_count_threshold < 0)
|
||||
&& (settings.signal_to_noise_threshold <= 0))
|
||||
strong_pixel = false;
|
||||
|
||||
if ((settings.photon_count_threshold >= 0)
|
||||
&& (image[coord] < settings.photon_count_threshold)) {
|
||||
strong_pixel = false;
|
||||
}
|
||||
|
||||
if (settings.signal_to_noise_threshold > 0) {
|
||||
int64_t in_minus_mean = image[coord] * valid_count - sum;
|
||||
if ((in_minus_mean * in_minus_mean <= threshold)
|
||||
|| (in_minus_mean <= 0)
|
||||
|| (valid_count < N * N / 2))
|
||||
strong_pixel = false;
|
||||
}
|
||||
|
||||
if (strong_pixel)
|
||||
set.AddStrongPixel(big_column * N + x, big_row * N + y, image[coord]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FindSpots(StrongPixelSet& set,
|
||||
const SpotFindingSettings& settings,
|
||||
const int16_t* image) {
|
||||
for (int i = 0; i < RAW_MODULE_LINES / 32; i++) {
|
||||
for (int j = 0; j < RAW_MODULE_COLS / 32; j++)
|
||||
FindSpots<32>(set, j, i, settings, image);
|
||||
}
|
||||
}
|
||||
14
image_analysis/CPUSpotFinder.h
Normal file
14
image_analysis/CPUSpotFinder.h
Normal file
@@ -0,0 +1,14 @@
|
||||
// Copyright (2019-2024) Paul Scherrer Institute
|
||||
|
||||
#ifndef JUNGFRAUJOCH_CPUSPOTFINDER_H
|
||||
#define JUNGFRAUJOCH_CPUSPOTFINDER_H
|
||||
|
||||
#include "../common/DiffractionExperiment.h"
|
||||
#include "SpotFindingSettings.h"
|
||||
#include "StrongPixelSet.h"
|
||||
|
||||
void FindSpots(StrongPixelSet& set,
|
||||
const SpotFindingSettings& settings,
|
||||
const int16_t* image);
|
||||
|
||||
#endif //JUNGFRAUJOCH_CPUSPOTFINDER_H
|
||||
65
image_analysis/MXAnalyzer.cpp
Normal file
65
image_analysis/MXAnalyzer.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
// Copyright (2019-2024) Paul Scherrer Institute
|
||||
|
||||
#include "MXAnalyzer.h"
|
||||
#include "CPUSpotFinder.h"
|
||||
|
||||
MXAnalyzer::MXAnalyzer(const DiffractionExperiment &in_experiment)
|
||||
: experiment(in_experiment) {
|
||||
auto uc = experiment.GetUnitCell();
|
||||
if (uc) {
|
||||
do_indexing = true;
|
||||
indexer.Setup(uc.value());
|
||||
}
|
||||
if (experiment.IsSpotFindingEnabled())
|
||||
find_spots = true;
|
||||
|
||||
}
|
||||
|
||||
void MXAnalyzer::ReadFromFPGA(const DeviceOutput *output, const SpotFindingSettings &settings, size_t module_number) {
|
||||
if (!find_spots)
|
||||
return;
|
||||
StrongPixelSet strong_pixel_set;
|
||||
strong_pixel_set.ReadFPGAOutput(*output);
|
||||
strong_pixel_set.FindSpots(experiment, settings, spots, module_number);
|
||||
}
|
||||
|
||||
void MXAnalyzer::ReadFromCPU(const int16_t *image, const SpotFindingSettings &settings, size_t module_number) {
|
||||
if (!find_spots)
|
||||
return;
|
||||
StrongPixelSet strong_pixel_set;
|
||||
FindSpots(strong_pixel_set, settings, image);
|
||||
strong_pixel_set.FindSpots(experiment, settings, spots, module_number);
|
||||
}
|
||||
|
||||
bool MXAnalyzer::Process(DataMessage &message) {
|
||||
message.indexing_result = 0;
|
||||
if (!find_spots)
|
||||
return false;
|
||||
|
||||
bool indexed = false;
|
||||
|
||||
std::vector<DiffractionSpot> spots_out;
|
||||
FilterSpotsByCount(experiment, spots, spots_out);
|
||||
|
||||
for (const auto &spot: spots_out)
|
||||
message.spots.push_back(spot);
|
||||
|
||||
if (do_indexing) {
|
||||
std::vector<Coord> recip;
|
||||
for (const auto &i: spots_out)
|
||||
recip.push_back(i.ReciprocalCoord(experiment));
|
||||
|
||||
auto indexer_result = indexer.Run(recip);
|
||||
|
||||
if (!indexer_result.empty()) {
|
||||
message.indexing_result = 1;
|
||||
for (int i = 0; i < recip.size(); i++)
|
||||
message.spots[i].indexed = indexer_result[0].indexed_spots[i];
|
||||
indexer_result[0].l.Save(message.indexing_lattice);
|
||||
message.indexing_unit_cell = indexer_result[0].l.GetUnitCell();
|
||||
indexed = true;
|
||||
}
|
||||
}
|
||||
spots.clear();
|
||||
return indexed;
|
||||
}
|
||||
30
image_analysis/MXAnalyzer.h
Normal file
30
image_analysis/MXAnalyzer.h
Normal file
@@ -0,0 +1,30 @@
|
||||
// Copyright (2019-2024) Paul Scherrer Institute
|
||||
|
||||
#ifndef JUNGFRAUJOCH_MXANALYZER_H
|
||||
#define JUNGFRAUJOCH_MXANALYZER_H
|
||||
|
||||
#include "../common/DiffractionExperiment.h"
|
||||
#include "IndexerWrapper.h"
|
||||
#include "StrongPixelSet.h"
|
||||
|
||||
class MXAnalyzer {
|
||||
const DiffractionExperiment &experiment;
|
||||
IndexerWrapper indexer;
|
||||
bool do_indexing = false;
|
||||
bool find_spots = false;
|
||||
std::vector<DiffractionSpot> spots;
|
||||
public:
|
||||
explicit MXAnalyzer(const DiffractionExperiment& experiment);
|
||||
|
||||
void ReadFromFPGA(const DeviceOutput* output,
|
||||
const SpotFindingSettings& settings,
|
||||
size_t module_number);
|
||||
void ReadFromCPU(const int16_t *image,
|
||||
const SpotFindingSettings& settings,
|
||||
size_t module_number);
|
||||
|
||||
bool Process(DataMessage &message);
|
||||
};
|
||||
|
||||
|
||||
#endif //JUNGFRAUJOCH_MXANALYZER_H
|
||||
Reference in New Issue
Block a user