def save_contour(ctx, step, latest): """Dump the contour data to CSV file All the data in x and y columns Args: ctx: the Click context from the base command step: the step to plot latest: whether to plot the latest step """ sequence( lambda x: x.parent.params["folder"], get_filename(step, latest), np.load, calc_position_, save2d("contour.csv", ["x", "y"]) )(ctx)
def read_and_calc(f_calc, ctx): """Read in the data and return a result """ return pipe( ctx.parent.params["folder"], lambda x: os.path.join(x, "data*.npz"), glob.glob, sorted, take_nth(ctx.parent.params["frequency"]), list, pbar, map_(sequence(np.load, f_calc)), list, np.array, )
def calc_gradient_free_energy(data): """Calculate the gradient free energy for one time step Args: data: dictionary of data from a output file for given time step Returns: a float representing the gradient free energy for a given time step """ func = sequence( lambda x: get_vars(x, set_eta(data["eta"]), get_mesh(x)), get("eta"), lambda x: x.grad.mag ** 2, ) return pipe( data["params"].item(), lambda x: assoc(x, "dx", x["lx"] / x["nx"]), lambda x: func(x) * (x["kappa"] / 2) * calc_dx2(x), np.array, np.sum, )
def read_and_save(filename, column_names, f_calc): """Read in a file and save data to CSV """ return sequence(read_and_calc(f_calc), save2d(filename, column_names))
def read_and_plot(f_calc): """Read in a file and plot using f_calc """ return sequence(read_and_calc(juxt(get("step_counter"), f_calc)), plot2d)
def calc_position_(data): """Calculate the postion of the interface Args: data: data dictionary Returns: the contour points as a numpy array """ return calc_contour( data["eta"], data["params"].item()["lx"], data["params"].item()["nx"] ) calc_position_10 = sequence(calc_position_, lambda x: np.amax(x[:, 0])) calc_position_01 = sequence(calc_position_, lambda x: np.amax(x[:, 1])) calc_position_d = sequence( calc_position_, lambda x: np.amax((x[:, 0] + x[:, 1]) / np.sqrt(2.)) ) @cli.command() @click.pass_context def a_10(ctx): """Command to plot the radius of the preciptate in the x direction """