Ejemplo n.º 1
0
def compute_exptime(band,trange,verbose=0,skypos=None,detsize=1.25,
                    retries=20,chunksz=10.e6,coadd=False):
    """Compute the effective exposure time."""
    # FIXME: This skypos[] check appears to not work properly and leads
    #  to dramatic _underestimates_ of the exposure time.
    if skypos and coadd:
        tranges = fGetTimeRanges(band,skypos,verbose=verbose,trange=trange,
                                 retries=retries)
    else:
        tranges=[trange]
    if verbose>1:
        print_inline('Computing exposure within {tr}'.format(tr=tranges))
        if skypos and coadd:
            print 'Based on skypos {sp}'.format(sp=skypos)
    exptime = 0.
    for trange in tranges:
        # Traverse the exposure ranges in manageable chunks to hopefully keep
        # the query response time below the HTTP timeout...
        chunks = (np.linspace(trange[0],trange[1],
                             num=np.ceil((trange[1]-trange[0])/chunksz)) if
                                 (trange[1]-trange[0])>chunksz else
                                 np.array(trange))
        for i,t in enumerate(chunks[:-1]):
            exptime += exposure(band,[chunks[i],chunks[i+1]],verbose=verbose,
                                retries=retries)
    return exptime
Ejemplo n.º 2
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]
Ejemplo n.º 3
0
def fGetTimeRanges(band,skypos,trange=None,detsize=1.1,verbose=0,
                   maxgap=1.,minexp=1.,retries=100.,predicted=False,
                   skyrange=None,maxgap_override=False):
    """Find the contiguous time ranges within a time range at a
    specific location.
	minexp - Do not include exposure time less than this.
	maxgap - Gaps in exposure longer than this initiate a new time range.
	detsize - Fiddle with this if you want to exlude the edges of the
    detector.
    predicted - Use the aspect solutions to estimate what exposure will be
    available once the database is fully populated.
	"""
    times = get_valid_times(band,skypos,trange=trange,detsize=detsize,
                            verbose=verbose,retries=retries,skyrange=skyrange)
    if not len(times):
        return np.array([],dtype='float64')
    if verbose:
        print_inline('Parsing ~'+str(len(times)-1)+' seconds of raw exposure.')

    # NOTE: The minimum meaningful maxgap is 1 second.
    if maxgap<1 and not maxgap_override:
        raise 'maxgap must be >=1 second'
    tranges = distinct_tranges(times,maxgap=maxgap)

    ix = np.where(np.array(tranges)[:,1]-np.array(tranges)[:,0]>=minexp)
    tranges = np.array(tranges)[ix].tolist()

    return np.array(tranges,dtype='float64')
Ejemplo n.º 4
0
def compute_exptime(band,trange,verbose=0,skypos=None,detsize=1.25,
                    retries=20,coadd=False):
    """Compute the effective exposure time."""
    # FIXME: This skypos[] check appears to not work properly and leads
    #  to dramatic _underestimates_ of the exposure time.
    if skypos and coadd:
        tranges = fGetTimeRanges(band,skypos,verbose=verbose,trange=trange,
                                 retries=retries)
    else:
        tranges=[trange]
    if verbose>1:
        print_inline('Computing exposure within {tr}'.format(tr=tranges))
        if skypos and coadd:
            print 'Based on skypos {sp}'.format(sp=skypos)
    exptime = 0.
    for trange in tranges:
        exptime += exposure(band,[trange[0],trange[1]],verbose=verbose,
                                                            retries=retries)
    return exptime
Ejemplo n.º 5
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]
Ejemplo n.º 6
0
def fGetTimeRanges(band,skypos,trange=None,tscale=1000.,detsize=1.25,verbose=0,
                   maxgap=1.,minexp=1.,retries=100.,predicted=False):
    """Find the contiguous time ranges within a time range at a
    specific location.
	minexp - Do not include exposure time less than this.
	maxgap - Gaps in exposure longer than this initiate a new time range.
	detsize - Fiddle with this if you want to exlude the edges of the
    detector.
    predicted - Use the aspect solutions to estimate what exposure will be
    available once the database is fully populated.
	"""
    try:
        if not np.array(trange).tolist():
            trange = [1,1000000000000]
        if len(np.shape(trange))==2:
            trange=trange[0]
        times = (np.array(gQuery.getArray(gQuery.exposure_ranges(band,
            skypos[0],skypos[1],t0=trange[0],t1=trange[1],detsize=detsize,
            tscale=tscale),verbose=verbose,retries=retries),
                                                dtype='float64')[:,0]/tscale
            if not predicted else get_aspect(band,skypos,trange,
                                        tscale=tscale,verbose=verbose)['t'])
    except IndexError:
        if verbose:
            print "No exposure time available at {pos}".format(pos=skypos)
        return np.array([],dtype='float64')
    except TypeError:
        print "Is one of the inputs malformed?"
        raise
    except:
        raise
    if verbose:
        print_inline('Parsing '+str(len(times)-1)+' seconds of exposure.: ['+str(trange[0])+', '+str(trange[1])+']')
    blah = []
    for i in xrange(len(times[0:-1])):
        blah.append(times[i+1]-times[i])
    # A drop in data with duration greater than maxgap initiates a
    #  new exposure
    gaps = np.where(np.array(blah)>maxgap)
    ngaps = len(gaps[0])
    chunks = []
    for i in range(ngaps):
        if not i:
            chunk = [times[0],times[gaps[0][i]]]
        elif i==ngaps-1:
            chunk = [times[gaps[0][i]+1],times[-1]]
        else:
            chunk = [times[gaps[0][i]+1],times[gaps[0][i+1]]]
        # If the duration of this slice is less than minexp, do not
        #  count it as valid exposure.
        if chunk[1]-chunk[0]<minexp:
            continue
        else:
            chunks.append(chunk)
    if not ngaps:
        if times.min()==times.max():
            chunks.append([times.min(),times.min()+1])
        else:
            chunks.append([times.min(),times.max()])

    return np.array(chunks,dtype='float64')