In [1]:
import warnings
warnings.filterwarnings('ignore')
import numpy
import iris
import iris.plot as iplt
from iris.experimental.regrid import regrid_weighted_curvilinear_to_rectilinear
import matplotlib.pyplot as plt
In [1]:
import sys, os
cwd = os.getcwd()
repo_dir = '/'
for directory in cwd.split('/')[1:]:
repo_dir = os.path.join(repo_dir, directory)
if directory == 'ocean-analysis':
break
modules_dir = os.path.join(repo_dir, 'modules')
sys.path.append(modules_dir)
import grids
In [14]:
%matplotlib inline
In [23]:
orig_ipsl_file = '/g/data/ua6/DRSv3/CMIP5/IPSL-CM5A-LR/historicalGHG/mon/ocean/r1i1p1/thetao/latest/thetao_Omon_IPSL-CM5A-LR_historicalGHG_r1i1p1_195001-199912.nc'
orig_noresm_file = '/g/data/ua6/DRSv3/CMIP5/NorESM1-M/historicalGHG/mon/ocean/r1i1p1/thetao/latest/thetao_Omon_NorESM1-M_historicalGHG_r1i1p1_185001-185312.nc'
In [25]:
orig_ipsl_cube = iris.load_cube(orig_ipsl_file)[0, 0 , ::]
print(orig_ipsl_cube)
In [26]:
orig_noresm_cube = iris.load_cube(orig_noresm_file)[0, 0 , ::]
print(orig_noresm_cube)
In [27]:
def get_dim_vals(user_input, bounds=False):
"""Get the list of values for a data dimension/axis.
Args:
bounds (bool): input represents the bounds, not centre points
"""
vals = user_input
if user_input:
if len(user_input) == 3:
start, stop, step = user_input
vals = list(numpy.arange(start, stop + step, step))
if bounds:
vals = numpy.array(vals)
vals = (vals[1:] + vals[:-1]) / 2
return list(vals)
In [28]:
lats = get_dim_vals([-80, 80, 1.0])
lons = get_dim_vals([2, 360, 2])
horizontal_grid = grids.make_grid(lats, lons)
In [29]:
new_noresm_cube, coord_names, regrid_status = grids.curvilinear_to_rectilinear(orig_noresm_cube, target_grid_cube=horizontal_grid)
iplt.contourf(new_noresm_cube)
Out[29]:
In [32]:
ipsl_area_cube = iris.load_cube('/g/data/ua6/DRSv3/CMIP5/IPSL-CM5A-LR/historical/fx/ocean/r0i0p0/areacello/latest/areacello_fx_IPSL-CM5A-LR_historical_r0i0p0.nc')
ipsl_area_cube
Out[32]:
In [33]:
new_ipsl_cube, coord_names, regrid_status = grids.curvilinear_to_rectilinear(orig_ipsl_cube,
weights=ipsl_area_cube.data,
target_grid_cube=horizontal_grid)
iplt.contourf(new_ipsl_cube)
Out[33]:
In [2]:
cdo_file = '/g/data/r87/dbi599/DRSv2/CMIP5/IPSL-CM5A-LR/historical/yr/ocean/r1i1p1/thetao/latest/thetao_Oyr_IPSL-CM5A-LR_historical_r1i1p1_185001-189912_susan-grid.nc'
In [3]:
cdo_cube = iris.load_cube(cdo_file, 'sea_water_potential_temperature')
In [4]:
cdo_cube
Out[4]:
In [6]:
iplt.contourf(cdo_cube[0, 0, ::])
Out[6]:
In [ ]: