Ejemplo n.º 1
0
def _gaussian2D(param, indy, indx, vals):
    """
    param: (mean, max - mean, y, x, sigma)
    """
    yyi = param[2] - indy
    xxi = param[3] - indx
    dist = -(yyi) * (yyi) - (xxi) * (xxi)

    sigma = 2. * (param[4] * param[4])
    return param[0] + param[1] * N.exp(dist / sigma) - vals
Ejemplo n.º 2
0
def _gaussian2D(param, indy, indx, vals):
    """
    param: (mean, max - mean, y, x, sigma)
    """
    yyi = param[2]-indy
    xxi = param[3]-indx
    dist = -(yyi)*(yyi) -(xxi)*(xxi)

    sigma  = 2. * (param[4]*param[4])
    return param[0] + param[1] * N.exp(dist /sigma) - vals
Ejemplo n.º 3
0
def _gaussian2D_ellipse(param, indy, indx, vals):
    """
    param: (mean, max - mean, y, x, sigmay, sigmax)
    """
    sy = 2. * (param[4]*param[4])
    sx = 2. * (param[5]*param[5])
    yyi = param[2]-indy
    xxi = param[3]-indx
    dist = -(yyi)*(yyi)/sy -(xxi)*(xxi)/sx

    return param[0] + param[1] * N.exp(dist) - vals
Ejemplo n.º 4
0
def _gaussian2D_ellipse(param, indy, indx, vals):
    """
    param: (mean, max - mean, y, x, sigmay, sigmax)
    """
    sy = 2. * (param[4] * param[4])
    sx = 2. * (param[5] * param[5])
    yyi = param[2] - indy
    xxi = param[3] - indx
    dist = -(yyi) * (yyi) / sy - (xxi) * (xxi) / sx

    return param[0] + param[1] * N.exp(dist) - vals
Ejemplo n.º 5
0
def yExpDecay(rhamda=1, t=0, n0=100):
    """
    rhamda: paramter
    n0:     the first value of the data
    """
    tt = N.asarray(t)
    try:
        if tt[0]:
            tt = tt.copy()
            tt -= tt[0]
    except TypeError:
        pass
    return n0 * N.exp(-rhamda * tt)
Ejemplo n.º 6
0
def yExpDecay(rhamda=1, t=0, n0=100):
    """
    rhamda: paramter
    n0:     the first value of the data
    """
    tt = N.asarray(t)
    try:
        if tt[0]:
            tt = tt.copy()
            tt -= tt[0]
    except TypeError:
        pass
    return n0 * N.exp(-rhamda * tt)
Ejemplo n.º 7
0
def yGaussianND(param, inds, sidx):
    """
    param: (mean, max - mean, z, y, x, sigmaz, sigmay, sigmax)
    ind:   coordinate as N.indices (float32)
    sidx:  idx of param where sigma starts (2 + ndim)
    """
    s = 2. * param[sidx:] * param[sidx:] # sigma
    zyx = param[2:sidx] #- 0.5 # use pixel center
    DST = N.zeros(inds[0].shape, inds[0].dtype.type)
    for i in range(sidx - 2):
        IND = zyx[i] - inds[i]
        DST -= (IND * IND) / s[i]

    return param[0] + param[1] * N.exp(DST)
Ejemplo n.º 8
0
def ySkew(param, ts):
    """
    param: (mean, max - mean, t, sigma, exp)
    ind:   coordinate as N.indices (float32)
    sidx:  idx of param where sigma starts (2 + ndim)
    """
    s = 2. * (param[3]**2)  # sigma
    ss = ts**param[4]  # exponential
    ss *= s  # sigma skewed by exp
    t = param[2] - 0.5  # use pixel center
    IND = t - ts
    DST = -(IND * IND) / ss

    return param[0] + param[1] * N.exp(DST)
Ejemplo n.º 9
0
def yGaussianND(param, inds, sidx):
    """
    param: (mean, max - mean, z, y, x, sigmaz, sigmay, sigmax)
    ind:   coordinate as N.indices (float32)
    sidx:  idx of param where sigma starts (2 + ndim)
    """
    s = 2. * param[sidx:] * param[sidx:]  # sigma
    zyx = param[2:sidx]  #- 0.5 # use pixel center
    DST = N.zeros(inds[0].shape, inds[0].dtype.type)
    for i in range(sidx - 2):
        IND = zyx[i] - inds[i]
        DST -= (IND * IND) / s[i]

    return param[0] + param[1] * N.exp(DST)
Ejemplo n.º 10
0
def ySkew(param, ts):
    """
    param: (mean, max - mean, t, sigma, exp)
    ind:   coordinate as N.indices (float32)
    sidx:  idx of param where sigma starts (2 + ndim)
    """
    s = 2. * (param[3]**2) # sigma
    ss = ts ** param[4] # exponential
    ss *= s # sigma skewed by exp
    t = param[2] - 0.5 # use pixel center
    IND = t - ts
    DST = -(IND * IND) / ss

    return param[0] + param[1] * N.exp(DST)
Ejemplo n.º 11
0
def yGaussian2D(param, indy, indx):
    """
    param:      (mean, max - mean, y, x, sigma[y], [sigmax])
    indy, indx: coordinate of y and x as N.indices
    """
    sy = 2. * (param[4] * param[4])
    if len(param) == 6:
        sx = 2. * (param[5] * param[5])
    else:
        sx = sy
    yyi = param[2] - indy
    xxi = param[3] - indx  # int32 -> float64
    #   print yyi.dtype.type
    dist = -(yyi) * (yyi) / sy - (xxi) * (xxi) / sx
    return param[0] + param[1] * N.exp(dist)
Ejemplo n.º 12
0
def yGaussian2D(param, indy, indx):
    """
    param:      (mean, max - mean, y, x, sigma[y], [sigmax])
    indy, indx: coordinate of y and x as N.indices
    """
    sy = 2. * (param[4]*param[4])
    if len(param) == 6:
        sx = 2. * (param[5]*param[5])
    else:
        sx = sy
    yyi = param[2]-indy
    xxi = param[3]-indx # int32 -> float64
 #   print yyi.dtype.type
    dist = -(yyi)*(yyi)/sy -(xxi)*(xxi)/sx
    return param[0] + param[1] * N.exp(dist)
Ejemplo n.º 13
0
def yGaussian1D(param, t=0):
    """
    param:  (mean, max - mean, y, sigma)
           or (mean, max - mean, y, sigma, sigmaSkew, sgimaSkew2)
           latter may be sensitive to initial guess
    """
    yyi = param[2]-t
    dist = -(yyi)*(yyi)
    
    if len(param) == 4:
        c = 2.
    elif len(param) == 6:
        c = param[4]*t+param[5]
    else:
        raise ValueError('param must be tuple of length 4 or 6')
    sigma  = (param[3]*param[3]) * c
    return param[0] + param[1] * N.exp(dist /sigma)
Ejemplo n.º 14
0
def yGaussian1D(param, t=0):
    """
    param:  (mean, max - mean, y, sigma)
           or (mean, max - mean, y, sigma, sigmaSkew, sgimaSkew2)
           latter may be sensitive to initial guess
    """
    yyi = param[2] - t
    dist = -(yyi) * (yyi)

    if len(param) == 4:
        c = 2.
    elif len(param) == 6:
        c = param[4] * t + param[5]
    else:
        raise ValueError('param must be tuple of length 4 or 6')
    sigma = (param[3] * param[3]) * c
    return param[0] + param[1] * N.exp(dist / sigma)
Ejemplo n.º 15
0
def yGaussian2DR(param, shape, LD, rot=0):
    """
    param: (mean, max - mean, y, x, sigma[y], [sigmax], [rot])
    shape: (y,x)
    rot:   scaler (counter clockwise) if len(param) < 7
    LD:    left down coordinate (offset)
    """
    if len(param) == 7:
        rot = parm[-1]
    sy = 2. * (param[4] * param[4])
    sx = 2. * (param[5] * param[5])
    #  import imgFilters
    yx = N.subtract(param[2:4], LD)
    #    ll.append(yx)
    yyi, xxi = rotateIndices2D(shape, rot, yx)  # return float64

    dist = -(yyi) * (yyi) / sy - (xxi) * (xxi) / sx
    return param[0] + param[1] * N.exp(dist)
Ejemplo n.º 16
0
def yGaussian2DR(param, shape, LD, rot=0):
    """
    param: (mean, max - mean, y, x, sigma[y], [sigmax], [rot])
    shape: (y,x)
    rot:   scaler (counter clockwise) if len(param) < 7
    LD:    left down coordinate (offset)
    """
    if len(param) == 7:
        rot = parm[-1]
    sy = 2. * (param[4]*param[4])
    sx = 2. * (param[5]*param[5])
  #  import imgFilters
    yx = N.subtract(param[2:4], LD)
#    ll.append(yx)
    yyi, xxi = rotateIndices2D(shape, rot, yx) # return float64

    dist = -(yyi)*(yyi)/sy -(xxi)*(xxi)/sx
    return param[0] + param[1] * N.exp(dist)
Ejemplo n.º 17
0
def gaussianArr2D(shape=(256,256), sigma=[2.,2.], peakVal=None, orig=None, rot=0):
    """
    >1.5x faster implemetation than gaussianArrND
    shape: (y,x)
    sigma: scaler or [sigmay, sigmax]
    orig: (y,x)
    rot:   scaler anti-clockwise

    return N.float32
    """
    shape = N.asarray(shape, N.uint)
    try:
        if len(sigma) == len(shape):
            sy = 2*(sigma[0]*sigma[0])
            sx = 2*(sigma[1]*sigma[1])
        elif len(sigma) == 1:
            sx = sy = 2*(sigma[0]*sigma[0])
        else:
            raise ValueError('sigma must be scaler or [sigmay, sigmax]')
    except TypeError: # sigma scaler
        sx = sy = 2*(sigma*sigma)


   # print y, x
    if rot:
        yyi, xxi = imgFit.rotateIndices2D(shape, rot, orig, N.float32)
    else:
        if orig is None:
            y, x = shape / 2. - 0.5 # pixel center remove
        else:
            y, x = N.subtract(orig, 0.5) # pixel center remove

        yi, xi = N.indices(shape, dtype=N.float32)
        yyi = y-yi
        xxi = x-xi
    k1 = -(yyi)*(yyi)/(sy) - (xxi)*(xxi)/(sx)

    if peakVal:
        k0 = peakVal
    else:
        k0 = 1. / ((sx+sy)/2. * ((2*N.pi)**0.5))
    return k0 * N.exp(k1)
Ejemplo n.º 18
0
def gaussianArr2D(
        shape=(256, 256), sigma=[2., 2.], peakVal=None, orig=None, rot=0):
    """
    >1.5x faster implemetation than gaussianArrND
    shape: (y,x)
    sigma: scaler or [sigmay, sigmax]
    orig: (y,x)
    rot:   scaler anti-clockwise

    return N.float32
    """
    shape = N.asarray(shape, N.uint)
    try:
        if len(sigma) == len(shape):
            sy = 2 * (sigma[0] * sigma[0])
            sx = 2 * (sigma[1] * sigma[1])
        elif len(sigma) == 1:
            sx = sy = 2 * (sigma[0] * sigma[0])
        else:
            raise ValueError('sigma must be scaler or [sigmay, sigmax]')
    except TypeError:  # sigma scaler
        sx = sy = 2 * (sigma * sigma)

# print y, x
    if rot:
        yyi, xxi = imgFit.rotateIndices2D(shape, rot, orig, N.float32)
    else:
        if orig is None:
            y, x = shape / 2. - 0.5  # pixel center remove
        else:
            y, x = N.subtract(orig, 0.5)  # pixel center remove

        yi, xi = N.indices(shape, dtype=N.float32)
        yyi = y - yi
        xxi = x - xi
    k1 = -(yyi) * (yyi) / (sy) - (xxi) * (xxi) / (sx)

    if peakVal:
        k0 = peakVal
    else:
        k0 = 1. / ((sx + sy) / 2. * ((2 * N.pi)**0.5))
    return k0 * N.exp(k1)
Ejemplo n.º 19
0
def yExpProb(rhamda=1, t=0):
    t = N.asarray(t)
    return rhamda * N.exp(-rhamda * t)
Ejemplo n.º 20
0
def yExpProb(rhamda=1, t=0):
    t = N.asarray(t)
    return rhamda * N.exp(-rhamda * t)