-
Notifications
You must be signed in to change notification settings - Fork 1
/
wt_moment.pro
56 lines (50 loc) · 1.84 KB
/
wt_moment.pro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function wt_moment, data, wt, errors = errors, oversample = oversample
;+
; NAME:
; WT_MOMENT
; PURPOSE:
; To calculate the weighted zeroth and first moments of an input
; variable weighted by the appropirate value and errors the values
; if appropriate.
;
; CALLING SEQUENCE:
; outstruc = WT_MOMENT(data, weight)
;
; INPUTS:
; DATA -- The data for moment analysis.
; WEIGHT -- Vector of the same size as data that contains the
; KEYWORD PARAMETERS:
; ERRORS -- Errors in the values of the weights (since these are
; usually the Antenna temperatures).
; OVERSAMPLE -- Factor by which the data are oversampled.
;
; OUTPUTS:
; OUTSTRUCTURE -- Structure with the following tags
; .mean -- Mean value with weights.
; .stdev -- Standard deviation with weights.
; .errmn -- Error in the mean (if errors specified)
; .errsd -- Error in the standard deviation (if
; errors specified).
; MODIFICATION HISTORY:
; Written --
; Tue Aug 7 12:20:52 2001, Erik Rosolowsky <eros@cosmic>
;-
if n_elements(data) ne n_elements(wt) then begin
message, 'WEIGHT vector must have the same number of elements as DATA', /con
return, 0
end
if keyword_set(oversample) then osf = sqrt(oversample) else osf = 1
tot = total(wt)
mean = total(wt*data)/tot
stdev = sqrt(total(wt*(data-mean)^2)/tot)
if n_elements(errors) gt 0 then begin
mean_err = sqrt(total(((tot*data-total(wt*data))/$
(tot^2))^2*errors^2))*osf
sig2err = sqrt(total(((tot*(data-mean)^2-$
total(wt*(data-mean)^2))/tot^2)^2*errors^2)+$
(2*total(wt*(data-mean))/tot)^2*mean_err^2)
sd_err = 1/(2*stdev)*sig2err*osf
return, {mean:mean, stdev:stdev, errmn:mean_err, errsd:sd_err}
endif
return, {mean:mean, stdev:stdev}
end