Merge branch 'master' into reconnection
This commit is contained in:
commit
08d8c6250e
@ -113,6 +113,9 @@ def amun_attribute(fname, aname):
|
||||
ret = np.squeeze(attr).astype(str)
|
||||
else:
|
||||
ret = np.squeeze(attr)
|
||||
else:
|
||||
print("Attribute '%s' cannot be retrieved from '%s'!" % (aname, fname))
|
||||
ret = False
|
||||
|
||||
f.close()
|
||||
|
||||
@ -154,6 +157,9 @@ def amun_coordinate(fname, iname):
|
||||
ret = np.squeeze(item).astype(str)
|
||||
else:
|
||||
ret = np.squeeze(item)
|
||||
else:
|
||||
print("Coordinate item '%s' cannot be retrieved from '%s'!" % (iname, fname))
|
||||
ret = False
|
||||
|
||||
f.close()
|
||||
|
||||
@ -207,13 +213,18 @@ def amun_dataset(fname, vname, shrink = 1, progress = False):
|
||||
# prepare array to hold data
|
||||
#
|
||||
ndims = amun_attribute(fname, 'ndims')
|
||||
nb = amun_attribute(fname, 'ncells')
|
||||
bm = np.array([nb, nb, nb])
|
||||
nn = amun_attribute(fname, 'ncells')
|
||||
bm = np.array([nn, nn, nn])
|
||||
if ndims == 2:
|
||||
bm[2] = 1
|
||||
rm = amun_attribute(fname, 'domain_base_dims')
|
||||
ng = amun_attribute(fname, 'nghosts')
|
||||
ml = amun_attribute(fname, 'maxlev')
|
||||
f = h5.File(fname, 'r')
|
||||
if 'rdims' in f['attributes'].attrs:
|
||||
rm = amun_attribute(fname, 'rdims')
|
||||
else:
|
||||
rm = amun_attribute(fname, 'domain_base_dims')
|
||||
f.close()
|
||||
|
||||
# build the list of supported variables
|
||||
#
|
||||
@ -225,6 +236,7 @@ def amun_dataset(fname, vname, shrink = 1, progress = False):
|
||||
|
||||
# add derived variables if possible
|
||||
#
|
||||
variables.append('level')
|
||||
if 'velx' in variables and 'vely' in variables and 'velz' in variables:
|
||||
variables.append('velo')
|
||||
variables.append('divv')
|
||||
@ -264,12 +276,20 @@ def amun_dataset(fname, vname, shrink = 1, progress = False):
|
||||
print('The requested variable cannot be extracted from the file datasets!')
|
||||
return False
|
||||
|
||||
# check if the shrink parameter is correct
|
||||
# check if the shrink parameter is correct (block dimensions should be
|
||||
# divisible by the shrink factor)
|
||||
#
|
||||
sh = bm[0:ndims].min()
|
||||
while(sh > shrink):
|
||||
sh /= 2
|
||||
shrink = int(sh)
|
||||
shrink = max(1, int(shrink))
|
||||
if shrink > 1:
|
||||
if (nn % shrink) != 0:
|
||||
print('The block dimension should be divisible by the shrink factor!')
|
||||
return False
|
||||
sh = shrink
|
||||
while(sh > 2 and sh % 2 == 0):
|
||||
sh = int(sh / 2)
|
||||
if (sh % 2) != 0:
|
||||
print('The shrink factor should be a power of 2!')
|
||||
return False
|
||||
|
||||
# prepare dimensions of the output array and allocate it
|
||||
#
|
||||
@ -292,7 +312,11 @@ def amun_dataset(fname, vname, shrink = 1, progress = False):
|
||||
dz = amun_coordinate(lname, 'dz')
|
||||
f = h5.File(lname, 'r')
|
||||
g = f['variables']
|
||||
if vname == 'velo':
|
||||
if vname == 'level':
|
||||
dataset = np.zeros(g[variables[0]].shape)
|
||||
for l in range(dblocks):
|
||||
dataset[:,:,:,l] = levels[l]
|
||||
elif vname == 'velo':
|
||||
dataset = np.sqrt(g['velx'][:,:,:,:]**2 \
|
||||
+ g['vely'][:,:,:,:]**2 \
|
||||
+ g['velz'][:,:,:,:]**2)
|
||||
|
Loading…
x
Reference in New Issue
Block a user