In [1]:
import numpy as np
from cdo import *
cdo = Cdo()
from os import getenv
import time
HOME = getenv('HOME')
bbox_cdo = '-20,20,-20,20'
bbox_ocgis = [-20,-22,20,20]
# global dataset CMIP5
resources = HOME+'/birdhouse/flyingpigeon/flyingpigeon/tests/testdata/cmip5/tasmax_Amon_MPI-ESM-MR_rcp45_r1i1p1_200701-200712.nc'
In [2]:
resources
Out[2]:
In [3]:
# get the North Atlanic region form global dataset with cdo
tic = time.time()
nc = cdo.sellonlatbox( bbox_cdo, input=resources, output=HOME+'/data/tests/subset.nc' )
tac = time.time()
print 'sec: %s' % (tac-tic)
In [4]:
# read in the file
from netCDF4 import Dataset, num2date
from flyingpigeon.utils import get_variable
var = get_variable(nc)
#print 'variable name: %s' % var
ds = Dataset(nc)
psl = ds.variables[var]
lat = ds.variables['lat']
lon = ds.variables['lon']
In [5]:
print lon[:]
In [7]:
from matplotlib import pyplot as plt
from cartopy import config
from cartopy.util import add_cyclic_point
import cartopy.crs as ccrs
from numpy import meshgrid
# to show the plots inline
%matplotlib inline
In [8]:
lons, lats = meshgrid(lon, lat)
# plot first time stepp:
ax = plt.axes(projection=ccrs.Robinson(central_longitude=0))
ax.coastlines()
cs = plt.contourf(lons, lats, psl[0,:,:], 60, transform=ccrs.PlateCarree(), interpolation='nearest')
plt.colorbar()
Out[8]:
In [9]:
cs = plt.contourf(lons, lats, psl[0,:,:])
In [10]:
# same stepps with ocgis
from flyingpigeon.ocgis_module import call
tic = time.time()
#from ocgis import RequestDataset ,OcgOperations
spatial_wrapping = 'wrap' # unwrap # None
nc = call(resources, geom=bbox_ocgis, spatial_wrapping=spatial_wrapping, dir_output=HOME+'/data/tests')
tac = time.time()
print 'sec: %s' % (tac-tic)
In [11]:
#read in the data
var = get_variable(nc)
#print 'variable name: %s' % var
ds = Dataset(nc)
psl = ds.variables[var]
lat = ds.variables['lat']
lon = ds.variables['lon']
In [12]:
print lon[:]
In [13]:
lons, lats = meshgrid(lon, lat)
# plot first time step:
ax = plt.axes(projection=ccrs.Robinson(central_longitude=0))
ax.coastlines()
cs = plt.contourf(lons, lats, psl[0,:,:], 60, transform=ccrs.PlateCarree(), interpolation='nearest')
plt.colorbar()
Out[13]:
In [14]:
cs = plt.contourf(lons, lats, psl[0,:,:])
In [15]:
lat[:]
Out[15]:
In [16]:
from flyingpigeon import subset as sb
# from flyingpigeon.subset import clipping
In [ ]:
In [17]:
africa = sb.clipping(resource=resources,
#historical_concatination=True,
prefix='test_africa',
spatial_wrapping='wrap',
polygons='Africa',
dir_output=HOME+'/data/tests/')
In [ ]:
In [18]:
var = get_variable(africa[0])
#print 'variable name: %s' % var
ds = Dataset(africa[0])
psl = ds.variables[var]
lat = ds.variables['lat']
lon = ds.variables['lon']
In [19]:
lons, lats = meshgrid(lon, lat)
# plot first time stepp:
ax = plt.axes(projection=ccrs.Robinson(central_longitude=0))
ax.coastlines()
cs = plt.contourf(lons, lats, psl[0,:,:], 60, transform=ccrs.PlateCarree(), interpolation='nearest')
plt.colorbar()
Out[19]:
In [20]:
lon[:]
Out[20]:
In [21]:
cs = plt.contourf(lons, lats, psl[0,:,:])
In [22]:
from flyingpigeon import utils
res_rot = HOME+'/birdhouse/flyingpigeon/flyingpigeon/tests/testdata/cordex/tasmax_EUR-44_MPI-M-MPI-ESM-LR_rcp45_r1i1p1_MPI-CSC-REMO2009_v1_mon_200602-200612.nc'
europe = sb.clipping(resource=res_rot, historical_concatination=True, memory_limit=1,
prefix='test_europe', spatial_wrapping='wrap', polygons='Europe', dir_output=HOME+'/data/tests/')
europe
Out[22]:
In [31]:
lats, lons = utils.unrotate_pole(europe[0], write_to_file=False)
var = get_variable(europe[0])
ds = Dataset(europe[0])
val = np.squeeze(ds.variables[var])
# plot first time stepp:
ax = plt.axes(projection=ccrs.PlateCarree()) #Robinson(central_longitude=0)
ax.coastlines()
cs = plt.contourf(lons, lats, val[0,:,:], 60, transform=ccrs.PlateCarree(), interpolation='nearest',
)
plt.colorbar()
ds.close()
In [ ]:
val_m = np.ma.array(val[:], mask=val[:] > 1000)
cs = plt.contourf(lons, lats, val_m[0,:,:], 60, vmin=200, vmax=300)
ticks = np.linspace(200,300, num=11, endpoint=True)
cb =plt.colorbar(ticks=ticks, )
cb.vmin=200
cb.vmax=300