Functions | Variables
PandAna.utils.sadd_pandana Namespace Reference

Functions

def main (dest, source)
 

Variables

 dest = sys.argv[1]
 
list source = []
 
 these = glob.glob(arg)
 

Function Documentation

def PandAna.utils.sadd_pandana.main (   dest,
  source 
)

Definition at line 8 of file sadd_pandana.py.

References novadaq::HexUtils.format(), parse_dependency_file_t.list, PandAna.core.core.load_tree(), print, PandAna.core.core.save_tree(), and runNovaSAM.str.

8 def main(dest, source):
9  if not type(source) is list: source = [source]
10  print('Saving spectra from {} files to {}'.format(len(source), dest))
11  # assume all of the files have the same groups in them
12  first = h5py.File(source[0], 'r')
13  groups = list(first.keys())
14  first.close()
15 
16  print('Found {} groups'.format(len(groups)))
17  # this will work if all files have the exact same spectra
18  source_spectra = {}
19  dest_spectra = {}
20 
21  # create dictionaries of empty lists. We'll put spectra into these later
22  for g in groups:
23  source_spectra[g] = []
24  dest_spectra[g] = None
25 
26  # for each source file, load all groups
27  for s in source:
28  print('Loading spectra from {}'.format(s))
29  spectra = load_tree(s, groups)
30 
31  # add each spectra to the dictionary of source_spectra according to group
32  for group, spec in spectra:
33  source_spectra[group].append(spec)
34 
35  # get list of source_spectra corresponding to each group
36  for g in groups:
37  for spec in source_spectra[g]:
38  # if first spectra make assignment
39  if dest_spectra[g] is None:
40  dest_spectra[g] = spec
41  # else add it to the spectrum that already exists for that group
42  else:
43  # make sure all spectra being summed have the same name
44  assert str(dest_spectra[g]._df.name) == str(spec._df.name), \
45  'Spectra must have the same name to add them together ({} =/= {})'.format(dest_spectra[g]._df.name, spec._df.name)
46  dest_spectra[g] = dest_spectra[g] + spec
47 
48  save_tree(dest, list(dest_spectra.values()), list(dest_spectra.keys()))
49 
50 
51 
52 
def main(dest, source)
Definition: sadd_pandana.py:8
::xsd::cxx::tree::type type
Definition: Database.h:110
bool print
std::string format(const int32_t &value, const int &ndigits=8)
Definition: HexUtils.cpp:14
def save_tree(fname, spectra, groups, attrs=True)
Definition: core.py:133
def load_tree(fname, groups, attrs=True)
Definition: core.py:183

Variable Documentation

PandAna.utils.sadd_pandana.dest = sys.argv[1]

Definition at line 54 of file sadd_pandana.py.

PandAna.utils.sadd_pandana.source = []

Definition at line 58 of file sadd_pandana.py.

PandAna.utils.sadd_pandana.these = glob.glob(arg)

Definition at line 60 of file sadd_pandana.py.