Added Astaroth 2.0
This commit is contained in:
24
analysis/python/astar/__init__.py
Normal file
24
analysis/python/astar/__init__.py
Normal file
@@ -0,0 +1,24 @@
|
||||
'''
|
||||
Copyright (C) 2014-2019, Johannes Pekkilae, Miikka Vaeisalae.
|
||||
|
||||
This file is part of Astaroth.
|
||||
|
||||
Astaroth is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Astaroth is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Astaroth. If not, see <http://www.gnu.org/licenses/>.
|
||||
'''
|
||||
|
||||
# Developers note. We require Python 3 approach to have
|
||||
# compatibility towards the future.
|
||||
|
||||
import numpy as np
|
||||
import pylab as plt
|
21
analysis/python/astar/data/__init__.py
Normal file
21
analysis/python/astar/data/__init__.py
Normal file
@@ -0,0 +1,21 @@
|
||||
'''
|
||||
Copyright (C) 2014-2019, Johannes Pekkilae, Miikka Vaeisalae.
|
||||
|
||||
This file is part of Astaroth.
|
||||
|
||||
Astaroth is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Astaroth is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Astaroth. If not, see <http://www.gnu.org/licenses/>.
|
||||
'''
|
||||
|
||||
|
||||
from . import read
|
142
analysis/python/astar/data/read.py
Normal file
142
analysis/python/astar/data/read.py
Normal file
@@ -0,0 +1,142 @@
|
||||
'''
|
||||
Copyright (C) 2014-2019, Johannes Pekkilae, Miikka Vaeisalae.
|
||||
|
||||
This file is part of Astaroth.
|
||||
|
||||
Astaroth is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Astaroth is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Astaroth. If not, see <http://www.gnu.org/licenses/>.
|
||||
'''
|
||||
|
||||
# This module is for reading data.
|
||||
|
||||
import numpy as np
|
||||
|
||||
def read_bin(fname, fdir, fnum, minfo, numtype=np.longdouble):
|
||||
'''Read in a floating point array'''
|
||||
filename = fdir + fname + '_' + fnum + '.mesh'
|
||||
datas = np.DataSource()
|
||||
read_ok = datas.exists(filename)
|
||||
if read_ok:
|
||||
print(filename)
|
||||
array = np.fromfile(filename, dtype=numtype)
|
||||
|
||||
timestamp = array[0]
|
||||
|
||||
array = np.reshape(array[1:], (minfo.contents['AC_mx'],
|
||||
minfo.contents['AC_my'],
|
||||
minfo.contents['AC_mz']), order='F')
|
||||
else:
|
||||
array = None
|
||||
timestamp = None
|
||||
|
||||
return array, timestamp, read_ok
|
||||
|
||||
def read_meshtxt(fdir, fname):
|
||||
with open(fdir+fname) as f:
|
||||
filetext = f.read().splitlines()
|
||||
|
||||
contents = {}
|
||||
|
||||
for line in filetext:
|
||||
line = line.split()
|
||||
if line[0] == 'int':
|
||||
contents[line[1]] = np.int(line[2])
|
||||
elif line[0] == 'real':
|
||||
contents[line[1]] = np.float(line[2])
|
||||
else:
|
||||
print('ERROR: ' + line[0] +' no recognized!')
|
||||
|
||||
return contents
|
||||
|
||||
class MeshInfo():
|
||||
'''Object that contains all mesh info'''
|
||||
|
||||
def __init__(self, fdir):
|
||||
self.contents = read_meshtxt(fdir, 'mesh_info.list')
|
||||
|
||||
class Mesh:
|
||||
'''Class tha contains all 3d mesh data'''
|
||||
|
||||
def __init__(self, fnum, fdir=""):
|
||||
fnum = str(fnum)
|
||||
self.framenum = fnum.zfill(10)
|
||||
|
||||
self.minfo = MeshInfo(fdir)
|
||||
|
||||
self.lnrho, self.timestamp, self.ok = read_bin('VTXBUF_LNRHO', fdir, fnum, self.minfo)
|
||||
|
||||
if self.ok:
|
||||
|
||||
self.ss, timestamp, ok = read_bin('VTXBUF_ENTROPY', fdir, fnum, self.minfo)
|
||||
|
||||
#TODO Generalize is a dict. Do not hardcode!
|
||||
uux, timestamp, ok = read_bin('VTXBUF_UUX', fdir, fnum, self.minfo)
|
||||
uuy, timestamp, ok = read_bin('VTXBUF_UUY', fdir, fnum, self.minfo)
|
||||
uuz, timestamp, ok = read_bin('VTXBUF_UUZ', fdir, fnum, self.minfo)
|
||||
self.uu = (uux, uuy, uuz)
|
||||
uux = []
|
||||
uuy = []
|
||||
uuz = []
|
||||
|
||||
aax, timestamp, ok = read_bin('VTXBUF_AX', fdir, fnum, self.minfo)
|
||||
aay, timestamp, ok = read_bin('VTXBUF_AY', fdir, fnum, self.minfo)
|
||||
aaz, timestamp, ok = read_bin('VTXBUF_AZ', fdir, fnum, self.minfo)
|
||||
self.aa = (aax, aay, aaz)
|
||||
aax = []
|
||||
aay = []
|
||||
aaz = []
|
||||
|
||||
self.xx = self.minfo.contents['AC_inv_dsx']*np.arange(self.minfo.contents['AC_mx'])
|
||||
self.yy = self.minfo.contents['AC_inv_dsy']*np.arange(self.minfo.contents['AC_my'])
|
||||
self.zz = self.minfo.contents['AC_inv_dsz']*np.arange(self.minfo.contents['AC_mz'])
|
||||
|
||||
self.xmid = int(self.minfo.contents['AC_mx']/2)
|
||||
self.ymid = int(self.minfo.contents['AC_my']/2)
|
||||
self.zmid = int(self.minfo.contents['AC_mz']/2)
|
||||
|
||||
|
||||
def parse_ts(fdir, fname):
|
||||
with open(fdir+fname) as f:
|
||||
filetext = f.read().splitlines()
|
||||
|
||||
var = {}
|
||||
|
||||
line = filetext[0].split()
|
||||
for i in range(len(line)):
|
||||
line[i] = line[i].replace('VTXBUF_', "")
|
||||
line[i] = line[i].replace('UU', "uu")
|
||||
line[i] = line[i].replace('_total', "tot")
|
||||
line[i] = line[i].replace('A', "aa")
|
||||
line[i] = line[i].replace('LNRHO', "lnrho")
|
||||
line[i] = line[i].replace('X', "x")
|
||||
line[i] = line[i].replace('Y', "y")
|
||||
line[i] = line[i].replace('Z', "z")
|
||||
|
||||
tsdata = np.loadtxt(fdir+fname,skiprows=1)
|
||||
|
||||
for i in range(len(line)):
|
||||
var[line[i]] = tsdata[:,i]
|
||||
|
||||
var['step'] = np.int64(var['step'])
|
||||
|
||||
print("HERE ARE ALL KEYS FOR TS DATA:")
|
||||
print(var.keys())
|
||||
|
||||
return var
|
||||
|
||||
class TimeSeries:
|
||||
'''Class for time series data'''
|
||||
|
||||
def __init__(self, fdir="", fname="timeseries.ts"):
|
||||
|
||||
self.var = parse_ts(fdir, fname)
|
21
analysis/python/astar/visual/__init__.py
Normal file
21
analysis/python/astar/visual/__init__.py
Normal file
@@ -0,0 +1,21 @@
|
||||
'''
|
||||
Copyright (C) 2014-2019, Johannes Pekkilae, Miikka Vaeisalae.
|
||||
|
||||
This file is part of Astaroth.
|
||||
|
||||
Astaroth is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Astaroth is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Astaroth. If not, see <http://www.gnu.org/licenses/>.
|
||||
'''
|
||||
|
||||
|
||||
from . import slices
|
92
analysis/python/astar/visual/slices.py
Normal file
92
analysis/python/astar/visual/slices.py
Normal file
@@ -0,0 +1,92 @@
|
||||
|
||||
'''
|
||||
Copyright (C) 2014-2019, Johannes Pekkilae, Miikka Vaeisalae.
|
||||
|
||||
This file is part of Astaroth.
|
||||
|
||||
Astaroth is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Astaroth is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Astaroth. If not, see <http://www.gnu.org/licenses/>.
|
||||
'''
|
||||
import pylab as plt
|
||||
import numpy as np
|
||||
import matplotlib.gridspec as gridspec
|
||||
import matplotlib.colors as colors
|
||||
|
||||
CM_INFERNO = plt.get_cmap('inferno')
|
||||
|
||||
def plot_3(mesh, input_grid, title = '', fname = 'default', bitmap=False, slicetype = 'middle', colrange=None, colormap=CM_INFERNO , contourplot=False):
|
||||
fig = plt.figure(figsize=(8, 8))
|
||||
grid = gridspec.GridSpec(2, 3, wspace=0.4, hspace=0.4, width_ratios=[1,1, 0.15])
|
||||
ax00 = fig.add_subplot( grid[0,0] )
|
||||
ax10 = fig.add_subplot( grid[0,1] )
|
||||
ax11 = fig.add_subplot( grid[1,1] )
|
||||
axcbar = fig.add_subplot( grid[:,2] )
|
||||
|
||||
print(mesh.minfo.contents.keys())
|
||||
|
||||
if slicetype == 'middle':
|
||||
yz_slice = input_grid[mesh.xmid, :, :]
|
||||
xz_slice = input_grid[:, mesh.ymid, :]
|
||||
xy_slice = input_grid[:, :, mesh.zmid]
|
||||
if colrange==None:
|
||||
plotnorm = colors.Normalize(vmin=input_grid.min(),vmax=input_grid.max())
|
||||
else:
|
||||
plotnorm = colors.Normalize(vmin=colrange[0],vmax=colrange[1])
|
||||
elif slicetype == 'sum':
|
||||
yz_slice = np.sum(input_grid, axis=0)
|
||||
xz_slice = np.sum(input_grid, axis=1)
|
||||
xy_slice = np.sum(input_grid, axis=2)
|
||||
cmin = np.amin([yz_slice.min(), xz_slice.min(), xy_slice.min()])
|
||||
cmax = np.amax([yz_slice.max(), xz_slice.max(), xy_slice.max()])
|
||||
if colrange==None:
|
||||
plotnorm = colors.Normalize(vmin=cmin,vmax=cmax)
|
||||
else:
|
||||
plotnorm = colors.Normalize(vmin=colrange[0],vmax=colrange[1])
|
||||
|
||||
|
||||
yy, zz = np.meshgrid(mesh.yy, mesh.zz, indexing='ij')
|
||||
if contourplot:
|
||||
map1 = ax00.contourf(yy, zz, yz_slice, norm=plotnorm, cmap=colormap, nlev=10)
|
||||
else:
|
||||
map1 = ax00.pcolormesh(yy, zz, yz_slice, norm=plotnorm, cmap=colormap)
|
||||
ax00.set_xlabel('y')
|
||||
ax00.set_ylabel('z')
|
||||
ax00.set_title('%s t = %.4e' % (title, mesh.timestamp) )
|
||||
ax00.set_aspect('equal')
|
||||
|
||||
xx, zz = np.meshgrid(mesh.xx, mesh.zz, indexing='ij')
|
||||
if contourplot:
|
||||
ax10.contourf(xx, zz, xz_slice, norm=plotnorm, cmap=colormap, nlev=10)
|
||||
else:
|
||||
ax10.pcolormesh(xx, zz, xz_slice, norm=plotnorm, cmap=colormap)
|
||||
ax10.set_xlabel('x')
|
||||
ax10.set_ylabel('z')
|
||||
ax10.set_aspect('equal')
|
||||
|
||||
xx, yy = np.meshgrid(mesh.xx, mesh.yy, indexing='ij')
|
||||
if contourplot:
|
||||
ax11.contourf(xx, yy, xy_slice, norm=plotnorm, cmap=colormap, nlev=10)
|
||||
else:
|
||||
ax11.pcolormesh(xx, yy, xy_slice, norm=plotnorm, cmap=colormap)
|
||||
ax11.set_xlabel('x')
|
||||
ax11.set_ylabel('y')
|
||||
ax11.set_aspect('equal')
|
||||
|
||||
cbar = plt.colorbar(map1, cax=axcbar)
|
||||
|
||||
if bitmap:
|
||||
plt.savefig('%s_%s.png' % (fname, mesh.framenum))
|
||||
print('Saved %s_%s.png' % (fname, mesh.framenum))
|
||||
plt.close(fig)
|
||||
|
||||
|
Reference in New Issue
Block a user