From 2fc8861683b60b2b417e282ea7358f52b85b0dde Mon Sep 17 00:00:00 2001 From: othocaeS Date: Thu, 14 Jul 2016 11:24:47 -0400 Subject: [PATCH] fixed the averaging in heasoft->psdlag translation to handle n values in a single bin --- scripts/heasoft_to_psdlag.pl | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/scripts/heasoft_to_psdlag.pl b/scripts/heasoft_to_psdlag.pl index d486cd6..746e3d5 100755 --- a/scripts/heasoft_to_psdlag.pl +++ b/scripts/heasoft_to_psdlag.pl @@ -47,18 +47,28 @@ while (<>) { # This mess to average measurements occuring at the same time coordinate $this_t = "$t𝓃.$t𝜀"; if ($this_t == $last_t) { - if ( $linetoprint =~ /([0-9\.]+)\s+([0-9e\-\.]+)\s+([0-9e\-\.]+)/ ) { - $new_flux_μ = ($flux_μ + $2)/2; - # Could just take the max error - # $new_flux_σ = max($flux_σ,$3); - # Average error seems fair - $new_flux_σ = ($flux_σ + $3)/2; - $linetoprint="$this_t $new_flux_μ $new_flux_σ"; - $num_avg++; - } - else { die "Malformed data"; } + if ($heap_count == 0) { + if ( $linetoprint =~ /([0-9\.]+)\s+([0-9e\-\.]+)\s+([0-9e\-\.]+)/ ) { + $new_flux_μ = $flux_μ + $2; + # Could just take the max error + # $new_flux_σ = max($flux_σ,$3); + # Average error seems fair + $new_flux_σ = $flux_σ + $3; + $num_avg++; + } + else { die "Malformed data"; } + } + else { + $new_flux_μ += $flux_μ; + $new_flux_σ += $flux_σ; + } + $heap_count++; } else { + $new_flux_μ /= $heap_count; + $new_flux_σ /= $heap_count; + $linetoprint="$this_t $new_flux_μ $new_flux_σ"; + our $heap_count = 0; say $linetoprint; $linetoprint = "$t𝓃.$t𝜀 $flux_μ $flux_σ"; }