# Applying a 2D band pass filter (Butterworth ?) to an array with NaNs

I am trying to filter out the low frequencies of an array looking like this :

For now, I am taking transects of this array and applying a 1D - butterworth band pass filter :

import numpy as np
from scipy.signal import find_peaks, butter, sosfiltfilt, sosfreqz

def Transect_angle(A, angle, Sp, length):
x0, y0 = Sp[0], Sp[1]
x1, y1  = x0 + cosd(angle)*length, y0 + sind(angle)*length
return Array_transect(A, [y0,x0], [y1,x1], 'nearest'), [x0,y0], [x1,y1]

def butter_bandpass(lowcut, highcut, fs, order=5):
nyq = 0.5 * fs
low = lowcut / nyq
high = highcut / nyq
sos = butter(order, [low, high], analog=False, btype='band', output='sos')
return sos

def butter_bandpass_filter(data, lowcut, highcut, fs, order=5):
sos = butter_bandpass(lowcut, highcut, fs, order=order)
y = sosfiltfilt(sos, data)
return y

transect, p0, p1 = Transect_angle(Array, angle, start ,length)
tr_withoutnan = transect[~np.isnan(transect)] ### removing nan
filtered = butter_bandpass_filter(tr_withoutnan, low_freq, High_freq, 1)


I would like to apply the same kind of filtering but directly in 2D to my array. I have two main problems :

1. For me, filtering is basically a convolution between data and a filter. Based on this, I can directly make the convolution of my array with a butterworth filter having an axial symmetry. However, in my function butter_bandpass_filter, I am using sosfiltfilt, which mention that the filter is appplied forward and backward. I don't know what that means it terms of convolution, but I remember that someaone mentioned it was important in a topic I read a long time ago.

2. Ho should I deal with the Nans values (in white in my image) ?

Finally, I use a butterworth bandpass filter because I read that it was the filter that was the least likely to produce artefacts. I am open to any suggestion !

2. NaN means "not a number" and indicates those indeterminate conditions like $$0/0$$, $$\infty/\infty$$, $$\infty - \infty$$. NaNs cannot be processed arithmetically, hence you should remove all the NaN samples with some suitable values before further processing.
• in 2D, imho the reversed signal array should be $x[-n,-m]$, at a single step. Nov 25, 2019 at 16:33