Пример #1
0
def _executeWdpa(args):
    """Query GEE using supplied WDPA id."""
    action, data = CartoDbExecutor.execute(args, BiomasLossSql)
    if action == 'error':
        return action, data
    rows = data['rows']
    data.pop('rows')
    data.pop('download_urls')
    if rows[0]['geojson'] == None:
        args['geojson'] = rows[0]['geojson']
        args['begin'] = args['begin'] if 'begin' in args else '2001-01-01'
        args['end'] = args['end'] if 'end' in args else '2013-01-01'
        data['params'].pop('geojson')
        data['gain'] = None
        data['loss'] = None
        data['tree-extent'] = None
        data['biomass'] = None
        data['biomass_loss'] = None
        data['biomass_loss_by_year'] = None
        data['c_loss_by_year'] = None
        data['co2_loss_by_year'] = None
    elif rows:
        args['geojson'] = rows[0]['geojson']
        args['begin'] = args['begin'] if 'begin' in args else '2001-01-01'
        args['end'] = args['end'] if 'end' in args else '2013-01-01'
        action, data = _execute_geojson(args)
        data['params'].pop('geojson')
    return action, data
Пример #2
0
def _executeWdpa(args):
    """Query GEE using supplied WDPA id."""
    action, data = CartoDbExecutor.execute(args, BiomasLossSql)
    if action == 'error':
        return action, data
    rows = data['rows']
    data.pop('rows')
    data.pop('download_urls')
    if rows[0]['geojson']==None:
        args['geojson'] = rows[0]['geojson']
        args['begin'] = args['begin'] if 'begin' in args else '2001-01-01'
        args['end'] = args['end'] if 'end' in args else '2013-01-01'
        data['params'].pop('geojson')
        data['gain'] = None
        data['loss'] = None
        data['tree-extent'] = None
        data['biomass'] = None
        data['biomass_loss'] = None
        data['biomass_loss_by_year'] = None
        data['c_loss_by_year'] = None
        data['co2_loss_by_year'] = None
    elif rows:
        args['geojson'] = rows[0]['geojson']
        args['begin'] = args['begin'] if 'begin' in args else '2001-01-01'
        args['end'] = args['end'] if 'end' in args else '2013-01-01'
        action, data = _execute_geojson(args)
        data['params'].pop('geojson')
    return action, data
Пример #3
0
def getAlertCount(args):
    begin = args.get('begin')
    end = args.get('end')

    if 'geojson' not in args:
        action, data = CartoDbExecutor.execute(args, GeometrySql)
        args['geojson'] = data['rows'][0]['geojson']

    confirmed_only = False
    if 'glad_confirmed_only' in args:
        confirmed_only = True

    rasters = rastersForPeriod(begin, end, confirmed_only)

    try:
        esri_json = geojsonToEsriJson(args.get('geojson'))
        alert_count = alertCount(begin, end, getHistogram(rasters, esri_json, confirmed_only))

        return 'respond', decorateWithArgs({
            "min_date": begin.isoformat(),
            "max_date": end.isoformat(),
            "value": alert_count,
            "notes": request_notes
        }, args)
    except HistogramError as e:
        return 'error', decorateWithArgs(e.value, args)
    except DeadlineExceededError as e:
        return 'error', decorateWithArgs({
            "error": {
                "code": 408,
                "message": "Request timed out"
            }}, args)
Пример #4
0
def getAlertCount(args):
    begin = args.get('begin')
    end = args.get('end')

    if 'geojson' not in args:
        action, data = CartoDbExecutor.execute(args, GeometrySql)
        args['geojson'] = data['rows'][0]['geojson']

    confirmed_only = False
    if 'glad_confirmed_only' in args:
        confirmed_only = True

    rasters = rastersForPeriod(begin, end, confirmed_only)

    try:
        esri_json = geojsonToEsriJson(args.get('geojson'))
        alert_count = alertCount(
            begin, end, getHistogram(rasters, esri_json, confirmed_only))

        return 'respond', decorateWithArgs(
            {
                "min_date": begin.isoformat(),
                "max_date": end.isoformat(),
                "value": alert_count,
                "notes": request_notes
            }, args)
    except HistogramError as e:
        return 'error', decorateWithArgs(e.value, args)
    except DeadlineExceededError as e:
        return 'error', decorateWithArgs(
            {"error": {
                "code": 408,
                "message": "Request timed out"
            }}, args)
Пример #5
0
def _executeIflId1(args):
    """Query subnational by iso code and GADM id."""
    action, data = CartoDbExecutor.execute(args, BiomasLossSql)
    if action == 'error':
        return action, data
    rows = data['rows']
    data.pop('rows')
    data.pop('download_urls')
    data['years'] = rows
    return action, data
Пример #6
0
def execute(args):
    if 'begin' in args:
        args['begin'] = args['begin'].strftime('%Y-%m-%d')
    if 'end' in args:
        args['end'] = args['end'].strftime('%Y-%m-%d')

    action, data = CartoDbExecutor.execute(args, QuiccSql)
    if action == 'redirect' or action == 'error':
        return action, data
    return _processResults(action, data)
Пример #7
0
def execute(args):
    if 'begin' in args:
        args['begin'] = args['begin'].strftime('%Y-%m-%d')
    if 'end' in args:
        args['end'] = args['end'].strftime('%Y-%m-%d')

    action, data = CartoDbExecutor.execute(args, FiresSql)
    if action == 'redirect' or action == 'error':
        return action, data
    return _processResults(action, data)
Пример #8
0
def _executeIfl(args):
    """Query national by iso code."""
    action, data = CartoDbExecutor.execute(args, UmdSql)
    if action == 'error':
        return action, data
    rows = data['rows']
    data.pop('rows')
    data.pop('download_urls')
    data['years'] = rows
    return action, data
Пример #9
0
def _executeIfl(args):
    """Query national by iso code."""
    action, data = CartoDbExecutor.execute(args, BiomasLossSql)
    if action == 'error':
        return action, data
    rows = data['rows']
    data.pop('rows')
    data.pop('download_urls')
    data['years'] = rows
    return action, data
Пример #10
0
def _executeIflId1(args):
    """Query subnational by iso code and GADM id."""
    action, data = CartoDbExecutor.execute(args, UmdSql)
    if action == 'error':
        return action, data
    rows = data['rows']
    data.pop('rows')
    data.pop('download_urls')
    data['years'] = rows
    return action, data
Пример #11
0
def _executeIfl(args):
    """Query national by iso code."""
    action, data = CartoDbExecutor.execute(args, UmdSql)
    if action == 'error' or data.get('rows', 'empty')=='empty':
        return action, data

    rows = data['rows']
    data.pop('rows')
    data.pop('download_urls')
    data['years'] = rows
    return action, data
Пример #12
0
def execute(args):
    #TODO: Document what can go in 'args'.
    args['version'] = 'v1'

    if 'begin' in args:
        args['begin'] = args['begin'].strftime('%Y-%m-%d')
    if 'end' in args:
        args['end'] = args['end'].strftime('%Y-%m-%d')

    action, data = CartoDbExecutor.execute(args, FormaSql)
    #To get the count: data.get('rows')[0].get('value')
    if action == 'redirect' or action == 'error':
        return action, data
    return _processResults(action, data)
Пример #13
0
def execute(args):
    #TODO: Document what can go in 'args'.
    args['version'] = 'v1'

    if 'begin' in args:
        args['begin'] = args['begin'].strftime('%Y-%m-%d')
    if 'end' in args:
        args['end'] = args['end'].strftime('%Y-%m-%d')

    action, data = CartoDbExecutor.execute(args, FormaSql)
    #To get the count: data.get('rows')[0].get('value')
    if action == 'redirect' or action == 'error':
        return action, data
    return _processResults(action, data)
Пример #14
0
def _executeUse(args):
    """Query GEE using supplied concession id."""
    action, data = CartoDbExecutor.execute(args, UmdSql)
    if action == 'error':
        return action, data
    rows = data['rows']
    data.pop('rows')
    data.pop('download_urls')
    if rows:
        args['geojson'] = rows[0]['geojson']
        args['begin'] = args['begin'] if 'begin' in args else '2001-01-01'
        args['end'] = args['end'] if 'end' in args else '2013-01-01'
        action, data = _execute_geojson(args)
        data['params'].pop('geojson')
    return action, data
Пример #15
0
def _executeUse(args):
    """Query GEE using supplied concession id."""
    action, data = CartoDbExecutor.execute(args, BiomasLossSql)
    if action == 'error':
        return action, data
    rows = data['rows']
    data.pop('rows')
    data.pop('download_urls')
    if rows:
        args['geojson'] = rows[0]['geojson']
        args['begin'] = args['begin'] if 'begin' in args else '2001-01-01'
        args['end'] = args['end'] if 'end' in args else '2013-01-01'
        action, data = _execute_geojson(args)
        data['params'].pop('geojson')
    return action, data
Пример #16
0
def _executeId1(args):
    """Query subnational by iso code and GADM id."""
    action, data = CartoDbExecutor.execute(args, BiomasLossSql)
    if action == 'error':
        return action, data
    begin = args.get('begin').split('-')[0]
    end = args.get('end').split('-')[0]
    rows = data['rows']
    data.pop('rows')
    data.pop('download_urls')
    data['tree_loss_by_year'] = _indicator_selector(rows, 1, begin, end)
    data['biomass_loss_by_year'] = _indicator_selector(rows, 12, begin, end)
    data['c_loss_by_year'] = _indicator_selector(rows, 13, begin, end)
    data['co2_loss_by_year'] = _indicator_selector(rows, 14, begin, end)
    data['biomass'] = _indicator_selector(rows, 4, begin, end)
    data['biomass_loss'] = _sum_range(data['biomass_loss_by_year'], begin, end)
    return action, data
Пример #17
0
def _executeId1(args):
    """Query subnational by iso code and GADM id."""
    action, data = CartoDbExecutor.execute(args, BiomasLossSql)
    if action == 'error':
        return action, data
    begin = args.get('begin').split('-')[0]
    end = args.get('end').split('-')[0]
    rows = data['rows']
    data.pop('rows')
    data.pop('download_urls')
    data['tree_loss_by_year'] = _indicator_selector(rows, 1, begin, end)
    data['biomass_loss_by_year'] = _indicator_selector(rows, 12, begin, end)
    data['c_loss_by_year'] = _indicator_selector(rows, 13, begin, end)
    data['co2_loss_by_year'] = _indicator_selector(rows, 14, begin, end)
    data['biomass'] = _indicator_selector(rows, 4, begin, end)
    data['biomass_loss'] = _sum_range(data['biomass_loss_by_year'], begin, end)
    return action, data
Пример #18
0
def execute(args):
    args['version'] = 'v1'
    action, data = CartoDbExecutor.execute(args, FormaSql)
    if action == 'redirect' or action == 'error':
        return action, data
    return _processResults(action, data)
Пример #19
0
def execute(args):
    args['version'] = 'v2'
    action, data = CartoDbExecutor.execute(args, TerraiSql)
    if action == 'redirect' or action == 'error':
        return action, data
    return _processResults(action, data)
def bbox(args):
    action, bboxResponse = CartoDbExecutor.execute(args, BoundingSql)
    return extent(json.loads(bboxResponse['rows'][0]['bbox']))
Пример #21
0
def execute(args):
    action, data = CartoDbExecutor.execute(args, ImazonSql)
    if action == 'redirect' or action == 'error':
        return action, data
    return _processResults(action, data, args)
Пример #22
0
def execute(args):
    action, data = CartoDbExecutor.execute(args, QuiccSql)
    if action == 'redirect' or action == 'error':
        return action, data
    return _processResults(action, data)
def bbox(args):
    action, bboxResponse = CartoDbExecutor.execute(args, BoundingSql)
    return extent(json.loads(bboxResponse['rows'][0]['bbox']))