I have an array of latitudes (lats, min=-88, max=88, shape=89) and longitudes (lons, min=0, max=358, shape=180), and a land mask (land_mask, ocean=1, land=0, shape=(89,180)).
xlon,xlat = np.meshgrid(lons,lats)
PP.pcolormesh(xlon,xlat,land_mask)
PP.colorbar()
PP.show()
I would like to loop over all the lats and lons and do a calculation for those lat/lon pairs that are over the ocean, and do nothing ie move on to the next lat/lon pair if over land. Some pseudo code:
# loop over lats
for lat in lats:
# loop over lons
for lon in lons:
# check to see if the current
# lat/lon is in the ocean.
# if True, do something
if (lat,lon) in ocean:
do something
# else if current lat/lon
# over land, do nothing and
# move to the next lat/lon
# pair
else: # ie if over land, skip this point
continue
Im not sure how to do this with the 2d land mask that I have. Also perhaps there is a better way to implement this code that is faster and/or more pythonic than nested for loops? Thanks in advance.