示例#1
0
def get_ratings(rating_id, human_classification=None):
    """
    Return a numpy array of rating corresponding to 'rating_id' provided.
    'human_classification' is a list of human assigned classifications (from
    the default 8-level classification scheme) to include. If 'human_classifications'
    is None then all ratings will be returned.
    """
    if human_classification:
	pdm_class_type_id = rating_utils.get_default_pdm_class_type_id()
	ratings = rating_utils.get_data("SELECT r.value FROM ratings AS r LEFT JOIN pdm_classifications AS cl ON r.pdm_cand_id=cl.pdm_cand_id AND cl.pdm_class_type_id=%d WHERE r.rating_id=%d GROUP BY cl.pdm_cand_id HAVING sum(cl.rank IN (%s))/sum(cl.rank>0) > 0.5;" % (pdm_class_type_id, rating_id, ','.join([str(cl) for cl in human_classification])))
    else:
	ratings = rating_utils.get_data("SELECT value FROM ratings WHERE rating_id=%d" % rating_id)
    return np.array(ratings).squeeze()
示例#2
0
def get_rating_types(rating_ids):
    """Return dictionary describing rating_types with
    rating_ids. Dictionaries are stored in a list.

    rating_ids is a list of integers.
    """
    return rating_utils.get_data("SELECT * FROM rating_types " \
				 "WHERE rating_id IN (%s)" % \
				 ','.join([str(id) for id in rating_ids]), \
				 dictcursor=True)
示例#3
0
def get_all_rating_types():
    """Return available ratings from database.
    Each rating is describe using a dictionary.
    All dictionaries are stored in a list.
    """
    return rating_utils.get_data("SELECT * FROM rating_types;", dictcursor=True)
示例#4
0
def produce_report(prepped_string, where="1", numbins=NUMBINS_DEFAULT, \
		    norm=False, log=False):
    """Produce a series of diagnostic plots given 
    the composite rating descibed in 'prepped_string'.

    'where' is a MySQL where clause to limit the candidates used.
    'numbins' is the number of bins to use in histograms
    'norm' is boolean. Determines if area under histograms should
	    be normalized to 1.
    'log' is boolean. Determines if vertical axis is log (base 10).
    """
    fig = plt.figure()

    # Plot all ratings in black
    query = build_query(prepped_string, where=where)
    ratings = rating_utils.get_data(query)
    if len(ratings):
	all_hist = plt.hist(ratings, numbins, edgecolor='k', histtype='step', \
		label="All Cands (%d)" % len(ratings), normed=norm)
    
    # Plot bad ratings (RFI, Noise) in red
    query = build_query(prepped_string, where=where, classifications=[4,5])
    ratings = rating_utils.get_data(query)
    if len(ratings):
	bad_hist = plt.hist(ratings, numbins, edgecolor='r', histtype='step', \
		label="RFI/Noise (%d)" % len(ratings), normed=norm)

    # Plot pulsars (known, harmonic) in green
    query = build_query(prepped_string, where=where, classifications=[6,7])
    ratings = rating_utils.get_data(query)
    if len(ratings):
	psr_hist = plt.hist(ratings, numbins, edgecolor='g', histtype='step', \
		label="Known/Harmonic (%d)" % len(ratings), normed=norm)
    
    # Plot good ratings (class 1, 2, 3) in blue
    query = build_query(prepped_string, where=where, classifications=[1,2,3])
    ratings = rating_utils.get_data(query)
    if len(ratings):
	good_hist = plt.hist(ratings, numbins, edgecolor='c', histtype='step', \
		label="Class 1/2/3 (%d)" % len(ratings), normed=norm)

    # Label plot
    plt.title(prepped_string)
    plt.xlabel("Composite rating value")
    plt.ylabel("Number")
    
    # legend
    leg = plt.legend(loc='best')
    leg.get_frame().set_alpha(0.5)
    
    # set vertical axis to log
    if log:
	ymin, ymax = plt.ylim()
	plt.ylim(0.1, ymax)
	plt.yscale('log')
    
    def onpress(event):
	if event.key in ('q', 'Q'):
	    sys.exit(0)
    
    fig.canvas.mpl_connect('key_press_event', onpress)
    
    plt.show()
示例#5
0
def get_all_rating_types():
    return rating_utils.get_data("SELECT * FROM rating_types;", dictcursor=True)