Beispiel #1
0
def SingleSimulation(simConfs, frameCnt, xLims, yLims, tLims, seed,
                     **simParams):
    frames = np.arange(frameCnt) + 1
    # Seed the PRNG
    np.random.seed(seed)

    (true_tracks, true_falarms, trackTags) = TrackSim(simConfs, frameCnt,
                                                      tLims, **simParams)

    # Clip tracks to the domain
    (clippedTracks,
     clippedFAlarms) = TrackUtils.ClipTracks(true_tracks,
                                             true_falarms,
                                             xLims,
                                             yLims,
                                             frameLims=(1, frameCnt))

    volume_data = TrackUtils.CreateVolData(true_tracks, true_falarms, frames,
                                           tLims, xLims, yLims)

    noise_volData = TrackUtils.CreateVolData(clippedTracks, clippedFAlarms,
                                             frames, tLims, xLims, yLims)

    return {
        'true_tracks': true_tracks,
        'true_falarms': true_falarms,
        'noisy_tracks': clippedTracks,
        'noisy_falarms': clippedFAlarms,
        'true_volumes': volume_data,
        'noisy_volumes': noise_volData,
        'trackTags': trackTags
    }
Beispiel #2
0
def track_wrap(f):
    def perform_tracking(trackRun,
                         simParams,
                         trackParams,
                         returnResults=True,
                         path='.'):
        dirName = path
        cornerInfo = TrackFileUtils.ReadCorners(os.path.join(
            dirName, simParams['inputDataFile']),
                                                path=dirName)

    if len(cornerInfo['volume_data']) <= 1:
        raise Exception("Not enough frames for tracking: %d" %
                        len(cornerInfo['volume_data']))

    lasttime = _load_times(simParams, cornerInfo['volume_data'])

    tracks, falarms = f(trackParams, lasttime)

    TrackUtils.CleanupTracks(tracks, falarms)
    TrackFileUtils.SaveTracks(
        os.path.join(dirName, simParams['result_file'] + "_" + trackRun),
        tracks, falarms)

    if returnResults:
        return tracks, falarms
Beispiel #3
0
def MHT_Track(trackRun, simParams, trackParams, returnResults=True, path='.'):
    import mht
    progDir = "~/Programs/mht_tracking/tracking/"
    dirName = path
    # Popping off the ParamFile key so that the rest of the available
    # configs can be used for making the MHT parameter file.
    paramFile, paramName = tempfile.mkstemp(text=True)
    # Don't need it open, just pass the name along.
    os.close(paramFile)

    # Temporary popping...
    trackParams.pop("algorithm")

    mht.SaveMHTParams(paramName, trackParams)
    resultFile = os.path.join(dirName,
                              simParams['result_file'] + '_' + trackRun)

    retcode = mht.track(resultFile, paramName,
                        os.path.join(dirName, simParams['inputDataFile']),
                        dirName)

    if retcode != 0:
        raise Exception("MHT Tracker failed! ResultFile: %s ParamFile: %s" %
                        (resultFile, paramName))

    os.remove(paramName)

    if returnResults:
        tracks = TrackFileUtils.ReadTracks(resultFile)
        return TrackUtils.FilterMHTTracks(*tracks)
Beispiel #4
0
def SCIT_Track(trackRun, simParams, trackParams, returnResults=True, path='.'):

    dirName = path
    cornerInfo = TrackFileUtils.ReadCorners(os.path.join(
        dirName, simParams['inputDataFile']),
                                            path=dirName)
    if simParams['frameCnt'] <= 1:
        raise Exception("Not enough frames for tracking: %d" %
                        simParams['frameCnt'])

    lasttime = _load_times(simParams, cornerInfo['volume_data'])

    import scit

    speedThresh = float(trackParams['speedThresh'])
    framesBack = int(trackParams['framesBack'])
    default_dir = float(trackParams['default_dir'])
    default_spd = float(trackParams['default_spd'])

    stateHist = []
    strmTracks = []
    infoTracks = []

    strmAdap = {
        'spdThresh': speedThresh,
        'framesBack': framesBack,
        'default_dir': default_dir,
        'default_spd': default_spd,
        'max_timestep': 15.0
    }

    frameOffset = cornerInfo['volume_data'][0]['frameNum']

    for aVol in cornerInfo['volume_data']:
        currtime = aVol['volTime']
        tDelta = currtime - lasttime
        lasttime = currtime
        scit.TrackStep_SCIT(strmAdap, stateHist, strmTracks, infoTracks, aVol,
                            tDelta, frameOffset)

    scit.EndTracks(stateHist, strmTracks)

    falarms = []
    TrackUtils.CleanupTracks(strmTracks, falarms)
    TrackFileUtils.SaveTracks(
        os.path.join(dirName, simParams['result_file'] + "_" + trackRun),
        strmTracks, falarms)

    if returnResults:
        return strmTracks, falarms
Beispiel #5
0
def ASCIT_Track(trackRun,
                simParams,
                trackParams,
                returnResults=True,
                path='.'):
    import ascit
    dirName = path
    cornerInfo = TrackFileUtils.ReadCorners(os.path.join(
        dirName, simParams['inputDataFile']),
                                            path=dirName)
    speedThresh = float(trackParams['speedThresh'])
    default_spd = float(trackParams['default_spd'])

    if simParams['frameCnt'] <= 1:
        raise Exception("Not enough frames for tracking: %d" %
                        simParams['frameCnt'])

    lasttime = _load_times(simParams, cornerInfo['volume_data'])

    t = ascit.ASCIT(framesBack=int(trackParams['framesBack']),
                    default_dir=float(trackParams['default_dir']))
    for aVol in cornerInfo['volume_data']:
        currtime = aVol['volTime']
        tDelta = currtime - lasttime
        t.distThresh = speedThresh * tDelta
        t._default_spd = default_spd * tDelta
        t.TrackStep(aVol, tDelta)
        lasttime = currtime

    # Tidy up tracks because there won't be any more data
    t.finalize()

    tracks = t.tracks
    falarms = []
    TrackUtils.CleanupTracks(tracks, falarms)
    TrackFileUtils.SaveTracks(
        os.path.join(dirName, simParams['result_file'] + "_" + trackRun),
        tracks, falarms)

    if returnResults:
        return tracks, falarms
Beispiel #6
0
def MakeTracks(trackGens,
               noiseModels,
               procParams,
               currGen,
               trackCnt,
               deltaT,
               prob_track_ends,
               maxTrackLen,
               cornerID=0,
               simState=None,
               trackTags=None):
    theTracks = []
    theFAlarms = []

    noisesToApply = procParams.get('noises', [])
    trackCnt = int(procParams.get('cnt', trackCnt))
    prob_track_ends = float(procParams.get('prob_track_ends', prob_track_ends))
    maxTrackLen = int(procParams.get('maxTrackLen', maxTrackLen))

    if simState is None:
        simState = {'theTracks': [], 'theFAlarms': [], 'theTrackLens': []}

    # Generate this model's set of tracks
    startID = cornerID
    tracks, falarms, cornerID = currGen(cornerID, trackCnt, simState, deltaT,
                                        prob_track_ends, maxTrackLen)
    if trackTags is not None:
        trackTags['ids'] = range(startID, cornerID)

    TrackUtils.CleanupTracks(tracks, falarms)
    trackLens = [len(aTrack) for aTrack in tracks]

    # Add them to this node's set of tracks
    theTracks.extend(tracks)
    theFAlarms.extend(falarms)

    # Add them to this branch's set tracks
    # currState collects the tracks in a way that
    # any subnodes are aware of those tracks.
    # This "memory" does not carry across parallel branches.
    currState = {
        'theTracks': simState['theTracks'] + tracks,
        'theFAlarms': simState['theFAlarms'] + falarms,
        'theTrackLens': simState['theTrackLens'] + trackLens
    }

    # Loop over the node's sub-branch generators
    for aGen in procParams.sections:
        # Recursively perform track simulations using this loop's simulation
        #   This is typically done to restrict splits/merges on only the
        #   storm tracks and allow for clutter tracks to be made without
        #   any splitting/merging done upon them.
        # This will also allow for noise models to be applied to specific
        #   subsets of the tracks.
        subTags = {} if trackTags is not None else None

        (subTracks, subFAlarms, cornerID) = MakeTracks(trackGens,
                                                       noiseModels,
                                                       procParams[aGen],
                                                       trackGens[aGen],
                                                       trackCnt,
                                                       deltaT,
                                                       prob_track_ends,
                                                       maxTrackLen,
                                                       cornerID,
                                                       currState,
                                                       trackTags=subTags)

        if trackTags is not None:
            trackTags[aGen] = subTags

        # Add this branch's tracks to this node's set of tracks
        theTracks.extend(subTracks)
        theFAlarms.extend(subFAlarms)

    # Noisify the all the tracks of this node
    for aNoise in noisesToApply:
        noiseModels[aNoise](theTracks, theFAlarms)
        TrackUtils.CleanupTracks(theTracks, theFAlarms)

    return theTracks, theFAlarms, cornerID
Beispiel #7
0
                'frameNum': frameNum,
                'stormCells': np.array(zip(xCentroids, yCentroids,
                                           sizeCentroids, idCentroids),
                                       dtype=TrackUtils.corner_dtype)}

        # Then build up the volume info
        volume_data.append(aVol)


    if len(volume_data) != 0 :
        simParams = dict()
        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,