Esempio n. 1
0
def get_timeseries(dataset_id, variable_name):
    '''Return the timeseries at specified point.'''

    longitude = float(request.args.get('longitude'))
    latitude = float(request.args.get('latitude'))
    start = request.args.get('start')
    end = request.args.get('end')

    raster_dataset = RasterDataset('data/' + dataset_id + '_' + variable_name +
                                   '.tif')

    begin = None if start is None else int(start)
    end = None if end is None else int(end) + 1
    series = list(
        raster_dataset.series_at_point(longitude, latitude, begin, end))

    response_body = {
        'datasetId': dataset_id,
        'variableName': variable_name,
        'boundaryGeometry': {
            'type': 'Point',
            'coordinates': [longitude, latitude]
        },
        'start': '0' if begin is None else str(begin),
        'end': '4' if end is None else str(end - 1),
        'values': series
    }

    return jsonify(response_body)
Esempio n. 2
0
def test_series_at_point_in_pixel_1_0_is_correct(
        raster_dataset: RasterDataset):
    assert raster_dataset.series_at_point(-123, 44).tolist() == [
        3.0, 13.0, 23.0, 33.0, 43.0, 53.0, 63.0, 73.0, 83.0, 93.0
    ]
Esempio n. 3
0
def test_series_at_point_in_pixel_0_1_is_correct(
        raster_dataset: RasterDataset):
    assert raster_dataset.series_at_point(-122, 45).tolist() == [
        2.0, 12.0, 22.0, 32.0, 42.0, 52.0, 62.0, 72.0, 82.0, 92.0
    ]
Esempio n. 4
0
def test_series_at_point_pixel_0_0_is_correct(raster_dataset: RasterDataset):
    assert raster_dataset.series_at_point(-123, 45).tolist() == [
        1.0, 11.0, 21.0, 31.0, 41.0, 51.0, 61.0, 71.0, 81.0, 91.0
    ]
Esempio n. 5
0
def test_range_5_to_6_of_series_at_point_in_pixel_0_0_is_single_element_array(
        raster_dataset: RasterDataset):
    assert raster_dataset.series_at_point(-123, 45, 5, 6).tolist() == [51.0]
Esempio n. 6
0
def test_range_5_to_5_of_series_at_point_in_pixel_0_0_is_empty_array(
        raster_dataset: RasterDataset):
    assert raster_dataset.series_at_point(-123, 45, 5, 5).tolist() == []
Esempio n. 7
0
def test_range_5_to_none_of_series_at_point_in_pixel_0_0_is_correct(
        raster_dataset: RasterDataset):
    assert raster_dataset.series_at_point(
        -123, 45, 5).tolist() == [51.0, 61.0, 71.0, 81.0, 91.0]
Esempio n. 8
0
def test_range_to_5_of_series_at_point_in_pixel_0_0_is_correct(
        raster_dataset: RasterDataset):
    assert raster_dataset.series_at_point(
        -123, 45, end=5).tolist() == [1.0, 11.0, 21.0, 31.0, 41.0]
Esempio n. 9
0
def test_range_from_0_to_none_at_point_in_pixel_0_0_is_correct(
        raster_dataset: RasterDataset):
    assert raster_dataset.series_at_point(-123, 45, 0, None).tolist() == [
        1.0, 11.0, 21.0, 31.0, 41.0, 51.0, 61.0, 71.0, 81.0, 91.0
    ]
Esempio n. 10
0
def test_series_at_point_in_pixel_1_1_is_correct(
        raster_dataset: RasterDataset):
    assert raster_dataset.series_at_point(-122, 44).tolist() == [
        4.0, 14.0, 24.0, 34.0, 44.0, 54.0, 64.0, 74.0, 84.0, 94.0
    ]