def combine_maps(datamaps, start, end): """ Combine datamaps from file list in datamaps from positions start to end, return. """ datamap = DataMap(datamaps[start]) for i, name in enumerate(datamaps[start+1:end]): add = DataMap(name) for row, _ in enumerate(datamap.cells): for cell, _ in enumerate(datamap.cells[row]): for key in datamap.cells[row][cell].keys(): prev = datamap.cells[row][cell][key] cur = add.cells[row][cell][key] avg = ((i+1)*prev + cur)/(i+2) datamap.cells[row][cell][key] = avg return datamap
args = parser.parse_args() xlims = [args.xmin, args.xmax] ylims = [args.ymin, args.ymax] times = [] d_visc_energy = [] d_slip_energy = [] # Create system system = System(base = args.base) system.files(start = args.start, end = args.end) for frame, _file in enumerate(system.datamaps): datamap = DataMap(_file, min_mass = args.min_mass) times.append(frame*args.delta_t) d_visc_energy.append(datamap._sum_viscous_dissipation(args.width, args.delta_t, args.num_cells, args.viscosity, args.mass_flow)) if args.slip: d_slip_energy.append(calc_slip_dissipation(datamap, args.floor)) times = list(np.array(times) + args.time_start) if args.print: for i, (time, energy) in enumerate(zip(times, d_visc_energy)): print(time, energy, end=' ') if args.slip: print(d_slip_energy[i], end='')
var.append('U') var.append('V') else: var.append(args.type) frames = [] for frame, _file in enumerate(system.datamaps): cells = [] if args.average and len(system.datamaps) > 1: print("\rReading %s (%d of %d) ... " % (_file, frame+1, len(system.datamaps)), end='') sys.stdout.flush() elif len(system.datamaps) > 1: print("\n==> %s <==" % _file) datamap = DataMap(_file, min_mass = args.min_mass) if args.type == 'shear': datamap._calc_cell_shear(args.shear_numcells, mass_flow=False, if_droplet=args.shear_remove_edges) interface = datamap.interface(get_cell_numbers=True) floor = interface[0][1] ceil = floor + args.num_cells[1] - 1 edge = {'left': interface[0][0], 'right': interface[-1][0]} columns = get_columns(edge) print_separator = to_print_separator(columns) data = []
""" import argparse import numpy as np import os from flowtools.datamaps import System, DataMap parser = argparse.ArgumentParser( description="Print data from maps.") # Input base arguments parser.add_argument('datamap', nargs='+', help="file name base of system") parser.add_argument('--droplet', action='store_true', help="filter cells that are part of main droplet (default: false), optionally supply a minimum mass for filtering using '-m'") parser.add_argument('-m', '--min_mass', type=float, default=0., metavar='MASS', help="minimum mass of cell to include") args = parser.parse_args() for i, _file in enumerate(args.datamap): if len(args.datamap) > 1: print('%s:' % _file) datamap = DataMap(_file, min_mass = args.min_mass) datamap.print(droplet=args.droplet) if len(args.datamap) > 1 and i < len(args.datamap) - 1: print()
else: system = System() system.datamaps = [args.file] for frame, _file in enumerate(system.datamaps): # If saved figures desired construct filename if args.save: if args.base != None: save = '%s%05d%s' % (args.save, frame + args.start, '.png') else: save = args.save else: save = '' datamap = DataMap(_file, min_mass = args.min_mass) datamap.draw_interface() plt.axis(args.axis) plt.xlim(xlims) plt.ylim(ylims) plt.xlabel(args.xlabel) plt.ylabel(args.ylabel) plt.title(args.title) if args.length: print(datamap._interface_length()) if args.angle: try:
""" Script for combining cells of data maps. """ import argparse import numpy as np import os from flowtools.datamaps import System, DataMap parser = argparse.ArgumentParser( description="Combine cells of data map.") # Input base arguments parser.add_argument('-f', '--file', type=str, required=True, help="datamap to combine cells of") parser.add_argument('-o', '--output', type=str, required=True, help="output datamap to this file") parser.add_argument('-n', '--num_cells', type=int, nargs=2, required=True, help="combine this many cells in directions corresponding to x and y") parser.add_argument('-d', '--debug', action='store_true', help="output debug information") args = parser.parse_args() data = DataMap(args.file) combined = data.combine(nx=args.num_cells[0], ny=args.num_cells[1], verbose=args.debug) combined.save(args.output)
def combine(_path): """Combine and return density and flow map in _path.""" # Read maps using non-public ways :O dens = DataMap(fields="dens") dens.path = _path["dens"] dens._read() flow = DataMap(fields="flow") flow.path = _path["flow"] flow._read() # Container for output output = DataMap() output.cells = [] # Go over all density cells, ie. entire system i = 0 with flow.FlatArray(flow.cells) as flow.cells: for cell in dens.cells: combined = cell.copy() # If cells equal, add flow and move to next flow cell if i < len(flow.cells) and cell["X"] == flow.cells[i]["X"] and cell["Y"] == flow.cells[i]["Y"]: combined.update(flow.cells[i]) i += 1 else: combined.update({"U": 0.0, "V": 0.0}) # Append to container output.cells.append(combined) # Convert by hand to good format and save output.cells = np.array(output.cells) output._info = output.info output._grid() return output
# If saved figures desired construct filename if args.save: if args.base != None: save = '%s%05d%s' % (args.save, frame + args.start, '.png') else: save = args.save else: save = '' if not args.quiet: print("\rReading %s (%d of %d) ... " % (_file, frame+1, len(system.datamaps)), end='') sys.stdout.flush() datamap = DataMap(_file, min_mass = args.min_mass) if not args.quiet: print("Done!", end='') if args.type == 'flow': datamap.flow( show = args.show, save = save, dpi = args.dpi, transparent = args.transparent, temp = args.temp, clim = [args.Tmin, args.Tmax], color = args.colour, xlim = xlims, ylim = ylims, axis = args.axis, noaxis = args.noaxis, width = args.width, scale = args.scale, xlabel = args.xlabel, ylabel = args.ylabel, title = args.title ) else: if args.type == 'shear':