Exemplo n.º 1
0
def test_fourier_coeffs(xs: Vector, Es: Vector) -> None:
    assert isclose(
        simps(
            convolution_v(np_sin(2 * xs), 10 * np_cos(xs) + np_sin(1 * xs)),
            xs,
        ),
        0.0,
        atol=1E-5,
    )
    A0 = a0(xs, np_cos(xs))
    print(bn(xs, np_cos(xs), 1, A0))
    print(bn(xs, np_cos(xs), 2, A0))
Exemplo n.º 2
0
 def createColorMapHSV(self):
     S = 1.0
     V = 1.0
     return LinearSegmentedColormap.from_list('GC', [
         htr((1.0 + np_sin(np_pi * (val / 1000.0) - np_pi / 2)) / 2., S, V)
         for val in xrange(0, 1000)
     ],
                                              N=1000)
Exemplo n.º 3
0
    def transformCP(self, silent=False, nolog=False, min=None, max=None):
        """Do the main ransformation on the coverage profile data"""
        shrinkFn = np_log10
        if(nolog):
            shrinkFn = lambda x:x
         
        s = (self.numContigs,3)
        self.transformedCP = np_zeros(s)

        if(not silent):
            print "    Dimensionality reduction"

        # get the median distance from the origin
        unit_vectors = [(np_cos(i*2*np_pi/self.numStoits),np_sin(i*2*np_pi/self.numStoits)) for i in range(self.numStoits)]
        for i in range(len(self.indices)):
            norm = np_norm(self.covProfiles[i])
            if(norm != 0):
                radial = shrinkFn(norm)
            else:
                radial = norm
            shifted_vector = np_array([0.0,0.0])
            flat_vector = (self.covProfiles[i] / sum(self.covProfiles[i]))
            
            for j in range(self.numStoits):
                shifted_vector[0] += unit_vectors[j][0] * flat_vector[j]
                shifted_vector[1] += unit_vectors[j][1] * flat_vector[j]

            # log scale it towards the centre
            scaling_vector = shifted_vector * self.scaleFactor
            sv_size = np_norm(scaling_vector)
            if(sv_size > 1):
                shifted_vector /= shrinkFn(sv_size)

            self.transformedCP[i,0] = shifted_vector[0]
            self.transformedCP[i,1] = shifted_vector[1]
            self.transformedCP[i,2] = radial

        if(not silent):
            print "    Reticulating splines"
            
        # finally scale the matrix to make it equal in all dimensions
        if(min is None):                
            min = np_amin(self.transformedCP, axis=0)
            max = np_amax(self.transformedCP, axis=0)
            max = max - min
            max = max / (self.scaleFactor-1)

        for i in range(0,3):
            self.transformedCP[:,i] = (self.transformedCP[:,i] -  min[i])/max[i]

        return(min,max)
Exemplo n.º 4
0
def _convert_local_operator_to_qutip(expr, full_space, mapping):
    """Convert a LocalOperator instance to qutip."""
    n = full_space.dimension
    if full_space != expr.space:
        all_spaces = full_space.local_factors
        own_space_index = all_spaces.index(expr.space)
        return qutip.tensor(
            *([qutip.qeye(s.dimension) for s in all_spaces[:own_space_index]] +
              [convert_to_qutip(expr, expr.space, mapping=mapping)] + [
                  qutip.qeye(s.dimension)
                  for s in all_spaces[own_space_index + 1:]
              ]))
    if isinstance(expr, Create):
        return qutip.create(n)
    elif isinstance(expr, Jz):
        return qutip.jmat((expr.space.dimension - 1) / 2.0, "z")
    elif isinstance(expr, Jplus):
        return qutip.jmat((expr.space.dimension - 1) / 2.0, "+")
    elif isinstance(expr, Jminus):
        return qutip.jmat((expr.space.dimension - 1) / 2.0, "-")
    elif isinstance(expr, Destroy):
        return qutip.destroy(n)
    elif isinstance(expr, Phase):
        arg = complex(expr.operands[1]) * arange(n)
        d = np_cos(arg) + 1j * np_sin(arg)
        return qutip.Qobj(np_diag(d))
    elif isinstance(expr, Displace):
        alpha = expr.operands[1]
        return qutip.displace(n, alpha)
    elif isinstance(expr, Squeeze):
        eta = expr.operands[1]
        return qutip.displace(n, eta)
    elif isinstance(expr, LocalSigma):
        j = expr.j
        k = expr.k
        if isinstance(j, str):
            j = expr.space.basis_labels.index(j)
        if isinstance(k, str):
            k = expr.space.basis_labels.index(k)
        ket = qutip.basis(n, j)
        bra = qutip.basis(n, k).dag()
        return ket * bra
    else:
        raise ValueError("Cannot convert '%s' of type %s" %
                         (str(expr), type(expr)))
Exemplo n.º 5
0
def tmax_pseudo_ellipse_array(phi, theta_x, theta_y):
    """The pseudo-ellipse tilt-torsion polar angle for numpy arrays.

    @param phi:     The azimuthal tilt-torsion angle.
    @type phi:      numpy rank-1 float64 array
    @param theta_x: The cone opening angle along x.
    @type theta_x:  float
    @param theta_y: The cone opening angle along y.
    @type theta_y:  float
    @return:        The array theta max angles for the given phi angle array.
    @rtype:         numpy rank-1 float64 array
    """

    # Zero points.
    if theta_x == 0.0:
        return 0.0 * phi
    elif theta_y == 0.0:
        return 0.0 * phi

    # Return the maximum angle.
    return theta_x * theta_y / np_sqrt((np_cos(phi)*theta_y)**2 + (np_sin(phi)*theta_x)**2)
Exemplo n.º 6
0
def tmax_pseudo_ellipse_array(phi, theta_x, theta_y):
    """The pseudo-ellipse tilt-torsion polar angle for numpy arrays.

    @param phi:     The azimuthal tilt-torsion angle.
    @type phi:      numpy rank-1 float64 array
    @param theta_x: The cone opening angle along x.
    @type theta_x:  float
    @param theta_y: The cone opening angle along y.
    @type theta_y:  float
    @return:        The array theta max angles for the given phi angle array.
    @rtype:         numpy rank-1 float64 array
    """

    # Zero points.
    if theta_x == 0.0:
        return 0.0 * phi
    elif theta_y == 0.0:
        return 0.0 * phi

    # Return the maximum angle.
    return theta_x * theta_y / np_sqrt((np_cos(phi) * theta_y)**2 +
                                       (np_sin(phi) * theta_x)**2)
Exemplo n.º 7
0
 def createColorMapHSV(self):
   S = 1.0
   V = 1.0
   return LinearSegmentedColormap.from_list('GC', [htr((1.0 + np_sin(np_pi * (val/1000.0) - np_pi/2))/2., S, V) for val in xrange(0, 1000)], N=1000)