def monomial_value_test ( ):

#*****************************************************************************80
#
## MONOMIAL_VALUE_TEST tests the MONOMIAL_VALUE library.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license. 
#
#  Modified:
#
#    07 April 2015
#
#  Author:
#
#    John Burkardt
#
  from i4vec_print               import i4vec_print_test
  from i4vec_transpose_print     import i4vec_transpose_print_test
  from i4vec_uniform_ab          import i4vec_uniform_ab_test
  from monomial_value            import monomial_value_test
  from r8mat_nint                import r8mat_nint_test
  from r8mat_print               import r8mat_print_test
  from r8mat_print_some          import r8mat_print_some_test
  from r8mat_uniform_ab          import r8mat_uniform_ab_test
  from timestamp                 import timestamp

  timestamp ( )
  print ''
  print 'MONOMIAL_VALUE_TEST'
  print '  Python version:'
  print '  Test the MONOMIAL_VALUE library.'
#
#  Utilities:
#
  i4vec_print_test ( )
  i4vec_transpose_print_test ( )
  i4vec_uniform_ab_test ( )

  r8mat_nint_test ( )
  r8mat_print_test ( )
  r8mat_print_some_test ( )
  r8mat_uniform_ab_test ( )
#
#  The library.
#
  monomial_value_test ( )
#
#  Terminate.
#
  print ''
  print 'MONOMIAL_VALUE_TEST:'
  print '  Normal end of execution.'
  print ''
  timestamp ( )

  return
Пример #2
0
def rnglib_test ( ):

#*****************************************************************************80
#
## MAIN is the main program for RNGLIB_TEST.
#
#  Discussion:
#
#    RNGLIB_TEST calls sample problems for the RNGLIB library.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license. 
#
#  Modified:
#
#    27 May 2013
#
#  Author:
#
#    John Burkardt
#
  from timestamp import timestamp
  from rnglib_test01 import rnglib_test01
  from rnglib_test02 import rnglib_test02
  from rnglib_test03 import rnglib_test03
  from rnglib_test04 import rnglib_test04

  timestamp ( )

  print ''
  print 'RNGLIB_TEST'
  print '  PYTHON version'
  print '  Test the RNGLIB library.'
#
#  Call tests.
#
  rnglib_test01 ( )
  rnglib_test02 ( )
  rnglib_test03 ( )
  rnglib_test04 ( )
#
#  Terminate.
#
  print ''
  print 'RNGLIB_TEST'
  print '  Normal end of execution.'
  print ''
  timestamp ( )
Пример #3
0
def convertImplicit(val):
    if val == '~':
        return None
    if val == '+':
        return 1
    if val == '-':
        return 0
    if val[0] == "'" and val[-1] == "'":
        val = val[1:-1]
        return string.replace(val, "''", "\'")
    if val[0] == '"' and val[-1] == '"':
        if re.search(r"\u", val):
            val = "u" + val
        unescapedStr = eval (val)
        return unescapedStr
    if matchTime.match(val):
        try:
            return timestamp(val)
        except: #sometimes things that look like timestamps are not
            pass #so let's ensure that something gets returned
    if INT_REGEX.match(val):
        return int(cleanseNumber(val))
    if OCTAL_REGEX.match(val):
        return int(val, 8)
    if HEX_REGEX.match(val):
        return int(val, 16)
    if FLOAT_REGEX.match(val):
        return float(cleanseNumber(val))
    if SCIENTIFIC_REGEX.match(val):
        return float(cleanseNumber(val))
    return val
Пример #4
0
def convertImplicit(val):
    if val == '~':
        return None
    if val == '+':
        return 1
    if val == '-':
        return 0
    if val[0] == "'" and val[-1] == "'":
        val = val[1:-1]
        return string.replace(val, "''", "\'")
    if val[0] == '"' and val[-1] == '"':
        if re.search(r"\u", val):
            val = "u" + val
        unescapedStr = eval (val)
        return unescapedStr
    if matchTime.match(val):
        return timestamp(val)
    if INT_REGEX.match(val):
        return int(cleanseNumber(val))
    if OCTAL_REGEX.match(val):
        return int(val, 8)
    if HEX_REGEX.match(val):
        return int(val, 16)
    if FLOAT_REGEX.match(val):
        return float(cleanseNumber(val))
    if SCIENTIFIC_REGEX.match(val):
        return float(cleanseNumber(val))
    return val
Пример #5
0
def generateScript():
    filename = timestamp.timestamp() + ".hmmern.sh"
    moduleScript = open(filename, "w")
    loadModules(moduleScript)
    generateORFs(moduleScript)
    hmmer(moduleScript)
    return filename
Пример #6
0
 def rmChild(self, itemId):
     backupFullPath = os.path.join(self.backupPath, self.getItemName()+timestamp.timestamp())
     try:
         print 'removing: ',self.getPath()
         shutil.move(self.getPath(), backupFullPath)
     except IOError, WindowsError:
         print 'move error'
Пример #7
0
def machine_test ( ):

#*****************************************************************************80
#
## MACHINE_TEST tests the MACHINE library.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    04 April 2015
#
#  Author:
#
#    John Burkardt
#
  from d1mach    import d1mach_test
  from i1mach    import i1mach_test
  from r1mach    import r1mach_test
  from timestamp import timestamp

  timestamp ( )
  print ''
  print 'MACHINE_TEST:'
  print '  Python version'
  print '  Test the MACHINE library.'

  d1mach_test ( )
  i1mach_test ( )
  r1mach_test ( )
#
#  Terminate.
#
  print ''
  print 'MACHINE_TEST:'
  print '  Normal end of execution.'
  print ''
  timestamp ( )

  return
Пример #8
0
    # So here we alternate reading contents and discarding end string
    def write(self, s):
        #print([c for c in s]) # DEBUG reveals second write for end string
        #print('end_phase %s' % self.end_phase) # DEBUG
        if self.end_phase:
            # ignore the end string, ed0 buffer lines must end with \n
            self.lines.append(self.contents) # already  includes final'\n'
        else:
            # store contents string until we get end string
            self.contents = s
        self.end_phase = not self.end_phase # False True False ...


# Test

ts0, ts1 = timestamp('ts0'), timestamp('ts1')
buf0, buf1 = Buffer(), Buffer()

def main():
    print('Two generators interleaving, each printing five lines to stdout')
    for i in range(5):
        print(next(ts0)) # no file=... print to stdout
        print(next(ts1))
    print("""Two generators interleaving, each printing five lines to different buffer
 then print each buffer in turn""")
    # first print to both buffers
    for i in range(5):
        print(next(ts0), file=buf0) # use file=... print to buffer
        print(next(ts1), file=buf1)
    # then print contents of each buffer
    for line in buf0.lines:
Пример #9
0
def wathen_test ( ):

#*****************************************************************************80
#
## WATHEN_TEST tests the WATHEN library.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    31 August 2014
#
#  Author:
#
#    John Burkardt
#
  from timestamp import timestamp
  from wathen_test01 import wathen_test01
  from wathen_test02 import wathen_test02
  from wathen_test03 import wathen_test03
  from wathen_test04 import wathen_test04
  from wathen_test05 import wathen_test05
  from wathen_test06 import wathen_test06
  from wathen_test07 import wathen_test07
  from wathen_test08 import wathen_test08
  from wathen_test09 import wathen_test09

  timestamp ( )
  print ''
  print 'WATHEN_TEST'
  print '  Python version:'
  print '  Test the WATHEN library.'
#
#  Direct Solve
#
  wathen_test01 ( )
  wathen_test02 ( )
#
#  Timings.
#
  wathen_test03 ( )
  wathen_test04 ( )
  wathen_test05 ( )
#
#  CG Solve
#
  wathen_test06 ( )
  wathen_test07 ( )
  wathen_test08 ( )
#
#  Use SPY to display the sparsity of the matrix.
#
  wathen_test09 ( )
#
#  Terminate.
#
  print ''
  print 'WATHEN_TEST:'
  print '  Normal end of execution.'
  print ''
  timestamp ( )

  return
Пример #10
0
#    08 February 2015
#
#  Author:
#
#    John Burkardt
#
  from r8mat_print import r8mat_print

  print ''
  print 'GK323_TEST'
  print '  GK323 computes the GK323 matrix.'

  m = 5
  n = m

  a = gk323 ( m, n )
 
  r8mat_print ( m, n, a, '  GK323 matrix:' )

  print ''
  print 'GK323_TEST'
  print '  Normal end of execution.'

  return

if ( __name__ == '__main__' ):
  from timestamp import timestamp
  timestamp ( )
  gk323_test ( )
  timestamp ( )
Пример #11
0
def fem2d_bvp_linear():
    #
    ## FEM2D_BVP_LINEAR solves a 2D boundary value problem in the unit square.
    #
    #  Location:
    #
    #    http://people.sc.fsu.edu/~jburkardt/py_src/fem2d_bvp_linear/fem2d_bvp_linear.py
    #
    #  Discussion:
    #
    #    The PDE is defined for 0 < x < 1, 0 < y < 1:
    #      - uxx - uyy = f(x)
    #    with boundary conditions
    #      u(0,y) = 0,
    #      u(1,y) = 0,
    #      u(x,0) = 0,
    #      u(x,1) = 0.
    #
    #    The exact solution is:
    #      exact(x) = x * ( 1 - x ) * y * ( 1 - y ).
    #    The right hand side f(x) is:
    #      f(x) = 2 * x * ( 1 - x ) + 2 * y * ( 1 - y )
    #
    #    The unit square is divided into N by N squares.  Bilinear finite
    #    element basis functions are defined, and the solution is sought as a
    #    piecewise linear combination of these basis functions.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    13 October 2014
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Local parameters:
    #
    #    Local, integer ELEMENT_NUM, the number of elements.
    #
    #    Local, integer LINEAR_ELEMENT_NUM, the number of elements
    #    in a row in the X or Y dimension.
    #
    #    Local, integer NODE_LINEAR_NUM, the number of nodes in the X or Y dimension.
    #
    #    Local, integer NODE_NUM, the number of nodes.
    #
    import numpy as np
    import scipy.linalg as la
    from timestamp import timestamp

    timestamp()
    print ""
    print "FEM2D_BVP_LINEAR"
    print "  Python version"
    print "  Given the boundary value problem on the unit square:"
    print "    - uxx - uyy = x, 0 < x < 1, 0 < y < 1"
    print "  with boundary conditions"
    print "    u(0,y) = u(1,y) = u(x,0) = u(x,1) = 0,"
    print "  demonstrate how the finite element method can be used to"
    print "  define and compute a discrete approximation to the solution."
    print ""
    print "  This program uses quadrilateral elements"
    print "  and piecewise continuous bilinear basis functions."

    element_linear_num = 4
    node_linear_num = element_linear_num + 1
    element_num = element_linear_num * element_linear_num
    node_num = node_linear_num * node_linear_num
    #
    #  Set the coordinates of the nodes.
    #  The same grid is used for X and Y.
    #
    a = 0.0
    b = 1.0
    grid = np.linspace(a, b, node_linear_num)

    print ""
    print "  Nodes along X axis:"
    print ""
    for i in range(0, node_linear_num):
        print "  %d  %f" % (i, grid[i])
#
#  Set up a quadrature rule.
#  This rule is defined on the reference interval [0,1].
#
    quad_num = 3

    quad_point = np.array ( ( \
      0.112701665379258311482073460022, \
      0.5, \
      0.887298334620741688517926539978 ) )

    quad_weight = np.array ( ( \
      5.0 / 18.0, \
      8.0 / 18.0, \
      5.0 / 18.0 ) )
    #
    #  Compute the system matrix A and right hand side RHS.
    #  There is an unknown at every node.
    #
    A = np.zeros((node_num, node_num))
    rhs = np.zeros(node_num)
    #
    #  Look at the square in row EX and column EY:
    #
    #    N  *-----*
    #       |     |
    #       |     |
    #    Y  |     |
    #       |     |
    #       |     |
    #    S  *-----*
    #
    #       W  X  E
    #
    for ex in range(0, element_linear_num):

        w = ex
        e = ex + 1

        xw = grid[w]
        xe = grid[e]

        for ey in range(0, element_linear_num):

            s = ey
            n = ey + 1

            ys = grid[s]
            yn = grid[n]
            #
            #  Determine the node indices.
            #
            sw = ey * node_linear_num + ex
            se = ey * node_linear_num + ex + 1
            nw = (ey + 1) * node_linear_num + ex
            ne = (ey + 1) * node_linear_num + ex + 1
            #
            #  The 2D quadrature rule is the "product" of X and Y copies of the 1D rule.
            #
            for qx in range(0, quad_num):
                xq = xw + quad_point[qx] * (xe - xw)
                for qy in range(0, quad_num):
                    yq = ys + quad_point[qy] * (yn - ys)
                    wq = quad_weight[qx] * quad_weight[qy] * (xe - xw) * (yn -
                                                                          ys)
                    #
                    #  Evaluate all four basis functions, and their X and Y derivatives.
                    #
                    vsw = (xe - xq) / (xe - xw) * (yn - yq) / (yn - ys)
                    vswx = (-1.0) / (xe - xw) * (yn - yq) / (yn - ys)
                    vswy = (xe - xq) / (xe - xw) * (-1.0) / (yn - ys)

                    vse = (xq - xw) / (xe - xw) * (yn - yq) / (yn - ys)
                    vsex = (1.0) / (xe - xw) * (yn - yq) / (yn - ys)
                    vsey = (xq - xw) / (xe - xw) * (-1.0) / (yn - ys)

                    vnw = (xe - xq) / (xe - xw) * (yq - ys) / (yn - ys)
                    vnwx = (-1.0) / (xe - xw) * (yq - ys) / (yn - ys)
                    vnwy = (xe - xq) / (xe - xw) * (1.0) / (yn - ys)

                    vne = (xq - xw) / (xe - xw) * (yq - ys) / (yn - ys)
                    vnex = (1.0) / (xe - xw) * (yq - ys) / (yn - ys)
                    vney = (xq - xw) / (xe - xw) * (1.0) / (yn - ys)
                    #
                    #  Compute contributions to the stiffness matrix.
                    #
                    A[sw, sw] = A[sw, sw] + wq * (vswx * vswx + vswy * vswy)
                    A[sw, se] = A[sw, se] + wq * (vswx * vsex + vswy * vsey)
                    A[sw, nw] = A[sw, nw] + wq * (vswx * vnwx + vswy * vnwy)
                    A[sw, ne] = A[sw, ne] + wq * (vswx * vnex + vswy * vney)
                    rhs[sw] = rhs[sw] + wq * vsw * rhs_fn(xq, yq)

                    A[se, sw] = A[se, sw] + wq * (vsex * vswx + vsey * vswy)
                    A[se, se] = A[se, se] + wq * (vsex * vsex + vsey * vsey)
                    A[se, nw] = A[se, nw] + wq * (vsex * vnwx + vsey * vnwy)
                    A[se, ne] = A[se, ne] + wq * (vsex * vnex + vsey * vney)
                    rhs[se] = rhs[se] + wq * vse * rhs_fn(xq, yq)

                    A[nw, sw] = A[nw, sw] + wq * (vnwx * vswx + vnwy * vswy)
                    A[nw, se] = A[nw, se] + wq * (vnwx * vsex + vnwy * vsey)
                    A[nw, nw] = A[nw, nw] + wq * (vnwx * vnwx + vnwy * vnwy)
                    A[nw, ne] = A[nw, ne] + wq * (vnwx * vnex + vnwy * vney)
                    rhs[nw] = rhs[nw] + wq * vnw * rhs_fn(xq, yq)

                    A[ne, sw] = A[ne, sw] + wq * (vnex * vswx + vney * vswy)
                    A[ne, se] = A[ne, se] + wq * (vnex * vsex + vney * vsey)
                    A[ne, nw] = A[ne, nw] + wq * (vnex * vnwx + vney * vnwy)
                    A[ne, ne] = A[ne, ne] + wq * (vnex * vnex + vney * vney)
                    rhs[ne] = rhs[ne] + wq * vne * rhs_fn(xq, yq)
#
#  Modify the linear system to enforce the boundary conditions where
#  X = 0 or 1 or Y = 0 or 1.
#
    v = 0
    for j in range(0, node_linear_num):
        for i in range(0, node_linear_num):

            if (i == 0 or i == node_linear_num - 1 or j == 0
                    or j == node_linear_num - 1):
                A[v, 0:node_num] = 0.0
                A[v, v] = 1.0
                rhs[v] = 0.0

            v = v + 1
#
#  Solve the linear system.
#
    u = la.solve(A, rhs)
    #
    #  Evaluate the exact solution at the nodes.
    #
    uex = np.zeros(node_linear_num * node_linear_num)

    v = 0
    for j in range(0, node_linear_num):
        y = grid[j]
        for i in range(0, node_linear_num):
            x = grid[i]
            uex[v] = exact_fn(x, y)
            v = v + 1
#
#  Compare the solution and the error at the nodes.
#
    print ""
    print "   I     J     V    X         Y              U               Uexact"
    print ""
    v = 0
    for j in range(0, node_linear_num):
        y = grid[j]
        for i in range(0, node_linear_num):
            x = grid[i]
            print "%4d  %4d  %4d  %8f  %8f  %14g  %14g" % (i, j, v, x, y, u[v],
                                                           uex[v])
            v = v + 1
#
#  Optionally, print the node coordinates.
#
    if (false):
        v = 0
        for j in range(0, node_linear_num):
            y = grid[j]
            for i in range(0, node_linear_num):
                x = grid[i]
                print "%8f  %8f" % (x, y)
                v = v + 1
#
#  Optionally, print the elements, listing the nodes in counterclockwise order.
#
    if (false):
        e = 0
        for j in range(0, element_linear_num):
            y = grid[j]
            for i in range(0, element_linear_num):
                sw = j * node_linear_num + i
                se = j * node_linear_num + i + 1
                nw = (j + 1) * node_linear_num + i
                ne = (j + 1) * node_linear_num + i + 1
                print "%4d  %4d  %4d  %4d" % (sw, se, ne, nw)
                e = e + 1
#
#  Terminate.
#
    print ""
    print "FEM2D_BVP_LINEAR:"
    print "  Normal end of execution."
    print ''
    timestamp()
Пример #12
0
def fem1d_model ( ):
#
## FEM1D_MODEL solves a 1D "model" boundary value problem using finite elements.
#
#  Location:
#
#    http://people.sc.fsu.edu/~jburkardt/py_src/fem1d/fem1d_model.py
#
#  Discussion:
#
#    The PDE is defined for 0 < x < 1:
#      -u'' + u = x
#    with boundary conditions
#      u(0) = 0,
#      u(1) = 0.
#
#    The exact solution is:
#      exact(x) = x - sinh(x) / sinh(1.0)
#
#    This program is different from FEM1D.PY:
#    * the problem to be solved is different, and includes a linear term;
#    * the code to assemble the matrix is different.  We evaluate all the
#      basis functions and derivatives, and then form the combinations
#      that must be added to the system matrix and right hand side.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license. 
#
#  Modified:
#
#    23 September 2014
#
#  Author:
#
#    John Burkardt
#
#  Local parameters:
#
#    Local, integer N, the number of elements.
#
  import matplotlib.pyplot as plt
  import numpy as np
  import scipy.linalg as la
  from timestamp import timestamp

  timestamp ( )
  print ""
  print "FEM1D_MODEL"
  print "  Python version"
  print "  Given the model two point boundary value problem:"
  print "    -u'' + u = x, 0 < x < 1"
  print "  with boundary conditions"
  print "    u(0) = 0, u(1) = 0,"
  print "  demonstrate how the finite element method can be used to"
  print "  define and compute a discrete approximation to the solution."
#
#  The mesh will use N+1 points between A and B.
#  These will be indexed X[0] through X[N].
#
  a = 0.0
  b = 1.0
  n = 5
  x = np.linspace ( a, b, n + 1 )

  print ""
  print "  Nodes:"
  print ""
  for i in range ( 0, n + 1 ):
    print "  %d  %f" %( i, x[i] )
#
#  Set a 3 point quadrature rule on the reference interval [0,1].
#
  ng = 3

  xg = np.array ( ( \
    0.112701665379258311482073460022, \
    0.5, \
    0.887298334620741688517926539978 ) )

  wg = np.array ( ( \
    5.0 / 18.0, \
    8.0 / 18.0, \
    5.0 / 18.0 ) )
#
#  Compute the system matrix A and right hand side RHS.
#
  A = np.zeros ( ( n + 1, n + 1 ) )
  rhs = np.zeros ( n + 1 )
#
#  Look at element E: (0, 1, 2, ..., N-1).
#
  for e in range ( 0, n ):

    l = e
    r = e + 1

    xl = x[l]
    xr = x[r]
#
#  Consider quadrature point Q: (0, 1, 2 ) in element E.
#
    for q in range ( 0, ng ):
#
#  Map XG and WG from [0,1] to
#      XQ and QQ in [XL,XR].
#
      xq = xl + xg[q] * ( xr - xl )
      wq = wg[q] * ( xr - xl )
#
#  Evaluate at XQ the basis functions and derivatives for XL and XR.
#
      phil = ( xr - xq  ) / ( xr - xl )
      philp = - 1.0 / ( xr - xl )

      phir = ( xq - xl ) / ( xr - xl )
      phirp = 1.0 / ( xr - xl )
#
#  Compute the following contributions:
#
#    L,L  L,R  L,Fx
#    R,L  R,R  R,Fx
#
      A[l][l] = A[l][l] + wq * ( philp * philp + phil * phil )
      A[l][r] = A[l][r] + wq * ( philp * phirp + phil * phir )
      rhs[l]  = rhs[l]  + wq *                   phil * rhs_fn ( xq )

      A[r][l] = A[r][l] + wq * ( phirp * philp + phir * phil )
      A[r][r] = A[r][r] + wq * ( phirp * phirp + phir * phir )
      rhs[r]  = rhs[r]  + wq *                   phir * rhs_fn ( xq )
#
#  Modify the linear system to enforce the left boundary condition.
#
  A[0,0] = 1.0
  A[0,1:n+1] = 0.0
  rhs[0] = 0.0
#
#  Modify the linear system to enforce the right boundary condition.
#
  A[n,n] = 1.0
  A[n,0:n] = 0.0
  rhs[n] = 0.0
#
#  Solve the linear system.
#
  u = la.solve ( A, rhs )
#
#  Evaluate the exact solution at the nodes.
#
  uex = np.zeros ( n + 1 )
  for i in range ( 0, n + 1 ):
    uex[i] = exact_fn ( x[i] )
#
#  Compare the solution and the error at the nodes.
#
  print ""
  print "  Node          Ucomp           Uexact          Error"
  print ""
  for i in range ( 0, n + 1 ):
    err = abs ( uex[i] - u[i] )
    print "  %4d  %14.6g  %14.6g  %14.6g" % ( i, u[i], uex[i], err )
#
#  Plot the computed solution and the exact solution.
#  Evaluate the exact solution at enough points that the curve will look smooth.
#
  npp = 51
  xp = np.linspace ( a, b, npp )
  up = np.zeros ( npp )
  for i in range ( 0, npp ):
    up[i] = exact_fn ( xp[i] )

  plt.plot ( x, u, 'bo-', xp, up, 'r.' )
  plt.show ( )
#
#  Terminate.
#
  print ""
  print "FEM1D_MODEL:"
  print "  Normal end of execution."
  print ""
  timestamp ( )
Пример #13
0
			continue
		elif hit.name[0:2] == 'RH':
			classifs.append(('Copia', hit.score + currentScore))
	classifs.append(('Copia', currentScore))

def clean():
	os.remove(orfFile)
	os.remove(hmmHitFile)
	os.remove(evidenceFile)

def log(string, logtype):
	if logtype == 'evidence' and 'evidenceFileHandle' in globals():
		evidenceFileHandle.write(string)
	if logtype == 'results' and 'resultsFileHandle' in globals():
		resultsFileHandle.write(string)

if __name__ == '__main__':
	#setup global & static variables
	timestamp = timestamp.timestamp()
	args = parseArgs()
	hmmProfilesForLTRs = '/share/jyllwgrp/nealedata/databases/ltr-Pfam.hmm'
	targetSeqs = '/share/jyllwgrp/nealedata/databases/pier-1.3.fa'
	orfFile = args.fasta + '.orfs'
	hmmHitFile = '{}-hmmer-output.txt'.format(args.job_name)
	evidenceFile = '{}-evidence.txt'.format(args.job_name)
	resultsFile = '{}-results.txt'.format(args.job_name)
	evidenceFileHandle = open(evidenceFile, 'w')
	resultsFileHandle = open(resultsFile, 'w')
	main()
	
Пример #14
0
"""

import terminal, display, piety, timestamp, session

# We haven't started display editor yet, window not initialized, 
#  so use ed commands
edsel = session.editor.edsel
ed = edsel.ed

# Add content to main buffer.
ed.do_command('i')
ed.do_command('This is the main buffer')
ed.do_command('.')

# create timestamp generators
ts1 = timestamp.timestamp('ts1')
ts2 = timestamp.timestamp('ts2')

# create buffers for timestamp messages
ed.do_command('b ts1')
ed.do_command('b ts2')

# aliases for timestamp buffers
ts1buf = ed.buffers['ts1']
ts2buf = ed.buffers['ts2']

# window update function - FIXME 
def update(buf):
    if session.session.foreground == session.eden and ed.buf == buf:
        terminal.set_line_mode()
        edsel.win.update(open_line=(not ed.command_mode)) # open line in insert mode
Пример #15
0
def fem1d():
    #
    ## FEM1D solves a 1D boundary value problem using finite elements.
    #
    #  Location:
    #
    #    http://people.sc.fsu.edu/~jburkardt/py_src/fem1d/fem1d.py
    #
    #  Discussion:
    #
    #    The PDE is defined for 0 < x < 1:
    #      -u'' = f
    #    with right hand side
    #      f(x) = -(exact(x)'')
    #    and boundary conditions
    #      u(0) = exact(0),
    #      u(1) = exact(1).
    #
    #    The exact solution is:
    #      exact(x) = x * ( 1 - x ) * exp ( x )
    #    The boundary conditions are
    #      u(0) = 0.0 = exact(0.0),
    #      u(1) = 0.0 = exact(1.0).
    #    The right hand side is:
    #      f(x) = x * ( x + 3 ) * exp ( x ) = - ( exact''(x) )
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    13 September 2014
    #
    #  Author:
    #
    #    John Burkardt
    #
    import matplotlib.pyplot as plt
    import numpy as np
    import scipy.linalg as la
    from timestamp import timestamp

    timestamp()
    print ""
    print "FEM1D"
    print "  Python version"
    print "  Given the two point boundary value problem:"
    print "    -u'' = x * ( x + 3 ) * exp ( x ), 0 < x < 1"
    print "  with boundary conditions"
    print "    u(0) = 0, u(1) = 0,"
    print "  demonstrate how the finite element method can be used to"
    print "  define and compute a discrete approximation to the solution."
    #
    #  Define the mesh, N+1 points between A and B.
    #  These will be X[0] through X[N].
    #
    a = 0.0
    b = 1.0
    n = 5
    x = np.linspace(a, b, n + 1)

    print ""
    print "  Nodes:"
    print ""
    for i in range(0, n + 1):
        print "  %d  %f" % (i, x[i])
#
#  Set a 3 point quadrature rule on the reference interval [0,1].
#
    ng = 3

    xg = np.array ( ( \
      0.112701665379258311482073460022, \
      0.5, \
      0.887298334620741688517926539978 ) )

    wg = np.array ( ( \
      5.0 / 18.0, \
      8.0 / 18.0, \
      5.0 / 18.0 ) )
    #
    #  Compute the system matrix A and right hand side RHS.
    #
    A = np.zeros((n + 1, n + 1))
    rhs = np.zeros(n + 1)
    #
    #  Look at element E: (0, 1, 2, ..., N-1).
    #
    for e in range(0, n):

        xl = x[e]
        xr = x[e + 1]
        #
        #  Consider quadrature point Q: (0, 1, 2 ) in element E.
        #
        for q in range(0, ng):
            #
            #  Map XG and WG from [0,1] to
            #      XQ and QQ in [XL,XR].
            #
            xq = xl + xg[q] * (xr - xl)
            wq = wg[q] * (xr - xl)
            #
            #  Consider the I-th test function PHI(I,X) and its derivative PHI'(I,X).
            #
            for i_local in range(0, 2):
                i = i_local + e

                if (i_local == 0):
                    phii = (xq - xr) / (xl - xr)
                    phiip = 1.0 / (xl - xr)
                else:
                    phii = (xq - xl) / (xr - xl)
                    phiip = 1.0 / (xr - xl)

                rhs[i] = rhs[i] + wq * phii * rhs_fn(xq)
                #
                #  Consider the J-th basis function PHI(J,X) and its derivative PHI'(J,X).
                #  (It turns out we don't need PHI for this particular problem, only PHI')
                #
                for j_local in range(0, 2):
                    j = j_local + e

                    if (j_local == 0):
                        phijp = 1.0 / (xl - xr)
                    else:
                        phijp = 1.0 / (xr - xl)

                    A[i][j] = A[i][j] + wq * phiip * phijp
#
#  Modify the linear system to enforce the left boundary condition.
#
    A[0, 0] = 1.0
    A[0, 1:n + 1] = 0.0
    rhs[0] = exact_fn(x[0])
    #
    #  Modify the linear system to enforce the right boundary condition.
    #
    A[n, n] = 1.0
    A[n, 0:n] = 0.0
    rhs[n] = exact_fn(x[n])
    #
    #  I wanted to check the matrix and right hand side so I printed them.
    #  I turned the printing off using "False" as the condition.
    #
    if False:
        print ""
        print "  Matrix and RHS:"
        print ""
        for i in range(0, n + 1):
            for j in range(0, n + 1):
                print "  %f" % (A[i, j]),
            print "  %f" % (rhs[i])
#
#  Solve the linear system.
#
    u = la.solve(A, rhs)
    #
    #  Evaluate the exact solution at the nodes.
    #
    uex = np.zeros(n + 1)
    for i in range(0, n + 1):
        uex[i] = exact_fn(x[i])
#
#  Compare the solution and the error at the nodes.
#
    print ""
    print "  Node          Ucomp           Uexact          Error"
    print ""
    for i in range(0, n + 1):
        err = abs(uex[i] - u[i])
        print "  %4d  %14.6g  %14.6g  %14.6g" % (i, u[i], uex[i], err)
#
#  Plot the computed solution and the exact solution.
#  Evaluate the exact solution at enough points that the curve will look smooth.
#
    npp = 51
    xp = np.linspace(a, b, npp)
    up = np.zeros(npp)
    for i in range(0, npp):
        up[i] = exact_fn(xp[i])

    plt.plot(x, u, 'bo-', xp, up, 'r.')
    plt.show()
    #
    #  Terminate.
    #
    print ""
    print "FEM1D:"
    print "  Normal end of execution."
    print ""
    timestamp()
Пример #16
0
# coding: utf-8

import sys
sys.path.append("../utils")
from timestamp import timestamp

print('test')
print(timestamp())
def add_title_using_gscholar(
    input_data_file_name,
    output_data_file_name,
    input_field_delimiter=',',
    output_field_delimiter=',',
    ):

    found_match_count = 0
    nofound_match_count = 0
    
    # create csv reader for input records
    timestamp.timestamp("Reading input records from '{0}'.".format(input_data_file_name))
    fr = open(input_data_file_name,'rb')
    input_data = csv.DictReader(fr, delimiter = input_field_delimiter)
    
    # fieldnames/keys of original input data (dictionary)
    original_data_fieldnames = input_data.fieldnames
    
    # find corresponding column position for specified header
    author_pos = fuzzymatch(original_data_fieldnames,'author')
    year_pos = fuzzymatch(original_data_fieldnames,'year')
    title_pos = fuzzymatch(original_data_fieldnames,'title')
    journal_pos = fuzzymatch(original_data_fieldnames,'journal')
    publisher_pos = fuzzymatch(original_data_fieldnames,'publisher')
    volume_pos = fuzzymatch(original_data_fieldnames,'volume')
    issue_pos = fuzzymatch(original_data_fieldnames,'issue')
    page_pos = fuzzymatch(original_data_fieldnames,'page')
    
    #count total data records
    record_num = 0
    
    for original_record in input_data:
        record_num += 1
        print
        timestamp.timestamp("Reading input record '{0:05d}'.".format(record_num))
        # exact values of fields to be validated
        original_record_title = original_record[title_pos.values()[0]]
        original_record_author = original_record[author_pos.values()[0]]
        original_record_year = original_record[year_pos.values()[0]]
        original_record_journal = original_record[journal_pos.values()[0]]
    
        if original_record_author == "[no agent data]":
            original_record_author = None
        if original_record_year == "0" or original_record_year == "":
            original_record_year = None
        if original_record_title == "no article title available":
            original_record_title = None
        if original_record_journal == "":
            original_record_journal = None
        
        output_record = original_record
        gscholar_match_result = None
        
        # try match search of the combination of author, publicaton year, title (if existing), and journal name.
        timestamp.timestamp("Trying Google Scholar match search for original record: '{0}'.".format(original_record)) 
        querier1 = scholar.ScholarQuerier()
        query1 = scholar.SearchScholarQuery()
        query1.set_num_page_results(1)
        query1.set_author(original_record_author)
        query1.set_pub(original_record_journal)
        query1.set_scope(original_record_title)
        if original_record_year is not None:          
            # extend the publisher year to an interval [original_record_year-10 original_record_year+10]
            query1.set_timeframe(str(int(original_record_year)-10),str(int(original_record_year)+10))
        else:
            query1.set_timeframe(None,None)
        settings1 = scholar.ScholarSettings()
        settings1.set_citation_format(scholar.ScholarSettings.CITFORM_BIBTEX)
        querier1.apply_settings(settings1)
        querier1.send_query(query1)        
        gscholar_record = scholar.citation_export(querier1) 
        if len(gscholar_record) < 1:
            timestamp.timestamp('Google Scholar match FAILED!')
            nofound_match_count += 1
        else:
            timestamp.timestamp('Google Scholar match was SUCESSFUL!')
            gscholar_match_result = True
            found_match_count += 1
            gscholar_record_str = gscholar_record[0]
            if gscholar_record_str.find('@') > -1:
                at_type = gscholar_record_str.find('@')
                sp_type = gscholar_record_str.find('{',at_type)
                new_type = gscholar_record_str[at_type+1 : sp_type]
                output_record['type'] = new_type
            if gscholar_record_str.find('title={') > -1:      
                at_title = gscholar_record_str.find('title={')
                sp_title = gscholar_record_str.find('}',at_title)
                new_title = gscholar_record_str[at_title+7 : sp_title]
                output_record['title'] = new_title 
            if gscholar_record_str.find('author={') > -1:
                at_author = gscholar_record_str.find('author={')
                sp_author = gscholar_record_str.find('}',at_author)
                new_author = gscholar_record_str[at_author+8 : sp_author]
                output_record['author'] = new_author
            if gscholar_record_str.find('journal={') > -1:
                at_journal = gscholar_record_str.find('journal={')
                sp_journal = gscholar_record_str.find('}',at_journal)
                new_journal = gscholar_record_str[at_journal+9 : sp_journal]
                output_record['journal'] = new_journal      
            if gscholar_record_str.find('volume={') > -1:
                at_volume = gscholar_record_str.find('volume={')
                sp_volume = gscholar_record_str.find('}',at_volume)
                new_volume = gscholar_record_str[at_volume+8 : sp_volume]
                output_record['volume'] = new_volume 
            if gscholar_record_str.find('pages={') > -1:
                at_pages = gscholar_record_str.find('pages={')
                sp_pages = gscholar_record_str.find('}',at_pages)
                new_pages = gscholar_record_str[at_pages+7 : sp_pages]
                output_record['pages'] = new_pages 
            if gscholar_record_str.find('year={') > -1:
                at_year = gscholar_record_str.find('year={')
                sp_year = gscholar_record_str.find('}',at_year)
                new_year = gscholar_record_str[at_year+6 : sp_year]
                output_record['year'] = new_year
            if gscholar_record_str.find('publisher={') > -1:
                at_publisher = gscholar_record_str.find('publisher={')
                sp_publisher = gscholar_record_str.find('}',at_publisher)
                new_publisher = gscholar_record_str[at_publisher+11 : sp_publisher]
                output_record['publisher'] = new_publisher               
    
        # open file for storing output data if not already open
        if 'output_data' not in locals():
            extra_fieldnames = ['type','title','author','journal','volume','pages','year','publisher']
            output_data_fieldnames = input_data.fieldnames + extra_fieldnames
            fw = open(output_data_file_name,'w')
            output_data = csv.DictWriter(fw,output_data_fieldnames,
                                        delimiter = output_field_delimiter)
            output_data.writeheader()
        output_data.writerow(output_record)
        
    print
    timestamp.timestamp("Summary: {0} matches found and {1} matches not found to '{2}'.".format(found_match_count, nofound_match_count, output_data_file_name))

    fr.close()
    fw.close()                                        
def fem1d_bvp_quadratic ( ):
#
## FEM1D_BVP_QUADRATIC solves a two point boundary value problem.
#
#  Location:
#
#    http://people.sc.fsu.edu/~jburkardt/py_src/fem1d_bvp_quadratic/fem1d_bvp_quadratic.html
#
#  Discussion:
#
#    The finite element method is used, with piecewise quadratic elements.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    17 September 2014
#
#  Author:
#
#    John Burkardt
#
  import matplotlib.pyplot as plt
  import numpy as np
  import scipy.linalg as la
  from timestamp import timestamp

  timestamp ( )
  print ""
  print "FEM1D_BVP_QUADRATIC"
  print "  Python version"
  print "  Given the two point boundary value problem:"
  print "    -u'' = x * ( x + 3 ) * exp ( x ), 0 < x < 1"
  print "  with boundary conditions"
  print "    u(0) = 0, u(1) = 0,"
  print "  demonstrate how the finite element method can be used to"
  print "  define and compute a discrete approximation to the solution."
  print "  This program uses piecewise quadratic elements."
#
#  Define the interval.
#
  a = 0.0
  b = 1.0
#
#  Define the mesh, N_NUM evenly spaced points between A and B.
#  Because we are using quadratic elements, we need N_NUM to be odd!
#
  n_num = 11
  x = np.linspace ( a, b, n_num )

  print ""
  print "  Nodes:"
  print ""
  for i in range ( 0, n_num ):
    print "  %d  %f" %( i, x[i] )
#
#  Set the number of elements.
#
#  Using quadratic elements, the relationship between number of nodes
#  and number of elements is more complicated.
#
#  0  1  2  3  4  5  6  7  8  8 10  0-based node indices
#  1  2  3  4  5  6  7  8  9 10 11  1-based node indices
#  N--n--N--n--N--n--N--n--N--n--N  11 nodes
#  *-----*-----*-----*-----*-----*   5 elements
#     1     2     3     4     5      1-based node indices
#     0     1     2     3     4      0-based node indices
#
  e_num = ( n_num - 1 ) / 2
#
#  Set a 3 point quadrature rule on the reference interval [-1,1].
#
  q_num = 3

  xg = np.array ( ( \
    -0.774596669241483377035853079956, \
     0.0, \
     0.774596669241483377035853079956 ) )

  wg = np.array ( ( \
    5.0 / 9.0, \
    8.0 / 9.0, \
    5.0 / 9.0 ) )
#
#  Compute the system matrix A and right hand side RHS.
#
  A = np.zeros ( ( n_num, n_num ) )
  rhs = np.zeros ( n_num )
#
#  Look at element E: (0, 1, 2, ..., E_NUM-1).
#
  for e in range ( 0, e_num ):

    l = 2 * e
    m = 2 * e + 1
    r = 2 * e + 2

    xl = x[l]
    xm = x[m]
    xr = x[r]
#
#  Consider quadrature point Q: (0, 1, 2 ) in element E.
#
    for q in range ( 0, q_num ):
#
#  Map XG and WG from [-1,1] to
#      XQ and WQ in [XL,XM,XR].
#
      xq = xl + ( xg[q] + 1.0 ) * ( xr - xl ) / 2.0
      wq = wg[q] * ( xr - xl ) / 2.0
#
#  Evaluate PHI(L), PHI(M) and PHI(R), and their derivatives at XQ.
#
#  It must be true that PHI(L) is 1 at XL and 0 at XM and XR,
#  with similar requirements for PHI(M) and PHI(R).
#
      phil =    ( xq - xm ) * ( xq - xr )   / \
              ( ( xl - xm ) * ( xl - xr ) )
      philp = ( ( xq - xr ) + ( xq - xm ) ) / \
              ( ( xl - xm ) * ( xl - xr ) )

      phim =    ( xq - xl ) * ( xq - xr )   / \
              ( ( xm - xl ) * ( xm - xr ) )
      phimp = ( ( xq - xr ) + ( xq - xl ) ) / \
              ( ( xm - xl ) * ( xm - xr ) )

      phir =    ( xq - xl ) * ( xq - xm )   / \
              ( ( xr - xl ) * ( xr - xm ) )
      phirp = ( ( xq - xm ) + ( xq - xl ) ) / \
              ( ( xr - xl ) * ( xr - xm ) )

      fxq = rhs_fn ( xq )
#
#  Add the terms from this element to the matrix.
#
      A[l][l] = A[l][l] + wq * philp * philp
      A[l][m] = A[l][m] + wq * philp * phimp
      A[l][r] = A[l][r] + wq * philp * phirp
      rhs[l]  = rhs[l]  + wq * phil  * fxq

      A[m][l] = A[m][l] + wq * phimp * philp
      A[m][m] = A[m][m] + wq * phimp * phimp
      A[m][r] = A[m][r] + wq * phimp * phirp
      rhs[m]  = rhs[m]  + wq * phim  * fxq

      A[r][l] = A[r][l] + wq * phirp * philp
      A[r][m] = A[r][m] + wq * phirp * phimp
      A[r][r] = A[r][r] + wq * phirp * phirp
      rhs[r]  = rhs[r]  + wq * phir  * fxq
#
#  Modify the linear system to enforce the left boundary condition.
#
  A[0,0] = 1.0
  A[0,1:n_num-1] = 0.0
  rhs[0] = exact_fn ( x[0] )
#
#  Modify the linear system to enforce the right boundary condition.
#
  A[n_num-1,n_num-1] = 1.0
  A[n_num-1,0:n_num-1] = 0.0
  rhs[n_num-1] = exact_fn ( x[n_num-1] )

  r8vec_print ( n_num, rhs, '  RHS' )
#
#  Solve the linear system.
#
  u = la.solve ( A, rhs )
#
#  Evaluate the exact solution at the nodes.
#
  uex = np.zeros ( n_num )
  for i in range ( 0, n_num ):
    uex[i] = exact_fn ( x[i] )
#
#  Compare the solution and the error at the nodes.
#
  print ""
  print "  Node          Ucomp           Uexact          Error"
  print ""
  for i in range ( 0, n_num ):
    err = abs ( uex[i] - u[i] )
    print "  %4d  %14.6g  %14.6g  %14.6g" % ( i, u[i], uex[i], err )
#
#  Plot the computed solution and the exact solution.
#  Evaluate the exact solution at enough points that the curve will look smooth.
#
  npp = 51
  xp = np.linspace ( a, b, npp )
  up = np.zeros ( npp )
  for i in range ( 0, npp ):
    up[i] = exact_fn ( xp[i] )

  plt.plot ( x, u, 'bo-', xp, up, 'r.' )
  plt.show ( )
#
#  Terminate.
#
  print ""
  print "FEM1D_BVP_QUADRATIC:"
  print "  Normal end of execution."
  print ""
  timestamp ( )
Пример #19
0
def wathen_test():

    #*****************************************************************************80
    #
    ## WATHEN_TEST tests the WATHEN library.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    31 August 2014
    #
    #  Author:
    #
    #    John Burkardt
    #
    from timestamp import timestamp
    from wathen_test01 import wathen_test01
    from wathen_test02 import wathen_test02
    from wathen_test03 import wathen_test03
    from wathen_test04 import wathen_test04
    from wathen_test05 import wathen_test05
    from wathen_test06 import wathen_test06
    from wathen_test07 import wathen_test07
    from wathen_test08 import wathen_test08
    from wathen_test09 import wathen_test09

    timestamp()
    print ''
    print 'WATHEN_TEST'
    print '  Python version:'
    print '  Test the WATHEN library.'
    #
    #  Direct Solve
    #
    wathen_test01()
    wathen_test02()
    #
    #  Timings.
    #
    wathen_test03()
    wathen_test04()
    wathen_test05()
    #
    #  CG Solve
    #
    wathen_test06()
    wathen_test07()
    wathen_test08()
    #
    #  Use SPY to display the sparsity of the matrix.
    #
    wathen_test09()
    #
    #  Terminate.
    #
    print ''
    print 'WATHEN_TEST:'
    print '  Normal end of execution.'
    print ''
    timestamp()

    return
    return {
        'name': '%s %s' % (first, last),
        'username': '******' % (first[0], last)
    }


def random_tweet():
    return random.choice([
        "I'm sick of %s, %s, moving to %s, %s!",
        "Leaving %s, %s behind. %s, %s is what I'll call home.",
        "Goodbye %s, %s, hello %s, %s."
    ])


tweets = []
now = int(round(timestamp.timestamp() * 1000))

with open('world_cities.json', 'r') as f:
    cities = json.loads(f.read())

with open('names.json', 'r') as f:
    names = json.loads(f.read())

for n in range(TWEET_COUNT):
    user = random_name(names)
    source = random_city(cities)
    destination = random_city(cities)
    message = random_tweet() % (source['city'], source['country'],
                                destination['city'], destination['country'])

    tweets.append({
#    John Burkardt
#
  print ''
  print 'TRIANGLE01_MONOMIAL_INTEGRAL_TEST'
  print '  TRIANGLE01_MONOMIAL_INTEGRAL returns the integral Q of'
  print '  a monomial X^I Y^J over the interior of the unit triangle.'

  print ''
  print '   I   J         Q(I,J)'

  for d in range ( 0, 6 ):
    print ''
    for i in range ( 0, d + 1 ):
      j = d - i
      q = triangle01_monomial_integral ( i, j )
      print '  %2d  %2d  %14.6g' % ( i, j, q )
#
#  Terminate.
#
  print ''
  print 'TRIANGLE01_MONOMIAL_INTEGRAL_TEST'
  print '  Normal end of execution.'

  return

if ( __name__ == '__main__' ):
  from timestamp import timestamp
  timestamp ( )
  triangle01_monomial_integral_test ( )
  timestamp ( )
Пример #22
0
    #print(str(skip_n) + " mongodb read " + ts.timestamp())

    reviews = pd.DataFrame()
    for doc in cursor:
        tmp = pd.DataFrame(data=[[doc['cId'], doc['desc']]],
                           columns=['cId', 'desc'])
        reviews = reviews.append(tmp, ignore_index=True)
        #print "cId: " + doc['cId'] + " desc: " + doc['desc']

    ma.analysis(reviews)

    print('Completed num: {0}, process: {1}'.format(skip_n, proc))


if __name__ == '__main__':
    print("start " + ts.timestamp())

    #connect to mongodb for creating cIds_list
    collection = cm.connect()

    #sorting by cIds except naverpay, count1
    pipeline = [{
        '$group': {
            '_id': '$cId',
            'count': {
                '$sum': 1
            }
        }
    }, {
        '$sort': {
            'count': -1