Example #1
0
def netdead(band,t0,t1,tstep=1.,refrate=79.,verbose=0):
	print 'Time range: ['+str(t0)+', '+str(t1)+']'
	refrate     = 79. # counts per second, nominal stim rate
	feeclkratio = 0.966 # not sure what detector property this adjusts for
	tec2fdead   = 5.52e-6 # TEC to deadtime correction (Method 2)
	stimcount = gQuery.getValue(gQuery.stimcount(band,t0,t1))
	totcount = (gQuery.getValue(gQuery.deadtime1(band,t0,t1)) +
		    gQuery.getValue(gQuery.deadtime2(band,t0,t1)))
	exptime = t1-t0
	# Method 0
	# Empirical formula
	dead0 = tec2fdead*(totcount/exptime)/feeclkratio
	minrate,maxrate = refrate*.4,refrate+2.
	# Method 2
	# Direct measurement of stims
	bins = np.linspace(0.,exptime-exptime%tstep,exptime//tstep+1)+t0
	h = np.zeros(len(bins))
	for i,t in enumerate(bins):
		print_inline(t1-t)
		h[i] = gQuery.getValue(gQuery.stimcount(band,t,t+tstep-0.0001))
	
	#h,xh = np.histogram(stimt-trange[0],bins=bins)
	ix = ((h<=maxrate) & (h>=minrate)).nonzero()[0]
	dead2 = (1.-((h[ix]/tstep)/feeclkratio)/refrate).mean()
	# Method 1
	# Empirical formula except with counts binned into 1s
	h = np.zeros(len(bins))
	for i,t in enumerate(bins):
		print_inline(t1-t)
		h[i] = gQuery.getValue(gQuery.deadtime1(band,t,t+tstep-0.0001)) + gQuery.getValue(gQuery.deadtime2(band,t,t+tstep-0.0001))

	dead1 = (tec2fdead*(h/tstep)/feeclkratio).mean()
	expt = compute_exptime(band,[t0,t1])
	print dead0,dead1,dead2
	return [t0, t1, dead0, dead1, dead2, expt, stimcount, totcount]
Example #2
0
    def test_stimcount(self):
        margin=[90.01,90.01]
        avgstim = CalUtils.avg_stimpos(self.NUV,self.eclipse)
        query = ('{baseURL}select count(*) from {baseDB}.{band}PhotonsNULLV '+
            'where time between {t0} and {t1} and ('+
            '((x between {x10} and {x11}) and (y between {y10} and {y11})) or '+
            '((x between {x20} and {x21}) and (y between {y20} and {y21})) or '+
            '((x between {x30} and {x31}) and (y between {y30} and {y31})) or '+
            '((x between {x40} and {x41}) and (y between {y40} and {y41}))'+
            '){formatURL}').format(baseURL=self.baseURL,
                baseDB=self.baseDB, band=self.NUV,
                t0=str(long(t0*self.tscale)), t1=str(long(t1*self.tscale)),
                x10=(avgstim['x1']-margin[0])/self.aspum,
                x11=(avgstim['x1']+margin[0])/self.aspum,
                y10=(avgstim['y1']-margin[1])/self.aspum,
                y11=(avgstim['y1']+margin[1])/self.aspum,
                x20=(avgstim['x2']-margin[0])/self.aspum,
                x21=(avgstim['x2']+margin[0])/self.aspum,
                y20=(avgstim['y2']-margin[1])/self.aspum,
                y21=(avgstim['y2']+margin[1])/self.aspum,
                x30=(avgstim['x3']-margin[0])/self.aspum,
                x31=(avgstim['x3']+margin[0])/self.aspum,
                y30=(avgstim['y3']-margin[1])/self.aspum,
                y31=(avgstim['y3']+margin[1])/self.aspum,
                x40=(avgstim['x4']-margin[0])/self.aspum,
                x41=(avgstim['x4']+margin[0])/self.aspum,
                y40=(avgstim['y4']-margin[1])/self.aspum,
                y41=(avgstim['y4']+margin[1])/self.aspum,
                formatURL=self.formatURL)

        self.assertEqual(gq.stimcount(self.NUV,self.t0,self.t1,eclipse=self.eclipse),query)
Example #3
0
def stimcount_shuttered(band,trange,verbose=0,retries=20.,timestamplist=False):
    try:
        t = (timestamplist if np.array(timestamplist).any() else
                np.array(gQuery.getArray(
                    gQuery.uniquetimes(band,trange[0],trange[1]),
                        verbose=verbose),dtype='float64')[:,0]/gQuery.tscale)
    except IndexError: # Shutter this whole time range.
        if verbose:
            print 'No data in {t0},{t1}'.format(t0=trange[0],t1=trange[1])
        return 0

    times = np.sort(np.unique(np.append(t,trange)))
    tranges = distinct_tranges(times,maxgap=0.05)
    stimcount = 0
    for trange in tranges:
        stimcount += gQuery.getValue(gQuery.stimcount(band,trange[0],trange[1]),
                                        verbose=verbose)+gQuery.getValue(
                                     gQuery.stimcount(band,trange[0],trange[1],
                                        null=False),verbose=verbose)
    return stimcount
Example #4
0
def netdead(band, t0, t1, tstep=1., refrate=79., verbose=0):
    print 'Time range: [' + str(t0) + ', ' + str(t1) + ']'
    refrate = 79.  # counts per second, nominal stim rate
    feeclkratio = 0.966  # not sure what detector property this adjusts for
    tec2fdead = 5.52e-6  # TEC to deadtime correction (Method 2)
    stimcount = gQuery.getValue(gQuery.stimcount(band, t0, t1))
    totcount = (gQuery.getValue(gQuery.deadtime1(band, t0, t1)) +
                gQuery.getValue(gQuery.deadtime2(band, t0, t1)))
    exptime = t1 - t0
    # Method 0
    # Empirical formula
    dead0 = tec2fdead * (totcount / exptime) / feeclkratio
    minrate, maxrate = refrate * .4, refrate + 2.
    # Method 2
    # Direct measurement of stims
    bins = np.linspace(0., exptime - exptime % tstep,
                       exptime // tstep + 1) + t0
    h = np.zeros(len(bins))
    for i, t in enumerate(bins):
        print_inline(t1 - t)
        h[i] = gQuery.getValue(gQuery.stimcount(band, t, t + tstep - 0.0001))

    #h,xh = np.histogram(stimt-trange[0],bins=bins)
    ix = ((h <= maxrate) & (h >= minrate)).nonzero()[0]
    dead2 = (1. - ((h[ix] / tstep) / feeclkratio) / refrate).mean()
    # Method 1
    # Empirical formula except with counts binned into 1s
    h = np.zeros(len(bins))
    for i, t in enumerate(bins):
        print_inline(t1 - t)
        h[i] = gQuery.getValue(gQuery.deadtime1(
            band, t, t + tstep - 0.0001)) + gQuery.getValue(
                gQuery.deadtime2(band, t, t + tstep - 0.0001))

    dead1 = (tec2fdead * (h / tstep) / feeclkratio).mean()
    expt = compute_exptime(band, [t0, t1])
    print dead0, dead1, dead2
    return [t0, t1, dead0, dead1, dead2, expt, stimcount, totcount]
Example #5
0
 def test_stimcount(self):
     self.assertEqual(gq.stimcount(self.NUV,self.t0,self.t1,eclipse=self.eclipse),'http://masttest.stsci.edu/portal/Mashup/MashupQuery.asmx/GalexPhotonListQueryTest?query=select count(*) from NUVPhotonsNULLV where time between 766525332995 and 866526576995 and ((x between -40902.9566054 and -38284.6717091 and y between 34381.2426431 and 36999.5275393) or (x between 34598.6815899 and 37216.9664861 and y between 34379.6427578 and 36997.9276541) or (x between -40897.1388409 and -38278.8539446 and y between -38627.3380359 and -36009.0531396) or (x between 34613.3714451 and 37231.6563414 and y between -38656.7177464 and -36038.4328502))&format=json&timeout={}')