168 compute_function=None,
179 init_analysis_plot_paths(self, analysis_folder, analysis_prefix)
183 ext_y = 2 * self.
ext_r
185 dx = (self.
ex[0] * ext_x, self.
ex[1] * ext_x, self.
ex[2] * ext_x)
186 dy = (self.
ey[0] * ext_y, self.
ey[1] * ext_y, self.
ey[2] * ext_y)
190 def column_integ_render(self, field_name, field_type, custom_getter=None):
192 arr_field = self.
model.render_cartesian_column_integ(
200 custom_getter=custom_getter,
205 def column_average_render(
206 self, field_name, field_type, min_normalization=1e-9, custom_getter=None
209 arr_field = self.
model.render_cartesian_column_integ(
217 custom_getter=custom_getter,
220 normalisation = self.
model.render_cartesian_column_integ(
230 return field_normalize(arr_field, normalisation, min_normalization)
236 do_normalization=True,
237 min_normalization=1e-9,
238 field_transform=None,
242 arr_field_data = self.
model.render_cartesian_slice(
250 custom_getter=custom_getter,
253 if field_transform
is not None:
254 arr_field_data = field_transform(arr_field_data)
256 if not do_normalization:
257 return arr_field_data
259 arr_field_normalization = self.
model.render_cartesian_slice(
269 return field_normalize(arr_field_data, arr_field_normalization, min_normalization)
271 def get_extent(self):
287 raise ValueError(
"compute_function is not set")
290 def analysis_save(self, iplot, data=None):
293 "time": self.
model.get_time(),
294 "sinks": self.
model.get_sinks(),
300 def load_analysis(self, iplot):
303 def get_list_analysis_id(self):
306 def metadata_to_screen_sink_pos(self, metadata):
308 for s
in metadata[
"sinks"]:
312 x_e_x = self.
ex[0] * x + self.
ex[1] * y + self.
ex[2] * z
313 y_e_y = self.
ey[0] * x + self.
ey[1] * y + self.
ey[2] * z
315 output_list.append((x_e_x, y_e_y, s))
318 def figure_init(self, holywood_mode=False, dpi=200):
319 figure_init(self.
aspect, holywood_mode, dpi, base_size=6, nx=self.
nx, ny=self.
ny)
321 def figure_render_sinks(self, metadata, ax, scale_factor, color, linewidth, fill):
323 figure_render_sinks(sink_list_plot, ax, scale_factor, color, linewidth, fill)
325 def figure_add_time_info(self, text, holywood_mode=False):
326 figure_add_time_info(text, holywood_mode)
328 def figure_add_colorbar(self, imshow_result, label, holywood_mode=False):
329 figure_add_colorbar(imshow_result, label, holywood_mode)
343 cmap_bad_color="black",
353 if shamrock.sys.world_rank() == 0:
356 dist_label_x, dist_conv_x = plot_codeu_to_unit(self.
model.get_units(), x_unit)
357 dist_label_y, dist_conv_y = plot_codeu_to_unit(self.
model.get_units(), y_unit)
359 metadata[
"extent"][0] *= dist_conv_x
360 metadata[
"extent"][1] *= dist_conv_x
361 metadata[
"extent"][2] *= dist_conv_y
362 metadata[
"extent"][3] *= dist_conv_y
364 time_label, time_conv = plot_codeu_to_unit(self.
model.get_units(), time_unit)
365 metadata[
"time"] *= time_conv
367 field_unit_label, field_conv = plot_codeu_to_unit(self.
model.get_units(), field_unit)
368 field_render *= field_conv
374 my_cmap = matplotlib.colormaps[cmap].copy()
375 my_cmap.set_bad(color=cmap_bad_color)
378 if contour_list
is not None:
380 ny, nx = field_render.shape
381 x = np.linspace(metadata[
"extent"][0], metadata[
"extent"][1], nx)
382 y = np.linspace(metadata[
"extent"][2], metadata[
"extent"][3], ny)
383 X, Y = np.meshgrid(x, y)
385 contour_set = plt.contour(
386 X, Y, field_render, levels=contour_list, colors=
"white", linewidths=0.5
389 plt.clabel(contour_set, inline=
True, fontsize=8, fmt=
"%g")
392 field_render, cmap=my_cmap, origin=
"lower", extent=metadata[
"extent"], **kwargs
399 metadata, ax, sink_scale_factor, sink_color, sink_linewidth, sink_fill
402 plt.xlabel(f
"{x_label} {dist_label_x}")
403 plt.ylabel(f
"{y_label} {dist_label_y}")
405 text = f
"t = {metadata['time']:0.3f} {time_label}"
408 cmap_label = f
"{field_label} {field_unit_label}"
411 print(f
"Saving plot to {self.plot_filename.format(iplot)}")
412 plt.savefig(self.plot_filename.format(iplot))
415 def render_all(self, **kwargs):
419 def render_gif(self, gif_filename, save_animation=False, fps=15, bitrate=1800):
420 if shamrock.sys.world_rank() == 0:
424 writer = animation.PillowWriter(
425 fps=fps, metadata=dict(artist=
"Me"), bitrate=bitrate
427 ani.save(self.analysis_prefix + gif_filename, writer=writer)
438 os.makedirs(analysis_folder, exist_ok=
True)
440 self.
analysis_prefix = os.path.join(analysis_folder, analysis_prefix) +
"_"
446 Save the analysis data npy file
448 if shamrock.sys.world_rank() == 0:
449 print(f
"Saving data to {self.npy_data_filename.format(iplot)}")
454 Load the analysis data from the json and npy files
458 def get_list_analysis_id(self):
461 def make_plot(self, iplot, plot_func):
463 if shamrock.sys.world_rank() == 0:
466 def render_all(self, plot_func):
470 def render_gif(self, glob_str_plot, gif_filename, save_animation=False, fps=15, bitrate=1800):
471 if shamrock.sys.world_rank() == 0:
475 writer = animation.PillowWriter(
476 fps=fps, metadata=dict(artist=
"Me"), bitrate=bitrate
make_plot(self, iplot, x_unit=None, y_unit=None, time_unit=None, field_unit=None, x_label=None, y_label=None, field_label=None, holywood_mode=False, cmap="magma", cmap_bad_color="black", contour_list=None, add_sinks=True, sink_scale_factor=1, sink_color="green", sink_linewidth=1, sink_fill=False, save_plot=True, **kwargs)