def map_raw_data_onto_grid(self, unfold=False, filter_tol=1e-5): vlog('\nMapping raw n(k) data onto regular grid') data = self.get_raw_data() structure = self.get_attribute('structure', assigned=unfold) if structure is not None: kaxes = structure.kaxes else: kaxes = self.get_attribute('kaxes') #end if if filter_tol is not None: vlog.increment() data = self.filter_raw_data(filter_tol, store=False) vlog.decrement() #end if if not unfold: for s, sdata in data.items(): vlog('Mapping {} data onto grid'.format(s), n=1, time=True) self[s] = grid_function( points=sdata.k, values=sdata.nk, axes=kaxes, ) #end for else: rotations = structure.point_group_operations() for s, sdata in data.items(): if s == 'd' and 'u' in data and id(sdata) == id(data.u): continue #end if vlog('Unfolding {} data'.format(s), n=1, time=True) k = [] nk = [] ks = sdata.k nks = sdata.nk for n, R in enumerate(rotations): vlog('Processing rotation {:<3}'.format(n), n=2, mem=True) k.extend(np.dot(ks, R)) nk.extend(nks) #end for k = np.array(k, dtype=float) nk = np.array(nk, dtype=float) vlog('Unfolding finished', n=2, time=True) vlog('Mapping {} data onto grid'.format(s), n=1, time=True) vlog.increment(2) self[s] = grid_function( points=k, values=nk, axes=kaxes, average=True, ) vlog.decrement(2) #end for #end if if 'd' not in self and 'u' in self: self.d = self.u #end if vlog('Mapping complete', n=1, time=True) vlog('Current memory: ', n=1, mem=True)
def read_xsf(self, filepath, component=None): component = self.process_component_name(component) vlog('Reading density data from XSF file for component "{}"'.format( component), time=True) if isinstance(filepath, XsfFile): vlog('XSF file already loaded, reusing data.') xsf = filepath copy_values = True else: vlog('Loading data from file', n=1, time=True) vlog('file location: {}'.format(filepath), n=2) vlog('memory before: ', n=2, mem=True) xsf = XsfFile(filepath) vlog('load complete', n=2, time=True) vlog('memory after: ', n=2, mem=True) copy_values = False #end if # read structure if not self.has_attribute('structure'): vlog('Reading structure from XSF data', n=1, time=True) s = Structure() s.read_xsf(xsf) self.set_attribute('structure', s) #end if # read grid if not self.has_attribute('grid'): vlog('Reading grid from XSF data', n=1, time=True) g = read_grid(xsf) self.set_attribute('grid', g) self.set_attribute('distance_units', 'B') #end if # read values xsf.remove_ghost() d = xsf.get_density() values = d.values_noghost.ravel() if copy_values: values = values.copy() #end if # create grid function for component vlog('Constructing grid function from XSF data', n=1, time=True) f = grid_function( type='parallelotope', grid=self.grid, values=values, copy=False, ) self.set_attribute(component, f) self.set_attribute('distance_units', 'A') vlog('Read complete', n=1, time=True) vlog('Current memory:', n=1, mem=True)