# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 2
#     language: python
#     name: python2
# ---

# %matplotlib inline

import matplotlib.pyplot as plt
import numpy as np
from grid.grid2d import Grid2D
from mpl_toolkits.basemap import Basemap

xmin = 118.5
xmax = 120.5
ymin = 32.0
ymax = 34.0
xdim = 0.25
ydim = 0.25
ncols = len(np.arange(xmin,xmax+xdim,xdim))
nrows = len(np.arange(ymin,ymax+ydim,ydim))
data = np.arange(0,nrows*ncols)
data.shape = (nrows,ncols)
geodict = {'xmin':xmin,
           'xmax':xmax,
           'ymin':ymin,
           'ymax':ymax,
           'xdim':xdim,
           'ydim':ydim,
           'nrows':nrows,
           'ncols':ncols}
grid = Grid2D(data,geodict)

plt.imshow(grid.getData(),interpolation='nearest');
plt.colorbar();

lat,lon = grid.getLatLon(4,4)
print 'The coordinates at the center of the grid are %.3f,%.3f' % (lat,lon)
value = grid.getValue(lat,lon)
print 'The data value at the center of the grid is %i' % (value)

sdict = {'ymin':32.7,'ymax':33.3,'xmin':119.2,'xmax':119.8,'xdim':0.33,'ydim':0.33}
grid.interpolateToGrid(sdict)

plt.imshow(grid.getData(),interpolation='nearest');
plt.colorbar();



StarcoderdataJupyterScriptsDedupFiltered