Skip to content

Instantly share code, notes, and snippets.

@ngoldbaum
Created August 10, 2017 15:49
Show Gist options
  • Save ngoldbaum/4d4eaaee72e7f13f16547d327e5ddd88 to your computer and use it in GitHub Desktop.
Save ngoldbaum/4d4eaaee72e7f13f16547d327e5ddd88 to your computer and use it in GitHub Desktop.
import yt
import netCDF4
import numpy as np
dataset = netCDF4.Dataset('http://www.smast.umassd.edu:8080/thredds/dodsC/FVCOM/NECOFS/Forecasts/NECOFS_FVCOM_OCEAN_MASSBAY_FORECAST.nc')
connectivity = dataset['nv'][:].T.astype('int64')-1
x = dataset['x'][:]
y = dataset['y'][:]
coordinates = np.vstack((x, y)).T.astype('float64')
temp = dataset['temp'][0][0][:].astype('float64')[connectivity]
node_data = {('connect1', 'temperature'): (temp, 'degC')}
ds = yt.load_unstructured_mesh(connectivity, coordinates, node_data=node_data,
length_unit='m', temperature_unit='degC')
plot = yt.SlicePlot(ds, 2, ('connect1', 'temperature'))
image = plot.frb['connect1', 'temperature']
image[image == 0] = np.nan
plot.annotate_mesh_lines(plot_args={'color': 'k', 'linewidth': 0.2})
plot.set_log(('connect1', 'temperature'), False)
plot.save(mpl_kwargs={'dpi': 400})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment