-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #160 from jswhit/cartopy
migrate test/*py from basemap to cartopy
- Loading branch information
Showing
49 changed files
with
352 additions
and
310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
__version__ = '2.1' | ||
__version__ = '2.1.1' | ||
|
||
import numpy as np | ||
import warnings | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
these examples read GRIB files and generate | ||
plots of the data using matplotlib and the basemap toolkit | ||
(both availabe from http://matplotlib.sf.net). | ||
plots of the data using matplotlib and cartopy | ||
|
||
test_spectral.py also uses pyspharm, available from | ||
http://code.google.com/p/pyspharm. | ||
http://github.com/jswhit/pyspharm | ||
|
||
to run all the tests with a non-gui backend (Agg) and compare | ||
images to archived baselines, run 'python run_tests.py'. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# run all matplotlib based tests | ||
import glob | ||
import matplotlib | ||
matplotlib.rcParams.update(matplotlib.rcParamsDefault) | ||
matplotlib.use('agg') | ||
# Find all test files. | ||
test_files = glob.glob('test_*.py') | ||
#test_files.remove('test_spectral.py') # skip spectral transform test | ||
for f in test_files: | ||
print('running %s...' % f) | ||
exec(open(f).read()) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,30 @@ | ||
import pygrib | ||
import matplotlib | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
from numpy import ma | ||
from mpl_toolkits.basemap import Basemap | ||
|
||
from cartopy.util import add_cyclic_point | ||
import cartopy.crs as ccrs | ||
from matplotlib.testing.compare import compare_images | ||
|
||
grbs = pygrib.open('../sampledata/ecmwf_tigge.grb') | ||
grb = grbs.select(parameterName='Soil moisture')[0] | ||
fld = grb.values; lats,lons = grb.latlons() | ||
lons1 = lons[0,:]; lats1 = lats[:,0] | ||
# add cyclic (wrap-around) point to global grid | ||
fld,lons1 = add_cyclic_point(fld, coord=lons1) | ||
lons,lats = np.meshgrid(lons1,lats1) | ||
|
||
m = Basemap(lon_0=180) | ||
CS = m.contourf(lons,lats,fld,15,cmap=plt.cm.jet) | ||
plt.colorbar(shrink=0.6) | ||
m.drawcoastlines() | ||
# draw parallels | ||
delat = 30. | ||
circles = np.arange(-90.,90.+delat,delat) | ||
m.drawparallels(circles,labels=[1,0,0,0]) | ||
# draw meridians | ||
delon = 60. | ||
meridians = np.arange(0,360,delon) | ||
m.drawmeridians(meridians,labels=[0,0,0,1]) | ||
plt.title(grb['parameterName']+' on ECMWF Reduced Gaussian Grid') | ||
plt.figure() | ||
ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=0)) | ||
cs = ax.contourf(lons,lats,fld,15,cmap=plt.cm.jet) | ||
plt.colorbar(cs, shrink=0.6) | ||
ax.coastlines() | ||
gl = ax.gridlines(draw_labels=True) | ||
gl.ylabels_top = False; gl.xlabels_top = False | ||
gl.ylabels_right = False; gl.xlabels_right = False | ||
plt.title(grb.parameterName+' on ECMWF Reduced Gaussian Grid') | ||
if matplotlib.get_backend().lower() == 'agg': | ||
# raise exception if generated image doesn't match baseline | ||
plt.savefig('ectigge.png') | ||
assert( compare_images('ectigge_baseline.png','ectigge.png',10) is None ) | ||
plt.show() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,27 @@ | ||
import pygrib | ||
import numpy as np | ||
import matplotlib | ||
import matplotlib.pyplot as plt | ||
from mpl_toolkits.basemap import Basemap | ||
from cartopy.util import add_cyclic_point | ||
from matplotlib.testing.compare import compare_images | ||
import cartopy.crs as ccrs | ||
grbs = pygrib.open('../sampledata/flux.grb') | ||
grb = grbs.message(2) | ||
lats, lons = grb.latlons() | ||
data = grb['values'] | ||
m = Basemap(lon_0=180) | ||
#m.scatter(lons.flat,lats.flat,1,marker='o',color='k',zorder=10) | ||
x,y = m(lons,lats) | ||
m.drawcoastlines() | ||
m.contourf(x,y,data,15) | ||
#m.fillcontinents() | ||
lons1 = lons[0,:]; lats1 = lats[:,0] | ||
data = grb.values | ||
# add cyclic (wrap-around) point to global grid | ||
data,lons1 = add_cyclic_point(data, coord=lons1) | ||
lons,lats = np.meshgrid(lons1,lats1) | ||
plt.figure() | ||
ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=0)) | ||
ax.coastlines() | ||
ax.contourf(lons,lats,data,15) | ||
# plot location of every 4th grid point | ||
plt.scatter(lons[::4,::4].ravel(),lats[::4,::4].ravel(),1,marker='o',color='k',zorder=10) | ||
plt.title('Global Gaussian Grid') | ||
if matplotlib.get_backend().lower() == 'agg': | ||
# raise exception if generated image doesn't match baseline | ||
plt.savefig('gaussian.png') | ||
assert( compare_images('gaussian_baseline.png','gaussian.png',10) is None ) | ||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,30 @@ | ||
import pygrib | ||
import numpy as np | ||
import matplotlib | ||
import matplotlib.pyplot as plt | ||
from mpl_toolkits.basemap import Basemap | ||
import cartopy.crs as ccrs | ||
from matplotlib.testing.compare import compare_images | ||
|
||
grbs = pygrib.open('../sampledata/eta.grb') | ||
grb = grbs.select(parameterName='Pressure',typeOfLevel='surface')[0] | ||
data = grb.values | ||
lats, lons = grb.latlons() | ||
llcrnrlon = lons[0,0] | ||
llcrnrlat = lats[0,0] | ||
urcrnrlon = lons[-1,-1] | ||
urcrnrlat = lats[-1,-1] | ||
rsphere = (grb.projparams['a'], grb.projparams['b']) | ||
lon_0 = grb.projparams['lon_0'] | ||
lat_1 = grb.projparams['lat_1'] | ||
lat_2 = grb.projparams['lat_2'] | ||
projection = grb.projparams['proj'] | ||
m = Basemap(llcrnrlon=llcrnrlon,llcrnrlat=llcrnrlat, | ||
urcrnrlon=urcrnrlon,urcrnrlat=urcrnrlat,rsphere=rsphere,lon_0=lon_0, | ||
lat_1=lat_1,lat_2=lat_2,resolution='l',projection=projection) | ||
x,y = m(lons, lats) | ||
m.scatter(x.flat,y.flat,3,marker='o',color='k',zorder=10) | ||
m.drawcoastlines() | ||
x,y = m(lons,lats) | ||
m.contourf(x,y,data,15) | ||
|
||
globe = ccrs.Globe(ellipse='sphere', semimajor_axis=grb.projparams['a'], semiminor_axis=grb.projparams['b']) | ||
pj = ccrs.LambertConformal(globe=globe,central_longitude=grb.projparams['lon_0'], | ||
central_latitude=grb.projparams['lat_0'], | ||
standard_parallels =(grb.projparams['lat_1'],grb.projparams['lat_2'])) | ||
ax = plt.axes(projection=pj) | ||
coords = pj.transform_points( | ||
ccrs.PlateCarree(), np.asarray([lons[0,0],lons[-1,-1]]), np.asarray([lats[0,0],lats[-1,-1]])) | ||
ax.set_extent([coords[0, 0], coords[1, 0], coords[0, 1], coords[1, 1]], crs=pj) | ||
ax.scatter(lons.flat,lats.flat,3,marker='o',color='k',zorder=10,transform=ccrs.PlateCarree()) | ||
ax.coastlines() | ||
coords = pj.transform_points(ccrs.PlateCarree(), lons, lats) | ||
cs = ax.contourf(coords[:,:,0],coords[:,:,1],data,15) | ||
plt.title('Lambert Conformal Model Grid') | ||
if matplotlib.get_backend().lower() == 'agg': | ||
# raise exception if generated image doesn't match baseline | ||
plt.savefig('lambert.png') | ||
assert( compare_images('lambert_baseline.png','lambert.png',10) is None ) | ||
plt.show() |
Oops, something went wrong.