Exemple #1
0
 def test_float_profile(self, time, burst, wind, const, linear):
     wind_ds = Mock()
     time.return_value = 'time'
     burst.return_value = 'burst'
     wind.return_value = 'wind'
     const.return_value = 'const'
     linear.return_value = 'linear'
     model = models.float_profile(5.0, 12000.0, 7200.0, wind_ds)
     const.assert_called_with(5.0)
     wind.assert_called_with(wind_ds)
     linear.assert_called_with(['const', 'wind'])
     burst.assert_called_with(12000.0)
     time.assert_called_with(7200.0)
     assert_equal(model, (('linear', 'burst'), ('wind', 'time')))
Exemple #2
0
 def test_float_profile(self, time, burst, wind, const, linear):
     wind_ds = Mock()
     time.return_value = 'time'
     burst.return_value = 'burst'
     wind.return_value = 'wind'
     const.return_value = 'const'
     linear.return_value = 'linear'
     model = models.float_profile(5.0, 12000.0, 7200.0, wind_ds)
     const.assert_called_with(5.0)
     wind.assert_called_with(wind_ds)
     linear.assert_called_with(['const', 'wind'])
     burst.assert_called_with(12000.0)
     time.assert_called_with(7200.0)
     assert_equal(model, (('linear', 'burst'), ('wind', 'time')))
Exemple #3
0
def run_prediction(req):
    """
    Run the prediction.
    """
    # Response dict
    resp = {
        "request": req,
        "prediction": [],
    }

    # Dataset
    try:
        if req['dataset'] == LATEST_DATASET_KEYWORD:
            tawhiri_ds = WindDataset.open_latest(persistent=True)
        else:
            tawhiri_ds = WindDataset(datetime.fromtimestamp(req['dataset']))
    except IOError:
        raise InvalidDatasetException("No matching dataset found.")
    except ValueError as e:
        raise InvalidDatasetException(*e.args)

    # Note that hours and minutes are set to 00 as Tawhiri uses hourly datasets
    resp['request']['dataset'] = tawhiri_ds.ds_time.strftime(
        "%Y-%m-%dT%H:00:00Z")

    # Stages
    if req['profile'] == PROFILE_STANDARD:
        stages = models.standard_profile(req['ascent_rate'],
                                         req['burst_altitude'],
                                         req['descent_rate'], tawhiri_ds,
                                         ruaumoko_ds())
    elif req['profile'] == PROFILE_FLOAT:
        stages = models.float_profile(req['ascent_rate'],
                                      req['float_altitude'],
                                      req['stop_datetime'], tawhiri_ds)
    else:
        raise InternalException("No implementation for known profile.")

    # Run solver
    try:
        result = solver.solve(req['launch_datetime'], req['launch_latitude'],
                              req['launch_longitude'], req['launch_altitude'],
                              stages)
    except Exception as e:
        raise PredictionException("Prediction did not complete: '%s'." %
                                  str(e))

    # Format trajectory
    if req['profile'] == PROFILE_STANDARD:
        resp['prediction'] = _parse_stages(["ascent", "descent"], result)
    elif req['profile'] == PROFILE_FLOAT:
        resp['prediction'] = _parse_stages(["ascent", "float"], result)
    else:
        raise InternalException("No implementation for known profile.")

    # Convert request UNIX timestamps to RFC3339 timestamps
    for key in resp['request']:
        if "datetime" in key:
            resp['request'][key] = _timestamp_to_rfc3339(resp['request'][key])

    return resp
Exemple #4
0
from datetime import datetime
import json
import calendar

from tawhiri import solver, models, kml
from tawhiri.dataset import Dataset as WindDataset
from ruaumoko import Dataset as ElevationDataset

lat0 = 52.5563
lng0 = 360 - 3.1970
alt0 = 0.0
t0 = calendar.timegm(datetime(2014, 2, 19, 15).timetuple())
tE = calendar.timegm(datetime(2014, 2, 20, 6, 1).timetuple())

wind = WindDataset.open_latest()
stages = models.float_profile(2.0, 10000, tE, wind)

rise, float = solver.solve(t0, lat0, lng0, alt0, stages)

assert rise[-1] == float[0]

with open("test_prediction_data.js", "w") as f:
    f.write("var data = ")
    json.dump([(lat, lon) for _, lat, lon, _ in rise + float], f, indent=4)
    f.write(";\n")

markers = [
    {'name': 'launch', 'description': 'TODO', 'point': rise[0]},
    {'name': 'reached float', 'description': 'TODO', 'point': float[0]}
]
Exemple #5
0
def run_prediction(req):
    """
    Run the prediction.
    """
    # Response dict
    resp = {
        "request": req,
        "prediction": [],
    }

    warningcounts = WarningCounts()

    # Find wind data location
    ds_dir = app.config.get('WIND_DATASET_DIR', WindDataset.DEFAULT_DIRECTORY)

    # Dataset
    try:
        if req['dataset'] == LATEST_DATASET_KEYWORD:
            tawhiri_ds = WindDataset.open_latest(persistent=True, directory=ds_dir)
        else:
            tawhiri_ds = WindDataset(datetime.fromtimestamp(req['dataset']), directory=ds_dir)
    except IOError:
        raise InvalidDatasetException("No matching dataset found.")
    except ValueError as e:
        raise InvalidDatasetException(*e.args)

    # Note that hours and minutes are set to 00 as Tawhiri uses hourly datasets
    resp['request']['dataset'] = \
            tawhiri_ds.ds_time.strftime("%Y-%m-%dT%H:00:00Z")

    # Stages
    if req['profile'] == PROFILE_STANDARD:
        stages = models.standard_profile(req['ascent_rate'],
                                         req['burst_altitude'],
                                         req['descent_rate'],
                                         tawhiri_ds,
                                         ruaumoko_ds(),
                                         warningcounts)
    elif req['profile'] == PROFILE_FLOAT:
        stages = models.float_profile(req['ascent_rate'],
                                      req['float_altitude'],
                                      req['stop_datetime'],
                                      tawhiri_ds,
                                      warningcounts)
    else:
        raise InternalException("No implementation for known profile.")

    # Run solver
    try:
        result = solver.solve(req['launch_datetime'], req['launch_latitude'],
                              req['launch_longitude'], req['launch_altitude'],
                              stages)
    except Exception as e:
        raise PredictionException("Prediction did not complete: '%s'." %
                                  str(e))

    # Format trajectory
    if req['profile'] == PROFILE_STANDARD:
        resp['prediction'] = _parse_stages(["ascent", "descent"], result)
    elif req['profile'] == PROFILE_FLOAT:
        resp['prediction'] = _parse_stages(["ascent", "float"], result)
    else:
        raise InternalException("No implementation for known profile.")

    # Convert request UNIX timestamps to RFC3339 timestamps
    for key in resp['request']:
        if "datetime" in key:
            resp['request'][key] = _timestamp_to_rfc3339(resp['request'][key])

    resp["warnings"] = warningcounts.to_dict()

    return resp
Exemple #6
0
from datetime import datetime
import json
import calendar

from tawhiri import solver, models, kml
from tawhiri.dataset import Dataset as WindDataset
from ruaumoko import Dataset as ElevationDataset

lat0 = 52.5563
lng0 = 360 - 3.1970
alt0 = 0.0
t0 = calendar.timegm(datetime(2014, 2, 19, 15).timetuple())
tE = calendar.timegm(datetime(2014, 2, 20, 6, 1).timetuple())

wind = WindDataset.open_latest()
stages = models.float_profile(2.0, 10000, tE, wind)

rise, float = solver.solve(t0, lat0, lng0, alt0, stages)

assert rise[-1] == float[0]

with open("test_prediction_data.js", "w") as f:
    f.write("var data = ")
    json.dump([(lat, lon) for _, lat, lon, _ in rise + float], f, indent=4)
    f.write(";\n")

markers = [{
    'name': 'launch',
    'description': 'TODO',
    'point': rise[0]
}, {