zero-size array when calling to trees

Ignacio Gargiulo
  • 3
  • 2 Jul '15


I'm working with the example scripts. I was trying to run the following example In the Merger Trees section :

fields=['SubhaloMass', 'SubfindID', 'SnapNum']

for i in range(start, start+5):
    tree = il.sublink.loadTree(basePath, 135, GroupFirstSub[i], fields=fields, onlyMPB=True)
    plt.plot(tree['Snapnum'], tree['SubhaloMass'] * 1e10 / 0.704 ,'-')

plt.xlabel('Snapshot Number')
plt.ylabel('Total Subhalo Mass [$M\odot$]')

and get an error: ValueError: zero-size array to reduction operation maximum which has no identity , with this traceback:

ValueError                                Traceback (most recent call last)
<ipython-input-95-9ce9d16cf6f9> in <module>()
      4 #fig, axs=plt.subplots(ncols=2, figsize= (14,6))
      5 for i in range(start, start+5):
----> 6     tree = il.sublink.loadTree(basePath, 135, GroupFirstSub[i], fields=fields, onlyMPB=True)
      7     plt.plot(tree['Snapnum'], tree['SubhaloMass'] * 1e10 / 0.704 ,'-')
      8 #    axs[0].plot(tree['Snapnum'], tree['SubhaloMass'] * 1e10 / 0.704 ,'-')

/home/tuna/ILLUSTRIS/illustris_python/sublink.pyc in loadTree(basePath, snapNum, id, fields, onlyMPB)
     58     # find the tree file chunk containing this row
     59     rowOffsets = rowStart - offsets
---> 60     fileNum = np.max(np.where( rowOffsets >= 0 ))
     61     fileOff = rowOffsets[fileNum]

/home/tuna/.local/lib64/python2.7/site-packages/numpy/core/fromnumeric.pyc in amax(a, axis, out, keepdims)
   2247         except AttributeError:
   2248             return _methods._amax(a, axis=axis,
-> 2249                                   out=out, keepdims=keepdims)
   2250         # NOTE: Dropping the keepdims parameter
   2251         return amax(axis=axis, out=out)

/home/tuna/.local/lib64/python2.7/site-packages/numpy/core/_methods.pyc in _amax(a, axis, out, keepdims)
     24 # small reductions
     25 def _amax(a, axis=None, out=None, keepdims=False):
---> 26     return umr_maximum(a, axis, None, out, keepdims)
     28 def _amin(a, axis=None, out=None, keepdims=False):

Value Error:  zero-size array to reduction operation maximum which has no identity.

It seems that somewhere there is an empty array passing through the functions. I have downloaded the full merger trees for the Illustris-3 simulation that i'm working with (First question: 46 tree_extended.hdf5 files, is that ok ? i didn't find where to look to check if my merger trees are complete). Second question: Do you have a clue of what is going on?

Many thanks in advance!

Ignacio Gargiulo
  • 2 Jul '15

Already solved! There was a problem with my path to the trees directory (Sublink in place of SubLink). Oddly, there was no error message involving the path, and a counter in was 0, and that triggered the latter error :

numTreeFiles = len(glob.glob(treePath(basePath,'*'))) #line 51 ! In light of future problems with this, it could be a good practice to put some control and error message about the path to the trees directory. When i changed the basePath name for example, this error message ocurred, so i discarded for some time a path name problem. Just a suggestion Many thanks.

Dylan Nelson
  • 3 Jul '15

Glad that it was a minor problem. You're right, there is very little control logic in the example scripts - they were made very minimal, so as to hopefully be understandable and changeable. If you want to make a pull request though I'm happy to include any reasonable improvements you might make.

In my own stuff, I generally would make/save a "simulation parameters" dictionary type object, to store all the related meta-data for each simulation. This would include paths and number of files, etc, to avoid filesystem searches such as glob.glob().

  • Page 1 of 1