In [1]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as mcm
import matplotlib.colors as mcolors
from mpl_toolkits.basemap import Basemap
In [12]:
ascfile = open('file.asc').read()
im = np.ones((1024,1024))*np.nan
for i, line in enumerate(ascfile.split("\n")[:-1]):
im[i] = np.array(list(line)).astype(int)
np.unique(im)
lats = np.fromfile('imslat_24km.dat', dtype=np.dtype('f4'))
lons = np.fromfile('imslon_24km.dat', dtype=np.dtype('f4'))
lats.shape = (1024,1024)
lons.shape = (1024,1024)
In [32]:
# print lats[-12,512]
print np.nanmax(lats)
print np.nanmin(lats)
print lons[512, 512]
In [115]:
#1 sea, 2 land,3 sea ice, 4 snow, 0 out of bounds
bounds = np.unique(im)
cmap = mcolors.ListedColormap(['red', 'blue', 'green', 'yellow', 'white'])
norm = mcolors.BoundaryNorm(bounds, cmap.N)
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(1,1,1)
m = Basemap(projection='npstere', boundinglat=lats[712,512], lon_0=lons[512, 512],resolution='h')
m.imshow(im[312:712,312:712], cmap=cmap, norm=norm)
x, y = m(lats[612, 512], lons[512, 512])
m.drawcountries()
m.drawcoastlines()
#fig.colorbar(ims)
Out[115]:
In [ ]: