module documentation
Regrids a numpy array.
Example of grid definition:
- input_grid : |---^---| |---^---| |---^---| |---^---|
- : |---^---| |---^---| |---^---|
bin_width : |-------|
bin_step : |-----|
- output_grid : |--------^-------| |--------^-------|
- : |--------^-------|
offset : |---|
new_bin_width : |----------------|
new_bin_step : |----------|
"|" = bin edge
"^" = bin centre
- width
- The distance between the start and end of a bin
- step
- The distance between the start of two consencutive bins
- offset
- The distance between the start/end of the new grid and the start/end of the old grid
Function | edges |
Get the bin edges of bins defined by a lower bound, upper bound, steps between bins, and widths of each bin. |
Function | edges |
Get bin edges as a 2d-numpy array of shape (2,N), where the 0th sub-array is the starting point of each bin, and the 1st sub-array is the ending points. |
Function | regrid |
Rebin data from the old bins to a new set of bins, old data is summed into new data bins. Set NANs to zero before summing if you want to treat them that way. |
Variable | _lgr |
Undocumented |
def edges_from_bounds(lbound:
float
, ubound: float
, steps: float
, widths: float
, bins_extend_past_ubound=True) -> np.ndarray
:
¶
Get the bin edges of bins defined by a lower bound, upper bound, steps between bins, and widths of each bin.
- # ARGUMENTS #
- lbound : float
- Lower bound of the range to create bins on.
- ubound : float
- Upper bound of the range to create bins on.
- steps : float
- Size of the steps between the starting edge of each bin.
- widths : float
- Size of the bins, i.e., distance between the starting edge and ending edge of each bin.
- bins_extend_past_ubound : bool = True
- Should the bins be allowed to extend past "ubound" if they could contain values < "ubound". I.e., Could a bin of width = 5, start at ubound-2 and end at ubound+3?
- # RETURNS #
- edges : np.ndarray[2,N]
- A 2D numpy array, "edges[0]" holds the starting edges of each bin, "edges[1]" holds the ending edges of each bin.
Get bin edges as a 2d-numpy array of shape (2,N), where the 0th sub-array is the starting point of each bin, and the 1st sub-array is the ending points.
- # ARGUMENTS #
- midpoints : np.ndarray[N]
- Midpoints of bins to find the edges of.
- fix_edges : bool = True
- If we should account for bin size when working out the 0th and Nth bin edges.
- # RETURNS #
- edges : np.ndarray[2,N]
- A 2D numpy array, "edges[0]" holds the starting edges of each bin, "edges[1]" holds the ending edges of each bin.
def regrid(data:
np.ndarray
, input_bin_edges: np.ndarray
, output_bin_edges: np.ndarray
, axis: int
= 0) -> np.ndarray
:
¶
Rebin data from the old bins to a new set of bins, old data is summed into new data bins. Set NANs to zero before summing if you want to treat them that way.
- # ARGUMENTS #
- data : np.array[...,N,...]
- The data to be re-gridded. Should make sense to add the data together, N is the size of the axis over which data is to be rebinned. Choice of axis is controlled by "axis" argument.
- input_bin_edges : np.array[2,N]
- Edges of the old bins, input_bin_edges[0] are the starts of each bin input_bin_edges[1] are the ends of each bin.
- output_bin_edges : np.array[2,M]
- Edges of the new bins, output_bin_edges[0] are the starts of each bin, output_bin_edges[1] are the ends of each bin.
- axis : int = 0
- Axis to rebin "data" across.
- # RETURNS #
- output_bin_values : np.array[...,M,...]
- Rebinned data values, same shape as "data" except along the rebinned axis.
- n_bins_combined : np.array[M]
- Number of original bins combined into each new bin, fractional bins accounted for.