def read_group(group, key_lim=None): if key_lim == None: klist = list(group.items()) else: klist = [] for key in key_lim: index = list(group.keys()).index(key) klist.append(list(group.items())[index]) d = Dummy() for key, item in klist: #print key, type(item) if isgroup(item): if isgreensfunction(item): setattr(d, key, read_gf_group(item)) else: setattr(d, key, read_group(item)) elif isdataset(item): setattr(d, key, read_ndarray_from_data_set(item)) else: print(key, type(item)) raise NotImplementedError return d
def read_gf_slices_group(group): if not isgreensfunction_slices(group): raise NotImplementedError dall = [] dmat = [] for key, item in group.items(): if key == "t-1": d = read_all_sets(item) dmat.append(d) else: d = read_all_sets(item) dall.append(d) # -- Reshape the Green's function components dout = Dummy() data = getattr(dmat[0], 'mat') setattr(dout, 'mat', data) key = ['les', 'ret'] maximum = max(p.tstp for p in dall) for key in key: new_data = np.zeros((len(dall), maximum + 1, dall[len(dall) - 1].size1, dall[len(dall) - 1].size2), dtype=np.complex) tstep = np.array([], dtype=int) for t in np.arange(len(dall)): data = getattr(dall[t], key) tstep = np.append(tstep, int(len(data))) new_data[t][0:len(data)] = data setattr(dout, key, new_data) setattr(dout, 'steps', tstep) return dout
def read_all_sets(group): # -- Read in data to dummy class d = Dummy() for key, item in group.items(): np_data = read_ndarray_from_data_set(group[key]) setattr(d, key, np_data) return d
def read_imp_h5file_old(filename): fd = h5py.File(filename) imp = Dummy() for key, item in fd.items(): if isgreensfunction(item): setattr(imp, key, read_gf_group(item)) else: setattr(imp, key, read_all_sets(item)) fd.close() return imp
def read_group_slices(filename): fd = h5py.File(filename) imp = Dummy() for key, item in fd.items(): if isgreensfunction_slices(item): setattr(imp, key, read_gf_slices_group(item)) elif isgreensfunction(item): setattr(imp, key, read_gf_group(item)) elif isgreensfunction_tavtrel(item): setattr(imp, key, read_gf_tavrel_group(item)) else: setattr(imp, key, read_all_sets(item)) return imp
def read_gf_tavrel_group(group): if not isgreensfunction_tavtrel(group): raise NotImplementedError dout = Dummy() for key, item in group.items(): length = len(item.items()) maximum = max(max(p[1].shape for p in item.iteritems())) size1 = item.items()[0][1].shape[1] size2 = item.items()[0][1].shape[2] new_data = np.zeros((length, maximum, size1, size2), dtype=complex) t = 0 for skey, sitem in item.items(): data = sitem[:][:][:] new_data[t][0:len(data)] = data t += 1 setattr(dout, key, new_data) return dout
def read_imp_h5file_slices(filename, key_lim=None): fd = h5py.File(filename) if key_lim == None: klist = list(fd.items()) else: klist = [] for key in key_lim: index = list(fd.keys()).index(key) klist.append(list(fd.items())[index]) imp = Dummy() for key, item in klist: if isgreensfunction_slices(item): setattr(imp, key, read_gf_slices_group(item)) elif isgreensfunction(item): setattr(imp, key, read_gf_group(item)) elif isgreensfunction_tavtrel(item): continue #setattr(imp, key, read_gf_tavrel_group(item)) else: setattr(imp, key, read_all_sets(item)) fd.close() return imp