def generate_anstar_3d_lattice(maxv1, minv1, maxv2, minv2, maxv3, minv3, mindist):
    import lal

    tiling = lal.CreateFlatLatticeTiling(3)
    lal.SetFlatLatticeConstantBound(tiling, 0, minv1, maxv1)
    lal.SetFlatLatticeConstantBound(tiling, 1, minv2, maxv2)
    lal.SetFlatLatticeConstantBound(tiling, 2, minv3, maxv3)
    lal.SetFlatLatticeGenerator(tiling, lal.AnstarLatticeGeneratorPtr)
    # Make a 3x3 Euclidean lattice
    a = lal.gsl_matrix(3, 3)
    a.data[0, 0] = 1
    a.data[1, 1] = 1
    a.data[2, 2] = 1
    lal.SetFlatLatticeMetric(tiling, a, mindist)

    vs1 = []
    vs2 = []
    vs3 = []
    count = 0
    while lal.NextFlatLatticePoint(tiling) >= 0:
        count += 1
        if not (count % 100000):
            print "Now %d points" % (count)
        p = lal.GetFlatLatticePoint(tiling)
        vs1.append(p.data[0])
        vs2.append(p.data[1])
        vs3.append(p.data[2])
    return vs1, vs2, vs3
Esempio n. 2
0
assert(lal.swig_lal_test_viewin_gsl_matrix_float(mfout, mf))
assert((mfout.data == mf.data).all())
mfout.data = numpy.zeros(numpy.shape(mfdat), dtype=mfdat.dtype)
assert(lal.swig_lal_test_viewin_gsl_matrix_float(mfout, mfdat))
assert((mfout.data == mfdat).all())
mfout.data = numpy.zeros(numpy.shape(mfdat), dtype=mfdat.dtype)
assert(lal.swig_lal_test_viewinout_gsl_matrix_float(mfout, mf))
assert((2 * mfout.data == mf.data).all())
mfout.data = numpy.zeros(numpy.shape(mfdat), dtype=mfdat.dtype)
assert(lal.swig_lal_test_viewinout_gsl_matrix_float(mfout, mfdat))
assert((2 * mfout.data == mfdat).all())
del mf
del mfout
del mfdat
lal.CheckMemoryLeaks()
md = lal.gsl_matrix(mddat.shape[0], mddat.shape[1])
md.data = mddat
mdout = lal.gsl_matrix(mddat.shape[0], mddat.shape[1])
mdout.data = numpy.zeros(numpy.shape(mddat), dtype=mddat.dtype)
assert(lal.swig_lal_test_viewin_gsl_matrix(mdout, md))
assert((mdout.data == md.data).all())
mdout.data = numpy.zeros(numpy.shape(mddat), dtype=mddat.dtype)
assert(lal.swig_lal_test_viewin_gsl_matrix(mdout, mddat))
assert((mdout.data == mddat).all())
mdout.data = numpy.zeros(numpy.shape(mddat), dtype=mddat.dtype)
assert(lal.swig_lal_test_viewinout_gsl_matrix(mdout, md))
assert((2 * mdout.data == md.data).all())
mdout.data = numpy.zeros(numpy.shape(mddat), dtype=mddat.dtype)
assert(lal.swig_lal_test_viewinout_gsl_matrix(mdout, mddat))
assert((2 * mdout.data == mddat).all())
del md
Esempio n. 3
0
def _convert_array_to_gsl_matrix(array):
    gsl_matrix = lal.gsl_matrix(*array.shape)
    gsl_matrix.data = array
    return gsl_matrix
Esempio n. 4
0
def generate_anstar_3d_lattice(maxv1, minv1, maxv2, minv2, maxv3, minv3, \
                               mindist):
    """
    This function calls into LAL routines to generate a 3-dimensional array
    of points using the An^* lattice.

    Parameters
    -----------
    maxv1 : float
        Largest value in the 1st dimension to cover
    minv1 : float
        Smallest value in the 1st dimension to cover
    maxv2 : float
        Largest value in the 2nd dimension to cover
    minv2 : float
        Smallest value in the 2nd dimension to cover
    maxv3 : float
        Largest value in the 3rd dimension to cover
    minv3 : float
        Smallest value in the 3rd dimension to cover
    mindist : float
        Maximum allowed mismatch between a point in the parameter space and the
        generated bank of points.

    Returns
    --------
    v1s : numpy.array
        Array of positions in the first dimension
    v2s : numpy.array
        Array of positions in the second dimension
    v3s : numpy.array
        Array of positions in the second dimension
    """
    # Lalpulsar not a requirement for the rest of pycbc, so check if we have it
    # here in this function.
    try:
        import lalpulsar
    except:
        raise ImportError("A SWIG-wrapped install of lalpulsar is needed to use the anstar tiling functionality.")

    tiling = lalpulsar.CreateLatticeTiling(3)
    lalpulsar.SetLatticeConstantBound(tiling, 0, minv1, maxv1)
    lalpulsar.SetLatticeConstantBound(tiling, 1, minv2, maxv2)
    lalpulsar.SetLatticeConstantBound(tiling, 2, minv3, maxv3)
    # Make a 3x3 Euclidean lattice
    a = lal.gsl_matrix(3,3)
    a.data[0,0] = 1
    a.data[1,1] = 1
    a.data[2,2] = 1
    lalpulsar.SetLatticeTypeAndMetric(tiling, lalpulsar.LATTICE_TYPE_ANSTAR,
                                      a, mindist)

    vs1 = []
    vs2 = []
    vs3 = []
    count = 0
    curr_point = lal.gsl_vector(3)
    while (lalpulsar.NextLatticePoint(tiling, curr_point) >= 0):
        vs1.append(curr_point.data[0])
        vs2.append(curr_point.data[1])
        vs3.append(curr_point.data[2])
    return vs1, vs2, vs3
Esempio n. 5
0
def generate_anstar_3d_lattice(maxv1, minv1, maxv2, minv2, maxv3, minv3, mindist):
    """
    This function calls into LAL routines to generate a 3-dimensional array
    of points using the An^* lattice.

    Parameters
    -----------
    maxv1 : float
        Largest value in the 1st dimension to cover
    minv1 : float
        Smallest value in the 1st dimension to cover
    maxv2 : float
        Largest value in the 2nd dimension to cover
    minv2 : float
        Smallest value in the 2nd dimension to cover
    maxv3 : float
        Largest value in the 3rd dimension to cover
    minv3 : float
        Smallest value in the 3rd dimension to cover
    mindist : float
        Maximum allowed mismatch between a point in the parameter space and the
        generated bank of points.

    Returns
    --------
    v1s : numpy.array
        Array of positions in the first dimension
    v2s : numpy.array
        Array of positions in the second dimension
    v3s : numpy.array
        Array of positions in the second dimension
    """
    # Lalpulsar not a requirement for the rest of pycbc, so check if we have it
    # here in this function.
    try:
        import lalpulsar
    except:
        raise ImportError("A SWIG-wrapped install of lalpulsar is needed to use the anstar tiling functionality.")

    tiling = lalpulsar.CreateLatticeTiling(3)
    lalpulsar.SetLatticeTilingConstantBound(tiling, 0, minv1, maxv1)
    lalpulsar.SetLatticeTilingConstantBound(tiling, 1, minv2, maxv2)
    lalpulsar.SetLatticeTilingConstantBound(tiling, 2, minv3, maxv3)
    # Make a 3x3 Euclidean lattice
    a = lal.gsl_matrix(3, 3)
    a.data[0, 0] = 1
    a.data[1, 1] = 1
    a.data[2, 2] = 1
    try:
        # old versions of lalpulsar used an enumeration
        lattice = lalpulsar.TILING_LATTICE_ANSTAR
    except AttributeError:
        # newer versions of lalpulsar use a string
        lattice = "An-star"
    lalpulsar.SetTilingLatticeAndMetric(tiling, lattice, a, mindist)
    try:
        iterator = lalpulsar.CreateLatticeTilingIterator(tiling, 3)
    except TypeError:
        # old versions of lalpulsar required the flags argument
        # (set to 0 for defaults)
        iterator = lalpulsar.CreateLatticeTilingIterator(tiling, 3, 0)

    vs1 = []
    vs2 = []
    vs3 = []
    count = 0
    curr_point = lal.gsl_vector(3)
    while lalpulsar.NextLatticeTilingPoint(iterator, curr_point) > 0:
        vs1.append(curr_point.data[0])
        vs2.append(curr_point.data[1])
        vs3.append(curr_point.data[2])
    return vs1, vs2, vs3