2

So my research mates and I are trying to save a pretty big (47104,5) array into a TTree in a ROOT file. The array on the Python side works fine. We can access everything and run normal commands, but when we run the root_numpy.array2root() command, we get a weird error.

Object of type 'NoneType' has no len()

The code we are running for this portion is as follows:

import root_numpy as rnp
import numpy as np
import scipy
import logging

def save_array(outputArray, outputName):
    outputString =str(outputName)
    logging.info("Creating .Root file")
    rnp.array2root(outputArray,outputString,treename="Training_Variables",mode="recreate")

We placed the outputString variable as a way to make sure we were putting the filename in as a string. ( In our python terminal, we add .root at the end of outputName to save it as a .root file.).

Here is a picture of the terminal. Showing exact error location in root_numpy

Pretty much, we are confused about why array2root() is calling for the len() of an object, which we dont think should have a len? It should just have a shape. Any insight would be greatly appreciated.

11
  • Remember to take good care to be sure that you have proper punctuation and grammar. It can be very distracting to see a sentence start with a lowercase letter. Commented Mar 8, 2016 at 4:29
  • 1
    My bad. I will change that immediately. Thank you! Commented Mar 8, 2016 at 4:58
  • 1
    you can use hdf5, at least I think you can. Commented Mar 9, 2016 at 17:13
  • What is HDF5? But @Pierre helped me out by telling me to make a structured array! Commented Mar 9, 2016 at 20:37
  • @zhilothebest you can use google to learn about hdf5. Specifically, h5py is probably the best solution for your problem unless you're collaborating with someone who needs to use ROOT. Why do you need to use ROOT? Commented Mar 15, 2016 at 12:01

1 Answer 1

1

The conversion routines from NumPy arrays to ROOT datatypes work with structured arrays. See the two following links. (Not tested, but this is very likely the problem as the routines use the arr.dtypes.names and arr.dtypes.fields attributes).

http://rootpy.github.io/root_numpy/reference/generated/root_numpy.array2tree.html#root_numpy.array2tree

http://rootpy.github.io/root_numpy/reference/generated/root_numpy.array2root.html#root_numpy.array2root

Sign up to request clarification or add additional context in comments.

4 Comments

Thats the website where I found the commands on. It doesnt really help with troubleshooting though. Edit: What exactly does dtypes.names and dtypes.fields mean? I dont understand the use of the second period.
In the examples, the arrays have "column names", that is the dtype=... option. Does your array sig have those "column names"? If not, they apparently cannot be converted to ROOT data.
Interesting. Ill try that out and let you know what happens. Thanks for the advice!
Thank you so much! It works! It took a while to figure out how to make a list of tuples, but once I figured it out, I have my files. Thank you so much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.