def HistogramWeighted(data,bins,weights,sidx=None,no_copy = False): bins = np.ascontiguousarray(bins,dtype = data.dtype) bincounts = np.ascontiguousarray(np.zeros(bins.shape[0] -1,dtype = np.float64)) if no_copy: data = np.ravel(data) weights = np.ravel(weights) else: data = np.ravel(data.copy()) weights = np.ravel(weights) if sidx is None: sidx = argsort(data,no_copy=True) data = np.ascontiguousarray(data[sidx]) weights = np.ascontiguousarray(weights[sidx],dtype=data.dtype) codefile = open(loompath+"/csrc/inline_histogram_weighted.cc","r") code = codefile.read().format(FLOAT = c_spec.num_to_c_types[data.dtype.char]) codefile.close() auxcodefile = open(loompath+"/csrc/weighted_histogram_aux.cc","r") auxcode = auxcodefile.read().format(FLOAT = c_spec.num_to_c_types[data.dtype.char]) auxcodefile.close() Configuration.weave(code, ["bins","data","weights","bincounts"], locals(), support_code=auxcode) return bincounts, bins,sidx
def Histogram(data,bins,no_copy=False): bins = np.ascontiguousarray(bins,dtype = data.dtype) bincounts = np.ascontiguousarray(np.zeros(bins.shape[0] -1,dtype = np.float64)) if no_copy: data = np.ascontiguousarray(np.ravel(data)) else: data = np.ascontiguousarray(np.ravel(np.copy(data))) codefile = open(loompath+"/csrc/inline_histogram.cc","r") code = codefile.read().format(FLOAT = c_spec.num_to_c_types[data.dtype.char]) codefile.close() Configuration.weave(code, ["bins","data","bincounts"], locals()) return bincounts, bins
def argsort(data,no_copy=False): if not no_copy: data = data.copy() codefile = open(loompath+"/csrc/argsort.cc","r") code = codefile.read().format(FLOAT = c_spec.num_to_c_types[data.dtype.char]) codefile.close() auxcodefile = open(loompath+"/csrc/weighted_histogram_aux.cc","r") auxcode = auxcodefile.read().format(FLOAT = c_spec.num_to_c_types[data.dtype.char]) auxcodefile.close() idx = np.ascontiguousarray(np.arange(data.size,dtype = np.uint64)) Configuration.weave(code, ["data","idx"], locals(), support_code=auxcode) return idx
def Bin(positions,gridN1d,boxsize = 1.0,dt = np.float64(),method = "tsc",rfft=False): assert(method == "tsc","Other binning methods have not been added. Please request them or check back later") positions = positions[:,0:3] positions = np.ascontiguousarray(positions,dtype=dt) N = positions.shape[0] #we pad the array to make in place rfft based convolutions easier density = np.ascontiguousarray(np.zeros((gridN1d,gridN1d,2*(gridN1d/2+1)),dtype = dt)) codefile = open(Configuration.loompath +"/csrc/inline_tsc.cc","rb") tsc_code = codefile.read().format(FLOAT=c_spec.num_to_c_types[dt.dtype.char],gridN1D = gridN1d) codefile.close() Configuration.weave(tsc_code, ["positions","N","density","boxsize"], locals()) if rfft: return density else: return density[:gridN1d,:gridN1d,gridN1d]