def plot_subsurface(vis, col, ax, label, color=None, cmap=None): if cmap is None: cmap = colors.alpha_cmap(color) z = vis.centroids[:, 2] if len(vis.times) == 1: cm = colors.cm_mapper(vis.times[0] - 1, vis.times[0], cmap) else: cm = colors.cm_mapper(vis.times[0], vis.times[-1], cmap) formats = ['-', '--', '-.'] for varname, form in zip(col, formats): data = vis.getArray(varname) assert (len(data.shape) == 2) assert (data.shape[1] == len(vis.centroids)) for i, time in enumerate(vis.times): mylabel = None if i == len(vis.times) - 1: mylabel = label ax.plot(data[i, :], z, form, color=cm(time), label=mylabel)
def plot(self, color=None, ax=None): if color is None: import colors cm = colors.cm_mapper(0, self.num_cells() - 1) colors = [cm(i) for i in range(self.num_cells())] else: colors = color verts = [[self.coords[i, 0:2] for i in f] for f in self.conn] from matplotlib import collections gons = collections.PolyCollection(verts, facecolors=colors) from matplotlib import pyplot as plt if ax is None: fig, ax = plt.subplots(1, 1) ax.add_collection(gons) ax.autoscale_view()
def plot(vis_objs, layout, axs, dirname, color_or_cmap, color_mode): for i, row in enumerate(layout): for j, col in enumerate(row): ax = axs[i][j] domain, _ = domain_var(col[0]) vis = vis_objs[domain] if color_mode == 'runs': # color_or_cmap is a color if domain == '': plot_subsurface(vis, col, ax, dirname, color_or_cmap) else: plot_surface(vis, col, ax, dirname, color_or_cmap) elif color_mode == 'time': if domain == '': plot_subsurface(vis, col, ax, dirname, None, color_or_cmap) else: cm = colors.cm_mapper(-.1, 1, color_or_cmap) color = cm(0) plot_surface(vis, col, ax, dirname, color)
type=colors.float_list_type, default=None, help= "List of color indices to use, of the form: --colors=[0,0.1,1], where the doubles are in the range (0,1) and are mapped to a color using the colormap." ) parser.add_argument("--colormap", "-m", type=str, default="jet", help="Colormap used to pick a color.") parser.add_argument("--domain_suffix", type=str, help="Suffix of surface and snow domains.") args = parser.parse_args() cm = colors.cm_mapper(0, 1, args.colormap) fig, axs = get_axs() dirnames = args.INPUT_DIRECTORIES markers = reversed(['x', '+', 'o', '^', 'v', 's'][0:len(dirnames)]) for i, (dirname, marker) in enumerate(zip(dirnames, itertools.cycle(markers))): version, domain_suffix = get_version(dirname, args.domain_suffix) print("Directory %s got version: %s and domain_suffix: %r" % (dirname, version, domain_suffix)) hackfactor = None if dirname == "run-transient4": hackfactor = 2.0 if args.colors is None: if len(dirnames) > 1:
for k in range(nt): # search each time where_unsat = np.where(col_dat[3,k,i,:] == 0)[0] if len(where_unsat) == 0: # nothing is unsaturated itd[k,i] = 0. elif where_unsat[0] == 0: # nothing is saturated, wtd is the full column thickness (i.e. the bottom) itd[k,i] = z_surf[i] - z_bott[i] else: # wt is in the domain -- average the first unsaturated with the last # saturated, then subtract from the surf to get depth itd[k,i] = z_surf[i] - (col_dat[1,k,i,where_unsat[0]] + col_dat[1,k,i,where_unsat[0]-1])/2 # plot fig,ax = plt.subplots(m,n, sharey=True, sharex=True,figsize=(12,3)) cm = colors.cm_mapper(0,nt-1) #print nt #ax = ax.ravel() #for i in range(2): for i in range(m): for k in range(n): #print k j = k + (i*n) #print j ax[i,k].plot(col_dat[0,0,:,0], -wtd[j,:], color='b', label="{0} years".format(times_subset[j])) ax[i,k].plot(col_dat[0,0,:,0], -itd[j,:], color='c', label="{0} years".format(times_subset[j])) #ax[i,k].set_xlabel("x [m]") #ax[i,k].set_ylabel("depth to water table [m]") #ax[k].set_title() #ax[k].legend()
import argparse parser = argparse.ArgumentParser(description="Plot timestep histories from an ATS run logfile. Store the results in a .npz file for future faster reading.") parser.add_argument("LOG_FILES", nargs="+", type=str, help="List of logfiles to parse.") parser.add_argument("--colors", "-c", type=float_list_type, default=None, help="List of color indices to use, of the form: --colors=[0,0.1,1], where the doubles are in the range (0,1) and are mapped to a color using the colormap.") parser.add_argument("--colormap", "-m", type=str, default="jet", help="Colormap used to pick a color.") parser.add_argument("--overwrite", "-o", action="store_true", help="Do not use any existing .npz file -- instead reload from the logfile and overwrite the .npz file.") args = parser.parse_args() import colors cm = colors.cm_mapper(0,1,args.colormap) fig, axs = get_axs() fnames = args.LOG_FILES for i,fname in enumerate(fnames): if fname.endswith(".npz"): data = read_from_file(fname) elif os.path.isfile(fname+".npz") and not args.overwrite: data = read_from_file(fname+".npz") else: with open(fname,'r') as fid: data = parse_logfile(fid) write_to_file(data, fname) if args.colors is None: if len(fnames) > 1:
if len(where_unsat) == 0: # nothing is unsaturated wtd[j, i] = 0. elif where_unsat[0] == 0: # nothing is saturated, wtd is the full column thickness (i.e. the bottom) wtd[j, i] = z_surf[i] - z_bott[i] else: # wt is in the domain -- average the first unsaturated with the last # saturated, then subtract from the surf to get depth #print i #print z_surf[i] #print col_dat.shape #print where_unsat.shape #print col_dat[1,:,i,where_unsat[0]-1] wtd[j, i] = z_surf[i] - (col_dat[1, :, i, where_unsat[0]] + col_dat[1, :, i, where_unsat[0] - 1]) / 2 #print(where_unsat) # plot fig, ax = plt.subplots(1, 1, figsize=(18, 6)) cm = colors.cm_mapper(0, num_runs - 1) for j in range(1, num_runs): ax.plot(col_dat[0, 0, :, 0], -wtd[j, :], color=cm(j), label="{0} run".format(j)) ax.set_xlabel("x [m]") ax.set_ylabel("depth to ice table [m]") ax.legend() plt.show()
if is_temp: to_get.append("temperature") to_get.append("saturation_liquid") if is_ice: to_get.append("saturation_ice") to_get.append("saturation_gas") dat = column_data.column_data(to_get) # convert times to days times = [time*365.25 for time in times] # create subsurface coordinate z = dat[0,0,:] # get colors ice = colors.cm_mapper(-10, times[-1], colors.ice_cmap()) water = colors.cm_mapper(-10, times[-1], colors.water_cmap()) gas = colors.cm_mapper(-10, times[-1], colors.gas_cmap()) # create figures fig, axs = getFigs(inset, is_temp, is_seb) # plot for i,time in enumerate(times): if is_temp: j = 3 else: j = 2 axs[0].plot(dat[j,i,:],z,color=water(time)) j = j + 1