A similar question was posted in the archive without any answer: Assume I have SST(i,j) over the globe (say, including the Pacific and Atlantic), how can I calculate averaged SST of the Atlantic only if I can provide the ocean land mask(i,j) as following mask(i,j)=0 over land mask(i,j)=1 over Atlantic mask(i,j)=2 over Pacific etc