1

I'm trying to save a large amount of Numpy arrays to a root file using uproot. I've read through the uproot documentation, and as far as I can tell this ability was remove in uproot3. Note I can't save this as a histogram because the order of the data is important (it's a waveform). Does anyone know of a work around, or thing I'm missing to do this?

e.g: I want something like this

'''

import numpy as np
import uproot as up

array = np.random.normal(0,1,1000)
file = up.recreate('./test.root')
file['Tree1'] = array

'''

  • Instead of `array`, write `{"branch_name": array}`. https://uproot.readthedocs.io/en/latest/basic.html#writing-ttrees-to-a-file – Jim Pivarski May 24 '22 at 17:23
  • @JimPivarski Thank you for the reply! I've tried that and I get a variation of the error message I get with my initial code, saying that dict is an unrecognized type and can't be converted to a root file. As far as I can tell, only strings, and histograms can be converted. – Glenn Richardson May 24 '22 at 19:01
  • In the latest version, at least, it can write TTrees, and the syntax it uses is the above. (The documentation has more examples, with more variations to try.) It is the case that histograms and strings were implemented first, so there could be some intermediate versions that can do those types but not a dict of arrays → TTree, but it would be a narrow range of versions. Maybe augment your question with examples of things you tried, the results, and your version of Uproot? – Jim Pivarski May 24 '22 at 22:29

0 Answers0