In [3]:
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/estimr2/EUCLEIA/ftp.ceda.ac.uk/badc/eucleia/data/EUCLEIA/output/MOHC/HadGEM3-A-N216/historical/day/atmos/day/r1i1p1/latest/psl_day_HadGEM3-A-N216_historical_r1i1p1_20100101-20131230.nc'
In [4]:
# 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 [5]:
# 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 [6]:
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
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[7]:
In [8]:
cs = plt.contourf(lons, lats, psl[0,:,:])
In [9]:
# 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 [10]:
#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 [11]:
print lon[:]
In [12]:
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[12]:
In [13]:
# cartopy puts it together how I would like to have it ;-)
# simple plot shows the 'problem'
cs = plt.contourf(lons, lats, psl[0,:,:])
In [14]:
lat[:]
Out[14]:
In [15]:
from flyingpigeon import subset as sb
In [14]:
africa = sb.clipping(resource=resources, historical_concatination=True,
prefix='test_africa', spatial_wrapping='wrap', polygons='Africa', dir_output=HOME+'/data/tests/')
In [ ]:
In [15]:
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 [16]:
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[16]:
In [17]:
lon[:]
Out[17]:
In [18]:
cs = plt.contourf(lons, lats, psl[0,:,:])
In [19]:
from flyingpigeon import utils
reload(sb)
res_rot = HOME+'/.conda/envs/birdhouse/var/lib/cache/pywps/esgf1.dkrz.de/thredds/fileServer/cordex/cordex/output/EUR-44/CLMcom/MPI-M-MPI-ESM-LR/historical/r1i1p1/CLMcom-CCLM4-8-17/v1/mon/tas/v20140520/tas_EUR-44_MPI-M-MPI-ESM-LR_historical_r1i1p1_CLMcom-CCLM4-8-17_v1_mon_200101-200512.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[19]:
In [ ]:
In [20]:
lats, lons = utils.unroate_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 [21]:
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
In [22]:
ds = Dataset(europe[0])
val = np.squeeze(ds.variables[var])
In [ ]:
In [ ]: