Skip to content

Commit 8c0f5e8

Browse files
authored
Merge pull request #337 from illorenzo7/shell_slice_and_spectra_consistency
Shell slice and spectra consistency
2 parents 2a2dddd + c005d05 commit 8c0f5e8

File tree

1 file changed

+45
-15
lines changed

1 file changed

+45
-15
lines changed

post_processing/rayleigh_diagnostics.py

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,9 @@ class Shell_Slices:
949949
self.nphi : number of phi points
950950
self.qv[0:nq-1] : quantity codes for the diagnostics output
951951
self.radius[0:nr-1] : radii of the shell slices output
952-
self.inds[0:nr-1] : radial indices of the shell slices output
952+
self.rad_inds[0:nr-1] : radial indices of the shell slices output (from the full simulation radial grid)
953+
: corresponding to each point in self.radius
954+
self.inds : same as self.rad_inds (for backwards compatibility)
953955
self.costheta[0:ntheta-1] : cos(theta grid)
954956
self.sintheta[0:ntheta-1] : sin(theta grid)
955957
self.vals[0:nphi-1,0:ntheta-1,0:nr-1,0:nq-1,0:niter-1]
@@ -958,6 +960,10 @@ class Shell_Slices:
958960
self.time[0:niter-1] : The simulation time corresponding to each time step
959961
self.version : The version code for this particular output (internal use)
960962
self.lut : Lookup table for the different diagnostics output
963+
964+
--Note that the indices (rad_inds = inds) use Python's 0-based array indexing.
965+
--This means that if rad_inds are 1,2,5, say, then in Rayleigh they correspond to points 2,3,6
966+
--on the global grid that runs from 1 through N_R.
961967
"""
962968

963969
def print_info(self, print_costheta = False):
@@ -971,7 +977,7 @@ def print_info(self, print_costheta = False):
971977
print( '.......................')
972978
print( 'radius : ', self.radius)
973979
print( '.......................')
974-
print( 'inds : ', self.inds)
980+
print( 'rad_inds : ', self.rad_inds)
975981
print( '.......................')
976982
print( 'iters : ', self.iters)
977983
print( '.......................')
@@ -1018,18 +1024,18 @@ def __init__(self,filename='none',path='Shell_Slices/',slice_spec = [], rec0 = F
10181024
self.lut = get_lut(qv)
10191025

10201026
radius = np.reshape(swapread(fd,dtype='float64',count=nr,swap=bs),(nr), order = 'F')
1021-
inds = np.reshape(swapread(fd,dtype='int32',count=nr,swap=bs),(nr), order = 'F')
1027+
rad_inds = np.reshape(swapread(fd,dtype='int32',count=nr,swap=bs),(nr), order = 'F')
10221028
self.costheta = np.reshape(swapread(fd,dtype='float64',count=ntheta,swap=bs),(ntheta), order = 'F')
10231029
self.sintheta = (1.0-self.costheta**2)**0.5
10241030

10251031
# convert from Fortran 1-based to Python 0-based indexing
1026-
inds = inds - 1
1032+
rad_inds = rad_inds - 1
10271033

10281034
if (len(slice_spec) == 3):
10291035

10301036
self.iters = np.zeros(1,dtype='int32')
10311037
self.qv = np.zeros(1,dtype='int32')
1032-
self.inds = np.zeros(1,dtype='int32')
1038+
self.rad_inds = np.zeros(1,dtype='int32')
10331039
self.time = np.zeros(1,dtype='float64')
10341040
self.iters = np.zeros(1,dtype='float64')
10351041
self.radius = np.zeros(1,dtype='float64')
@@ -1096,7 +1102,7 @@ def __init__(self,filename='none',path='Shell_Slices/',slice_spec = [], rec0 = F
10961102
fd.seek(seek_bytes,1)
10971103

10981104
self.radius[0] = radius[rspec]
1099-
self.inds[0] = inds[rspec]
1105+
self.rad_inds[0] = rad_inds[rspec]
11001106
self.qv[0] = qspec
11011107
tmp = np.reshape(swapread(fd,dtype='float64',count=ntheta*nphi,swap=bs),(nphi,ntheta), order = 'F')
11021108
self.vals[:,:,0,0,0] = tmp
@@ -1107,7 +1113,8 @@ def __init__(self,filename='none',path='Shell_Slices/',slice_spec = [], rec0 = F
11071113
#If true, read only the first record of the file.
11081114
nrec = 1
11091115
self.radius = radius
1110-
self.inds = inds
1116+
self.rad_inds = rad_inds
1117+
self.inds = rad_inds
11111118
self.qv = qv
11121119
self.niter = nrec
11131120
self.vals = np.zeros((nphi,ntheta,nr,nq,nrec),dtype='float64')
@@ -1131,7 +1138,9 @@ class SPH_Modes:
11311138
self.nell : number of ell values
11321139
self.qv[0:nq-1] : quantity codes for the diagnostics output
11331140
self.radius[0:nr-1] : radii of the shell slices output
1134-
self.inds[0:nr-1] : radial indices of the shell slices output
1141+
self.rad_inds[0:nr-1] : radial indices of the shell slices output (from the full simulation radial grid)
1142+
: corresponding to each point in self.radius
1143+
self.inds : same as self.rad_inds (for backwards compatibility)
11351144
self.lvals[0:nell-1] : ell-values output
11361145
self.vals[0:lmax,0:nell-1,0:nr-1,0:nq-1,0:niter-1]
11371146
: The complex spectra of the SPH modes output
@@ -1140,6 +1149,10 @@ class SPH_Modes:
11401149
self.time[0:niter-1] : The simulation time corresponding to each time step
11411150
self.version : The version code for this particular output (internal use)
11421151
self.lut : Lookup table for the different diagnostics output
1152+
1153+
--Note that the indices (rad_inds = inds) use Python's 0-based array indexing.
1154+
--This means that if rad_inds are 1,2,5, say, then in Rayleigh they correspond to points 2,3,6
1155+
--on the global grid that runs from 1 through N_R.
11431156
"""
11441157

11451158
def __init__(self,filename='none',path='SPH_Modes/'):
@@ -1168,13 +1181,14 @@ def __init__(self,filename='none',path='SPH_Modes/'):
11681181

11691182
self.qv = np.reshape(swapread(fd,dtype='int32',count=nq,swap=bs),(nq), order = 'F')
11701183
self.radius = np.reshape(swapread(fd,dtype='float64',count=nr,swap=bs),(nr), order = 'F')
1171-
self.inds = np.reshape(swapread(fd,dtype='int32',count=nr,swap=bs),(nr), order = 'F')
1184+
self.rad_inds = np.reshape(swapread(fd,dtype='int32',count=nr,swap=bs),(nr), order = 'F')
11721185
self.lvals = np.reshape(swapread(fd,dtype='int32',count=nell,swap=bs),(nell), order = 'F')
11731186
lmax = np.max(self.lvals)
11741187
nm = lmax+1
11751188

11761189
# convert from Fortran 1-based to Python 0-based indexing
1177-
self.inds = self.inds - 1
1190+
self.rad_inds = self.rad_inds - 1
1191+
self.inds = self.rad_inds
11781192

11791193
self.vals = np.zeros((nm,nell,nr,nq,nrec),dtype='complex128')
11801194

@@ -1218,7 +1232,9 @@ class Shell_Spectra:
12181232
self.mmax : maximum spherical harmonic degree m
12191233
self.qv[0:nq-1] : quantity codes for the diagnostics output
12201234
self.radius[0:nr-1] : radii of the shell slices output
1221-
self.inds[0:nr-1] : radial indices of the shell slices output
1235+
self.rad_inds[0:nr-1] : radial indices of the shell slices output (from the full simulation radial grid)
1236+
: corresponding to each point in self.radius
1237+
self.inds : same as self.rad_inds (for backwards compatibility)
12221238
self.vals[0:lmax,0:mmax,0:nr-1,0:nq-1,0:niter-1]
12231239
: The complex spectra of the shells output
12241240
self.lpower[0:lmax,0:nr-1,0:nq-1,0:niter-1,3] : The power as a function of ell, integrated over m
@@ -1227,6 +1243,10 @@ class Shell_Spectra:
12271243
self.time[0:niter-1] : The simulation time corresponding to each time step
12281244
self.version : The version code for this particular output (internal use)
12291245
self.lut : Lookup table for the different diagnostics output
1246+
1247+
--Note that the indices (rad_inds = inds) use Python's 0-based array indexing.
1248+
--This means that if rad_inds are 1,2,5, say, then in Rayleigh they correspond to points 2,3,6
1249+
--on the global grid that runs from 1 through N_R.
12301250
"""
12311251

12321252
def print_info(self):
@@ -1242,7 +1262,7 @@ def print_info(self):
12421262
print( '.......................')
12431263
print( 'radius : ', self.radius)
12441264
print( '.......................')
1245-
print( 'inds : ', self.inds)
1265+
print( 'rad_inds : ', self.rad_inds)
12461266
print( '.......................')
12471267
print( 'iters : ', self.iters)
12481268
print( '.......................')
@@ -1282,15 +1302,16 @@ def __init__(self,filename='none',path='Shell_Spectra/'):
12821302

12831303
self.qv = np.reshape(swapread(fd,dtype='int32',count=nq,swap=bs),(nq), order = 'F')
12841304
self.radius = np.reshape(swapread(fd,dtype='float64',count=nr,swap=bs),(nr), order = 'F')
1285-
self.inds = np.reshape(swapread(fd,dtype='int32',count=nr,swap=bs),(nr), order = 'F')
1305+
self.rad_inds = np.reshape(swapread(fd,dtype='int32',count=nr,swap=bs),(nr), order = 'F')
12861306
self.vals = np.zeros((nell,nm,nr,nq,nrec),dtype='complex128')
12871307

12881308
self.iters = np.zeros(nrec,dtype='int32')
12891309
self.time = np.zeros(nrec,dtype='float64')
12901310
self.version = version
12911311

12921312
# convert from Fortran 1-based to Python 0-based indexing
1293-
self.inds = self.inds - 1
1313+
self.rad_inds = self.rad_inds - 1
1314+
self.inds = self.rad_inds
12941315

12951316
for i in range(nrec):
12961317

@@ -1334,13 +1355,19 @@ class Power_Spectrum():
13341355
self.nr : number of radii at which power spectra are available
13351356
self.lmax : maximum spherical harmonic degree l
13361357
self.radius[0:nr-1] : radii of the shell slices output
1337-
self.inds[0:nr-1] : radial indices of the shell slices output
1358+
self.rad_inds[0:nr-1] : radial indices of the shell slices output (from the full simulation radial grid)
1359+
: corresponding to each point in self.radius
1360+
self.inds : same as self.rad_inds (for backwards compatibility)
13381361
self.power[0:lmax,0:nr-1,0:niter-1,0:2] : the velocity power spectrum. The third
13391362
: index indicates (0:total,1:m=0, 2:total-m=0 power)
13401363
self.mpower[0:lmax,0:nr-1,0:niter-1,0:2] : the magnetic power spectrum
13411364
self.iters[0:niter-1] : The time step numbers stored in this output file
13421365
self.time[0:niter-1] : The simulation time corresponding to each time step
13431366
self.magnetic : True if mpower exists
1367+
1368+
--Note that the indices (rad_inds = inds) use Python's 0-based array indexing.
1369+
--This means that if rad_inds are 1,2,5, say, then in Rayleigh they correspond to points 2,3,6
1370+
--on the global grid that runs from 1 through N_R.
13441371
"""
13451372
#Power Spectrum Class - generated using shell spectra files
13461373
def __init__(self,infile, dims=[],power_file = False, magnetic = False, path="Shell_Spectra"):
@@ -1368,6 +1395,7 @@ def set_pars(self,iters,time,inds,radius):
13681395
self.iters[:] = iters[:]
13691396
self.time[:] = time[:]
13701397
self.inds[:] = inds[:]
1398+
self.rad_inds = self.inds
13711399
self.radius[:] = radius[:]
13721400
def power_file_init(self,pfile):
13731401
fd = open(pfile,'rb')
@@ -1383,6 +1411,7 @@ def power_file_init(self,pfile):
13831411
self.iters = np.reshape(swapread(fd,dtype='int32',count=niter,swap=bs),(niter), order = 'F')
13841412
self.time = np.reshape(swapread(fd,dtype='float64',count=niter,swap=bs),(niter), order = 'F')
13851413
self.inds = np.reshape(swapread(fd,dtype='int32',count=nr,swap=bs),(nr), order = 'F')
1414+
self.rad_inds = self.inds
13861415
self.radius = np.reshape(swapread(fd,dtype='float64',count=nr,swap=bs),(nr), order = 'F')
13871416
pcount = (lmax+1)*nr*niter*3
13881417
pdim = (lmax+1,nr,niter,3)
@@ -1430,6 +1459,7 @@ def spectra_file_init(self,sfile):
14301459
self.niter = nt
14311460
self.radius = a.radius
14321461
self.inds = a.inds
1462+
self.rad_inds = self.inds
14331463
self.iters = a.iters
14341464
self.time = a.time
14351465

0 commit comments

Comments
 (0)