def dilate(field, bonds): ngb = bonds2ngbs_list(bonds, field.shape[0]) dil = np.zeros_like(field) for p,n in enumerate(ngb): a = field[n] dil[p] = a[np.absolute(a).argmax(axis=0), range(a.shape[1])] return dil
def neighbouring_bonds(self, t, bonds_of_interest): """Returns the set of bonds that are neighbouring the bonds of interest at time t. Input and output are in terms of trajectories.""" p2tr = self.p2tr(t) #load all the bonds at time t bonds = np.loadtxt(self.get_format_string(ext='bonds')%t, int) #construct neighbours for each particle ngb = bonds2ngbs_list(bonds, p2tr.shape[0]) result = [] for tra, trb in bonds_of_interest: for tr in [tra, trb]: a = self.trajs[tr][t - self.starts[tr]] for ngb_tr in p2tr[ngb[a]]: #iterate on neighbours #exclude the bonds of interest if ngb_tr in [tra, trb]: continue result.append(sorted([tr, ngb_tr])) #convert into a nice array of bonds return np.array(result).reshape([len(result), 2]).astype(int)
def average(field, bonds): ngb = bonds2ngbs_list(bonds, field.shape[0]) av = np.zeros_like(field) for p,n in enumerate(ngb): av[p] = (field[p]+field[n].mean(axis=0))/2 return av