tsadar.utils.plotting.plotters#
Functions
|
Creates a custom matplotlib colormap based on the 'jet' colormap with a white segment at the lower end. |
|
TODO Creates a set of plots, up to 8, comparing the best and worst fits to the data. |
|
Formats and saves the final fitted parameters and distribution function. |
|
Creates a set of plots, up to 8, comparing the best and worst fits to the data. |
|
Plots and then saves a set of 2 color plots (each 2D). |
|
Plots lineout comparing the fits to the data, but designed for angular data. |
|
Plots the resulting spectrum from the fit vs the raw data for angularly resolved data. |
|
Plots the fitted or used distribution function. |
|
Plots the fitted parameters as a function of lineout. |
|
Plots histograms of the raw loss and reduced loss. |
|
Plots the resulting spectrum from the fit vs the raw data for EPW and IAW data. |
|
Formats and saves the uncertainty values for the distribution function. |
|
Formats and saves the uncertainty values for the fitted parameters. |
- tsadar.utils.plotting.plotters.get_final_params(config, best_weights, all_axes, td)Source#
Formats and saves the final fitted parameters and distribution function. This function processes the fitted parameters and distribution functions for all species, formats them into pandas DataFrames, and saves them as CSV files in a specified temporary directory. It handles different parameter structures depending on the species and configuration, and combines the results into a single output dictionary. :param config: Configuration dictionary created from the input decks. :type config: dict :param best_weights: Dictionary containing all the fitted parameters for all the species. :type best_weights: dict :param all_axes: Dictionary with calibrated axes and axes labels. :type all_axes: dict :param td: Temporary directory path where output files will be saved. :type td: str
- Returns:
dict – Dictionary containing all the fitted parameters and distribution function data. The keys are a combination of parameter and species names, and the values are pandas Series or arrays. The output merges the distribution function dictionary with the fitted parameter dictionary.
- tsadar.utils.plotting.plotters.plot_final_params(config, all_params, sigmas_ds, td)Source#
Plots the fitted parameters as a function of lineout. These plots include a blue uncertainty region from the hessian and a red uncertainty region from the moving average. The plots are saved to files but nothing is returned.
- Parameters:
config – configuration dictionary created from the input decks
all_params – dictionary containing all the fitted parameters for all the species, same as the best_params from the function get_final_params
sigmas_ds – dictionary with uncertainty values for each of the fitted parameters calculated using the hessian
td – temporary directory that will be uploaded to mlflow
- Returns:
None – The function saves the plots to a temporary directory and logs them to MLflow.
- tsadar.utils.plotting.plotters.plot_loss_hist(config, losses_init, losses, reduced_points, td)Source#
Plots histograms of the raw loss and reduced loss. Each histogram contains 2 data sets, blue for before refitting and orange for after refitting. The losses and reduced losses are saved to file as well. Note: A fit metric of chi-squared is used and the reduced metric is chi-squared per degree of freedom but this will not necessarily be near 1 since Thomson scattering often does not conform to chi-squared statistics.
With the update of losses to loss/point this may be reduced to just “reduced losses”
- Parameters:
config – configuration dictionary created from the input decks
losses – array of losses with one value per lineout
all_params – dictionary containing all the fitted parameters for all the species, same as the best_params from the function get_final_params
used_points – int with the number of wavelength points used in each fit, calculated at the same time as loss
td – temporary directory that will be uploaded to mlflow
- Returns:
red_losses – array of the losses per degree of freedom for each lineout
- tsadar.utils.plotting.plotters.plot_dist(config, final_params, sigma_fe, td)Source#
Plots the fitted or used distribution function. For 1D distributions plots are does as line plots verse the 1D velocity. For 2D distributions a surface plot is shown as a function of the 2 velocities and contours are projected onto each plane. In both cases the distribution is plotted in linear spacing, log base 10 spacing, and log base e.
- Parameters:
config – configuration dictionary created from the input decks
final_params – dictionary containing the distribution function as produced by the function get_final_params
sigma_fe – dictionary with uncertainty values for the distribution function as produced by the function save_sigmas_fe
td – temporary directory that will be uploaded to mlflow
Returns:
- tsadar.utils.plotting.plotters.save_sigmas_fe(all_params, best_weights_std, sigmas, td)Source#
Formats and saves the uncertainty values for the distribution function.
- Know Issues:
THis code has not been updated to reflect the changes for multi-species
- Parameters:
all_params – dictionary containing the distribution function as produced by the function get_final_params
best_weights_std – standard deviations of the fitted parameters over repeated fitting
sigmas – uncertainty values for the distribution function
td – temporary directory that will be uploaded to mlflow
- Returns:
sigma_fe – uncertainty values for the distribution function restructured as a DataArray.
- tsadar.utils.plotting.plotters.save_sigmas_params(config, all_params, sigmas, all_axes, td)Source#
Formats and saves the uncertainty values for the fitted parameters.
- Parameters:
config – configuration dictionary created from the input decks
all_params – dictionary containing the distribution function as produced by the function get_final_params
sigmas – uncertainty values for the fitted parameters
all_axes – dictionary with calibrated axes and axes labels
td – temporary directory that will be uploaded to mlflow
- Returns:
sigma_ds – uncertainty values for each of the fitted parameters restructured as a DataArray.
- tsadar.utils.plotting.plotters.plot_data_angular(config, fits, all_data, all_axes, td)Source#
Plots the resulting spectrum from the fit vs the raw data for angularly resolved data. The data and fit will be plotted over the region used in the analysis. The function only creates the grids and structures the data before calling the general 2D plotting code.
- Parameters:
config – configuration dictionary created from the input decks
fits – dictionary containing the fitted spectra in a field called ‘ele’
all_data – dictionary containing the raw or processed data must have a field called ‘e_data’ which contains the angular EPW data
all_axes – dictionary with calibrated axes and axes labels
td – temporary directory that will be uploaded to mlflow
- Returns:
savedata – dictionary containing the data and fits as DataArrays
- tsadar.utils.plotting.plotters.plot_ts_data(config, fits, all_data, all_axes, td)Source#
Plots the resulting spectrum from the fit vs the raw data for EPW and IAW data. The data and fit will be plotted over the region used in the analysis. The function only creates the grids and structures the data before calling the general 2D plotting code.
- Parameters:
config – configuration dictionary created from the input decks
fits – dictionary containing the fitted spectra
all_data – dictionary containing the raw or processed data
all_axes – dictionary with calibrated axes and axes labels
td – temporary directory that will be uploaded to mlflow
Returns:
- tsadar.utils.plotting.plotters.plot_2D_data_vs_fit(config, x, y, data, fit, td, xlabel='Time (ps)', ylabel='Wavelength (nm)', name='fit_and_data.png')Source#
Plots and then saves a set of 2 color plots (each 2D). Mainly used to plot data vs fit images.
- Parameters:
config – configuration dictionary created from the input decks
x – x-axis coordinates from meshgrid
y – y-axis coordinates from meshgrid
data – data array
fit – fit array
td – temporary directory that will be uploaded to mlflow
xlabel – label to be used for the x-axis
ylabel – label to be used for the y-axis
name – name under which the file will be saved
Returns:
- tsadar.utils.plotting.plotters.plot_ang_lineouts(used_points, sqdevs, losses, all_params, all_axes, savedata, td)Source#
Plots lineout comparing the fits to the data, but designed for angular data. The value of the fit metric chi^2 per point is plotted beneath the data and fit.
- Parameters:
used_points – numer of points used in the calculation of the fit metric
sqdevs – chi^2 per point. Must be the same shape as data
losses – array of losses with one value per lineout
all_params – dictionary containing all the fitted parameters for all the species, same as the best_params from the function get_final_params
all_axes – dictionary with the calibrated axes and axes labels
savedata – dictionary with data and fitted spectra
td – temporary directory that will be uploaded to mlflow
Returns:
- tsadar.utils.plotting.plotters.model_v_actual(config, all_data, all_axes, fits, losses, red_losses, sqdevs, td)Source#
Creates a set of plots, up to 8, comparing the best and worst fits to the data. THis function does the sorting and the lineout_plot code is used to do the plotting.
- Parameters:
config – configuration dictionary created from the input decks
all_data – dictionary containing the raw or processed data
fits – dictionary containing the fitted spectra
losses – array of losses with one value per lineout
red_losses – array of the losses per lineout divided by the number of degrees of freedom
sqdevs – chi^2 per point. Must be the same shape as data
td – temporary directory that will be uploaded to mlflow
Returns:
- tsadar.utils.plotting.plotters.detailed_lineouts(config, all_data, all_axes, fits, losses, red_losses, sqdevs, td)Source#
TODO Creates a set of plots, up to 8, comparing the best and worst fits to the data. THis function does the sorting and the lineout_plot code is used to do the plotting.
- Parameters:
config – configuration dictionary created from the input decks
all_data – dictionary containing the raw or processed data
fits – dictionary containing the fitted spectra
losses – array of losses with one value per lineout
red_losses – array of the losses per lineout divided by the number of degrees of freedom
sqdevs – chi^2 per point. Must be the same shape as data
td – temporary directory that will be uploaded to mlflow
Returns:
- tsadar.utils.plotting.plotters.TScmap()Source#
Creates a custom matplotlib colormap based on the ‘jet’ colormap with a white segment at the lower end. The resulting colormap starts with a smooth transition from white to the first color of the ‘jet’ colormap, followed by the standard ‘jet’ colors. This is useful for visualizations where zero or low values should be represented as white. :returns: matplotlib.colors.ListedColormap – The custom colormap with a white-to-jet transition at the lower end.