Example #1
0
def plot1(gp, ngrid=100, lim=None, k=range(-3, 4)):
    k = sorted(k)
    if lim is None:
        lim = (np.amin(gp.x[:, 1]), np.amax(gp.x[:, 1]))
    x = np.linspace(lim[0], lim[1], ngrid).T
    (m, v) = gp.inf(x)
    m = np.asarray(m).squeeze()
    v = np.asarray(v).squeeze()
    plt.plot(x, m,
             color=DARKBLUE,
             linewidth=2)
    for i in k:
        if i == 0: continue
        lo = m - i*np.sqrt(v)
        hi = m + i*np.sqrt(v)
        plt.fill_between(x, lo, hi,
                         linestyle='solid',
                         edgecolor=DARKGRAY,
                         facecolor=LIGHTGRAY,
                         alpha=0.2)
    plt.plot(gp.x, gp.y,
             'o',
             markersize=8,
             markeredgewidth=1,
             markeredgecolor=DARKGRAY,
             markerfacecolor=LIGHTBLUE)
    plt.xlim(lim)
Example #2
0
def rotation_matrix_from_quaternion(q):
    """
        Returns the rotation matrix associated to a unitary
        quaternion represented by a 4 dimensional vector
    """
    a, b, c, d = npmat.asarray(q).reshape(-1)
    a2 = a * a
    b2 = b * b
    c2 = c * c
    d2 = d * d

    return npmat.asmatrix(
        [[a2 + b2 - c2 - d2, 2. * (b * c - a * d), 2. * (a * c + b * d)],
         [2. * (a * d + b * c), a2 - b2 + c2 - d2, 2. * (c * d - a * b)],
         [2. * (b * d - a * c), 2. * (a * b + c * d), a2 - b2 - c2 + d2]])
Example #3
0
 def plot_aux(self, mode, ngrid):
     mpl.rc('text', usetex=True)
     mpl.rc('font', family='serif')
     fig = plt.figure()
     ax = fig.gca()
     (x1, x2, y) = self.grid(ngrid)
     if mode == 'all':
         plt.contourf(np.asarray(x1), np.asarray(x2), np.asarray(y),
                      20, cmap=plt.cm.jet)
         plt.contour(np.asarray(x1), np.asarray(x2), np.asarray(y),
                     20, colors='k', linestyles='solid')
     elif mode == 'this':
         plt.contourf(np.asarray(x1), np.asarray(x2), np.asarray(y),
                      cmap=plt.cm.jet, levels=[-1e10, self.h, 1e10])
         plt.contour(np.asarray(x1), np.asarray(x2), np.asarray(y),
                     colors='k', linestyles='solid', levels=[self.h])
     ax.set_xlabel('$x_1$')
     ax.set_ylabel('$x_2$')
     plt.show()
Example #4
0
 def plot_aux(self, mode, ngrid):
     mpl.rc('text', usetex=True)
     mpl.rc('font', family='serif')
     fig = plt.figure()
     ax = fig.gca()
     (x1, x2, y) = self.grid(ngrid)
     if mode == 'all':
         plt.contourf(np.asarray(x1),
                      np.asarray(x2),
                      np.asarray(y),
                      20,
                      cmap=plt.cm.jet)
         plt.contour(np.asarray(x1),
                     np.asarray(x2),
                     np.asarray(y),
                     20,
                     colors='k',
                     linestyles='solid')
     elif mode == 'this':
         plt.contourf(np.asarray(x1),
                      np.asarray(x2),
                      np.asarray(y),
                      cmap=plt.cm.jet,
                      levels=[-1e10, self.h, 1e10])
         plt.contour(np.asarray(x1),
                     np.asarray(x2),
                     np.asarray(y),
                     colors='k',
                     linestyles='solid',
                     levels=[self.h])
     ax.set_xlabel('$x_1$')
     ax.set_ylabel('$x_2$')
     plt.show()
Example #5
0
def rand_init(fan_in, fan_out):
    ret = np.asarray(rng.uniform(low=-np.sqrt(3. / fan_in),
                                 high=np.sqrt(3. / fan_in),
                                 size=(fan_in, fan_out)),
                     dtype=T.config.floatX)
    return ret
Example #6
0
def calculate(crs, normalized_img):
    """
    :param crs: cosmic rays list
    :param normalized_img: 2D image normalized by exposition time
    :return: a map with statistics about crs
    """

    # Calculate basic statistics on connected objects

    pixel_count = [cr.area for cr in crs]
    len_mean = mean(pixel_count)
    len_std = std(pixel_count)
    len_skew = skew(asarray(pixel_count))
    len_percentiles = percentile(pixel_count, [10, 25, 50, 75, 90])

    len_10_percentile = len_percentiles[0]
    len_25_percentile = len_percentiles[1]
    len_50_percentile = len_percentiles[2]
    len_75_percentile = len_percentiles[3]
    len_90_percentile = len_percentiles[4]

    # Calculate flux based on cr intensity
    flux_total = normalized_img.sum()
    flux_mean = flux_total / len(crs)

    # For each CR get its flux by summing up the pixels
    flux_crs = []

    for cr in crs:
        flux = 0
        for coord in cr.coords:
            flux += normalized_img[coord[0]][coord[1]]
            flux_crs.append(flux)

    flux_std = std(flux_crs)
    flux_skew = skew(asarray(flux_crs))
    flux_percentiles = percentile(flux_crs, [10, 25, 50, 75, 90])

    flux_10_percentile = flux_percentiles[0]
    flux_25_percentile = flux_percentiles[1]
    flux_50_percentile = flux_percentiles[2]
    flux_75_percentile = flux_percentiles[3]
    flux_90_percentile = flux_percentiles[4]

    return dict(
        len_mean=len_mean,
        len_std=len_std,
        len_skew=len_skew,
        len_10_percentile=len_10_percentile,
        len_25_percentile=len_25_percentile,
        len_50_percentile=len_50_percentile,
        len_75_percentile=len_75_percentile,
        len_90_percentile=len_90_percentile,
        flux_total=flux_total,
        flux_mean=flux_mean,
        flux_std=flux_std,
        flux_skew=flux_skew,
        flux_10_percentile=flux_10_percentile,
        flux_25_percentile=flux_25_percentile,
        flux_50_percentile=flux_50_percentile,
        flux_75_percentile=flux_75_percentile,
        flux_90_percentile=flux_90_percentile
    )
Example #7
0
def rand_init(fan_in, fan_out):
    ret = np.asarray(rng.uniform(
        low = -np.sqrt(3. / fan_in),
        high = np.sqrt(3. / fan_in),
        size = (fan_in, fan_out)), dtype = T.config.floatX)
    return ret
Example #8
0
File: 2.py Project: Raven-L/for-
import numpy as np
import numpy.matlib as npm
import random
import matplotlib.pyplot as plt

p1 = 100  #100*random.random()
p2 = 10  #100*random.random()

X = range(1, 1001)
X = npm.asarray(X)

N = 200
Y = []
YY = []

for each in X:
    Y.append(each * p1 + p2 + N * random.uniform(-1.0, 1.0))
    YY.append(each * p1 + p2)

Y = npm.asarray(Y)

#plt.scatter(X,Y)
#plt.show()

p = npm.ones((1, 2)) * 50

y = npm.asarray(Y)
x1 = npm.asarray(X)
x2 = npm.ones((1, 1000))

x = np.vstack([x1, x2])