from iris.coords import DimCoord
from iris.coord_systems import RotatedGeogCS, GeogCS
from iris.analysis.cartography import unrotate_pole
from iris.exceptions import CoordinateNotFoundError
from numpy import meshgrid, array
import pdb
def unrotate_pole_update_cube(cube):
try:
lat = cube.coord('grid_latitude').points
lon = cube.coord('grid_longitude').points
lat_coord_name='grid_latitude'
lon_coord_name='grid_longitude'
except CoordinateNotFoundError:
print 'Uses latitude/longitude coords, not grid_latitude/grid_longitude'
pass
try:
cs = cube.coord_system()
except TypeError:
cs=[]
if isinstance(cs, RotatedGeogCS):
lons, lats = meshgrid(lon, lat)
lons,lats = unrotate_pole(lons,lats, cs.grid_north_pole_longitude, cs.grid_north_pole_latitude)
lon=lons[0]
lat=lats[:,0]
#pdb.set_trace()
for i, coord in enumerate (cube.coords()):
if coord.standard_name==lat_coord_name:
lat_dim_coord_cube = i
if coord.standard_name==lon_coord_name:
lon_dim_coord_cube = i
# IRIS unrotate_pole uses the default cartopy.crs.Geodetic, which is
# WGS84 by default
#wgs84_cs = GeogCS(semi_major_axis= 6378137.,
# inverse_flattening=298.257223563)
wgs84_cs = GeogCS(6371229.0)
cube.remove_coord(lat_coord_name)
cube.remove_coord(lon_coord_name)
cube.add_dim_coord(DimCoord(points=lat, standard_name='latitude', units='degrees', coord_system=wgs84_cs), lat_dim_coord_cube)
cube.add_dim_coord(DimCoord(points=lon, standard_name='longitude', units='degrees', coord_system=wgs84_cs), lon_dim_coord_cube)
return cube
import iris
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import numpy as np
import iris.plot as iplt
diag = 'rain_mean'
pp_file_path='/projects/cascade/pwille/moose_retrievals/'
experiment_id = 'djzny'
expmin1 = experiment_id[:-1]
lon_high = 101
lon_low = 64.
lat_high = 33.
lat_low =-6.
min_contour = 0.
max_contour = 3.
tick_interval=0.2
clevs = np.linspace(min_contour, max_contour,32)
fu = '/projects/cascade/pwille/moose_retrievals/%s/%s/%s.pp' % (expmin1, experiment_id, diag)
cube = iris.load_cube(fu)*3600
# Mean Rain
fig = plt.figure()
ax = plt.axes(projection=ccrs.PlateCarree(), extent=(lon_low,lon_high,lat_low,lat_high))
pdb.set_trace()
iplt.contourf(cube, clevs)
ax.coastlines(resolution='110m', color='k', linewidths=1.5)
plt.show()
# Unrotated Mean Rain
rain_mean = unrotate_pole_update_cube(cube)
fig = plt.figure()
ax = plt.axes(projection=ccrs.PlateCarree(), extent=(lon_low,lon_high,lat_low,lat_high))
#iplt.contourf(rain_mean, clevs, cmap=cmap)
plt.contourf(rain_mean.coord('longitude').points, rain_mean.coord('latitude').points, rain_mean.data, clevs)
ax.coastlines(resolution='110m', color='k', linewidths=1.5)
plt.show()
#plt.savefig()
lons, lats = meshgrid(lon, lat)
lons, lats = unrotate_pole(lons,lats, cs.grid_north_pole_longitude, cs.grid_north_pole_latitude)
lon=lons[0] # DON'T DO THIS
lat=lats[:,0] # OR THIS
--
You received this message because you are subscribed to the Google Groups "Iris" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scitools-iri...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
OK, thanks
I need to unrotate onto a lat lon grid to do an area weighted regrid.