Utils
utils
pooling_2d
pooling_2d(
input_array: ndarray,
kernel_size: int = 4,
stride: int = 4,
padding: Union[int, Tuple[int, int]] = 0,
stat: Callable = nanmedian,
) -> ndarray
Performs 2D pooling on the input array with optional zero padding.
Parameters:
-
input_array
(ndarray
) –A 2D numpy array representing the input data.
-
kernel_size
(int
, default:4
) –The size of the pooling kernel (square), by default 4. Must be positive.
-
stride
(int
, default:4
) –The stride of the pooling operation, by default 4. Must be positive.
-
padding
(Union[int, Tuple[int, int]]
, default:0
) –Padding to be added to the input array before pooling. - If an int
p
: applies symmetric padding ofp
zeros.p
rows of zeros are added to the top andp
to the bottom.p
columns of zeros are added to the left andp
to the right. - If a tuple(p_h, p_w)
: appliesp_h
rows of zeros to the top andp_h
to the bottom, andp_w
columns of zeros to the left andp_w
to the right. Padding values must be non-negative. Default is 0 (no padding). -
stat
(Callable
, default:nanmedian
) –The aggregation function to use for pooling (e.g., np.mean, np.max, np.nanmedian), by default np.nanmedian.
Returns:
-
ndarray
–A 2D numpy array representing the pooled output.
fill_nans_interp
Replace nan values in a data cube using plynomial interpolation
Parameters:
-
cube
(ndarray
) –Data cube with nan values to be interpolated
-
deg
(int
, default:3
) –Degree of polynomial, defualt is 3.
Returns:
-
ndarray
–Interpolated data cube without nan values
plot_img
plot_img(
img: ndarray,
scol_2d: Optional[ndarray] = None,
srow_2d: Optional[ndarray] = None,
plot_type: str = "img",
extent: Optional[Tuple] = None,
cbar: bool = True,
ax: Optional[Axes] = None,
title: str = "",
vmin: Optional[float] = None,
vmax: Optional[float] = None,
cnorm: Optional[Normalize] = None,
bar_label: str = "Flux [e-/s]",
) -> Axes
Plots an image with optional scatter points and colorbar.
Parameters:
-
img
(ndarray
) –The 2D image data to be plotted.
-
scol_2d
(Optional[ndarray]
, default:None
) –The column coordinates of scatter points, by default None.
-
srow_2d
(Optional[ndarray]
, default:None
) –The row coordinates of scatter points, by default None.
-
plot_type
(str
, default:'img'
) –The type of plot to create ('img' or 'scatter'), by default "img".
-
extent
(Optional[Tuple]
, default:None
) –The extent of the image (left, right, bottom, top), by default None.
-
cbar
(bool
, default:True
) –Whether to display a colorbar, by default True.
-
ax
(Optional[Axes]
, default:None
) –The matplotlib Axes object to plot on, by default None. If None, a new figure and axes are created.
-
title
(str
, default:''
) –The title of the plot, by default "".
-
vmin
(Optional[float]
, default:None
) –The minimum value for the colormap, by default None.
-
vmax
(Optional[float]
, default:None
) –The maximum value for the colormap, by default None.
-
cnorm
(Optional[Normalize]
, default:None
) –Custom color normalization, by default None.
-
bar_label
(str
, default:'Flux [e-/s]'
) –The label for the colorbar, by default "Flux [e-/s]"."
Returns:
-
axes
–
animate_cube
animate_cube(
cube: ndarray,
scol_2d: Optional[ndarray] = None,
srow_2d: Optional[ndarray] = None,
cadenceno: Optional[ndarray] = None,
time: Optional[ndarray] = None,
plot_type: str = "img",
extent: Optional[Tuple] = None,
interval: int = 200,
repeat_delay: int = 1000,
step: int = 1,
suptitle: str = "",
bar_label: str = "Flux [e-/s]",
) -> FuncAnimation
Animates a 3D data cube (time series of 2D images).
Parameters:
-
cube
(ndarray
) –The 3D data cube to be animated (time, row, column).
-
scol_2d
(Optional[ndarray]
, default:None
) –The column coordinates of scatter points, by default None.
-
srow_2d
(Optional[ndarray]
, default:None
) –The row coordinates of scatter points, by default None.
-
cadenceno
(Optional[ndarray]
, default:None
) –Cadence numbers corresponding to the time axis, by default None.
-
time
(Optional[ndarray]
, default:None
) –Time values corresponding to the time axis, by default None.
-
plot_type
(str
, default:'img'
) –The type of plot to create ('img' or 'scatter'), by default "img".
-
extent
(Optional[Tuple]
, default:None
) –The extent of the images (left, right, bottom, top), by default None.
-
interval
(int
, default:200
) –Delay between frames in milliseconds, by default 200.
-
repeat_delay
(int
, default:1000
) –Delay in milliseconds before repeating the animation, by default 1000.
-
step
(int
, default:1
) –Step size for frame selection, by default 1.
-
suptitle
(str
, default:''
) –Overall title for the animation figure, by default "".
-
bar_label
(str
, default:'Flux [e-/s]'
) –The label for the colorbar, by default "Flux [e-/s]".
Returns:
-
FuncAnimation
–The matplotlib FuncAnimation object.
int_to_binary_array
Converts a non-negative integer to its binary representation as a NumPy array.
Parameters:
-
integer
(int
) –The non-negative integer to convert.
-
num_bits
(int
) –The desired number of bits in the output binary representation. The binary string will be left-padded with zeros if necessary. Must be greater than zero.
Returns:
-
ndarray
–A NumPy array of dtype uint8 representing the binary digits (0 or 1), with the most significant bit first. The length of the array is
num_bits
.
has_bit
Checks if a specific bit is set in each element of a quality flag array.
Parameters:
-
quality_array
(ndarray
) –A NumPy array of integers (quality flags).
-
bit
(int
) –The bit position to check (1-based index, where 1 is the LSB). Must be between 1 and 16 (inclusive).
Returns:
-
ndarray
–A boolean NumPy array of the same shape as
quality_array
, where True indicates that the specifiedbit
is set (1) in the corresponding quality flag integer.