diff options
author | Thomas White <taw@physics.org> | 2020-08-28 11:12:44 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2020-08-28 11:12:44 +0200 |
commit | 3cae5a88c880a3f20dd8305c58b13fd85665882f (patch) | |
tree | bc25db2fa3ba68104dee46129aeb3b218141337b | |
parent | f6faf221bc4282a85d35db3340fefd245f7e0e38 (diff) |
Avoid GSL running statistics for CrystFELImageView auto-scale
This changes the meaning slightly (it assumes all the panels are at
least roughly the same size), and the code isn't very nice. However,
it's not "science-critical" and it's worth it to get back to compatability
with old GSL versions.
-rw-r--r-- | src/crystfelimageview.c | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/src/crystfelimageview.c b/src/crystfelimageview.c index a96c3a9c..a99c1b08 100644 --- a/src/crystfelimageview.c +++ b/src/crystfelimageview.c @@ -36,7 +36,7 @@ #include <assert.h> #include <gtk/gtk.h> #include <glib-object.h> -#include <gsl/gsl_rstat.h> +#include <gsl/gsl_statistics_float.h> #include <utils.h> #include <detgeom.h> @@ -766,30 +766,40 @@ static GdkPixbuf *render_panel(float *data, int *badmap, int w, int h, static double auto_scale_top(const struct image *image) { int pn; - gsl_rstat_workspace *wksp; - double top; - - wksp = gsl_rstat_alloc(); - if ( wksp == NULL ) return 100.0; + double total_mean = 0.0; + double total_variance = 0.0; for ( pn=0; pn<image->detgeom->n_panels; pn++ ) { - long int i; + + long int i, j; int w, h; + float *data; + float this_mean; + w = image->detgeom->panels[pn].w; h = image->detgeom->panels[pn].h; + + data = malloc(w*h*sizeof(float)); + if ( data == NULL ) return 100.0; + + j = 0; for ( i=0; i<w*h; i++ ) { if ( !image->bad[pn][i] ) { - gsl_rstat_add(image->dp[pn][i], wksp); + data[j++] = image->dp[pn][i]; } } - } - top = gsl_rstat_mean(wksp) + gsl_rstat_sd(wksp); - gsl_rstat_free(wksp); + this_mean = gsl_stats_float_mean(data, 1, j); - top *= 6; + total_mean += this_mean; + total_variance += gsl_stats_float_variance_m(data, 1, j, + this_mean); + + free(data); + } - return top; + return (total_mean/image->detgeom->n_panels) + + 10.0*sqrt(total_variance/image->detgeom->n_panels); } |