Ejemplo n.º 1
0
def test_xy2ang(facenum, x, y, ra, dec):
    '''
	Test QLSC xy2facenum. This is independent of bin size.
	'''
    q = QLSC(depth=1)  # the bin level doesn't matter
    ra_out, dec_out = q.xy2ang(facenum=facenum, x=x, y=y)
    assert_approx_equal(ra, ra_out)
    assert_approx_equal(dec, dec_out)
Ejemplo n.º 2
0
def test_ipix2ang_center(depth, ipix, ra, dec):
    '''
	Test QLSC ipixcenter2ang.
	'''
    q = QLSC(depth=depth)  # use default nside value
    ra_out, dec_out = q.ipix2ang_center(ipix)

    assert_approx_equal(ra, ra_out)
    assert_approx_equal(dec, dec_out)
Ejemplo n.º 3
0
def test_ang2ipix_points_with_dec_out_of_range():
	'''
	Test ang2ipix from array with dec values out of range.
	'''
	points = np.array([[0, 102], [35, -132], [32, 99]], dtype=np.double)

	q = QLSC(depth=30)
	
	ipix = q.ang2ipix(points=points)
	
	assert (ipix == np.array([ 876126745706244234, 5824629191300107707,  680379582899038849], dtype=np.int64)).all(), "use of points array with dec out of range failed"
Ejemplo n.º 4
0
def test_ang2ipix_points():
	'''
	Test ang2ipix from array.
	'''
	points = np.array([[0, 12], [35, 32], [32, -32]], dtype=np.double)

	q = QLSC(depth=30)
	
	ipix = q.ang2ipix(points=points)
	
	assert (ipix == np.array([2029048250313091210, 2275510515682463237, 1550784043278934694], dtype=np.int64)).all(), "use of points array failed"
Ejemplo n.º 5
0
def test_ang2ipix_dec_above_range():
	'''
	Test that out of range dec values (> 90) are caught.
	'''
	# The underlying Q3C code will truncate dec values outside of [-90,90].
	# Make sure that we check for this before calling the function.
	ra = 56.0
	dec = 255.0
	
	q = QLSC(depth=30)
	
	truncated_dec_ipix = q.ang2ipix(56.0, 90) # 864691128455135232
	correct_ipix = 6037741812941379589
	
	assert q.ang2ipix(ra,dec) == correct_ipix, "QLSC.ang2ipix is allowing out of range dec values (> 90) to be truncated."
Ejemplo n.º 6
0
def test_ang2ipix_dec_below_range():
	'''
	Test that out of range dec values (< -90) are caught.
	'''
	# The underlying Q3C code will truncate dec values outside of [-90,90].
	# Make sure that we check for this before calling the function.
	ra = 56.0
	dec = -135
	
	q = QLSC(depth=30)
	
	truncated_dec_ipix = q.ang2ipix(56.0, -90) # 6629298651489370112
	correct_ipix = 5816706551187910542
	
	assert q.ang2ipix(ra,dec) == correct_ipix, "QLSC.ang2ipix is allowing out of range dec values (< -90) to be truncated."
Ejemplo n.º 7
0
def test_radial_query():
    '''
	Test a radial query.
	'''

    q30 = QLSC(depth=30)
    idx = QLSCIndex(qlsc=q30)

    sample_points = sunflower_points_on_sphere(n=5e5)

    idx.add_points(points=sample_points)

    matches = idx.radial_query(ra=12, dec=-33, radius=2000 / 3600)

    expected_matches = np.array([[11.9470522717, -32.8642186861],
                                 [12.0478643726, -33.301040754],
                                 [12.2109817407, -33.0308141307],
                                 [11.5200054079, -32.9671430623],
                                 [12.4749112364, -33.1977251167],
                                 [12.1101696666, -32.5953220055],
                                 [11.7839348769, -33.1339331435],
                                 [11.6831228027, -32.6979355995],
                                 [12.6380286046, -32.9278156427],
                                 [11.6208174821, -33.4044789167],
                                 [12.3117938416, -33.4684691438],
                                 [12.3740991356, -32.7614136187]])

    assert_allclose(matches,
                    expected_matches,
                    err_msg="expected matches not found")
Ejemplo n.º 8
0
def test_add_points_with_single_array():
    '''
	Test QLSC.add_point using position parameters.
	'''
    q30 = QLSC(depth=30)
    idx = QLSCIndex(qlsc=q30)

    sample_points = sunflower_points_on_sphere(n=100)

    idx.add_points(points=sample_points)

    assert idx.number_of_points == 100, "points don't appear to be in the database"
Ejemplo n.º 9
0
def test_add_points_radec_keyword_parameter():
    '''
	Test QLSC.add_points using ra,dec and keyword parameters.
	'''
    q30 = QLSC(depth=30)
    idx = QLSCIndex(qlsc=q30)

    sample_points = sunflower_points_on_sphere(n=100)

    ra = sample_points[:, 0]
    dec = sample_points[:, 1]

    idx.add_points(ra=ra, dec=dec)

    assert idx.number_of_points == 100, "points don't appear to be in the database"
Ejemplo n.º 10
0
def test_add_point_keyword_parameter():
	'''
	Test QLSC.add_point using keyword parameters.
	'''
	q30 = QLSC(depth=30)
	idx = QLSCIndex(qlsc=q30)
	
	ra = 12
	dec = 34
	
	idx.add_point(ra=ra, dec=dec)
	
	# make sure point is there
	matches = idx.radial_query(ra=ra, dec=dec, radius=10/3600)
	
	assert np.any(matches == [ra,dec])
Ejemplo n.º 11
0
def test_add_points_duplicate_points_ignored():
    '''
	Test that duplicate ra,dec pairs are ignored.
	'''

    q30 = QLSC(depth=30)
    idx = QLSCIndex(qlsc=q30)

    sample_points = sunflower_points_on_sphere(n=100)

    idx.add_points(points=sample_points)
    idx.add_points(points=sample_points)
    idx.add_points(points=sample_points)
    idx.add_points(points=sample_points)
    idx.add_points(points=sample_points)

    assert idx.number_of_points == 100, "duplicate points are being incorrectly added"
Ejemplo n.º 12
0
def test_add_point_duplicate_points_ignored():
	'''
	Test that duplicate ra,dec pairs are ignored.
	'''
	
	q30 = QLSC(depth=30)
	idx = QLSCIndex(qlsc=q30)
	
	ra = 12
	dec = 34
	key = "my key"
	
	idx.add_point(ra,dec,key)
	idx.add_point(ra,dec,key)
	idx.add_point(ra,dec,key)
	idx.add_point(ra,dec,key)
	idx.add_point(ra,dec,key)

	assert idx.number_of_points == 1, "duplicate points are being incorrectly added"
Ejemplo n.º 13
0
def test_add_point_retrieve_key():
	'''
	Test that a key added with a point is returned.
	'''
	q30 = QLSC(depth=30)
	idx = QLSCIndex(qlsc=q30)
	
	ra = 12
	dec = 34
	key = "my key"
	
	idx.add_point(ra,dec,key)
	
	# make sure point is there
	matches = idx.radial_query(ra=ra, dec=dec, radius=10/3600, return_key=True)
	
	# find record, note that keys are not required to be unique
	record =  matches[matches['key'] == key][0] # returns a recarray, get the tuple with [0]
	
	assert record[2] == key, "a provided coordinate key was not correctly retrieved"
Ejemplo n.º 14
0
def test_ipix2polygon(depth, ipix, polygon):
    '''
	Test QLSC ipix2polygon.
	'''
    q = QLSC(depth=depth)
    assert_allclose(polygon, q.ipix2polygon(ipix))
Ejemplo n.º 15
0
def test_pixarea(ipix, depth, area):
    '''
	Test QLSC pixarea.
	'''
    q = QLSC()
    assert_approx_equal(area, q.pixarea(ipix, depth))
Ejemplo n.º 16
0
#!/usr/local/env python
'''
This script demonstrates how the QLSCIndex class can be used.

In this example, coordinates are stored in an in-memory SQLite database
which is not persisted to disk; it will be deleted when the script exits.
'''

from qlsc import QLSC, QLSCIndex
import numpy as np

input_file = "1e5_wise.txt"

# create a sphere with 6,144 bins (6 * 2**(2*depth))
qlsc = QLSC(depth=5)

# create an index:
# by default, an in memory SQLite database is used
qlsc_index = QLSCIndex(qlsc=qlsc)

ra_list = list()
dec_list = list()
#i = 0

with open(input_file) as f:
    f.readline()  # skip header
    for line in f:
        cntr, ra, dec = line.rstrip("\n").split("\t")
        ra_list.append(float(ra))
        dec_list.append(float(dec))
#		i += 1
Ejemplo n.º 17
0
def test_ang2ipix_array( depth, ra, dec, ipix):
	'''
	Test ang2ipix using arrays, testing both float and double array types.
	'''
	q = QLSC(depth=depth)
	assert ipix == q.ang2ipix(ra, dec)
Ejemplo n.º 18
0
def test_ang2ipix_scalar(depth, ra, dec, ipix):
	'''
	Test QLSC ang2ipix using scalar values.
	'''
	q = QLSC(depth=depth)
	assert ipix == q.ang2ipix(ra, dec)
Ejemplo n.º 19
0
def test_facenum(depth, ra, dec, facenum):
    '''
	Test QLSC ang2ipix.
	'''
    q = QLSC(depth=depth)
    assert facenum == q.face_number(ra, dec)
Ejemplo n.º 20
0
In this example, coordinates are stored in an SQLite database
that persists on disk, useful for repeated runs.
'''

import os.path
import sqlite3
import numpy as np
from qlsc import QLSC, QLSCIndex

# File contains 10000 points from the WISE catalog.
#input_file = "1e5_wise.txt"
input_file = "../_ignore/1m_wise.txt"

# define a QLSC scheme at a specific bin level
qlsc = QLSC()

qlsc_index = QLSCIndex(qlsc=qlsc)

# The QLSCIndex object will create an SQLite database
# to hold coordinates given to it. Define the database name here (optional).
db_filename = "qlsc_db.qlscidx"
qlsc_index.data_source = db_filename

# The database is not deleted, so repeated runs of this
# script will not reload the points from the file above.

if qlsc_index.number_of_points == 0:
    i = 0

    points = list()