Classes | Functions | Variables
PandAna.core.core Namespace Reference

Classes

class  associate
 
class  Cut
 
class  dfproxy
 
class  filledSpectrum
 
class  interactive_loader
 
class  loader
 
class  spectrum
 
class  Var
 

Functions

def save_spectra (fname, spectra, groups)
 
def save_tree (fname, spectra, groups, attrs=True)
 
def load_spectra (fname, groups)
 
def load_tree (fname, groups, attrs=True)
 

Variables

list KL = ['run', 'subrun', 'cycle', 'evt', 'subevt']
 
list KLN = ['run', 'subrun', 'cycle', 'evt']
 
list KLS = ['run', 'subrun', 'evt']
 

Function Documentation

def PandAna.core.core.load_spectra (   fname,
  groups 
)

Definition at line 164 of file core.py.

Referenced by PandAna.reco_validation.prod5_pid_validation.main(), and PandAna.reco_validation.prod5_pid_validation_data_mc.prod5_pid_data_mc().

164 def load_spectra(fname, groups):
165  if not type(groups) is list: groups = [groups]
166 
167  # ah that's more like it
168  store = pd.HDFStore(fname, 'r')
169 
170  ret = []
171  for group in groups:
172  df = store[group+'/dataframe']
173  pot = store.get_storer(group+'/dataframe').attrs.pot
174  weight = store[group+'/weights']
175 
176  ret.append(filledSpectrum(df, pot, weight=weight))
177 
178  store.close()
179 
180  if len(groups) == 1: return ret[0]
181  return ret
182 
def load_spectra(fname, groups)
Definition: core.py:164
::xsd::cxx::tree::type type
Definition: Database.h:110
def PandAna.core.core.load_tree (   fname,
  groups,
  attrs = True 
)

Definition at line 183 of file core.py.

References caf_analysis.keys, PandAna.Demos.demo1.range, and runNovaSAM.str.

Referenced by PandAna.utils.sadd_pandana.main().

183 def load_tree(fname, groups, attrs=True):
184  if not type(groups) is list: groups = [groups]
185  f = h5py.File(fname, 'r')
186  ret = []
187  for group in groups:
188  data = f[group+'/df'][()]
189  spec = {}
190  name = {}
191  cols = ['df0']
192  if len(data.shape) > 1:
193  cols = ['df'+str(i) for i in range(data.shape[1])]
194  coldata = [data]
195  if len(data.shape) > 1 and data.shape[1] != 1:
196  coldata = [data[:,i] for i in range(data.shape[1])]
197  spec = dict(zip(cols, coldata))
198  index = []
199  for key in f[group].keys():
200  if key != 'pot' and key != 'weights' and key != 'df' and key != 'name':
201  spec[key] = f[group+'/'+key][()]
202  index.append(key)
203  df = pd.DataFrame(spec)
204  df.set_index(index, inplace=True)
205  if 'name' in f[group].keys():
206  name = f[group+'/name'][()]
207  df.columns = name
208 
209  if attrs:
210  pot = f[group+'/pot'][()]
211  weights = pd.Series(f[group+'/weights'][()], df.index, name='weight')
212  ret.append(filledSpectrum(df, pot, weight=weights))
213  else:
214  ret.append(df)
215 
216  f.close()
217  return dict(zip(groups, ret))
218 
keys
Reco plots.
Definition: caf_analysis.py:46
::xsd::cxx::tree::type type
Definition: Database.h:110
def load_tree(fname, groups, attrs=True)
Definition: core.py:183
def PandAna.core.core.save_spectra (   fname,
  spectra,
  groups 
)

Definition at line 116 of file core.py.

References stan::math.head(), and print.

Referenced by PandAna.reco_validation.prod5_pid_validation.main(), and PandAna.reco_validation.prod5_pid_validation_data_mc.prod5_pid_data_mc().

116 def save_spectra(fname, spectra, groups):
117  if not type(spectra) is list: spectra = [spectra]
118  if not type(groups) is list : groups = [groups]
119  assert len(spectra)==len(groups), 'Each spectrum must have a group name.'
120 
121  # idk why we are giving things to the store
122  store = pd.HDFStore(fname, 'w')
123 
124  for spectrum, group in zip(spectra, groups):
125  print(spectrum.df().head())
126  store[group+'/dataframe'] = spectrum.df()
127  store.get_storer(group+'/dataframe').attrs.pot = spectrum.POT()
128  store[group+'/weights'] = spectrum.weight()
129 
130  store.close()
131 
132 # alternate save data function that doesn't utilise pytables
Eigen::Matrix< T, Eigen::Dynamic, 1 > head(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &v, size_t n)
Definition: head.hpp:24
::xsd::cxx::tree::type type
Definition: Database.h:110
bool print
def save_spectra(fname, spectra, groups)
Definition: core.py:116
def PandAna.core.core.save_tree (   fname,
  spectra,
  groups,
  attrs = True 
)

Definition at line 133 of file core.py.

References PandAna.Demos.demo1.range.

Referenced by PandAna.utils.sadd_pandana.main().

133 def save_tree(fname, spectra, groups, attrs=True):
134  if not type(spectra) is list: spectra = [spectra]
135  if not type(groups) is list : groups = [groups]
136  assert len(spectra)==len(groups), 'Each spectrum must have a group name.'
137 
138  f = h5py.File(fname, 'w')
139  for spectrum, group in zip(spectra, groups):
140  g = f.create_group(group)
141  df = spectrum.df()
142  vals = df.values
143  ismap = 'map' in group
144  if ismap:
145  for i in range(len(vals)):
146  vals[i] = vals[i].reshape(1, vals[i].shape[0])
147  vals = np.stack(np.concatenate(vals), axis = 0)
148 
149  g.create_dataset('df', data=vals)
150  if type(df) == pd.Series:
151  g.create_dataset('name', data=[df.name])
152  else:
153  g.create_dataset('name', data=df.columns.values.astype('S'))
154  if attrs:
155  g.create_dataset('pot', data=spectrum.POT())
156  g.create_dataset('weights', data=spectrum.weight())
157  index = df.index.names
158  indexdf = df.reset_index()
159  for name in index:
160  g.create_dataset(name, data=indexdf[name].values)
161 
162  f.close()
163 # Load spectra from a file. Takes one or a list of group names to read
::xsd::cxx::tree::type type
Definition: Database.h:110
def save_tree(fname, spectra, groups, attrs=True)
Definition: core.py:133

Variable Documentation

list PandAna.core.core.KL = ['run', 'subrun', 'cycle', 'evt', 'subevt']

Definition at line 10 of file core.py.

list PandAna.core.core.KLN = ['run', 'subrun', 'cycle', 'evt']

Definition at line 11 of file core.py.

list PandAna.core.core.KLS = ['run', 'subrun', 'evt']

Definition at line 12 of file core.py.