From 8f99dad3c42ab08d631b1ac02b195b33944c7240 Mon Sep 17 00:00:00 2001 From: Yaroslav Gevorkov Date: Thu, 24 May 2018 10:07:11 +0200 Subject: Add "peakfinder9" --- libcrystfel/src/peaks.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++ libcrystfel/src/peaks.h | 6 +++ 2 files changed, 112 insertions(+) (limited to 'libcrystfel') diff --git a/libcrystfel/src/peaks.c b/libcrystfel/src/peaks.c index 28c79538..7f6e0ba7 100644 --- a/libcrystfel/src/peaks.c +++ b/libcrystfel/src/peaks.c @@ -13,6 +13,7 @@ * 2011 Andrew Martin * 2011 Richard Kirian * 2017 Valerio Mariani + * 2017-2018 Yaroslav Gevorkov * * This file is part of CrystFEL. * @@ -563,6 +564,111 @@ int search_peaks_peakfinder8(struct image *image, int max_n_peaks, } +//#define HAVE_FDIP +#ifdef HAVE_FDIP + +#include "fastDiffractionImageProcessing/adaptions/crystfel/peakFinder9.h" +#include "fastDiffractionImageProcessing/adaptions/crystfel/mask.h" +#include "fastDiffractionImageProcessing/peakList.h" + +#include "fastDiffractionImageProcessing/peakFinder9.h" //debug, only for eclipse +#include "fastDiffractionImageProcessing/detectorRawFormat.h" //debug, only for eclipse + +int search_peaks_peakfinder9(struct image *image, float sig_fac_biggest_pix, + float sig_fac_peak_pix, float sig_fac_whole_peak, float min_sig, + float min_peak_over_neighbour, int window_radius) +{ + if (image->features != NULL) { + image_feature_list_free(image->features); + } + image->features = image_feature_list_new(); + image->num_peaks = 0; + image->num_saturated_peaks = 0; + + peakFinder9_accuracyConstants_t accuracy_consts; + accuracy_consts.sigmaFactorBiggestPixel = sig_fac_biggest_pix; + accuracy_consts.sigmaFactorPeakPixel = sig_fac_peak_pix; + accuracy_consts.sigmaFactorWholePeak = sig_fac_whole_peak; + accuracy_consts.minimumSigma = min_sig; + accuracy_consts.minimumPeakOversizeOverNeighbours = + min_peak_over_neighbour; + accuracy_consts.windowRadius = (unsigned int) window_radius; + + long NpeaksMax = 10000; //more peaks per panel should not appear + + float *data_copy = NULL, *data_copy_new; + peakList_t peakList; + if (allocatePeakList(&peakList, NpeaksMax)) { + return 1; + } + + for (int panel_number = 0; panel_number < image->det->n_panels; + panel_number++) { + + if (image->det->panels[panel_number].no_index) + continue; + + int w = image->det->panels[panel_number].w; + int h = image->det->panels[panel_number].h; + + detectorRawFormat_t det_size_one_panel; + det_size_one_panel.asic_nx = w; + det_size_one_panel.asic_ny = h; + det_size_one_panel.nasics_x = 1; + det_size_one_panel.nasics_y = 1; + det_size_one_panel.pix_nx = w; + det_size_one_panel.pix_ny = h; + det_size_one_panel.pix_nn = w * h; + + data_copy_new = (float*) realloc(data_copy, + w * h * sizeof(*data_copy)); + if (data_copy_new == NULL) { + if (data_copy != NULL) + free(data_copy); + freePeakList(peakList); + return 1; + } + else { + data_copy = data_copy_new; + } + + mergeMaskAndDataIntoDataCopy(image->dp[panel_number], data_copy, + image->bad[panel_number], + &det_size_one_panel); + + peakList.peakCount = 0; + image->num_peaks += peakFinder9_onePanel_noSlab(data_copy, + &accuracy_consts, + &det_size_one_panel, &peakList); + + for (int peak_number = 0; peak_number < peakList.peakCount; + peak_number++) { + image_add_feature(image->features, + peakList.centerOfMass_rawX[peak_number], + peakList.centerOfMass_rawY[peak_number], + &image->det->panels[panel_number], + image, + peakList.totalIntensity[peak_number], + NULL); + } + + } + + freePeakList(peakList); + free(data_copy); + return 0; +} +#else +int search_peaks_peakfinder9(struct image *image, float sig_fac_biggest_pix, + float sig_fac_peak_pix, float sig_fac_whole_peak, float min_sig, + float min_peak_over_neighbour, int window_radius) +{ + ERROR("This copy of CrystFEL was compiled without peakfinder9 support.\n"); + return 0; +} +#endif // HAVE_FDIP + + int peak_sanity_check(struct image *image, Crystal **crystals, int n_cryst) { int n_feat = 0; diff --git a/libcrystfel/src/peaks.h b/libcrystfel/src/peaks.h index a5095127..e63287d4 100644 --- a/libcrystfel/src/peaks.h +++ b/libcrystfel/src/peaks.h @@ -9,6 +9,7 @@ * Authors: * 2010-2015 Thomas White * 2017 Valerio Mariani + * 2017-2018 Yaroslav Gevorkov * * This file is part of CrystFEL. * @@ -55,6 +56,11 @@ extern int search_peaks_peakfinder8(struct image *image, int max_n_peaks, int local_bg_radius, int min_res, int max_res, int use_saturated); +extern int search_peaks_peakfinder9(struct image *image, float sig_fac_biggest_pix, + float sig_fac_peak_pix, float sig_fac_whole_peak, float min_sig, + float min_peak_over_neighbour, int window_radius); + + extern int peak_sanity_check(struct image *image, Crystal **crystals, int n_cryst); -- cgit v1.2.3 From c1be9fab0693fb4e51755ea83954e6cf4c65f7f0 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 24 May 2018 10:30:14 +0200 Subject: Formatting --- libcrystfel/src/peaks.c | 174 +++++++++++++++++++++++++----------------------- libcrystfel/src/peaks.h | 10 +-- 2 files changed, 95 insertions(+), 89 deletions(-) (limited to 'libcrystfel') diff --git a/libcrystfel/src/peaks.c b/libcrystfel/src/peaks.c index 7f6e0ba7..571f79ae 100644 --- a/libcrystfel/src/peaks.c +++ b/libcrystfel/src/peaks.c @@ -575,97 +575,101 @@ int search_peaks_peakfinder8(struct image *image, int max_n_peaks, #include "fastDiffractionImageProcessing/detectorRawFormat.h" //debug, only for eclipse int search_peaks_peakfinder9(struct image *image, float sig_fac_biggest_pix, - float sig_fac_peak_pix, float sig_fac_whole_peak, float min_sig, - float min_peak_over_neighbour, int window_radius) + float sig_fac_peak_pix, float sig_fac_whole_peak, + float min_sig, float min_peak_over_neighbour, + int window_radius) { - if (image->features != NULL) { - image_feature_list_free(image->features); - } - image->features = image_feature_list_new(); - image->num_peaks = 0; - image->num_saturated_peaks = 0; - - peakFinder9_accuracyConstants_t accuracy_consts; - accuracy_consts.sigmaFactorBiggestPixel = sig_fac_biggest_pix; - accuracy_consts.sigmaFactorPeakPixel = sig_fac_peak_pix; - accuracy_consts.sigmaFactorWholePeak = sig_fac_whole_peak; - accuracy_consts.minimumSigma = min_sig; - accuracy_consts.minimumPeakOversizeOverNeighbours = - min_peak_over_neighbour; - accuracy_consts.windowRadius = (unsigned int) window_radius; - - long NpeaksMax = 10000; //more peaks per panel should not appear - - float *data_copy = NULL, *data_copy_new; - peakList_t peakList; - if (allocatePeakList(&peakList, NpeaksMax)) { - return 1; - } - - for (int panel_number = 0; panel_number < image->det->n_panels; - panel_number++) { - - if (image->det->panels[panel_number].no_index) - continue; - - int w = image->det->panels[panel_number].w; - int h = image->det->panels[panel_number].h; - - detectorRawFormat_t det_size_one_panel; - det_size_one_panel.asic_nx = w; - det_size_one_panel.asic_ny = h; - det_size_one_panel.nasics_x = 1; - det_size_one_panel.nasics_y = 1; - det_size_one_panel.pix_nx = w; - det_size_one_panel.pix_ny = h; - det_size_one_panel.pix_nn = w * h; - - data_copy_new = (float*) realloc(data_copy, - w * h * sizeof(*data_copy)); - if (data_copy_new == NULL) { - if (data_copy != NULL) - free(data_copy); - freePeakList(peakList); - return 1; - } - else { - data_copy = data_copy_new; - } - - mergeMaskAndDataIntoDataCopy(image->dp[panel_number], data_copy, - image->bad[panel_number], - &det_size_one_panel); - - peakList.peakCount = 0; - image->num_peaks += peakFinder9_onePanel_noSlab(data_copy, - &accuracy_consts, - &det_size_one_panel, &peakList); - - for (int peak_number = 0; peak_number < peakList.peakCount; - peak_number++) { - image_add_feature(image->features, - peakList.centerOfMass_rawX[peak_number], - peakList.centerOfMass_rawY[peak_number], - &image->det->panels[panel_number], - image, - peakList.totalIntensity[peak_number], - NULL); - } - - } - - freePeakList(peakList); - free(data_copy); - return 0; + peakFinder9_accuracyConstants_t accuracy_consts; + peakList_t peakList; + long NpeaksMax = 10000; //more peaks per panel should not appear + float *data_copy = NULL; + float *data_copy_new; + int panel_number; + + if ( image->features != NULL ) { + image_feature_list_free(image->features); + } + image->features = image_feature_list_new(); + image->num_peaks = 0; + image->num_saturated_peaks = 0; + + accuracy_consts.sigmaFactorBiggestPixel = sig_fac_biggest_pix; + accuracy_consts.sigmaFactorPeakPixel = sig_fac_peak_pix; + accuracy_consts.sigmaFactorWholePeak = sig_fac_whole_peak; + accuracy_consts.minimumSigma = min_sig; + accuracy_consts.minimumPeakOversizeOverNeighbours = min_peak_over_neighbour; + accuracy_consts.windowRadius = window_radius; + + if ( allocatePeakList(&peakList, NpeaksMax) ) return 1; + + for ( panel_number=0; panel_numberdet->n_panels; panel_number++ ) { + + int w, h; + int peak_number; + detectorRawFormat_t det_size_one_panel; + + if ( image->det->panels[panel_number].no_index ) continue; + + w = image->det->panels[panel_number].w; + h = image->det->panels[panel_number].h; + + det_size_one_panel.asic_nx = w; + det_size_one_panel.asic_ny = h; + det_size_one_panel.nasics_x = 1; + det_size_one_panel.nasics_y = 1; + det_size_one_panel.pix_nx = w; + det_size_one_panel.pix_ny = h; + det_size_one_panel.pix_nn = w * h; + + data_copy_new = realloc(data_copy, w*h*sizeof(*data_copy)); + if ( data_copy_new == NULL ) { + if ( data_copy != NULL ) { + free(data_copy); + } + freePeakList(peakList); + return 1; + } else { + data_copy = data_copy_new; + } + + mergeMaskAndDataIntoDataCopy(image->dp[panel_number], data_copy, + image->bad[panel_number], + &det_size_one_panel); + + peakList.peakCount = 0; + image->num_peaks += peakFinder9_onePanel_noSlab(data_copy, + &accuracy_consts, + &det_size_one_panel, + &peakList); + + for ( peak_number=0; peak_numberfeatures, + peakList.centerOfMass_rawX[peak_number], + peakList.centerOfMass_rawY[peak_number], + &image->det->panels[panel_number], + image, + peakList.totalIntensity[peak_number], + NULL); + } + + } + + freePeakList(peakList); + free(data_copy); + return 0; } + #else + int search_peaks_peakfinder9(struct image *image, float sig_fac_biggest_pix, - float sig_fac_peak_pix, float sig_fac_whole_peak, float min_sig, - float min_peak_over_neighbour, int window_radius) + float sig_fac_peak_pix, float sig_fac_whole_peak, + float min_sig, float min_peak_over_neighbour, + int window_radius) { - ERROR("This copy of CrystFEL was compiled without peakfinder9 support.\n"); - return 0; + ERROR("This copy of CrystFEL was compiled without peakfinder9 support.\n"); + return 0; } + #endif // HAVE_FDIP diff --git a/libcrystfel/src/peaks.h b/libcrystfel/src/peaks.h index e63287d4..04957143 100644 --- a/libcrystfel/src/peaks.h +++ b/libcrystfel/src/peaks.h @@ -56,10 +56,12 @@ extern int search_peaks_peakfinder8(struct image *image, int max_n_peaks, int local_bg_radius, int min_res, int max_res, int use_saturated); -extern int search_peaks_peakfinder9(struct image *image, float sig_fac_biggest_pix, - float sig_fac_peak_pix, float sig_fac_whole_peak, float min_sig, - float min_peak_over_neighbour, int window_radius); - +extern int search_peaks_peakfinder9(struct image *image, + float sig_fac_biggest_pix, + float sig_fac_peak_pix, + float sig_fac_whole_peak, float min_sig, + float min_peak_over_neighbour, + int window_radius); extern int peak_sanity_check(struct image *image, Crystal **crystals, int n_cryst); -- cgit v1.2.3 From 4f087e3954699ba96d2915af8d82fa10ebd53280 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 24 May 2018 10:31:53 +0200 Subject: Update authorship and copyright dates --- libcrystfel/src/peaks.c | 2 +- libcrystfel/src/peaks.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'libcrystfel') diff --git a/libcrystfel/src/peaks.c b/libcrystfel/src/peaks.c index 571f79ae..d656050e 100644 --- a/libcrystfel/src/peaks.c +++ b/libcrystfel/src/peaks.c @@ -3,7 +3,7 @@ * * Peak search and other image analysis * - * Copyright © 2012-2017 Deutsches Elektronen-Synchrotron DESY, + * Copyright © 2012-2018 Deutsches Elektronen-Synchrotron DESY, * a research centre of the Helmholtz Association. * Copyright © 2012 Richard Kirian * diff --git a/libcrystfel/src/peaks.h b/libcrystfel/src/peaks.h index 04957143..06ca8e6c 100644 --- a/libcrystfel/src/peaks.h +++ b/libcrystfel/src/peaks.h @@ -3,7 +3,7 @@ * * Peak search and other image analysis * - * Copyright © 2012-2017 Deutsches Elektronen-Synchrotron DESY, + * Copyright © 2012-2018 Deutsches Elektronen-Synchrotron DESY, * a research centre of the Helmholtz Association. * * Authors: -- cgit v1.2.3 From fce9cd58362d09366c8a1c474017ef3e63f0b3aa Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 24 May 2018 10:32:11 +0200 Subject: Move FDIP includes to top, and remove unnecessary ones --- libcrystfel/src/peaks.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'libcrystfel') diff --git a/libcrystfel/src/peaks.c b/libcrystfel/src/peaks.c index d656050e..14371271 100644 --- a/libcrystfel/src/peaks.c +++ b/libcrystfel/src/peaks.c @@ -46,6 +46,12 @@ #include #include +#ifdef HAVE_FDIP +#include "fastDiffractionImageProcessing/adaptions/crystfel/peakFinder9.h" +#include "fastDiffractionImageProcessing/adaptions/crystfel/mask.h" +#include "fastDiffractionImageProcessing/peakList.h" +#endif + #include "image.h" #include "utils.h" #include "peaks.h" @@ -564,16 +570,8 @@ int search_peaks_peakfinder8(struct image *image, int max_n_peaks, } -//#define HAVE_FDIP #ifdef HAVE_FDIP -#include "fastDiffractionImageProcessing/adaptions/crystfel/peakFinder9.h" -#include "fastDiffractionImageProcessing/adaptions/crystfel/mask.h" -#include "fastDiffractionImageProcessing/peakList.h" - -#include "fastDiffractionImageProcessing/peakFinder9.h" //debug, only for eclipse -#include "fastDiffractionImageProcessing/detectorRawFormat.h" //debug, only for eclipse - int search_peaks_peakfinder9(struct image *image, float sig_fac_biggest_pix, float sig_fac_peak_pix, float sig_fac_whole_peak, float min_sig, float min_peak_over_neighbour, -- cgit v1.2.3 From d3f9ed0a184bea13ba36c4291b593ecd7a91fc14 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 24 May 2018 10:32:43 +0200 Subject: Generalise peakfinder9 error messages, and fail if not compiled in --- libcrystfel/src/peaks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libcrystfel') diff --git a/libcrystfel/src/peaks.c b/libcrystfel/src/peaks.c index 14371271..1ec4ae59 100644 --- a/libcrystfel/src/peaks.c +++ b/libcrystfel/src/peaks.c @@ -665,7 +665,7 @@ int search_peaks_peakfinder9(struct image *image, float sig_fac_biggest_pix, int window_radius) { ERROR("This copy of CrystFEL was compiled without peakfinder9 support.\n"); - return 0; + return 1; } #endif // HAVE_FDIP -- cgit v1.2.3 From f14479316abf0c438e0ccbd59a4fdf4f8ccfbede Mon Sep 17 00:00:00 2001 From: Yaroslav Gevorkov Date: Thu, 24 May 2018 16:00:04 +0200 Subject: Changed sig_fac to min_snr --- libcrystfel/src/peaks.c | 14 +++++++------- libcrystfel/src/peaks.h | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'libcrystfel') diff --git a/libcrystfel/src/peaks.c b/libcrystfel/src/peaks.c index 1ec4ae59..6c48bd3a 100644 --- a/libcrystfel/src/peaks.c +++ b/libcrystfel/src/peaks.c @@ -572,8 +572,8 @@ int search_peaks_peakfinder8(struct image *image, int max_n_peaks, #ifdef HAVE_FDIP -int search_peaks_peakfinder9(struct image *image, float sig_fac_biggest_pix, - float sig_fac_peak_pix, float sig_fac_whole_peak, +int search_peaks_peakfinder9(struct image *image, float min_snr_biggest_pix, + float min_snr_peak_pix, float min_snr_whole_peak, float min_sig, float min_peak_over_neighbour, int window_radius) { @@ -591,9 +591,9 @@ int search_peaks_peakfinder9(struct image *image, float sig_fac_biggest_pix, image->num_peaks = 0; image->num_saturated_peaks = 0; - accuracy_consts.sigmaFactorBiggestPixel = sig_fac_biggest_pix; - accuracy_consts.sigmaFactorPeakPixel = sig_fac_peak_pix; - accuracy_consts.sigmaFactorWholePeak = sig_fac_whole_peak; + accuracy_consts.minSNR_biggestPixel = min_snr_biggest_pix; + accuracy_consts.minSNR_peakPixel = min_snr_peak_pix; + accuracy_consts.minSNR_wholePeak = min_snr_whole_peak; accuracy_consts.minimumSigma = min_sig; accuracy_consts.minimumPeakOversizeOverNeighbours = min_peak_over_neighbour; accuracy_consts.windowRadius = window_radius; @@ -659,8 +659,8 @@ int search_peaks_peakfinder9(struct image *image, float sig_fac_biggest_pix, #else -int search_peaks_peakfinder9(struct image *image, float sig_fac_biggest_pix, - float sig_fac_peak_pix, float sig_fac_whole_peak, +int search_peaks_peakfinder9(struct image *image, float min_snr_biggest_pix, + float min_snr_peak_pix, float min_snr_whole_peak, float min_sig, float min_peak_over_neighbour, int window_radius) { diff --git a/libcrystfel/src/peaks.h b/libcrystfel/src/peaks.h index 06ca8e6c..3abef729 100644 --- a/libcrystfel/src/peaks.h +++ b/libcrystfel/src/peaks.h @@ -57,9 +57,9 @@ extern int search_peaks_peakfinder8(struct image *image, int max_n_peaks, int max_res, int use_saturated); extern int search_peaks_peakfinder9(struct image *image, - float sig_fac_biggest_pix, - float sig_fac_peak_pix, - float sig_fac_whole_peak, float min_sig, + float min_snr_biggest_pix, + float min_snr_peak_pix, + float min_snr_whole_peak, float min_sig, float min_peak_over_neighbour, int window_radius); -- cgit v1.2.3