def write_script_output(fn_h5, grp_name, results, args): '''Store the output of a script in an open HDF5 file **Arguments:** fn_h5 The HDF5 filename grp_name The name of the group where the results will be stored. results A dictionary with results. args The results of the command line parser. All arguments are stored as attributes in the HDF5 output file. ''' with LockedH5File(fn_h5) as f: # Store results grp = f.require_group(grp_name) for key in grp.keys(): del grp[key] dump_h5(grp, results) # Store command-line arguments arguments store_args(args, grp) if log.do_medium: log('Results written to %s:%s' % (fn_h5, grp_name))
def write_part_output(fn_h5, grp_name, part, keys, args): '''Write the output of horton-wpart.py or horton-cpart.py **Arguments:** fn_h5 The filename for the HDF5 output file. grp_name the destination group part The partitioning object (instance of subclass of horton.part.base.Part) keys The keys of the cached items that must go in the HDF5 outut file. args The results of the command line parser. All arguments are stored as attributes in the HDF5 output file. ''' def get_results(part, keys): results = {} for key in keys: if isinstance(key, basestring): results[key] = part[key] elif isinstance(key, tuple): assert len(key) == 2 index = key[1] assert isinstance(index, int) assert index >= 0 assert index < part.natom atom_results = results.setdefault('atom_%05i' % index, {}) atom_results[key[0]] = part[key] return results # Store the results in an HDF5 file with LockedH5File(fn_h5) as f: # Transform results to a suitable dictionary structure results = get_results(part, keys) # Store results grp = f.require_group(grp_name) for key in grp.keys(): del grp[key] dump_h5(grp, results) # Store command line arguments store_args(args, grp) if args.debug: # Collect debug results debug_keys = [ key for key in part.cache.iterkeys() if key not in keys ] debug_results = get_results(part, debug_keys) # Store additional data for debugging if 'debug' in grp: del grp['debug'] debuggrp = f.create_group('debug') dump_h5(debuggrp, debug_results) if log.do_medium: log('Results written to %s:%s' % (fn_h5, grp_name))
def write_part_output(fn_h5, grp_name, part, keys, args): '''Write the output of horton-wpart.py or horton-cpart.py **Arguments:** fn_h5 The filename for the HDF5 output file. grp_name the destination group part The partitioning object (instance of subclass of horton.part.base.Part) keys The keys of the cached items that must go in the HDF5 outut file. args The results of the command line parser. All arguments are stored as attributes in the HDF5 output file. ''' def get_results(part, keys): results = {} for key in keys: if isinstance(key, basestring): results[key] = part[key] elif isinstance(key, tuple): assert len(key) == 2 index = key[1] assert isinstance(index, int) assert index >= 0 assert index < part.natom atom_results = results.setdefault('atom_%05i' % index, {}) atom_results[key[0]] = part[key] return results # Store the results in an HDF5 file with LockedH5File(fn_h5) as f: # Transform results to a suitable dictionary structure results = get_results(part, keys) # Store results grp = f.require_group(grp_name) for key in grp.keys(): del grp[key] dump_h5(grp, results) # Store command line arguments store_args(args, grp) if args.debug: # Collect debug results debug_keys = [key for key in part.cache.iterkeys() if key not in keys] debug_results = get_results(part, debug_keys) # Store additional data for debugging if 'debug' in grp: del grp['debug'] debuggrp = f.create_group('debug') dump_h5(debuggrp, debug_results) if log.do_medium: log('Results written to %s:%s' % (fn_h5, grp_name))