示例#1
0
def no_poverty_data(bioregion, threshold):
    if report_cache_exists(bioregion, 'nopov_perc'):
        nopov_perc = get_report_cache(bioregion, 'nopov_perc')
        if nopov_perc >= threshold:
            return True
        else:
            return False
    else:
        nopov_regions = PovertyNoData.objects.filter(
            geometry__bboverlaps=bioregion.output_geom)
        nopov_areas = [
            region.geometry.intersection(bioregion.output_geom).area
            for region in nopov_regions
            if region.geometry.intersects(bioregion.output_geom)
        ]
        nopov_area = 0
        for area in nopov_areas:
            nopov_area += area
        terra_geom = get_terra_geom(bioregion)
        nopov_perc = nopov_area / terra_geom.area
        create_report_cache(bioregion, dict(nopov_perc=nopov_perc))
        if nopov_perc >= threshold:
            return True
        else:
            return False
def get_terr_npp_avg(bioregion):
    terra_geom = get_terra_geom(bioregion)
    if terra_geom.area == 0.0:
        return 0
    npp_geom = RasterDataset.objects.get(name='npp_terr')
    npp_stats = zonal_stats(terra_geom, npp_geom)
    if npp_stats.avg:
        npp_avg = npp_stats.avg / (26064.03459 ** 2)
    else:
        npp_avg = 0
    return npp_avg
示例#3
0
def get_terr_npp_avg(bioregion):
    terra_geom = get_terra_geom(bioregion)
    if terra_geom.area == 0.0:
        return 0
    npp_geom = RasterDataset.objects.get(name='npp_terr')
    npp_stats = zonal_stats(terra_geom, npp_geom)
    if npp_stats.avg:
        npp_avg = npp_stats.avg / (26064.03459**2)
    else:
        npp_avg = 0
    return npp_avg
def get_soil_suitability(bioregion):
    terra_geom = get_terra_geom(bioregion)
    if terra_geom.area == 0.0:
        return (0, 0, 0)
    suit_geom = RasterDataset.objects.get(name='soil_suitability')
    suit_stats = zonal_stats(terra_geom, suit_geom)
    if suit_stats.avg:
        proportion = suit_stats.avg
        area_km, area_mi = get_size(terra_geom)
        prop_area_km = area_km * proportion
        prop_area_mi = area_mi * proportion
        return (proportion, prop_area_km, prop_area_mi)
    else:
        return (0, 0, 0)
示例#5
0
def get_soil_suitability(bioregion):
    terra_geom = get_terra_geom(bioregion)
    if terra_geom.area == 0.0:
        return (0, 0, 0)
    suit_geom = RasterDataset.objects.get(name='soil_suitability')
    suit_stats = zonal_stats(terra_geom, suit_geom)
    if suit_stats.avg:
        proportion = suit_stats.avg
        area_km, area_mi = get_size(terra_geom)
        prop_area_km = area_km * proportion
        prop_area_mi = area_mi * proportion
        return (proportion, prop_area_km, prop_area_mi)
    else:
        return (0, 0, 0)
def get_proportion_equipped_for_irrigation(bioregion):
    terra_geom = get_terra_geom(bioregion)
    if terra_geom.area == 0.0:
        return (0, 0, 0)
    irrig_geom = RasterDataset.objects.get(name='irrig_equipped')
    irrig_stats = zonal_stats(terra_geom, irrig_geom)
    if irrig_stats.sum:
        hectares = irrig_stats.sum
        area_km, area_mi = get_size(terra_geom)
        proportion = hectares / 100 / area_km
        prop_area_km = area_km * proportion
        prop_area_mi = area_mi * proportion
        return (proportion, prop_area_km, prop_area_mi)
    else:
        return (0, 0, 0)
示例#7
0
def get_proportion_equipped_for_irrigation(bioregion):
    terra_geom = get_terra_geom(bioregion)
    if terra_geom.area == 0.0:
        return (0, 0, 0)
    irrig_geom = RasterDataset.objects.get(name='irrig_equipped')
    irrig_stats = zonal_stats(terra_geom, irrig_geom)
    if irrig_stats.sum:
        hectares = irrig_stats.sum
        area_km, area_mi = get_size(terra_geom)
        proportion = hectares / 100 / area_km
        prop_area_km = area_km * proportion
        prop_area_mi = area_mi * proportion
        return (proportion, prop_area_km, prop_area_mi)
    else:
        return (0, 0, 0)
示例#8
0
def get_agricultural_impacts(bioregion):
    terra_geom = get_terra_geom(bioregion)
    if terra_geom.area == 0.0:
        return [default_value]
    ag_geom = RasterDataset.objects.get(name='ag_impacts')
    ag_stats = zonal_stats(terra_geom, ag_geom)
    if ag_stats.pixels:
        total_pixels = float(ag_stats.pixels)
        categories = ag_stats.categories.all()
        impacts_dict = {}
        for cat in categories:
            impacts_dict[cat.category] = cat.count
        perc_impacts = []
        for cat, count in impacts_dict.items():
            perc_impacts.append((count / total_pixels, cat))
        perc_impacts.sort(reverse=True)
        final_impacts = []
        for impact in perc_impacts:
            if impact[1] == 0:
                final_impacts.append(('No Data', impact[0]))
                if impact[0] > .9:
                    final_impacts = [default_value]
                    break
            elif impact[1] == 1:
                final_impacts.append(
                    ('a Major Increase in Production', impact[0]))
            elif impact[1] == 2:
                final_impacts.append(
                    ('an General Increase in Production', impact[0]))
            elif impact[1] == 3:
                final_impacts.append(
                    ('a Slight Increase in Production', impact[0]))
            elif impact[1] == 4:
                final_impacts.append(
                    ('a Slight Decrease in Production', impact[0]))
            elif impact[1] == 5:
                final_impacts.append(
                    ('a General Decrease in Production', impact[0]))
            elif impact[1] == 6:
                final_impacts.append(
                    ('a Major Decrease in Production', impact[0]))
        return final_impacts
    else:
        return [default_value]
示例#9
0
def get_agricultural_impacts(bioregion):
    terra_geom = get_terra_geom(bioregion)
    if terra_geom.area == 0.0:
        return [default_value]
    ag_geom = RasterDataset.objects.get(name="ag_impacts")
    ag_stats = zonal_stats(terra_geom, ag_geom)
    if ag_stats.pixels:
        total_pixels = float(ag_stats.pixels)
        categories = ag_stats.categories.all()
        impacts_dict = {}
        for cat in categories:
            impacts_dict[cat.category] = cat.count
        perc_impacts = []
        for cat, count in impacts_dict.items():
            perc_impacts.append((count / total_pixels, cat))
        perc_impacts.sort(reverse=True)
        final_impacts = []
        for impact in perc_impacts:
            if impact[1] == 0:
                final_impacts.append(("No Data", impact[0]))
                if impact[0] > 0.9:
                    final_impacts = [default_value]
                    break
            elif impact[1] == 1:
                final_impacts.append(("a Major Increase in Production", impact[0]))
            elif impact[1] == 2:
                final_impacts.append(("an General Increase in Production", impact[0]))
            elif impact[1] == 3:
                final_impacts.append(("a Slight Increase in Production", impact[0]))
            elif impact[1] == 4:
                final_impacts.append(("a Slight Decrease in Production", impact[0]))
            elif impact[1] == 5:
                final_impacts.append(("a General Decrease in Production", impact[0]))
            elif impact[1] == 6:
                final_impacts.append(("a Major Decrease in Production", impact[0]))
        return final_impacts
    else:
        return [default_value]
示例#10
0
def no_poverty_data(bioregion, threshold):
    if report_cache_exists(bioregion, "nopov_perc"):
        nopov_perc = get_report_cache(bioregion, "nopov_perc")
        if nopov_perc >= threshold:
            return True
        else:
            return False
    else:
        nopov_regions = PovertyNoData.objects.filter(geometry__bboverlaps=bioregion.output_geom)
        nopov_areas = [
            region.geometry.intersection(bioregion.output_geom).area
            for region in nopov_regions
            if region.geometry.intersects(bioregion.output_geom)
        ]
        nopov_area = 0
        for area in nopov_areas:
            nopov_area += area
        terra_geom = get_terra_geom(bioregion)
        nopov_perc = nopov_area / terra_geom.area
        create_report_cache(bioregion, dict(nopov_perc=nopov_perc))
        if nopov_perc >= threshold:
            return True
        else:
            return False
def get_terra_area(bioregion):
    terra_geom = get_terra_geom(bioregion)
    terra_area_km = int(round(geometry_area_in_display_units(terra_geom)))        
    terra_area_mi = int(round(convert_sq_km_to_sq_mi(terra_area_km)))
    return terra_area_km, terra_area_mi    
示例#12
0
def get_terra_area(bioregion):
    terra_geom = get_terra_geom(bioregion)
    terra_area_km = int(round(geometry_area_in_display_units(terra_geom)))
    terra_area_mi = int(round(convert_sq_km_to_sq_mi(terra_area_km)))
    return terra_area_km, terra_area_mi