Skip to content

Instantly share code, notes, and snippets.

@matthewturk
Created November 13, 2018 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewturk/57360f40433817ecee4ef76bb817d970 to your computer and use it in GitHub Desktop.
Save matthewturk/57360f40433817ecee4ef76bb817d970 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/mturk/conda-py3/lib/python3.6/site-packages/ipykernel_launcher.py:12: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.\n",
" if sys.path[0] == '':\n"
]
}
],
"source": [
"from netCDF4 import Dataset\n",
"import numpy as np\n",
"import yt\n",
"\n",
"data_filename = \"/home/mturk/Downloads/DNA13_percent.nc\"\n",
"\n",
"nc_dataset = Dataset(data_filename)\n",
"latitude = nc_dataset.variables[\"latitude\"][:]\n",
"longitude = nc_dataset.variables[\"longitude\"][:]\n",
"depth = 6371 - nc_dataset.variables[\"depth\"][:][::-1]\n",
"\n",
"data = {v: nc_dataset.variables[v][::-1,::-1,:] for v in ('vp', 'vsh', 'vsv', 'vsvj')}\n",
"\n",
"bbox = np.array([[depth[0], depth[-1]],\n",
" [latitude[0], latitude[-1]],\n",
" [longitude[0],longitude[-1]]])\n",
"\n",
"ds = yt.load_uniform_grid(data, domain_dimensions = (depth.shape[0], latitude.shape[0], longitude.shape[0]),\n",
" bbox = bbox, length_unit=yt.units.km,\n",
" geometry = (\"internal_geographic\",(\"depth\", \"latitude\", \"longitude\")),\n",
")\n",
"\n",
"ds.outer_radius = yt.units.km * 6371"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(YTArray([5091., 25., 234.]) code_length,\n",
" YTArray([6371., 52., 288.]) code_length)"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ds.domain_left_edge, ds.domain_right_edge"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"yt : [WARNING ] 2018-11-13 14:11:51,997 Plot image for field ('stream', 'vsvj') has both positive and negative values. Min = -1.937000, Max = 9999.000000.\n",
"yt : [WARNING ] 2018-11-13 14:11:51,998 Switching to symlog colorbar scaling unless linear scaling is specified later\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"[-57.29557217 -57.29557201 -57.10031841] [ inf inf 57.10031841]\n"
]
}
],
"source": [
"yt.SlicePlot(ds, \"depth\", \"vsvj\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment