def prediction_worker(sample, prediction_timedelta):
    predictor = TrajectoryPredictor(sample.past_traj)
    if PREDICTION_MODE == 'linear':
        predicted_location = predictor.predict_linearly(prediction_timedelta)
    elif PREDICTION_MODE == 'kinetic':
        predicted_location = predictor.predict_kinetically(
            prediction_timedelta)
    errors = TrajectoryPredictionEvaluator(sample, predicted_location,
                                           'epsg:25832').get_errors()
    context = sample.past_traj.context
    prediction = EvaluatedPrediction(predicted_location, context, errors)
    return prediction
Exemplo n.º 2
0
def compute_predictions(samples, past, future, pool):
    out = OUTPUT.replace('in.csv',
                         'in_{}_{}_{}.csv'.format(SHIPTYPE, past, future))
    print("Writing to {}".format(out))
    future = timedelta(minutes=future)
    with open(out, 'w') as output:
        output.write(EvaluatedPrediction.get_csv_header())
        for prediction in pool.starmap(prediction_worker,
                                       zip(samples, repeat(future))):
            try:
                if prediction: output.write(prediction.to_csv())
            except TypeError as e:
                print(e)
    output.close()
Exemplo n.º 3
0
def compute_final_sts_prediction(df, sample, past, future):
    #print(sample.id)
    #print(df[df['ID']==sample.id])
    predictions_for_current_sample = df[df['ID'] == sample.id]
    print(len(predictions_for_current_sample))
    #predicted_location = get_center_of_main_cluster(predictions_for_current_sample, past, future)
    predicted_location = get_location_closest_to_linear_prediction(
        predictions_for_current_sample, sample, past, future)
    if predicted_location is None:
        return None
    errors = TrajectoryPredictionEvaluator(sample, predicted_location,
                                           'epsg:25832').get_errors()
    context = sample.past_traj.context
    prediction = EvaluatedPrediction(predicted_location, context, errors)
    return prediction
Exemplo n.º 4
0
def compute_final_sts_predictions(input_predictions, input_samples, past,
                                  future):
    out = OUTPUT.replace('.csv',
                         '_{}_{}_{}.csv'.format(SHIPTYPE, past, future))
    print("Writing to {}".format(out))
    with open(out, 'w') as output:
        output.write(EvaluatedPrediction.get_csv_header())
        for counter, sample in enumerate(input_samples):
            sample.id = '{}_{}'.format(counter, sample.id)
            prediction = compute_final_sts_prediction(input_predictions,
                                                      sample, past, future)
            try:
                output.write(prediction.to_csv())
            except TypeError as e:
                print(e)
            except AttributeError as e:
                pass
    output.close()