def save_subdomain_config(self, subdomains): if self.config.output: dname = os.path.dirname(self.config.output) if dname and not os.path.exists(dname): os.makedirs(dname) with open(io.subdomains_filename(self.config.output), 'wb') as f: pickle.dump(subdomains, f)
def merge_subdomains(base, digits, it, save=True): fn_subdomains = io.subdomains_filename(base) with open(fn_subdomains, 'rb') as f: subdomains = pickle.load(f) bb = get_bounding_box(subdomains) data = np.load(io.filename(base, digits, subdomains[0].id, it)) dtype = data['v'].dtype dim = data['v'].shape[0] out = {} for field in data.files: if len(data[field].shape) == dim: shape = bb else: shape = list(data[field].shape) shape[-dim:] = bb out[field] = np.zeros(shape, dtype=dtype) out[field][:] = np.nan # np.ma.masked_all(shape, dtype=dtype) for s in subdomains: fn = io.filename(base, digits, s.id, it) data = np.load(fn) for field in data.files: selector = [slice(None)] * (len(data[field].shape) - dim) selector.extend([slice(i0, i1) for i0, i1 in reversed(list(zip(s.location, s.end_location)))]) out[field][selector] = data[field] if save: np.savez(io.merged_filename(base, digits, it), **out) return out
def merge_subdomains(base, digits, it, save=True): fn_subdomains = io.subdomains_filename(base) subdomains = pickle.load(open(fn_subdomains, 'r')) bb = get_bounding_box(subdomains) data = np.load(io.filename(base, digits, subdomains[0].id, it)) dtype = data['v'].dtype dim = data['v'].shape[0] out = {} for field in data.files: if len(data[field].shape) == dim: shape = bb else: shape = list(data[field].shape) shape[-dim:] = bb out[field] = np.zeros(shape, dtype=dtype) out[field][:] = np.nan # np.ma.masked_all(shape, dtype=dtype) for s in subdomains: fn = io.filename(base, digits, s.id, it) data = np.load(fn) for field in data.files: selector = [slice(None)] * (len(data[field].shape) - dim) selector.extend([ slice(i0, i1) for i0, i1 in reversed(zip(s.location, s.end_location)) ]) out[field][selector] = data[field] if save: np.savez(io.merged_filename(base, digits, it), **out) return out
def save_subdomain_config(self, subdomains): if self.config.output: pickle.dump(subdomains, open(io.subdomains_filename(self.config.output), 'w'))