예제 #1
0
def addmagsn(m, dm=None):
    # F = 10 ** (-0.4 * m)
    # dF = -0.4 * ln(10) * 10 ** (-0.4 * m) * dm = -0.921034 * F * dm
    # somehow this is wrong, should be:
    # dF / F = 10 ** (0.4 * dm) - 1  (as in bpz_tools.e_frac2mag)
    #good = less(m, 99)
    good = between(0, m, 99)
    m = compress(good, m)
    dm = compress(good, dm)
    if len(m) == 0:
        m, dm = 99, 99
    else:
        m = array(m)
        F = 10**(-0.4 * m)
        Ftot = sum(F)
        m = -2.5 * log10(Ftot)
        #dF1 = 0.921034 * F1 * dm1
        #dF2 = 0.921034 * F2 * dm2
        #dF = sqrt(dF1 ** 2 + dF2 ** 2)
        #dm = dF / F / 0.921034
        if dm <> None:
            #dm = hypot(F*dm) / Ftot
            dm = hypotn(F * dm) / Ftot
    if dm == None:
        output = m
    else:
        output = (m, dm)

    return output
예제 #2
0
def addmagsn(m, dm=None):
    # F = 10 ** (-0.4 * m)
    # dF = -0.4 * ln(10) * 10 ** (-0.4 * m) * dm = -0.921034 * F * dm
    # somehow this is wrong, should be:
    # dF / F = 10 ** (0.4 * dm) - 1  (as in bpz_tools.e_frac2mag)
    good = less(m, 99)
    m = compress(good, m)
    if len(m) == 0:
        m, dm = 99, 99
    else:
        m = array(m)
        F = 10 ** (-0.4 * m)
        Ftot = sum(F)
        m = -2.5 * log10(Ftot)
        #dF1 = 0.921034 * F1 * dm1
        #dF2 = 0.921034 * F2 * dm2
        #dF = sqrt(dF1 ** 2 + dF2 ** 2)
        #dm = dF / F / 0.921034
        if dm <> None:
            dm = hypot(F*dm) / Ftot
    if dm == None:
        output = m
    else:
        output = (m, dm)
    
    return output
예제 #3
0
def invertselection(ids, all):
    if type(all) == int:  # size input
        all = arange(all) + 1
        put(all, array(ids) - 1, 0)
        all = compress(all, all)
        return all
    else:
        out = []
        for val in all:
            #if val not in ids:
            if not floatin(val, ids):
                out.append(val)
        return out
예제 #4
0
def common(id1, id2):
    # ASSUME NO IDS ARE NEGATIVE
    id1 = array(id1).astype(int)
    id2 = array(id2).astype(int)
    n = max((max(id1), max(id2)))
    in1 = zeros(n + 1, int)
    in2 = zeros(n + 1, int)
    put(in1, id1, 1)
    put(in2, id2, 1)
    inboth = in1 * in2
    ids = arange(n + 1)
    ids = compress(inboth, ids)
    return ids
예제 #5
0
def invertselection(ids, all):
    if type(all) == int:  # size input
        all = arange(all) + 1
        put(all, array(ids)-1, 0)
        all = compress(all, all)
        return all
    else:
        out = []
        for val in all:
            #if val not in ids:
            if not floatin(val, ids):
                out.append(val)
        return out
예제 #6
0
def common(id1, id2):
    # ASSUME NO IDS ARE NEGATIVE
    id1 = array(id1).astype(int)
    id2 = array(id2).astype(int)
    n = max((max(id1), max(id2)))
    in1 = zeros(n+1, int)
    in2 = zeros(n+1, int)
    put(in1, id1, 1)
    put(in2, id2, 1)
    inboth = in1 * in2
    ids = arange(n+1)
    ids = compress(inboth, ids)
    return ids
예제 #7
0
def census(a, returndict=1):
    a = sort(ravel(a))
    if returndict:
        i = arange(min(a), max(a) + 2)
    else:
        i = arange(max(a) + 2)
    s = searchsorted(a, i)
    s = s[1:] - s[:-1]
    i = i[:-1]
    if returndict:
        print i
        print s
        #i, s = compress(s, (i, s))
        i = compress(s, i)
        s = compress(s, s)
        print 'is'
        print i
        print s
        d = {}
        for ii in range(len(i)):
            d[i[ii]] = s[ii]
        return d
    else:
        return s
예제 #8
0
def census(a, returndict=1):
    a = sort(ravel(a))
    if returndict:
        i = arange(min(a), max(a)+2)
    else:
        i = arange(max(a)+2)
    s = searchsorted(a, i)
    s = s[1:] - s[:-1]
    i = i[:-1]
    if returndict:
        #print i
        #print s
        #i, s = compress(s, (i, s))
        i = compress(s, i)
        s = compress(s, s)
        #print 'is'
        #print i
        #print s
        d = {}
        for ii in range(len(i)):
            d[i[ii]] = s[ii]
        return d
    else:
        return s
예제 #9
0
def minmax(x, range=None):
    if range:
        lo, hi = range
        good = between(lo, x, hi)
        x = compress(good, x)
    return min(x), max(x)
예제 #10
0
def minmax(x, range=None):
    if range:
        lo, hi = range
        good = between(lo, x, hi)
        x = compress(good, x)
    return min(x), max(x)