Beispiel #1
0
def _save_downsample(simParams,
                     newName,
                     newVols,
                     newFrames,
                     newTimes,
                     path='.'):
    simParams['frameCnt'] = len(newFrames)
    simParams['tLims'] = (min(newTimes), max(newTimes))
    simParams['simName'] = newName
    simParams['trackers'] = []
    if simParams['times'] is not None:
        simParams['times'] = newTimes

    ParamUtils.SaveSimulationParams(os.path.join(path, 'simParams.conf'),
                                    simParams)
    SaveCorners(os.path.join(path, simParams['inputDataFile']),
                simParams['corner_file'],
                newVols,
                path=path)
Beispiel #2
0
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'])
Beispiel #3
0
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)
Beispiel #4
0
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)