Skip to content

Commit

Permalink
Prevent warning and add variable to plot
Browse files Browse the repository at this point in the history
  • Loading branch information
Jannis Teunissen committed Jun 2, 2024
1 parent e5acbe3 commit 1922445
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
11 changes: 8 additions & 3 deletions tools/plot_raw_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ def get_uniform_data(grids, domain, min_pixels, interpolation='linear',


def plot_uniform_data(uniform_data, x, time, vmin=None, vmax=None, cmap=None,
xlim=None, ylim=None, hide_axes=False, save_plot=None):
xlim=None, ylim=None, hide_axes=False, save_plot=None,
variable=None):
# Plot data
fig, ax = plt.subplots()
ndim = uniform_data.ndim
Expand All @@ -128,7 +129,10 @@ def plot_uniform_data(uniform_data, x, time, vmin=None, vmax=None, cmap=None,
if ylim:
ax.set_ylim(*ylim)

ax.set_title(f't = {time:.3e}')
title = f't = {time:.3e}'
if variable is not None:
title = title + ' - ' + variable
ax.set_title(title)

if save_plot:
print(f'Saving to {save_plot}')
Expand Down Expand Up @@ -165,7 +169,8 @@ def plot_uniform_data(uniform_data, x, time, vmin=None, vmax=None, cmap=None,
vmin=args.vmin, vmax=args.vmax,
cmap=args.cmap, xlim=args.xlim, ylim=args.ylim,
hide_axes=args.hide_axes,
save_plot=args.save_plot)
save_plot=args.save_plot,
variable=args.variable)
else:
# All spatial dimensions are projected, only print time and sum
grid_values = np.array([g['values'] for g in grids])
Expand Down
12 changes: 6 additions & 6 deletions tools/raw_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def read_single_grid(f):

# Number of cell centers is one less than number of faces
n_cells = dims-1
fmt = '=' + str(np.product(n_cells)) + 'd'
fmt = '=' + str(np.prod(n_cells)) + 'd'
tmp = unpack(fmt, f.read(calcsize(fmt)))
vals = np.array(tmp).reshape(n_cells, order='F')

Expand Down Expand Up @@ -143,7 +143,7 @@ def write_single_grid(f, grid):

# Number of cell centers is one less than number of faces
n_cells = grid['dims']-1
fmt = '=' + str(np.product(n_cells)) + 'd'
fmt = '=' + str(np.prod(n_cells)) + 'd'
f.write(grid['values'].tobytes(order='F'))


Expand Down Expand Up @@ -226,13 +226,13 @@ def grid_project(in_grid, project_dims, axisymmetric):
if axisymmetric and 0 in pdims:
# Multiply with 2 * pi * r
r = g['coords_cc'][0][valid_ix[0]]
w = np.product(g['dr'][pdims]) * 2 * np.pi * r
w = np.prod(g['dr'][pdims]) * 2 * np.pi * r

# Broadcast to have volume weight for every grid cell
w = np.broadcast_to(w[:, None], ihi-ilo)
g['values'] = (g['values'][valid_ix] * w).sum(axis=tuple(pdims))
else:
fac = np.product(g['dr'][pdims])
fac = np.prod(g['dr'][pdims])
g['values'] = fac * g['values'][valid_ix].sum(axis=tuple(pdims))

g['n_dims'] -= len(project_dims)
Expand Down Expand Up @@ -328,7 +328,7 @@ def map_grid_data_to(g, r_min, r_max, dr, axisymmetric=False,
cdata = np.zeros(nx)

if axisymmetric:
rvolume = np.product(g['dr']/dr) * coords_fine[0]/coords_coarse[0]
rvolume = np.prod(g['dr']/dr) * coords_fine[0]/coords_coarse[0]

if rvolume.ndim < len(g['ihi']):
# Broadcast to have volume weight for every grid cell
Expand All @@ -338,7 +338,7 @@ def map_grid_data_to(g, r_min, r_max, dr, axisymmetric=False,
values = rvolume.ravel() * g['values'][valid_ix].ravel()
else:
# Cartesian grid, simple averaging
rvolume = np.product(g['dr']/dr)
rvolume = np.prod(g['dr']/dr)
values = rvolume * g['values'][valid_ix].ravel()

np.add.at(cdata, tuple(map(np.ravel, ixs)), values)
Expand Down

0 comments on commit 1922445

Please sign in to comment.