Custom convolution layer to handle nans in image

Hi everybody,

I am working on creating a custom cnn layer to process the data from a map. The data values are masked on landmass, hence I was thinking of creating a convolution that either ignores nans or forces their weight to be zero (previously converting nans in for instance -1).

Is this a feasible approach? Can you maybe give me some hints on how to start/which class to extend?