coconut_tools.plot¶
This module provides plotting utilities for analyzing and comparing the magnetic, thermodynamic, and velocity outputs from COCONUT simulation results.
- Functions included:
plot_boundary_profil: Plot boundary magnetic and plasma profiles from dat files.
Surface_2D_onetime: Plot 2D slices of key physical quantities at a single time from dat file.
create_plot_B: Plot magnetic field components for solar minimum and maximum conditions.
create_plot_comparison: Compare multiple simulation runs with different parameters (e.g., ζ).
create_plot_max_quantities_vs_b0: Compare the scaling of max V, B, and density vs B0 from different runs.
Note
Some plotting functions assume that the relevant simulation data has been preprocessed and saved into .hdf5 files. These HDF5 files must contain the expected datasets (e.g., ‘B’, ‘V’, ‘rho’, ‘time’, etc.). Cf. create_hdf script.
This design allows for efficient reuse of simulation outputs and avoids recomputing or reloading raw binary data multiple times.
Functions
|
Plot thermodynamic and magnetic quantities from a COCONUT output file. |
|
Plot 2D maps using colatitude/longitude axes read from the input file. |
|
Plot magnetic field components for solar minimum and maximum from COCONUT hdf5 files. |
|
Plot velocity, magnetic field, and density comparisons from multiple COCONUT simulation outputs. |
|
Plot maximum V, B, and density as functions of B0 for solar min and max cases. |
|
Convert a distance expressed in meters to solar radii. |
|
Plot magnetic and thermodynamic quantities from HDF5 files. |
- coconut_tools.plot.Surface_2D_onetime(inputfile, outputfile, mode='all', extended=False, showP=False)[source]¶
Plot thermodynamic and magnetic quantities from a COCONUT output file.
- Parameters:
inputfile (str) – Path to the input directory containing COCONUT binary output.
outputfile (str) – Path where the figure should be saved.
mode (Literal["all", "reduced"], optional) – “all” plots 8 variables, “reduced” plots only density, temperature, Br, and Vr. Default is “all”.
extended (bool, optional) – If True, read radius from the .dat file. Default is False.
showP (bool, optional) – If True, also plot pressure and include it in the saved figure. Default is False.
- Return type:
None- Returns:
None
- coconut_tools.plot.Surface_2D_onetime_file_axes(inputfile, outputfile, mode='all', extended=False, showP=False, invert_yaxis=True)[source]¶
Plot 2D maps using colatitude/longitude axes read from the input file.
This version uses the exact clt/lon grids from the .dat file to avoid implicit flipping. Axes are labeled in degrees of colatitude/longitude.
- Return type:
None- Parameters:
inputfile (str)
outputfile (str)
mode (Literal['all', 'reduced'])
extended (bool)
showP (bool)
invert_yaxis (bool)
- coconut_tools.plot.create_plot_B(path_min, path_max, save_path=None, scale_factor=0.402, show=False)[source]¶
Plot magnetic field components for solar minimum and maximum from COCONUT hdf5 files.
- Parameters:
path_min (str) – Path to the HDF5 file for solar minimum data.
path_max (str) – Path to the HDF5 file for solar maximum data.
save_path (str, optional) – Path where the plot should be saved as PDF. If None, no file is saved.
scale_factor (float) – Time scaling factor to convert simulation time to hours.
show (bool) – Whether to display the plot using matplotlib.
- Return type:
None- Returns:
None
- coconut_tools.plot.create_plot_comparison(data_indices, input_dir, output_dir, output_filename='comp_zeta_max.pdf', time_scale=0.402)[source]¶
Plot velocity, magnetic field, and density comparisons from multiple COCONUT simulation outputs.
- Parameters:
data_indices (dict) – Dictionary mapping data keys (e.g. file index) to labels.
input_dir (str) – Directory containing the HDF5 files named like ‘Data_{index}.hdf5’.
output_dir (str) – Directory where the plot will be saved.
output_filename (str) – Name of the output PDF file. Default is ‘comp_zeta_max.pdf’.
time_scale (float) – Scaling factor to convert simulation time to hours.
- Return type:
None- Returns:
None
- coconut_tools.plot.create_plot_max_quantities_vs_b0(dict_folder_min, dict_folder_max, input_dir, output_dir, time_limit_index=50, output_filename='max_quantities.pdf')[source]¶
Plot maximum V, B, and density as functions of B0 for solar min and max cases.
- Parameters:
dict_folder_min (dict) – Dictionary mapping zeta -> B0 for solar minimum.
dict_folder_max (dict) – Dictionary mapping zeta -> B0 for solar maximum.
input_dir (str) – Base directory where ‘min_result/plot/’ and ‘max_result/plot/’ subfolders are located.
output_dir (str) – Directory to save the resulting plot.
time_limit_index (int) – Limit index used for zeta in [7, 8, 9] to restrict data range.
output_filename (str) – Name of the PDF output file.
- Return type:
None- Returns:
None
- coconut_tools.plot.m_to_rsun(x)[source]¶
Convert a distance expressed in meters to solar radii.
The conversion assumes 1 astronomical unit equals 215 solar radii, which implies 1 Rsun = 149597870700 / 215 meters.
- Parameters:
x (float) – Distance in meters.
- Returns:
Distance in solar radii.
- Return type:
float
- coconut_tools.plot.plot_boundary_profil(inputdir, outputfile, label_dict, color_map)[source]¶
Plot magnetic and thermodynamic quantities from HDF5 files.
- Parameters:
inputdir (str) – Path to the directory containing the HDF5 data files.
outputfile (str) – Path where the resulting figure will be saved.
label_dict (dict) – Dictionary mapping filenames (str) to legend labels (str).
color_map (dict) – Dictionary mapping labels to their corresponding colors.
Notes
The function expects each HDF5 file to contain datasets: ‘vr’, ‘vlon’, ‘vclt’, ‘br’, ‘blon’, ‘bclt’, ‘density’, ‘temperature’, ‘date’.
Vertical lines and annotations are added when the color is ‘purple’.
- The plot contains four subplots:
Velocity [km/s]
Magnetic field [nT]
Density [m⁻³]
Temperature [K]