I have an elevation array from a .tif LiDAR surface. Example array plot below.

I am using the below code to rotate the array at an arbitrary angle
import numpy as np
import matplotlib.pyplot as plt
from scipy.ndimage import rotate
# 2D array
array_size = (y_pixels, x_pixels)
array = np.array(Fill_Surface)
# Define the rotation angle in degrees
angle_degrees = -30
# Rotate the array by the specified angle with interpolation
rotated_array = rotate(array, angle_degrees, reshape=False, order=0, mode='nearest')
# Find the bounding box of the non-zero values in the rotated array
non_zero_indices = np.argwhere(rotated_array != 0)
(min_y, min_x), (max_y, max_x) = non_zero_indices.min(0), non_zero_indices.max(0)
# Trim the rotated array to the bounding box
trimmed_rotated_array = rotated_array[min_y:max_y + 1, min_x:max_x + 1]
the code produces the following plot that is correctly rotated.
The issue is that the code also introduces a string of elements diagonally from the LiDAR surface to the edge of the array boundary in all directions. (only visible in the plot at the bottom left) but they are in every corner.
Are there any recommendations on how to repeatedly remove these elements while maintaining the LiDAR surface.
