Exemplo n.º 1
0
 def plotGrid(self):
   from matplotlib import pyplot as plt
   from numpy import empty as npempty
   pts = len(self.indices)
   xpts = npempty(pts)
   if self.dim==1:
     for i in xrange(pts):
       pt = tuple(self.indices[i])
       xpts[i] = self.gP[pt].pointPosition(pt)[0]
     ax = plt.gca()
     ax.yaxis.set_visible(False)
     plt.plot(xpts,xpts/xpts,'*')
   elif self.dim==2:
     ypts = npempty(pts)
     for i in xrange(pts):
       pt = tuple(self.indices[i])
       xpts[i], ypts[i] = self.gP[pt].pointPosition(pt)
     plt.plot(xpts,ypts,'*')
   else:
     if self.dim > 3:
       print "Showing first three dimensions only"
     from mpl_toolkits.mplot3d import Axes3D
     Axes3D
     fig = plt.figure()
     ax = fig.add_subplot(111, projection='3d')
     ypts = npempty(pts)
     zpts = npempty(pts)
     for i in xrange(pts):
       pt = tuple(self.indices[i])
       xpts[i], ypts[i], zpts[i] = self.gP[pt].pointPosition(pt)[:3]
     ax.scatter(xpts, ypts, zpts)    
   plt.show()
Exemplo n.º 2
0
 def plotGrid(self):
     from matplotlib import pyplot as plt
     from numpy import empty as npempty
     pts = len(self.indices)
     xpts = npempty(pts)
     if self.dim == 1:
         for i in xrange(pts):
             pt = tuple(self.indices[i])
             xpts[i] = self.gP[pt].pointPosition(pt)[0]
         ax = plt.gca()
         ax.yaxis.set_visible(False)
         plt.plot(xpts, xpts / xpts, '*')
     elif self.dim == 2:
         ypts = npempty(pts)
         for i in xrange(pts):
             pt = tuple(self.indices[i])
             xpts[i], ypts[i] = self.gP[pt].pointPosition(pt)
         plt.plot(xpts, ypts, '*')
     else:
         if self.dim > 3:
             print "Showing first three dimensions only"
         from mpl_toolkits.mplot3d import Axes3D
         Axes3D
         fig = plt.figure()
         ax = fig.add_subplot(111, projection='3d')
         ypts = npempty(pts)
         zpts = npempty(pts)
         for i in xrange(pts):
             pt = tuple(self.indices[i])
             xpts[i], ypts[i], zpts[i] = self.gP[pt].pointPosition(pt)[:3]
         ax.scatter(xpts, ypts, zpts)
     plt.show()
def main(argv):
    """
    Main part of program.

    :param argv:
    :return:
    """
    window = Tk()
    canvas = Canvas(window, width=WIDTH, height=HEIGHT, bg=WHITE)
    canvas.pack()
    img = PhotoImage(width=WIDTH, height=HEIGHT)
    canvas.create_image((WIDTH / 2, HEIGHT / 2), image=img, state="normal")
    with JPTimer() as t:
        # compute x*x values and store them in a numpy array
        x_squareds = npempty((WIDTH, 1), dtype=float)
        for i in range(WIDTH):
            x = CORNA + (SIDE * i / 100.0)
            x_squareds[i, 0] = x * x

        # compute y*y values and store them in a numpy array
        y_squareds = npempty((HEIGHT, 1), dtype=float)
        for j in range(HEIGHT):
            y = CORNA + (SIDE * j / 100.0)
            y_squareds[j, 0] = y * y

        # compute the bits and store them in a character array
        lines = []
        for j in range(HEIGHT):
            horizontal_line = '{'
            for i in range(WIDTH):
                colorbit = color(x_squareds[i, 0], y_squareds[j, 0])
                horizontal_line += (' ' + colorbit)
            horizontal_line += '}'
            lines.append(horizontal_line)
        img.put(' '.join(lines))

    print('Time required for this version was {:06,.2f} '
          'seconds'.format(t.interval))
    mainloop()
Exemplo n.º 4
0
    def __init__(self, size: int):
        """
        Constructor

        Parameters
        ----------
        size
            Size of each array in this class
        """
        self.cs_indexes: ndarray = npfull(size, -1, int32)
        self.median_indexes: ndarray = npfull(size, -1, int32)
        self.taken_previous: ndarray = npempty(size, int32)
        self.taken_next: ndarray = npempty(size, int32)
        self.empty_next: ndarray = nparray([i + 1 for i in arange(size)],
                                           int32)

        self.empty_next[size - 1] = -1  # last entry set to -1

        self.empty_start: int = 0
        self.empty_end: int = size - 1
        self.taken_start: int = -1
        self.taken_end: int = -1
Exemplo n.º 5
0
def dworetsky_period_find(time,
                          mag,
                          err,
                          init_p,
                          end_p,
                          f_step,
                          verbose=False):
    '''

    This is the super-slow naive version taken from my thesis work.

    Uses the string length method in Dworetsky 1983 to calculate the period of a
    time-series of magnitude measurements and associated magnitude
    errors. Searches in linear frequency space (which obviously doesn't
    correspond to a linear period space).

    PARAMETERS:

    time: series of times at which mags were measured (usually some form of JD)
    mag: timeseries of magnitudes (np.array)
    err: associated errs per magnitude measurement (np.array)
    init_p, end_p: interval to search for periods between (both ends inclusive)
    f_step: step in frequency [days^-1] to use

    RETURNS:

    tuple of the following form:

    (periods (np.array),
     string_lengths (np.array),
     good_period_mask (boolean array))

    '''

    mod_mag = (mag - npmin(mag)) / (2.0 * (npmax(mag) - npmin(mag))) - 0.25
    fold_time = npmin(time)  # fold at the first time element

    init_f = 1.0 / end_p
    end_f = 1.0 / init_p

    n_freqs = npceil((end_f - init_f) / f_step)

    if verbose:
        print('searching %s frequencies between %s and %s days^-1...' %
              (n_freqs, init_f, end_f))

    out_periods = npempty(n_freqs, dtype=np.float64)
    out_strlens = npempty(n_freqs, dtype=np.float64)
    p_goodflags = npempty(n_freqs, dtype=bool)

    j_range = len(mag) - 1

    for i in range(int(n_freqs)):

        period = 1.0 / init_f

        # print('P: %s, f: %s, i: %s, n_freqs: %s, maxf: %s' %
        #       (period, init_f, i, n_freqs, end_f))

        phase = (time - fold_time) / period - npfloor(
            (time - fold_time) / period)
        phase_sort_ind = npargsort(phase)

        phase_sorted = phase[phase_sort_ind]
        mod_mag_sorted = mod_mag[phase_sort_ind]

        strlen = 0.0

        epsilon = 2.0 * npmean(err)
        delta_l = 0.34 * (epsilon - 0.5 *
                          (epsilon**2)) * (len(time) - npsqrt(10.0 / epsilon))
        keep_threshold_1 = 1.6 + 1.2 * delta_l

        l = 0.212 * len(time)
        sig_l = len(time) / 37.5
        keep_threshold_2 = l + 4.0 * sig_l

        # now calculate the string length
        for j in range(j_range):
            strlen += npsqrt((mod_mag_sorted[j + 1] - mod_mag_sorted[j])**2 +
                             (phase_sorted[j + 1] - phase_sorted[j])**2)

        strlen += npsqrt((mod_mag_sorted[0] - mod_mag_sorted[-1])**2 +
                         (phase_sorted[0] - phase_sorted[-1] + 1)**2)

        if ((strlen < keep_threshold_1) or (strlen < keep_threshold_2)):
            p_goodflags[i] = True

        out_periods[i] = period
        out_strlens[i] = strlen

        init_f += f_step

    return (out_periods, out_strlens, p_goodflags)
Exemplo n.º 6
0
Arquivo: tensor.py Projeto: guochu/RQC
def empty(shape, dtype=float, order='C'):
    return tensor(npempty(shape, dtype=dtype, order=order))