def create_pixel_histogram(cspad_det,dark=None,Nmax=None): cc = 0 npatt = len(cspad_dat.time[cc]) if Nmax==None or Nmax>npatt: Nmax = npatt chunks = cspad_dat.chunks(Nmax=Nmax) histbins = [] histograms = [] for ch in chunks[cc]: data = ch.data if not dark==None: data = data-dark if histbins==[]: datshp = np.shape(data[0]) Nel = np.prod(datshp) histbins = np.empty(datshp,dtype=np.object_) data = data.reshape(datshp[0],-1) ind = 0 for n in range(Nel): ind = np.ravel_index(n,datshp) histbins[ind] = histEdges(data[ind]) for n in range(Nel): ind = np.ravel_index(n,datshp) if histograms ==[]: histograms = np.empty(datshp,dtype=np.object_) histpgrams[ind] = np.histogram(data[ind],histbins[ind]) else: histograms[ind] += np.histogram(data[ind],histbins[ind]) return histograms,histbins
def predict(self, data): label_ids = [] for inp in self.scaler.transform(data): label_ids.append(np.ravel_index(compute_bmu(inp),(self.dim, self.dim))) if self.labels != None: return self.labels[label_ids] else: return np.array(label_ids)