def saveStatesCSV(states, f): """Given list of state dictionaries, saves them to CSV format to the given output stream f""" saveStateHeaderCSV(states[0], f) for state in states: f.write(','.join(str(v) for v in map.flatten(state))) f.write('\n') return
def saveStatesCSV(states,f): """Given list of state dictionaries, saves them to CSV format to the given output stream f""" saveStateHeaderCSV(states[0],f) for state in states: f.write(','.join(str(v) for v in map.flatten(state))) f.write('\n') return
def saveStateHeaderCSV(state,f): """Given a state dictionary, saves the header CSV format to the given output stream f""" vflat = [map.flatten(state[k]) for k in state] #write header itemNames = [] for k,v in zip(state.keys(),vflat): if len(v)==1: itemNames.append(k) else: for i in range(len(v)): itemNames.append(k+'['+str(i)+']') f.write(','.join(items)) f.write('\n')
def saveStateHeaderCSV(state, f): """Given a state dictionary, saves the header CSV format to the given output stream f""" vflat = [map.flatten(state[k]) for k in state] #write header itemNames = [] for k, v in zip(state.keys(), vflat): if len(v) == 1: itemNames.append(k) else: for i in range(len(v)): itemNames.append(k + '[' + str(i) + ']') f.write(','.join(items)) f.write('\n')
def saveStateTrajectoryCSV(stateTraj,f): """Given a state trajectory (dict mapping keys to lists), saves it to CSV format to the given output stream f.""" state0 = dict((k,v[0]) for (k,v) in stateTraj.iteritems()) state0['iter'] = 0 saveStateHeaderCSV(state0,f) if len(stateTraj.items())==0: return length = len(stateTraj.values()[0]) for i in xrange(length): state0['iter'] = i for k in stateTraj.iterkeys(): state0[k] = stateTraj[k][i] f.write(','.join(str(v) for v in map.flatten(state0))) f.write('\n') return
def saveStateTrajectoryCSV(stateTraj, f): """Given a state trajectory (dict mapping keys to lists), saves it to CSV format to the given output stream f.""" state0 = dict((k, v[0]) for (k, v) in stateTraj.iteritems()) state0['iter'] = 0 saveStateHeaderCSV(state0, f) if len(stateTraj.items()) == 0: return length = len(stateTraj.values()[0]) for i in xrange(length): state0['iter'] = i for k in stateTraj.iterkeys(): state0[k] = stateTraj[k][i] f.write(','.join(str(v) for v in map.flatten(state0))) f.write('\n') return
def saveStateCSV(state,f): """Given a state dictionary, saves it to CSV format to the given output stream f""" saveStateHeaderCSV(state,f) f.write(','.join(str(v) for v in map.flatten(state))) f.write('\n')
def saveStateCSV(state, f): """Given a state dictionary, saves it to CSV format to the given output stream f""" saveStateHeaderCSV(state, f) f.write(','.join(str(v) for v in map.flatten(state))) f.write('\n')