cube1.regrid(cube2, iris.analysis.Linear())
import numpy as np
import pandas as pd
from iris.pandas import as_cube
#Use the extends of one cube to generate a set of lat/lon coordinate dimensios
lat,lon = cube1.coord('latitude'),cube1.coord('longitude')
lat_min,lon_min = lat.points.min(),lon.points.min()
lat_max,lon_max = lat.points.max(),lon.points.max()
lat25 = np.arange(lat_min, lat_max, 2.5)
lon25 = np.arange(lon_min, lon_max, 2.5)
#Generate a 'grid cube' from a pandas DataFrame to act as the target grid
df = pd.DataFrame(np.random.random((len(lat25),len(lon25))))
df.index = lat25
df.columns = lon25
grid_cube = as_cube(df)
grid_cube.coord('index').rename('latitude')
grid_cube.coord('columns').rename('longitude')
grid_cube.coord('latitude').units = 'degrees'
grid_cube.coord('longitude').units = 'degrees'
#Do the regridding
cube1.regrid(grid_cube, iris.analysis.Linear())
lat,lon = cube1.coord('latitude'),cube1.coord('longitude')
lat_min,lon_min = lat.points.min(),lon.points.min()
lat_max,lon_max = lat.points.max(),lon.points.max()
lat25 = np.arange(lat_min, lat_max, 2.5)
lon25 = np.arange(lon_min, lon_max, 2.5)
result = cube1.interpolate([('latitude', lat25), ('longitude', lon25)],
iris.analysis.Linear())def startAtZero(cube):
"""
The project function above unfortunately ignores its keyword
so I have to interpolate the data manually
so that it fits with what I want
"""
lonPoints = cube.coord('longitude').points - 179.5
cube.coord('longitude').circular = True
samplePoints = [('longitude', lonPoints)]
return cube.interpolate(samplePoints, iris.analysis.Linear())
>>> iris.__version__
'1.7.3-rc.1'
>>> t = op.startAtZero(test)
Traceback (most recent call last):
File "<pyshell#94>", line 1, in <module>
t = op.startAtZero(test)
File "orca_project.py", line 53, in startAtZero
return cube.interpolate(samplePoints, iris.analysis.Linear())
File "/project/avd/iris/live/pre-release/iris/cube.py", line 3231, in interpolate
interp = scheme.interpolator(self, coords)
File "/project/avd/iris/live/pre-release/iris/analysis/__init__.py", line 1561, in interpolator
extrapolation_mode=self.extrapolation_mode)
File "/project/avd/iris/live/pre-release/iris/analysis/_interpolator.py", line 162, in __init__
self._setup()
File "/project/avd/iris/live/pre-release/iris/analysis/_interpolator.py", line 339, in _setup
offset = ((coord_points.max() + coord_points.min() - modulus)
TypeError: unsupported operand type(s) for -: 'float' and 'NoneType'
>>> print test
integral_of_sea_water_potential_temperature_wrt_depth_expressed_as_heat_content / (J/m2) (latitude: 180; longitude: 360)
Dimension coordinates:
latitude x -
longitude - x
Scalar coordinates:
time: 2010-01-16 12:00:00, bound=(2010-01-01 00:00:00, 2010-02-01 00:00:00)
Attributes:
Conventions: CF-1.1
NCO: 4.2.0
interval_operation: 1350.0
interval_write: -1.0
online_operation: ave(only(x))
production: An IPSL model
>>> print test.coord('longitude')
DimCoord(array([-179.5, -178.5, -177.5, -176.5, -175.5, -174.5, -173.5, -172.5,
-171.5, -170.5, -169.5, -168.5, -167.5, -166.5, -165.5, -164.5,
...
164.5, 165.5, 166.5, 167.5, 168.5, 169.5, 170.5, 171.5,
172.5, 173.5, 174.5, 175.5, 176.5, 177.5, 178.5, 179.5]), standard_name='longitude', units=Unit('1'), circular=True)