Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
 def save_subdomain_config(self, subdomains):
     if self.config.output:
         pickle.dump(subdomains,
                 open(io.subdomains_filename(self.config.output), 'w'))
Ejemplo n.º 6
0
 def save_subdomain_config(self, subdomains):
     if self.config.output:
         pickle.dump(subdomains,
                     open(io.subdomains_filename(self.config.output), 'w'))