{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# AMR slice animation with YT"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Module import"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"import time\n",
"import yt\n",
"import dispatch.yt\n",
"import numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Optionally, turn of YT info lines"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"yt.funcs.mylog.setLevel(40)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Data directory, run directory, and data source field"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"data='../data'\n",
"run='amr_7'\n",
"fld='density'"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"z=0.6\n",
"ds=dispatch.yt.snapshot(30,run,data)\n",
"slc=yt.SlicePlot(ds,axis=2,fields=fld,center=[.5,.5,z])\n",
"slc.set_log(fld,True)\n",
"slc.set_colorbar_label(fld,\"Density\")\n",
"slc.set_xlabel(\"\")\n",
"slc.set_ylabel(\"\")\n",
"slc.annotate_grids(edgecolors=\"white\")\n",
"slc.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Make a sub-directory for images"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"os.makedirs(data+'/'+run+'/im',exist_ok=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Loop over a number of timesteps, producing images for an animation:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020\n",
"021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040\n",
"041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060\n",
"061 062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080\n",
"081 082 083 084 085 086 087 088 089 090 091 092 "
]
}
],
"source": [
"z=0.6 # slice plane\n",
"i0=5 # 1st snapshot\n",
"i1=50 # last snapshot\n",
"im=(i0-5)*2+1 # first frame number\n",
"for i in range(i0,i1+1):\n",
" ds=dispatch.yt.snapshot(i,run,'../data') # data source\n",
" slc=yt.SlicePlot(ds,axis=2,fields=fld,center=[.5,.5,z]) # slice it\n",
" slc.set_log(fld,True) # use log density\n",
" slc.set_colorbar_label(fld,\"Density\") # replace label on colbar\n",
" slc.set_xlabel(\"\"); slc.set_ylabel(\"\") # blank out x- and y-labels\n",
" slc.annotate_grids(edgecolors=\"white\") # color of grid annotation\n",
" for j in (0,1): # double frames\n",
" file='{}/{}/im/{:03d}.png'.format(data,run,im) # .png file\n",
" sys.stdout.write('{:03d}'.format(im)) # progress\n",
" c='\\n' if im%20 == 0 else ' ' # new line or not\n",
" sys.stdout.write(c)\n",
" im+=1\n",
" slc.save(file)"
]
}
],
"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.7.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}