0
votes

This must be possible but I am unsure as to how to approach it.

I have a geographical domain, with a set number of lat and lons. Using these, I am able to plot a simple Basemap of the domain:

fp_mhd = name.footprints('path/to/file')
domain_lon = fp_mhd.lon
domain_lat = fp_mhd.lat


### Construct Basemap ###
m = Basemap(resolution='c',projection='gall', 
            llcrnrlat=(np.min(domain_lat)), 
            urcrnrlat=(np.max(domain_lat)),
            llcrnrlon=(np.min(domain_lon)),
            urcrnrlon=(np.max(domain_lon)))

What I need is someway of distinguishing countries from oceans within this domain, and returning the results as an array i.e. 1s for land and 0s for ocean (though these values don't matter). The array needs to be 2-D where each point corresponds to a specific lat and lon. So say there were 100 lats and 200 lons, there would be 20000 1s and 0s. I wondered if there was some way to convert the Basemap object to an array, but failed to achieve this. Is it possible?

Thanks in advance!

1
What is Basemap? What package are you using to plot? What data do you have to tell oceans from countries, and how do you use it?Nick Marinakis

1 Answers

1
votes

Have a look at the following function. You should be able to extract the mask as it returns a numpy masked array.

.mask returns a Boolean array.

mpl_toolkits.basemap.maskoceans(lonsin, latsin, datain, inlands=True, resolution='l', grid=5)

returns a masked array the same shape as datain with “wet” points masked.

Basemap documentation

Numpy Masked Array Documentation