Skip to content

Instantly share code, notes, and snippets.

@ScottWales
Created September 21, 2016 07:28
Show Gist options
  • Save ScottWales/631433fd3ba914b8b9b317b0aaa1b0d0 to your computer and use it in GitHub Desktop.
Save ScottWales/631433fd3ba914b8b9b317b0aaa1b0d0 to your computer and use it in GitHub Desktop.
import xarray
import numpy
from scipy.interpolate import RectBivariateSpline
data = xarray.open_mfdataset('/g/data1/v45/APE-MOM/gfdl_nyf_1080_cp/output539/ocean__539_00*.nc', decode_cf=False)
# Bouy locations
bouy = {
'lat': [-58.239, -57.916, -57.612, -57.513, -57.321, -56.897, -56.484, -56.058],
'lon': [82.001, 82.228, 82.381, 82.523, 82.779, 83.305, 83.770, 84.261],
}
# Get a subset of the data around the bouy locations
u = data['u'].sel(xu_ocean=slice(-60.0,-55.0), yu_ocean=slice(80.0,90.0))
v = data['v'].sel(xu_ocean=slice(-60.0,-55.0), yu_ocean=slice(80.0,90.0))
print(u)
# Interpolate u and v to the bouy locations
bouy['u'] = numpy.zeros((u.shape[0],u.shape[1],len(bouy['lat'])))
bouy['v'] = numpy.zeros((v.shape[0],v.shape[1],len(bouy['lat'])))
for ti in range(u.shape[0]):
for zi in range(u.shape[1]):
bouy['u'][ti,zi,:] = RectBivariateSpline(
u['yu_ocean'], u['xu_ocean'], u[ti,zi,:,:],
kx=1, ky=1,
).ev(bouy['lon'], bouy['lat'])
bouy['v'][ti,zi,:] = RectBivariateSpline(
v['yu_ocean'], v['xu_ocean'], v[ti,zi,:,:],
kx=1, ky=1,
).ev(bouy['lon'], bouy['lat'])
print(zi)
print(ti)
print(bouy['u'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment