;+ ; NAME: ; avsig_temp ; PURPOSE: ; Calculates the average and the sigma of an array, ; passes out (Av counts*Av time interval), and ; the suqred st. deviation in that quantity. ; CALLING SEQUENCE: ; Avsig_temp, x, xbar, sigx2, dt=dt ; INPUT: ; x is an array, counts please, not count rate ; OUTPUT: ; xbar = average count rate*average time interval ; sigx2 = sigma(x)^2 ; KEYWORDS: ; No0 = if set drop out zeros ; dt = interval times, default is 1.0 seconds ; plot = if set, plot up a histogram, with a poisson distribution. ; RESTRICTIONS: ; Don't pass in a count rate, things'll get messy ; HISTORY: ; 27-jul-94, jmm ; 21-jun-1999, jmm, rewrote to fail gracefully, changed the name, ; hacked out code since this is only to be used ; for auto_bck_find0 ;- PRO Avsig_temp, x, xbar, sigx2, dt=dt n=N_ELEMENTS(x) IF(KEYWORD_SET(dt)) THEN BEGIN IF(N_ELEMENTS(dt) NE n) THEN dt0 = replicate(dt[0], n) ELSE dt0 = dt ENDIF ELSE dt0 = fltarr(n)+1.0 dtt = total(dt0) n = N_ELEMENTS(x) xbar = total(x)/dtt dt0_av = dtt/float(n) sigx2 = (total(x^2/dt0)/dtt)-xbar^2 xbar = xbar*dt0_av sigx2 = sigx2*dt0_av^2 RETURN END ;+ ; NAME: ; auto_bck_find0 ; PURPOSE: ; Given a stream of data, find the appropriate background ; levels, and the times, for the background interval and ; for where the data is a certain specified level above ; the background. ; CALLING SEQUENCE: ; ratio_f = auto_bck_find0(time, data, bck_trange, dtb_max=dtb_max, $ ; dtb_min=dtb_min, dt_dat=dt_dat, channel=channel, $ ; zero_ok=zero_ok, two=two, use_minimum=use_minimum, $ ; quiet=quiet, sig_ratio=sig_ratio, subscripts=subscripts, $ ; data_is_a_rate=data_is_a_rate, dtb_inc=dtb_inc, $ ; b_ratio=b_ratio, stops=stops) ; INPUT: ; time = time array for data, any ANYTIM readable format ; data = an array of (nchannels, ndset) or (ndset) ; OUTPUT: ; ratio_f = is the final value of the ratio of sigma(counts)/sqrt(counts), ; -1 is passed out, if we're not satisfied with the result. ; bck_trange= start and end times for background interval(s) ; KEYWORDS: ; dtb_max = the interval in seconds, that you want the background ; accumulated for, the default is 2.0 minutes or 120.0 seconds. ; But the actual interval time may be somewhat less, depending ; on how good the data is, also the background is accumulated ; for an integral number of intervals, This number of ; intervals, when summed, may not equal the input dtb. ; dtb_min = minimum interval, in seconds, for the background ; accumulation, default is 10.0. This is automatically ; reset to max(interval time) if it is smaller than ; the largest interval. HXT-LO data almost invariably ; gets to this point. ; dtb_inc = interval increment, in seconds, for the background ; accumulation, default is 10.0. ; dt_dat = accumulation times or exposure times for the data, ; if not set, dt(i)=time(i+1)-time(i). REMEMBER that ; you'll need this even if you passed in index as a ; time array. ; channel = the channel used to find the interval, the default is 0, ; If an array is passed in, the routine will sum over the ; channels. ; zero_ok = if set, this will allow zero values in the data. ; two = if set, find two intervals, one before the max value ; and one after. dtb_max and dtb_min may be given two values ; the background level will be found by interpolation. ; quiet = if set, don't plot the data and show intervals. ; data_is_a_rate = set this if you pass in a count rate, and not counts ; sig_ratio = the routine will reject intervals if ; sigma(counts)/sqrt(counts) is greater than this value, ; and will reduce dtb to try again. Default is 1.25 ; b_ratio = the routine will reject intervals if the chosen background ; level over the minimum is more than this value. Default is ; 1.25 ; subscripts= if set, pass the ranges out as subscripts of the input ; array. ; use_minimum= short circuits the whole program, just use the interval ; that has the minimum counts for the given time interval, ; This is good for GOES and HXT ; RESTRICTIONS: ; Use some sense, this is designed to find the background levels near ; a flare, don't use it on a whole days worth of data. Don't use it ; if there are big gaps in the data, if there are long stretches of ; zeros, don't set the zero_ok keyword. If it looks like the flare ; starts before the data, as if you're only have flare mode data, ; don't use the two keyword. ; HISTORY: ; 27-jul-94, JMM ; 12-jul-95, added the /two option, finally, nbcks and nsigmas keywords ; and trange output are gone, they don't make sense without ; doing the interpolation... ; 26-jul-95, changed the name from bck_finder to auto_bck_find ; 12-feb-96, jmm, added use_minimum keyword ; 21-jun-1999, jmm, changed time formats, and default ratios ; changed ()'s to []'s for IDL 5 where applicable ; 23-jun-1999, jmm, slightly different, now the approved background ; is the min value with sigma