예제 #1
0
def analyze(geojson, area_ha):
    """Analyze histogram"""
    if not geojson:
        return error(status=400, detail='Geojson is required')

    threshold, begin, end, table = set_params()
    layer = get_layer()
    count_pixels = return_pixel_count()

    if not layer:
        logging.debug(get_landcover_types())
        return error(status=400, detail='Layer type must ' \
                                        'be one of {}'.format(', '.join(get_landcover_types())))

    try:
        data = HistogramService.analyze(geojson=geojson,
                                        threshold=threshold,
                                        begin=begin,
                                        end=end,
                                        layer=layer,
                                        count_pixels=count_pixels)
    except Exception as e:
        logging.error('[ROUTER]: ' + str(e))
        return error(status=500, detail='Generic Error')

    data['area_ha'] = area_ha

    return jsonify(data=serialize_histogram(data, layer)), 200
def analyze(geojson, area_ha):
    """Analyze BiomassLoss"""
    logging.info('[ROUTER]: Getting biomassloss v2')
    if not geojson:
        return error(status=400, detail='Geojson is required')

    threshold, begin, end, table = set_params()

    try:
        data = BiomassLossService.analyze(geojson=geojson,
                                          threshold=threshold,
                                          begin=begin,
                                          end=end)
    except BiomassLossError as e:
        logging.error('[ROUTER]: ' + e.message)
        return error(status=500, detail=e.message)
    except Exception as e:
        logging.error('[ROUTER]: ' + str(e))
        return error(status=500, detail='Generic Error')

    data['area_ha'] = area_ha
    if table:
        return jsonify(
            data=serialize_biomass_table_v2(data, 'biomass-loss')), 200
    else:
        return jsonify(data=serialize_biomass_v2(data, 'biomass-loss')), 200
예제 #3
0
def analyze(geojson, area_ha):
    """Analyze Hansen"""
    if not geojson:
        return error(status=400, detail='Geojson is required')
    threshold, begin, end, table = set_params()
    #logging.info(f'[ROUTER]: umd params thresh={threshold}, {begin}, {end}, {table}')
    if request.args.get('aggregate_values', '').lower() == 'false':
        aggregate_values = False
    else:
        aggregate_values = True

    try:
        data = HansenService.analyze(geojson=geojson,
                                     threshold=threshold,
                                     begin=begin,
                                     end=end,
                                     aggregate_values=aggregate_values)
    except HansenError as e:
        logging.error('[ROUTER]: ' + e.message)
        return error(status=500, detail=e.message)
    except Exception as e:
        logging.error(f"[ROUTER]: {e}")
        return error(status=500, detail='Generic Error')

    data['area_ha'] = area_ha
    logging.error(f"[ROUTER]: dict returned {data}")
    if table and not aggregate_values:
        return jsonify(data=serialize_table_umd(data, 'umd')), 200
    else:
        return jsonify(data=serialize_umd(data, 'umd')), 200
예제 #4
0
def analyze(geojson, area_ha):
    """Analyze WHRC Biomass"""
    logging.info('[ROUTER]: WHRC Getting biomass')
    if not geojson:
        return error(status=400, detail='A Geojson argument is required')
    threshold, start, end, table = set_params()
    logging.info(f'[ROUTER]: whrc biomass params {threshold}, {start}, {end}')
    try:
        data = WHRCBiomassService.analyze(geojson=geojson, threshold=threshold)

    except WHRCBiomassError as e:
        logging.error('[ROUTER]: ' + e.message)
        return error(status=500, detail=e.message)
    except Exception as e:
        logging.error('[ROUTER]: ' + str(e))
        return error(status=500, detail='Generic Error')
    data['area_ha'] = area_ha
    data['biomass_density'] = data['biomass'].get('b1') / area_ha
    return jsonify(data=serialize_whrc_biomass(data, 'whrc-biomass')), 200
def analyze(geojson, area_ha):
    """Analyze Soil Carbon"""
    # logging.info('[ROUTER]: In Soil carbon router')
    if not geojson:
        return error(status=400, detail='A Geojson argument is required')
    threshold, start, end, table = set_params()
    # logging.info(f'[ROUTER]: soil carbon params {threshold}, {start}, {end}')
    try:
        data = SoilCarbonService.analyze(geojson=geojson, threshold=threshold)

    except soilCarbonError as e:
        logging.error('[ROUTER]: ' + e.message)
        return error(status=500, detail=e.message)
    except Exception as e:
        logging.error('[ROUTER]: ' + str(e))
        return error(status=500, detail='Generic Error')
    data['area_ha'] = area_ha
    data['soil_carbon_density'] = data['total_soil_carbon'].get(
        'b1_first') / area_ha
    return jsonify(data=serialize_soil_carbon(data, 'soil-carbon')), 200
예제 #6
0
def analyze(geojson, area_ha):
    """Analyze forma250"""
    logging.info('[ROUTER]: Getting forma')
    if not geojson:
        return error(status=400, detail='Geojson is required')

    threshold, begin, end, table = set_params()

    try:
        data = Forma250Service.analyze(geojson=geojson,
                                       start_date=begin,
                                       end_date=end)
    except FormaError as e:
        logging.error('[ROUTER]: ' + e.message)
        return error(status=500, detail=e.message)
    except Exception as e:
        logging.error('[ROUTER]: ' + str(e))
        return error(status=500, detail='Generic Error')

    data['area_ha'] = area_ha
    return jsonify(data=serialize_forma(data, 'forma250gfw')), 200