Exemplo n.º 1
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)
Exemplo n.º 2
0
def main(args):
    dirName = os.path.join(args.path, args.scenario)

    paramFile = os.path.join(dirName, "simParams.conf")

    if os.path.exists(paramFile):
        sceneParams = ParamUtils.ReadSimulationParams(paramFile)
    else:
        sceneParams = dict()
        sceneParams.update(ParamUtils.simDefaults)
        sceneParams.update(ParamUtils.trackerDefaults)

        sceneParams.pop('seed')
        sceneParams.pop('totalTracks')
        sceneParams.pop('endTrackProb')
        sceneParams.pop('simConfFile')

        sceneParams['simName'] = args.scenario

    origTrackFile = os.path.join(dirName, sceneParams['simTrackFile'])
    filtTrackFile = os.path.join(dirName, sceneParams['noisyTrackFile'])
    volumeFile = os.path.join(dirName, sceneParams['inputDataFile'])
    volumeLoc = os.path.dirname(volumeFile)

    tracks, falarms = [], []

    if os.path.exists(origTrackFile):
        tracks, falarms = TrackFileUtils.ReadTracks(origTrackFile)

    volume = dict(frameCnt=0,
                  corner_filestem=sceneParams['corner_file'],
                  volume_data=[])
    if os.path.exists(volumeFile):
        # dictionary with "volume_data", "frameCnt", "corner_filestem"
        #    and "volume_data" contains a list of dictionaries with
        #    "volTime", "frameNum", "stormCells" where "stormCells" is
        #    a numpy array of dtype corner_dtype
        volume = TrackFileUtils.ReadCorners(volumeFile, volumeLoc)
        sceneParams['corner_file'] = volume['corner_filestem']

    # TODO: Temporary!
    # I would rather not do pickling, but I am pressed for time.
    # Plus, if I intend to make it a part of the ZigZag system,
    # then the name should be stored in the parameters file.
    polygonfile = os.path.join(dirName, "polygons.foo")
    polygons = {}

    if os.path.exists(polygonfile):
        polygons = load(open(polygonfile, 'rb'))

    do_save, state = AnalyzeRadar(volume, tracks, falarms, polygons,
                                  args.input_files)

    if do_save:
        # Create the directory if it doesn't exist already
        if not os.path.exists(dirName):
            makedirs(dirName)

        tracks, falarms, volume, polygons = state.save_features()
        volume['corner_filestem'] = sceneParams['corner_file']

        # Final save
        SaveState(paramFile, sceneParams, volumeFile, volume, origTrackFile,
                  filtTrackFile, tracks, falarms, polygonfile, polygons)