arcanumpy.histogram_plots module

class arcanumpy.histogram_plots.hist_plots[source]

Bases: object

Class to plot histograms and brazil plots for the given data and thresholds respectively. It also contains a method to calculate the probability density function of a given array. Name of the functions contain the following: - calc_pdf: calculates the probability density function of a given array - joint_pdf: calculates the joint probability density function of two given arrays - brazil_plot_with_threshold: plots the brazil plot for the given data with thresholds - get_thresh: gets the threshold values for the given data - compute_rr: computes the threshold values for the given data

__init__()[source]
compute_rr(bb=None, gamma=-2, instab='cycl')[source]

Threshold calculation based on Verscharen and Chandran 2018

get_thresh(instab, gamma, verbose=False, parnt_drct=None, drct=None, res='hi-res')[source]
brazil_plot_with_threshold(bp, rp, xmin=None, xmax=None, ymin=None, ymax=None, bins=None, nbins=None, cmin=None, vmin=None, vmax=None, g_lim_1=None, g_lim_2=None, g_lim_3=None, g_lim_4=None, dir_par=None, dir_per=None, res='hi-res', loc=1, sim=None, density=False, plot_thresh=False, plot_ver_thresh=None, save_fig=True, plot_show=False, pcolormesh_kwargs=None)[source]

The code to plot the brazil plot for any kind of data. The scale of both x- and y-axes is “log”, this can be changed in the line which 65 or so where “bins” is defined and setting both scales of x- and y-axes to linear instead of log.

bp : ion parallel beta (type:array) rp : ion anisotropy (type:array) xmin : minimum value of x-axis (type:float) xmax : maximum value of x-axis (type:float) ymin : minimum value of y-axis (type:float) ymax : maximum value of y-axis (type:float) bins : x and y bins (type:array) nbins : number of bins in each direction, defaults to 50 (type:float) cmin : minimum value in a bin to be plotted, defaults to 10 (type:float) vmin : minimum value of colorbar vmax : maximum value fo colorbar g_lim_1 to 4 : value of instability thresholds to be plotted

1 => cyclotron instability 2 => parallel firehose instability 3 => mirror instability 4 => oblique firehose instability

dir_par : directory for parallel instabilities dir_per : directory for oblique instabilities res : resolution of thresholds to be plotted, defaults to “hi-res”, other option is “lo-res” loc : location of legend sim : type of data, this is used while saving figure density : whether to plot probabilty density or somple histogram, defaults to false plot_thresh : whether to plot thresholds, defaults to false save_fig : to save the figure or not, defaults to true plot_show : display the plot, defaults to false pcolormesh_kwargs : additional arguments to be passed to pcolormesh

Returns:

  • ex (x-axis bins)

  • ey (y-axis bins)

  • hist (histogram of the data)

  • n_hist (normalized histogram of the data)

Examples

>>> import numpy as np
>>> from arcanumpy.histogram_plots import hist_plots
>>> bp = np.random.lognormal(mean=0, sigma=2, size=10000)
>>> bp = np.clip(bp, 1e-3, 1e2)
>>> rp = np.random.lognormal(mean=0, sigma=2, size=10000)
>>> rp = np.clip(rp, 1e-1, 1e1)
>>> ex, ey, hist, n_hist = hist_plots().brazil_plot_with_threshold(bp=bp, rp=rp, xmin=1e-3, xmax=1e2, ymin=1e-1, ymax=1e1, cmin=0, g_lim_1=2, g_lim_2=2, g_lim_3=2, g_lim_4=2, nbins=100, dir_par="0.001_4.000_0.000_00.00", dir_per="0.001_4.000_0.000", res="hi-res", loc=1, plot_thresh=True, plot_ver_thresh=False, save_fig=True, sim="wnd", plot_show=False, density=True, pcolormesh_kwargs={"norm": "log", "cmap": "cividis_r"})
get_brzl_hist(x=None, y=None, z=[], xlim=None, ylim=None, bins=50, c_min=5)[source]
brazil_plot_multiple(data=None, ex=None, ey=None, xmin=None, xmax=None, ymin=None, ymax=None, bins=None, nbins=None, cmin=None, cmax=None, norm=None, cmap=None, vmin=None, vmax=None, spc=None, save_fig=False, plot_show=False)[source]
calc_pdf(input_array, weight=100, inc=None, Normalize=False, plot_pdf=False, save_fig=False, fig_name=None)[source]

Calculate the probability density function of a given array

Parameters:
  • input_array (np.array) – The array for which the pdf is to be calculated

  • weight (int, optional) – The number of points in each bin, by default 100

  • inc (int, optional) – The number of points to be shifted, by default None

  • Normalize (bool, optional) – Normalize the input array by the rms value, by default False

  • plot_pdf (bool, optional) – Plot the pdf, by default False

  • save_fig (bool, optional) – Save the figure, by default False

  • fig_name (str, optional) – The name of the figure, by default None

Returns:

  • np.array – The bins of the pdf

  • np.array – The pdf of the input array

Examples

>>> import numpy as np
>>> from arcanumpy.histogram_plots import hist_plots
>>> x = np.random.rand(100000)
>>> bins, x_pdf = hist_plots().calc_pdf(input_array=x, inc=5000, Normalize=False, weight=100, plot_pdf=True, save_fig=True)
joint_pdf(x=None, y=None, bins=100, x_label=None, y_label=None, save_fig=False, fig_name=None, joint_pdf_kwargs=None, imshow_kwargs=None)[source]

Calculate the joint probability density function of two given arrays

Parameters:
  • x (np.array) – The first array for which the pdf is to be calculated

  • y (np.array) – The second array for which the pdf is to be calculated

  • bins (int, optional) – The number of bins in the histogram, by default 100

  • x_label (str, optional) – The label of the x-axis, by default None

  • y_label (str, optional) – The label of the y-axis, by default None

  • save_fig (bool, optional) – Save the figure, by default False

  • fig_name (str, optional) – The name of the figure, by default None

  • joint_pdf_kwargs (dict, optional) – Additional arguments to be passed to the joint pdf plot, by default None. These keyword arguments are passed to the plt.hist2d function

Returns:

  • np.array – The histogram of the joint pdf

  • np.array – The x data

  • np.array – The y data

Examples

>>> import numpy as np
>>> from arcanumpy.histogram_plots import hist_plots
>>> x = np.random.lognormal(mean=0, sigma=2, size=100000)
>>> x = np.clip(x, 1e-3, 1e2)
>>> y = np.random.lognormal(mean=0, sigma=2, size=100000)
>>> y = np.clip(y, 1e-3, 1e2)
>>> hst, x_s, y_s = hist_plots().joint_pdf(x=x, y=y, bins=100, save_fig=True, joint_pdf_kwargs={ "bins": 1000, "cmap": "cividis_r","norm": "log",}, imshow_kwargs={
"cmap": "Spectral", "norm": "log", "origin": "lower",},)
kde_plots(x_data=None, y_data=None, x_label=None, y_label=None, save_fig=False, fig_name=None, sea_kwargs=None)[source]

The code to plot the kernel density estimate plot for any kind of data. The scale of both x- and y-axes is “linear”, this can be changed in the line which 65 or so where “bins” is defined and setting both scales of x- and y-axes to log instead of linear.

Parameters:
  • x_data (np.array) – The x data for the kde plot

  • y_data (np.array) – The y data for the kde plot

  • x_label (str) – The label for the x-axis

  • y_label (str) – The label for the y-axis

  • save_fig (bool) – Whether to save the figure or not

  • sea_kwargs (dict) – Additional arguments to be passed to the seaborn jointplot function. These keyword arguments are passed to the sns.jointplot function in the seaborn library

Returns:

The seaborn jointplot object

Return type:

sns.axisgrid.JointGrid

Examples

>>> import numpy as np
>>> from arcanumpy.histogram_plots import hist_plots
>>> x = np.random.lognormal(mean=0, sigma=2, size=10000)
>>> x = np.clip(x, 1e-3, 1e2)
>>> y = np.random.lognormal(mean=0, sigma=2, size=10000)
>>> y = np.clip(y, 1e-1, 1e1)
>>> hist_plots().kde_plots(x_data=x, y_data=y, save_fig=True, sea_kwargs={ "kind": "kde", "cbar": True, "thresh": 0.05, "fill": True, "levels": 10, "log_scale": True, "hue_norm": "log", "cmap": "Blues", "height": 6, "ratio": 8, "space": 0.01, "xlim": (1e-3, 1e2), "ylim": (1e-3, 1e2), },
    )
__dict__ = mappingproxy({'__module__': 'arcanumpy.histogram_plots', '__doc__': '\n    Class to plot histograms and brazil plots for the given data and thresholds respectively.\n    It also contains a method to calculate the probability density function of a given array.\n    Name of the functions contain the following:\n    - calc_pdf: calculates the probability density function of a given array\n    - joint_pdf: calculates the joint probability density function of two given arrays\n    - brazil_plot_with_threshold: plots the brazil plot for the given data with thresholds\n    - get_thresh: gets the threshold values for the given data\n    - compute_rr: computes the threshold values for the given data\n    ', '__init__': <function hist_plots.__init__>, 'compute_rr': <function hist_plots.compute_rr>, 'get_thresh': <function hist_plots.get_thresh>, 'brazil_plot_with_threshold': <function hist_plots.brazil_plot_with_threshold>, 'get_brzl_hist': <function hist_plots.get_brzl_hist>, 'brazil_plot_multiple': <function hist_plots.brazil_plot_multiple>, 'calc_pdf': <function hist_plots.calc_pdf>, 'joint_pdf': <function hist_plots.joint_pdf>, 'kde_plots': <function hist_plots.kde_plots>, '__dict__': <attribute '__dict__' of 'hist_plots' objects>, '__weakref__': <attribute '__weakref__' of 'hist_plots' objects>, '__annotations__': {}})
__module__ = 'arcanumpy.histogram_plots'