def _do_z_match(self, rz, z, weights=None): """ all the other match methods call this one """ import weighting wr = weighting.hist_match_remove(rz, z, self['binsize'], extra_weights1=weights) if weights is None: weights_out=None else: weights_out=weights[wr] return wr,weights_out
def compare_hist_match(binsize, binnum=9, l=None, r=None): """ Compare hist_match with weights and with remove method. """ import weighting import lensing if l is None or r is None: l,r = load_test_data() binner=lensing.binning.LambdaBinner(12) print("selecting ",binner.bin_label(binnum)) w=binner.select_bin(l, binnum) print(" kept %d/%d" % (w.size,l.size)) print("using remove method") keep = weighting.hist_match_remove(r['z'], l['z'][w], binsize) perc = keep.size/(1.*r.size) print(" used number: %d/%d = %0.2f" % (keep.size,r.size, perc)) print(" combining") comb_rm = average_lensums(r[keep]) for i in xrange(comb_rm['r'].size): print("%0.3f %15.12f %15.12f" % \ (comb_rm['r'][0,i], comb_rm['dsig'][0,i], comb_rm['wsum_mean'][0,i])) print("using weights method") weights = weighting.hist_match(r['z'], l['z'][w], binsize) effnum = weights.sum() effperc = effnum/r.size print(" effective number: %d/%d = %0.2f" % (effnum,r.size, effperc)) print(" combining") comb = average_lensums(r, weights=weights) for i in xrange(comb_rm['r'].size): print("%0.3f %15.12f %15.12f %15.12f %15.12f" % \ (comb['r'][0,i], comb['dsig'][0,i], comb_rm['dsig'][0,i], comb['wsum_mean'][0,i], comb_rm['wsum_mean'][0,i]))