def SaveSimulation(theSimulation, simParams, simConfs, automake=True, autoreplace=True, path='.'): # Use '' in os.path.join() to make the directory name explicity # have a path separator at the end of the name for testing # by os.path.exists(). simDir = os.path.join(path, simParams['simName'], '') # Create the simulation directory. if (not os.path.exists(simDir)): if automake: os.makedirs(simDir) else: raise ValueError("%s does not exist and automake==False" " in SaveSimulation()" % simDir) else: if not autoreplace: raise ValueError("%s already exists and autoreplace==False" " in SaveSimulation()" % simDir) ParamUtils.SaveSimulationParams(simDir + "simParams.conf", simParams) SaveTracks(os.path.join(simDir, simParams['simTrackFile']), theSimulation['true_tracks'], theSimulation['true_falarms']) SaveTracks(os.path.join(simDir, simParams['noisyTrackFile']), theSimulation['noisy_tracks'], theSimulation['noisy_falarms']) SaveCorners(os.path.join(simDir, simParams['inputDataFile']), simParams['corner_file'], theSimulation['noisy_volumes'], path=simDir) ParamUtils.SaveConfigFile(os.path.join(simDir, simParams['simConfFile']), simConfs) res = theSimulation['trackTags'].pop('ids', []) assert len(res) == 0, "The base tag list shouldn't have anything!" ParamUtils.SaveConfigFile(os.path.join(simDir, simParams['simTagFile']), theSimulation['trackTags'])
def SingleTracking(simFile, simName, simParams, trackConfs, path='.'): #simParams['trackers'] = trackConfs.keys() simDir = os.path.join(path, simName, '') storedConfFile = os.path.join(simDir, simParams['trackerparams']) if not os.path.exists(storedConfFile): # Initialize an empty config file ParamUtils.SaveConfigFile(storedConfFile, {}) # Now load that one file storedTrackConfs = ParamUtils.LoadTrackerParams([storedConfFile]) for trackRun in trackConfs: tracker = trackConfs[trackRun]['algorithm'] # This is where the tracking is performed! # Trackers.trackerList is a dictionary of Tracker objects Trackers.trackerList[tracker](trackRun, simParams.copy(), trackConfs[trackRun].copy(), returnResults=False, path=simDir) # We want this simulation to know which trackers they used, # so we will update the file after each successful tracking operation. # Note that we still want an ordered, unique list, henced the use of # set() and .sort() simParams['trackers'].append(trackRun) tempHold = list(set(simParams['trackers'])) tempHold.sort() simParams['trackers'] = tempHold # TODO: We could use some sort of 'with' clause here to restore # the original file if something goes wrong here. ParamUtils.SaveSimulationParams(simFile, simParams) # Add these tracker configurations to the sim's global # tracker configuration file for record-keeping storedTrackConfs[trackRun] = trackConfs[trackRun].copy() ParamUtils.SaveConfigFile(storedConfFile, storedTrackConfs)
def SaveState(paramFile, params, volumeFile, volume, origTrackFile, filtTrackFile, tracks, falarms, polygonfile, polygons): # Do I need to update the Params? volume['volume_data'] = SortVolume(volume['volume_data']) TrackFileUtils.SaveCorners(volumeFile, volume['corner_filestem'], volume['volume_data'], path=os.path.dirname(volumeFile)) ParamUtils.SaveConfigFile(paramFile, params) TrackFileUtils.SaveTracks(origTrackFile, tracks, falarms) TrackFileUtils.SaveTracks(filtTrackFile, tracks, falarms) # TODO: Save polygons in a better format dump(polygons, open(polygonfile, 'wb'))
def RenameRuns(simName, old, new, trackRuns, dirName='.'): """ For *trackRuns* in *simName*, replace the *old* portion with *new*. This over-writes existing trackruns and does a bit of house-keeping in situations where the old run is incomplete while the existing new run has extra files. Also takes care of the simulation param file and the stored tracker configuration file, if it exists. """ simDir = os.path.join(dirName, simName) simFile = os.path.join(simDir, "simParams.conf") storedConfFile = os.path.join(simDir, simParams['trackerparams']) simParams = ParamUtils.ReadSimulationParams(simFile) if not os.path.exists(storedConfFile): # Initialize an empty config file ParamUtils.SaveConfigFile(storedConfFile, {}) # Now load that one file trackerConfs = ParamUtils.LoadTrackerParams([storedConfFile]) for oldRun in trackRuns: newRun = oldRun.replace(old, new) RenameRun(simName, simParams, trackerConfs, oldRun, newRun, dirName=dirName) # TODO: We could use some sort of 'with' clause here to restore # the original file if something goes wrong here. ParamUtils.SaveSimulationParams(simFile, simParams) ParamUtils.SaveConfigFile(storedConfFile, trackerConfs)
simParams.update(ParamUtils.simDefaults) simParams.update(ParamUtils.trackerDefaults) (xLims, yLims, tLims, frameLims) = TrackUtils.DomainFromVolumes(volume_data) simParams['xLims'] = xLims simParams['yLims'] = yLims simParams['tLims'] = tLims simParams['frameCnt'] = len(volume_data) # These parameters are irrelevant. simParams.pop('seed') simParams.pop('totalTracks') simParams.pop('endTrackProb') simParams.pop('simConfFile') simParams.pop('analysis_stem') simParams['simName'] = args.runName TrackFileUtils.SaveCorners(os.path.join(runLoc, simParams['inputDataFile']), simParams['corner_file'], volume_data, path=runLoc) ParamUtils.SaveConfigFile(os.path.join(runLoc, 'simParams.conf'), simParams) if args.savePolys : dump(polygons, open(os.path.join(runLoc, 'polygons.foo'), 'wb'))