Plot Utilities

RIFT.plot_utilities.EOSPlotUtilities.eval_eos_list_vs(eos_list, xvar='energy_density', xgrid=None, yvar='pressure', units='cgs', use_monotonic=True)
RIFT.plot_utilities.EOSPlotUtilities.render_eos(eos, xvar='energy_density', yvar='pressure', units='cgs', npts=100, label=None, logscale=True, verbose=False, **kwargs)
RIFT.plot_utilities.EOSPlotUtilities.render_eos_list_quantiles_vs(eos_list, quantile_bounds=None, xvar='energy_density', xgrid=None, yvar='pressure', units='cgs', use_monotonic=True, use_log=True, return_outvals=False, input_outvals=None, show_traces=False, plot_kwargs={}, fill_kwargs={})
RIFT.plot_utilities.EOSPlotUtilities.render_reprimand_tovsequence_list_quantiles_vs(sequence_list, quantile_bounds=None, xvar='radius', ygrid=None, yvar='mass', range_mass='[0.5,2.0]', steps=1000, return_outvals=False, input_outvals=None, percentile_method='use nan percentile', plot_kwargs={}, fill_kwargs={})
RIFT.plot_utilities.TabularEOSPlotUtilities.EOS_data_loader(tabular_eos_file: str, data_label: str = None, verbose: bool = False, save_eos_manager: bool = False) → dict

Load tabular EOS data from a HDF5 file.

Parameters

tabular_eos_filestr

The path to the tabular EOS file. The file should be in the .h5 format. The function will automatically get the data label from the file if the format is ‘LCEHL_EOS_posterior_samples_<data_label>.h5’.

data_labelstr, optional

The label of the tabular EOS data that is loaded. If not provided the label will be generated from the file name automatically.

verbosebool, optional

If True, the function will print information about the progress.

save_eos_managerbool, optional

If True, the function will save the EOSManager object. Default is False.

Returns

EOS_datadict

A dictionary containing the necessary tabular EOS data for plotting functions. The dictionary contains the following keys: - ‘eos_tables’: the tabular EOS data (interpolated by default) - ‘tov_tables’: the TOV data (not interpolated) - ‘eos_names’: the names of the EOS tables - ‘data_label’: the label of the tabular EOS data - ‘eos_manager’: the EOSManager object (only if save_eos_manager is True)

RIFT.plot_utilities.TabularEOSPlotUtilities.LambdaTilderatio_data_gen(posterior_samples: ndarray, EOSManager_Local: EOSSequenceLandry, data_label: str) → dict

This function generates the data for the Lambda tilde ratio plot. This is a ratio of the tidal deformability Lambda tilde to the ordering statistics S. Tidal deformability Lambda tilde is calculated from the individual masses and lambdas of the binary components. The ordering statistics S is calculated from the reference mass of the binary and the EOS table index. This ratio serves as a test for the credibility of the EOS inference ordering statistics S. The data will be generated based on the posterior samples and the EOS tables. The posterior samples should be loaded from the posterior samples file. The user can use the ‘posterior_samples_all’ key from the posterior_data_loader if out_all is set to True in the posterior_data_loader function.

Parameters

posterior_samplesnp.ndarray

The posterior samples. Should be loaded from the posterior samples file. Must contain the following columns: ‘m1’, ‘m2’, ‘mc’, ‘q’, ‘lambda1’, ‘lambda2’, ‘eos_indx’.

EOSManager_LocalEOSManager.EOSSequenceLandry

The EOS manager object. Load the tabular EOS data separately and provide it as an input to avoid loading it multiple times.

data_labelstr

The label for the data. There are no restrictions on this parameter.

Returns

LambdaTilderatio_datadict

The dictionary with the data for the Lambda tilde ratio plot. It will contain the following keys: - ‘q’: the mass ratio of the binary - ‘Lambda_tilde_ratio’: the ratio of the tidal deformability Lambda tilde to the ordering statistics S - ‘data_label’: the label for the data (e.g. ‘PSR+GW+NICER’, ‘PSR’, etc.)

RIFT.plot_utilities.TabularEOSPlotUtilities.LambdaTilderatio_plot(*LambdaTilderatio_data: dict, qlim: tuple = None, ylim: tuple = (0, 2), title: str = None) → None

This function generates a plot of the Lambda tilde ratio vs. mass ratio for the given EOS data.

Parameters

LambdaTilderatio_datanp.ndarray

The data for the Lambda tilde ratio plot. Should be generated using the LambdaTilderatio_data_gen() function.

qlimtuple

The mass ratio limits. Default is None. If None, the limits will be set to (q_min, q_max). If the user provides the limits that do not fit in [0, 1] range, the code will raise a ValueError.

ylimtuple

Y-axis limits. Default is (0, 2).

titlestr

Title of the plot. Default is None. If no title has been provided, the title will be set to generic Lambda tilde ratio vs Mass ratio.

Returns

None

RIFT.plot_utilities.TabularEOSPlotUtilities.generate_posterior_eos_param_grid(posteriors_eos: ndarray, eos_tables: dict, eos_names: list, param: str = 'pressure', verbose: bool = False) → ndarray

This function generates a grid of the format (N, M), where N is the number of points in the EOS table, and M is the number of posterior samples. Each column of the grid will be the EOS table for a given posterior sample. Each row will be the values of the parameter of interest (e.g. pressure, energy density, etc.) for a given point of the parameter used as the x-axis of the plot (and the interpolation base) respectively. By default, the parameter of interest is the pressure and the interpolation base is the baryon density. Thus, each row of the grid will correspond to the pressure values at each posterior sample for a given baryon density value.

Parameters

posteriors_eosnp.ndarray

Array of EOS table indices for each posterior sample. Should be the ‘eos_indx’ column of the posterior samples.

eos_tablesdict

Dictionary of EOS tables. The keys should be the EOS names and the values should be the EOS tables. Should be generated using the EOSManager.interpolate_eos_tables() method. IMPORTANT! The EOS parameter used as the x-axis of the plot should be the same for all EOS tables. If this is not true, the percentiles will not make any sense!

eos_nameslist

List of EOS names. Should be generated using the EOSManager.eos_names attribute.

paramstr, optional

Parameter of interest. The default is ‘pressure’. Another options are ‘energy_density’ and ‘baryon_density’.

verbosebool, optional

If True, print the progress of the function. The default is False.

Returns

posteriors_eos_param_gridnp.ndarray

Grid of the format (N, M) where N is the number of points in the EOS table and M is the number of posterior samples.

Raises

ValueError

If the parameter of interest is not present in the EOS tables.

ValueError

If the number of points in the EOS table for any EOS is different from the number of points in the EOS tables for other EOSs.

This function links the EOS data to the posterior data and outputs a dictionary with the linked data suited for the corresponding plot type.

Parameters

eos_datadict

Dictionary containing the EOS data. Should be generated using the function EOS_data_loader. See TabularEOSPlotUtilities.EOS_data_loader for more information on the format of the dictionary.

plot_typestr

String specifying the type of plot to be generated. Currently supported options are: ‘pressure_density’ and ‘mass_radius’.

posterior_datadict

Dictionary containing the posterior data. Should be generated using the function posterior_data_loader. See TabularEOSPlotUtilities.posterior_data_loader for more information on the format of the dictionary. If posterior_data is not provided, the function will generate prior data from the EOS data.

Returns

plot_data_gen_dict: dict

Dictionary containing the linked EOS and posterior data suited for the corresponding plot type. The format will fit the input requirements of the plotting functions in TabularEOSPlotUtilities.

RIFT.plot_utilities.TabularEOSPlotUtilities.mass_radius_plot(*mass_radius_data: dict, xlim: tuple = (8, 17), ylim: tuple = (1, 1.9), title: str = None) → None

This function generates a plot of mass vs. radius for the given EOS data.

Parameters:

mass_radius_datadict

A dictionary with the following structure:

{‘x_rad_perc’: np.ndarray,

‘y_mass_grid’: np.ndarray, ‘posterior’: bool, ‘perc_values’: list, ‘data_label’: str, ‘custom_color’: str}

x_rad_perc : np.ndarray - the percentiles of the radius for each mass point IMPORTANT! Make sure that the percentiles were calculated of the radius grids interpolated over the same y_mass_grid values. Must be of the format (2, N), where N is the number of points in the y_mass_grid. x_rad_perc[0, :] is the lower percentile, x_rad_perc[1, :] is the upper percentile.

y_mass_grid : np.ndarray - the grid of mass values. If the TOV tables were interpolated, one can use the M values from any of the interpolated tables. (tov_interp_tables[‘eos_0’][‘M’])

posterior : bool - True if the data is for the posterior samples, False if it is for the prior samples.

perc_values : list - the percentiles used in x_rad_perc. Default is [5, 95].

data_label : str - the label for the data (e.g. ‘PSR+GW+NICER’, ‘PSR’, etc.). There are no restrictions on this parameter.

custom_color : color for the percentiles provided in this data entry. If none is provided, the default colormap is used.

xlimtuple

X-axis limits. Default is (8, 17). Corresponds the the km units.

ylimtuple

Y-axis limits. Default is (1, 1.9). Corresponds the the solar mass units.

title: str

Title of the plot. Default is None. If no title has been provided, the title will be set to generic Mass vs Radius.

Returns:

None

RIFT.plot_utilities.TabularEOSPlotUtilities.mass_radius_plot_data_gen(tov_tables: dict, posteriors_eos: ndarray, eos_names: list, data_label: str, posterior: bool = True, tov_interp: bool = False, perc_values: list = [5, 95], custom_color: str = None) → dict

This function generates the data dictionary for the mass-radius plot

Parameters

tov_tablesdict

The dictionary of TOV tables. Should be generated using the EOSManager.tov_tables attribute.

posteriors_eosnp.ndarray

The array of posterior samples. Should be the ‘eos_indx’ column from the posterior samples file. If the user wants to generate the data for the prior samples, np.arange(int(len(eos_names))) should be used.

eos_nameslist

The list of EOS names. Should be generated using the EOSManager.eos_names attribute.

data_labelstr

The label for the data (e.g. ‘PSR+GW+NICER’, ‘PSR’, etc.). There are no restrictions on this parameter.

posteriorbool

True if the data is for the posterior samples, False if it is for the prior samples. Default is True.

tov_interpbool

True if the inserted TOV tables are already interpolated. Default is False. If False, the code will interpolate the tables using the default settings (linear interpolation, 500 points between 1 and 1.9 Msun, extremum breakpoint at 1.9 Msun). See the tov_tables_interpolator() function documentation for more details.

perc_valueslist

The percentiles used. Default is [5, 95]. NOTE! These are percentile values, not quantile values. Should be in the range [0, 100]. The code will raise warning if the values are in [0, 1] range, but will still run, please be aware of this.

custom_colorstr

The color for the plot. If None, the color will be chosen automatically. Default is None.

Returns

mass_radius_datadict

The dictionary with the data for the mass-radius plot.

RIFT.plot_utilities.TabularEOSPlotUtilities.posterior_data_loader(posterior_file: str, data_label: str = None, verbose: bool = False, out_all: bool = False) → dict

Load the posterior data from a .dat file

Parameters

posterior_filestr

The path to the posterior samples file. The file should be in the .dat format. The function will automatically get the data label from the file if the format is ‘posterior_samples_<data_label>.dat’.

data_labelstr

The label of the data. If not provided, the function will try to get it from the file name.

verbosebool

If True, the function will print information about the progress.

out_allbool

If True, the function will return all the posterior samples. If False, the function will return only the EOS indices posteriors.

Returns

posterior_datadict

A dictionary containing the posterior samples. The dictionary contains the following keys: - ‘posterior_samples_eos’ : The posterior samples for the EOS indices. - ‘data_label’ : The label of the data. - ‘posterior_samples_all’ : The posterior samples for all the parameters. (Only if out_all is True)

RIFT.plot_utilities.TabularEOSPlotUtilities.posterior_hist_data_gen(posteriors_eos: ndarray, EOSManager_Local: EOSSequenceLandry, data_label: str, m_ref: float = 1.4) → dict

This function generates the data for the posterior histogram plots. It is designed as an auxiliary function to the posterior_hist_plot function and should be used as an input to that function. The user has to provide the posterior samples in terms of the EOS table index, the EOSManager object, the data label, and the reference mass (default is 1.4 M_sun).

Parameters

posteriors_eos: np.ndarray

The posterior samples in terms of the EOS table index.

EOSManager_Local: EOSManager.EOSSequenceLandry

The EOSManager object. Load the tabular EOS data separately and provide it as an input to avoid loading it multiple times.

data_label: str

The data label for the plot.

m_ref: float

The reference mass for the EOS. Default is 1.4 M_sun. The code will use functions R_of_m_indx and lambda_of_m_indx from the EOSManager object to calculate the radius and tidal deformability for a given mass m_ref. Should be in range [1.0, 2.5]

Returns

posterior_hist_data: dict

A dictionary containing the data for the posterior histogram plot. The dictionary contains the following keys: - ‘R’: the radius data of each of the posterior samples - ‘Lambda_’: the tidal deformability data of each of the posterior samples - ‘R_mean_std’: the mean and standard deviation of radius of the posterior samples (tuple) of format (mean, std) - ‘Lambda_mean_std’: the mean and standard deviation of tidal deformability of the posterior samples (tuple) of format (mean, std) - ‘data_label’: the data label for the plot - ‘m_ref’: the reference mass used for the EOS calculations

Raises

ValueError

If the reference mass is not in range [1.0, 2.5]

RIFT.plot_utilities.TabularEOSPlotUtilities.posterior_hist_plot(*posterior_hist_data: dict, r_lim: tuple = (8, 17), lambda_lim: tuple = (0, 1000), title: str = None) → None

This function generates the posterior histogram plots.

Parameters

posterior_hist_data: dict

The data for the posterior histogram plot. The user can provide multiple dictionaries as input, each containing the data for a different posterior sample. The dictionaries should be generated using the posterior_hist_data_gen function and should contain the following keys: - ‘R’: the radius data of each of the posterior samples - ‘Lambda_’: the tidal deformability data of each of the posterior samples - ‘R_mean_std’: the mean and standard deviation of radius of the posterior samples (tuple) of format (mean, std) - ‘Lambda_mean_std’: the mean and standard deviation of tidal deformability of the posterior samples (tuple) of format (mean, std) - ‘data_label’: the data label for the plot - ‘m_ref’: the reference mass used for the EOS calculations

r_lim: tuple, optional

The limits for the radius axis. Default is (8, 17).

lambda_lim: tuple, optional

The limits for the tidal deformability axis. Default is (0, 1000).

title: str, optional

The title for the plots. Default is None.

Returns

None

Raises

ValueError

If the reference masses for the different data entries are not the same.

RIFT.plot_utilities.TabularEOSPlotUtilities.pressure_density_plot(*density_pressure_data: dict, use_energy_dens: bool = False, units: str = 'cgs', xlim: tuple = (100000000000000.0, 1e+16), ylim: tuple = (1e+32, 1e+38), title: str = None) → None

This function generates a plot of pressure vs. baryon density for the given EOS data.

Parameters

density_pressure_datadict

A dictionary with the following structure:

{‘x_dens_grid’: np.ndarray,

‘y_pres_perc’: np.ndarray, ‘posterior’: bool, ‘perc_values’: list, ‘data_label’: str, ‘custom_color’: str}

x_dens_grid: np.ndarray - grid of baryon densities. If the EOS tables were interpolated, one can use the baryon_density column of any EOS table (eos_tables[‘eos_0’][‘baryon_density’]);

y_pres_perc: np.ndarray - percentiles of pressure values for each density point. IMPORTANT! Make sure that the percentiles were calculated of the pressure grids interpolated over the same x_dens_grid values. Must be of the format (2, N), where N is the number of points in the x_dens_grid. y_pres_perc[0, :] is the lower percentile, y_pres_perc[1, :] is the upper percentile.

posterior: bool - if True, the data is considered to be posterior samples. If False, the data is considered to be prior samples.

perc_values: list of 2 percentiles corresponding to the y_pres_perc array. If none is provided, the default values are [5, 95].

data_label: str - label for the data used, i. e. ‘PSR+GW+NICER’, ‘PSR+GW’, etc.

custom_color: color for the percentiles provided in this data entry. If none is provided, the default colormap is used.

energy_dens_boolbool

If you are using energy density instead of baryon density, set this to True. Default is False.

unitsstr

Units of the data. Default is ‘cgs’.

xlimtuple

X-axis limits. Default is (1e14, 1e16). Corresponds the the CGS units.

ylimtuple

Y-axis limits. Default is (1e32, 1e38). Corresponds the the CGS units.

title: str

Title of the plot. Default is None. If no title has been provided, the title will be set to generic Pressure vs Baryon Density.

Returns

None

RIFT.plot_utilities.TabularEOSPlotUtilities.pressure_density_plot_data_gen(eos_tables: dict, posteriors_eos: ndarray, eos_names: list, data_label: str, posterior: bool = True, perc_values: list = [5, 95], custom_color: str = None, use_energy_dens: bool = False) → dict

This function generates the data dictionary for the pressure-density plot. It is designed as an auxiliary function for the pressure_density_plot() function, and should be used as input for that function.

The dictionary will contain the following keys: - ‘x_dens_grid’: the grid of baryon densities for the x-axis - ‘y_pres_perc’: percentiles of the pressure for each baryon density. This will be a np.ndarray of shape (2, N), where N is the number of points in the EOS table. - ‘posterior’: True if the data is for the posterior samples, False if it is for the prior samples. - ‘perc_values’: the percentiles used. Default is [5, 95]. - ‘data_label’: the label for the data (e.g. ‘PSR+GW+NICER’, ‘PSR’, etc.) - ‘custom_color’: the color for the plot. If None, the color will be chosen automatically.

The function will return the data dictionary.

Parameters

eos_tablesdict

The dictionary of EOS tables. Should be generated using the EOSManager.interpolate_eos_tables() method.

posteriors_eosnp.ndarray

The array of posterior samples. Should be the ‘eos_indx’ column from the posterior samples file. If the user wants to generate the data for the prior samples, np.arange(int(len(eos_names))) should be used.

eos_nameslist

The list of EOS names. Should be generated using the EOSManager.eos_names attribute.

data_labelstr

The label for the data (e.g. ‘PSR+GW+NICER’, ‘PSR’, etc.). There are no restrictions on this parameter.

posteriorbool, optional

True if the data is for the posterior samples, False if it is for the prior samples. Default is True.

perc_valueslist, optional

The percentiles used. Default is [5, 95]. NOTE! These are percentile values, not quantile values. Should be in the range [0, 100]. The code will raise warning if the values are in [0, 1] range, but will still run, please be aware of this.

custom_colorstr, optional

The color for the plot. If None, the color will be chosen automatically. Default is None.

use_energy_densbool, optional

If True, the energy density will be used as the x-axis parameter instead of the baryon density. Default is False.

Returns

density_pressure_datadict

The dictionary with the data for the pressure-density plot.

RIFT.plot_utilities.TabularEOSPlotUtilities.tov_tables_interpolator(tov_tables: dict, m_interp_range: list = [1, 1.9], n_points: int = 500, m_extremum_breakpoint: float = 1.9, verbose: bool = False) → dict

This function interpolates inserted TOV tables and removes all the point from each table if the change in gradient occurs after a breakpoint (m_extremum_breakpoint). This is done to prevent the double counting in percentiles.

Parameters

tov_tablesdict

The dictionary of TOV tables. Should be generated using the EOSManager.tov_tables attribute.

m_interp_rangelist

The range of the interpolated mass values. Default is [1, 1.9].

n_pointsint

The number of points in the interpolated mass values. Default is 500.

m_extremum_breakpointfloat

The breakpoint value for the extremum in the mass-radius curve. Default is 1.9. The value 1.9 was established from the previous analysis of the TOV tables. Many EOS have extremums below 1 Msun, but they do not produce double M-R curves in the region 1 - 1.9 Msun. EOS that have extremums above the 1.9 Msun (in our previous analysis) would often have the M-R curve that returns to the region 1 - 1.9 Msun. This would cause the double counting of the R values in the percentiles. Therefore, we delete the points from the tov_tables after the extremum if it is above 1.9 Msun. Only a few EOS (~20 of 10000) have extremums in the region 1 - 1.9 Msun, and their impact on the percentiles is negligible. NOTE! This value may be different for different EOS tables. Please analyze your EOS tables before setting this parameter. See an example of the analysis in the notebook: https://github.com/oshaughn/RIT-matters/tree/master/communications/20230613-ROSAV-TabularEOSInference/plotting/EOS_plots.ipynb

verbosebool

If True, the function will print the progress of the interpolation. Default is False.

Returns

tov_interp_tablesdict

The dictionary of interpolated TOV tables.