Ejemplo n.º 1
0
def test_ExclusionCalculator_excludeVectorType():
    # exclude all features directly
    ec = gl.ExclusionCalculator(aachenShape)
    ec.excludeVectorType(cddaVector)

    assert np.isclose(np.nanmean(ec.availability), 76.47581482)
    assert np.isclose(np.nanstd(ec.availability), 42.41498947)

    # exclude all features directly, new srs
    ec = gl.ExclusionCalculator(aachenShape, srs='latlon', pixelRes=0.005)
    ec.excludeVectorType(cddaVector)

    assert np.isclose(np.nanmean(ec.availability), 76.31578827)
    assert np.isclose(np.nanstd(ec.availability), 42.51445770)

    # exclude a selection of features
    ec = gl.ExclusionCalculator(aachenShape)
    ec.excludeVectorType(cddaVector, where="YEAR>2000")

    assert np.isclose(np.nanmean(ec.availability), 86.89811707)
    assert np.isclose(np.nanstd(ec.availability), 33.74209595)

    # exclude a selection of features with buffer
    ec = gl.ExclusionCalculator(aachenShape)
    ec.excludeVectorType(cddaVector, where="YEAR>2000", buffer=400)

    assert np.isclose(np.nanmean(ec.availability), 77.95021057)
    assert np.isclose(np.nanstd(ec.availability), 41.45823669)
Ejemplo n.º 2
0
def calculate_pv_area(region):
    # Quaschning, Volker. Systemtechnik einer klimaverträglichen Elektrizitätsversorgung in Deutschland für
    # das 21. Jahrhundert. Düsseldorf, 2000
    # Fraunhofer Institut für Windenergie und Energiesystemtechnik (IWES). Vorstudie zur Integration großer
    # Anteile Photovoltaik in die elektrische Energieversorgung – Studie im Auftrag des BSW - Bundesverband
    # Solarwirtschaft e.V. – ergänzte Fassung vom 29.05.2012. 2012
    # WG: 818.31 km² und NWG: 698 km²  Gesamt: 1516 km²

    # Divide Potential by eligible area in Germany
    share_pv = 1516 / 43677

    # Intialise ExclusionCalculator object
    ecPV = gl.ExclusionCalculator(region,
                                  srs=3035,
                                  pixelSize=100,
                                  limitOne=False)
    # Perform exclusion
    ecPV.excludePrior("settlement_proximity", value=0)
    ecPV.excludePrior("settlement_urban_proximity", value=0)

    # Calculate area eligible for pv
    area_total = (float(ecPV.maskPixels) / 100) * 1e6  # Fläche in m²
    area_excluded = ecPV.areaAvailable
    area_available = area_total - area_excluded
    area_pv = area_available * share_pv

    return area_pv
Ejemplo n.º 3
0
def calculate_potential(gid, save_map=None):
    feature = gk.vector.extractFeature(paths["regions"], where=gid)
    ec = gl.ExclusionCalculator(feature.geom)

    corine = config.get("corine", {})
    if isinstance(corine, list):
        corine = {'grid_codes': corine}
    if "grid_codes" in corine:
        ec.excludeRasterType(clc, value=corine["grid_codes"], invert=True)
    if corine.get("distance", 0.) > 0.:
        ec.excludeRasterType(clc, value=corine["distance_grid_codes"], buffer=corine["distance"])

    if config.get("natura", False):
        ec.excludeRasterType(natura, value=1)
    if "max_depth" in config:
        ec.excludeRasterType(gebco, (None, -config["max_depth"]))

    # TODO compute a distance field as a raster beforehand
    if 'max_shore_distance' in config:
        ec.excludeVectorType(paths["country_shapes"], buffer=config['max_shore_distance'], invert=True)
    if 'min_shore_distance' in config:
        ec.excludeVectorType(paths["country_shapes"], buffer=config['min_shore_distance'])

    if save_map is not None:
        ec.draw()
        plt.savefig(save_map, transparent=True)
        plt.close()

    availability = downsample_to_coarse_grid(bounds, dx, dy, ec.region, np.where(ec.region.mask, ec._availability, 0))

    return csr_matrix(gk.raster.extractMatrix(availability).flatten() / 100.)
Ejemplo n.º 4
0
def test_ExclusionCalculator_excludePrior():
    # make a prior source
    pr = gl.core.priors.PriorSource(priorSample)

    # test same srs
    ec = gl.ExclusionCalculator(aachenShape)
    ec.excludePrior(pr, value=(400, None))

    assert np.isclose(np.nanmean(ec.availability), 24.77587891)
    assert np.isclose(np.nanstd(ec.availability), 43.17109680)

    # test different srs and resolution
    ec = gl.ExclusionCalculator(aachenShape, srs='latlon', pixelRes=0.001)
    ec.excludePrior(pr, value=(400, None))

    assert np.isclose(np.nanmean(ec.availability), 24.83173180)
    assert np.isclose(np.nanstd(ec.availability), 41.84893036)
Ejemplo n.º 5
0
def test_ExclusionCalculator_save():

    ec = gl.ExclusionCalculator(aachenShape)

    ec.save(join(RESULTDIR, "save1.tif"))
    mat = gk.raster.extractMatrix(join(RESULTDIR, "save1.tif"))
    assert np.nansum(mat - ec.availability) == 0
    assert np.isclose(np.nansum(mat), 28461360)
    assert np.isclose(np.nanstd(mat), 77.2323849648)
Ejemplo n.º 6
0
def test_ExclusionCalculator_draw():
    ec = gl.ExclusionCalculator(aachenShape)

    ec._availability[:, 140:160] = 0
    ec._availability[140:160, :] = 0

    ec.draw()
    plt.savefig(join(RESULTDIR, "DrawnImage.png"), dpi=200)
    plt.close()
Ejemplo n.º 7
0
def test_ExclusionCalculator_pruneIsolatedAreas():
    # make a prior source
    pr = gl.core.priors.PriorSource(priorSample)
    ec = gl.ExclusionCalculator(aachenShape)
    ec.excludePrior(pr, value=(None, 400))

    ec.pruneIsolatedAreas(12000000)

    assert np.isclose(np.nanmean(ec.availability), 65.41215515)
    assert np.isclose(np.nanstd(ec.availability), 47.56538391)
Ejemplo n.º 8
0
def test_ExclusionCalculator_shrinkAvailability():
    # make a prior source
    pr = gl.core.priors.PriorSource(priorSample)
    ec = gl.ExclusionCalculator(aachenShape)
    ec.excludePrior(pr, value=(None, 400))

    ec.shrinkAvailability(500)

    assert np.isclose(np.nanmean(ec.availability), 41.88655853)
    assert np.isclose(np.nanstd(ec.availability), 49.33732986)
Ejemplo n.º 9
0
def test_ExclusionCalculator_excludeRegionEdge():
    # make a prior source
    pr = gl.core.priors.PriorSource(priorSample)
    ec = gl.ExclusionCalculator(aachenShape)
    ec.excludePrior(pr, value=(None, 400))

    ec.excludeRegionEdge(500)

    assert np.isclose(np.nanmean(ec.availability), 63.68544388)
    assert np.isclose(np.nanstd(ec.availability), 48.09062958)
Ejemplo n.º 10
0
def test_multiple_exclusions():
    pr = gl.core.priors.PriorSource(priorSample)
    ec = gl.ExclusionCalculator(aachenShape)

    # apply exclusions
    ec.excludePrior(pr, value=(None, 400))
    ec.excludeVectorType(cddaVector, where="YEAR>2000")
    ec.excludeRasterType(clcRaster, value=(None, 12))

    assert np.isclose(np.nanmean(ec.availability), 37.1109619141, 1e-6)
    assert np.isclose(np.nanstd(ec.availability), 48.3101692200, 1e-6)
Ejemplo n.º 11
0
def test_ExclusionCalculator_excludeVectorType():
    # exclude all features directly
    ec = gl.ExclusionCalculator(aachenShape)
    ec.excludeVectorType(cddaVector)

    assert np.isclose(np.nanmean(ec.availability), 76.47581482)
    assert np.isclose(np.nanstd(ec.availability), 42.41498947)

    # exclude all features directly, new srs
    ec = gl.ExclusionCalculator(aachenShape, srs='latlon', pixelRes=0.005)
    ec.excludeVectorType(cddaVector)

    assert np.isclose(np.nanmean(ec.availability), 76.31578827)
    assert np.isclose(np.nanstd(ec.availability), 42.51445770)

    # exclude a selection of features
    ec = gl.ExclusionCalculator(aachenShape)
    ec.excludeVectorType(cddaVector, where="YEAR>2000")

    assert np.isclose(np.nanmean(ec.availability), 86.89811707)
    assert np.isclose(np.nanstd(ec.availability), 33.74209595)

    # exclude a selection of features with buffer
    ec = gl.ExclusionCalculator(aachenShape)
    ec.excludeVectorType(cddaVector, where="YEAR>2000", buffer=400)

    assert np.isclose(np.nanmean(ec.availability), 77.95021057)
    assert np.isclose(np.nanstd(ec.availability), 41.45823669)

    # test with intermediate functionality
    for i in range(2):
        ec = gl.ExclusionCalculator(aachenShape)
        ec.excludeVectorType(
            cddaVector,
            where="YEAR>2000",
            buffer=400,
            intermediate=join(RESULTDIR, "exclude_vector_intermediate.tif"))

        assert isfile(join(RESULTDIR, "exclude_vector_intermediate.tif"))
        assert np.isclose(np.nanmean(ec.availability), 77.95021057)
        assert np.isclose(np.nanstd(ec.availability), 41.45823669)
Ejemplo n.º 12
0
def test_ExclusionCalculator_excludeSet():
    ec = gl.ExclusionCalculator(aachenShape)
    exclusion_set = pd.read_csv(gl._test_data_["sample_exclusion_set.csv"])
    ec.excludeSet(
        exclusion_set=exclusion_set,
        clc=gl._test_data_['clc-aachen_clipped.tif'],
        osm_roads=gl._test_data_["aachenRoads.shp"],
        verbose=False,
    )

    assert np.isclose(np.nanmean(ec.availability), 15.231732)
    assert np.isclose(np.nanstd(ec.availability), 35.93282)
Ejemplo n.º 13
0
def test_ExclusionCalculator___init__():
    # Test by giving a shapefile
    ec = gl.ExclusionCalculator(aachenShape)

    assert ec.region.mask.shape == (509, 304)
    assert np.isclose(ec.region.mask.sum(), 70944)
    assert np.isclose(ec.region.mask.std(), 0.498273451386)

    # Test by giving a region mask
    rm = gk.RegionMask.load(aachenShape, padExtent=5000)
    ec = gl.ExclusionCalculator(rm)

    assert ec.region.mask.shape == (609, 404)
    assert np.isclose(ec.region.mask.sum(), 70944)
    assert np.isclose(ec.region.mask.std(), 0.45299387483)

    # Test by giving a region mask with different resolution and srs
    rm = gk.RegionMask.load(aachenShape, srs=gk.srs.EPSG4326, pixelRes=0.001)
    ec = gl.ExclusionCalculator(rm)

    assert ec.region.mask.shape == (457, 446)
    assert np.isclose(ec.region.mask.sum(), 90296)
    assert np.isclose(ec.region.mask.std(), 0.496741981394)
Ejemplo n.º 14
0
def test_ExclusionCalculator_distributeItems():
    # make a prior source
    pr = gl.core.priors.PriorSource(priorSample)
    ec = gl.ExclusionCalculator(aachenShape)
    ec.excludePrior(pr, value=(400, None))

    # Do a regular distribution
    ec.distributeItems(1000,
                       output=join(RESULTDIR, "distributeItems1.shp"),
                       outputSRS=3035)
    geoms = gk.vector.extractFeatures(join(RESULTDIR, "distributeItems1.shp"))
    assert geoms.shape[0] == 287

    minDist = 1000000
    for gi in range(geoms.shape[0] - 1):
        for gj in range(gi + 1, geoms.shape[0]):
            d = geoms.geom[gi].Distance(geoms.geom[gj])
            if d < minDist:
                minDist = d
                I = (gi, gj)

    assert minDist >= 999

    # Do an axial distribution
    ec.distributeItems((1000, 300),
                       axialDirection=180,
                       output=join(RESULTDIR, "distributeItems2.shp"),
                       outputSRS=3035)
    geoms = gk.vector.extractFeatures(join(RESULTDIR, "distributeItems2.shp"))
    assert geoms.shape[0] == 882

    x = np.array([g.GetX() for g in geoms.geom])
    y = np.array([g.GetY() for g in geoms.geom])

    for gi in range(geoms.shape[0] - 1):
        d = (x[gi] - x[gi + 1:])**2 / 1000**2 + (y[gi] -
                                                 y[gi + 1:])**2 / 300**2
        assert (d >= 1).all()  # Axial objects too close

    # Do make areas
    ec.distributeItems(2000,
                       asArea=True,
                       output=join(RESULTDIR, "distributeItems3.shp"),
                       outputSRS=4326)
    geoms = gk.vector.extractFeatures(join(RESULTDIR, "distributeItems3.shp"))

    assert np.isclose(geoms.shape[0], 97)
    assert np.isclose(geoms.area.mean(), 0.000230714164474)
    assert np.isclose(geoms.area.std(), 8.2766693979e-05)
def calculate_PV_sites(region, invert=True, separation=1000, name='NoRegion', convert2epsg=True):
        # Choose Region
        ecPV = gl.ExclusionCalculator(region, srs=3035, pixelSize=100, limitOne=False)

        # Apply selected exclusion criteria
        ecPV.excludePrior(pr.settlement_proximity, value=None)
        ecPV.excludePrior(pr.settlement_urban_proximity, value=None)
        ecPV.excludePrior(pr.industrial_proximity, value=None)

        # Placement Algorithm
        ecPV.distributeItems(separation=1000, invert=invert, outputSRS=4326)

        # Extract and convert site coords of turbines
        site_coords = pd.DataFrame(ecPV.itemCoords)
        site_coords.columns = ['latitude','longitude']
        site_coords_gdf = geom.create_geo_df(site_coords, wkt_column=None, lon_column="longitude", lat_column='latitude')

        # Convert2epsg for plotting purposes
        if convert2epsg==True:
                trsf= site_coords_gdf["geometry"]
                site_coords_gdf_epsg3857 = trsf.to_crs(epsg=3857)

                # Save coords in EPSG3587 to hard disk
                site_coords_gdf_epsg3857.to_file("site_coordsPV_epsg3857_" + name + ".geojson", driver='GeoJSON')
                site_coords_gdf.to_file("site_coordsPV_WGS84_" + name + ".geojson", driver='GeoJSON')
        elif convert2epsg==False:
                site_coords_gdf.to_file("site_coordsPV_WGS84_" + name + ".geojson", driver='GeoJSON')

        # Calculate Power per Site in MW
        p_mean = 300000 / len(site_coords) #Total possible PV-Power in MW divided by site count

        # Write turbines to power plants df
        res_df_PV = pd.DataFrame(columns=["energy_source_level_1", "energy_source_level_2", "technology",
                                "electrical_capacity", "lon", "lat", "data_source"])

        res_df_PV["lon"] = site_coords["latitude"]
        res_df_PV["lat"] = site_coords["longitude"]
        res_df_PV["energy_source_level_1"] = 'Renewable energy'
        res_df_PV["energy_source_level_2"] = 'Solar'
        res_df_PV["technology"] = 'Photovoltaics'
        res_df_PV["electrical_capacity"] = p_mean
        res_df_PV["data_source"] = 'GLAES'

        return res_df_PV, ecPV
Ejemplo n.º 16
0
def test_ExclusionCalculator_distributeItems():
    # make a prior source
    pr = gl.core.priors.PriorSource(priorSample)
    ec = gl.ExclusionCalculator(aachenShape)
    ec.excludePrior(pr, value=(400, None))

    # Do a regular distribution
    ec.distributeItems(1000,
                       output=join(RESULTDIR, "distributeItems1.shp"),
                       outputSRS=3035)
    geoms = gk.vector.extractFeatures(join(RESULTDIR, "distributeItems1.shp"))
    assert geoms.shape[0] == 287

    minDist = 1000000
    for gi in range(geoms.shape[0] - 1):
        for gj in range(gi + 1, geoms.shape[0]):
            d = geoms.geom[gi].Distance(geoms.geom[gj])
            if d < minDist:
                minDist = d
                I = (gi, gj)

    assert minDist >= 999

    # Do an axial distribution
    ec.distributeItems((1000, 300),
                       axialDirection=180,
                       output=join(RESULTDIR, "distributeItems2.shp"),
                       outputSRS=3035)
    geoms = gk.vector.extractFeatures(join(RESULTDIR, "distributeItems2.shp"))
    assert geoms.shape[0] == 882

    x = np.array([g.GetX() for g in geoms.geom])
    y = np.array([g.GetY() for g in geoms.geom])

    for gi in range(geoms.shape[0] - 1):
        d = (x[gi] - x[gi + 1:])**2 / 1000**2 + (y[gi] -
                                                 y[gi + 1:])**2 / 300**2
        assert (d >= 1).all()  # Axial objects too close

    # Do make areas
    ec.distributeItems(2000,
                       asArea=True,
                       output=join(RESULTDIR, "distributeItems3.shp"),
                       outputSRS=4326)
    geoms = gk.vector.extractFeatures(join(RESULTDIR, "distributeItems3.shp"))

    assert np.isclose(geoms.shape[0], 97)
    assert np.isclose(geoms.area.mean(), 0.000230714164474)
    assert np.isclose(geoms.area.std(), 8.2766693979e-05)

    # Do a variable separation distance placement
    ec = gl.ExclusionCalculator(gl._test_data_['aachenShapefile.shp'],
                                pixelRes=25,
                                srs="LAEA")

    ec.excludeRasterType(gl._test_data_['clc-aachen_clipped.tif'],
                         value=(1, 2),
                         invert=True)

    mat = np.zeros_like(ec.region.mask, dtype=np.uint16)
    for i in range(mat.shape[0]):
        mat[i, :] = (300 - 50) * i / mat.shape[0] + 100

    ras = ec.region.createRaster(data=mat)

    points = ec.distributeItems(separation=5, sepScaling=ras, _stamping=False)

    assert points.shape[0] == 335

    points = ec.distributeItems(separation=(8, 3),
                                sepScaling=ras,
                                axialDirection=0)
    assert points.shape[0] == 389
def calculate_wind_sites(region, invert=False, separation=700, name='NoRegion', convert2epsg=True):
        # Choose Region
        ecWind = gl.ExclusionCalculator(region, srs=3035, pixelSize=100, limitOne=False)

        # Define Exclusion Criteria
        selExlWind = {
                "access_distance": (5000, None ),
                #"agriculture_proximity": (None, 50 ),
                #"agriculture_arable_proximity": (None, 50 ),
                #"agriculture_pasture_proximity": (None, 50 ),
                #"agriculture_permanent_crop_proximity": (None, 50 ),
                #"agriculture_heterogeneous_proximity": (None, 50 ),
                "airfield_proximity": (None, 1760 ),    # Diss WB
                "airport_proximity": (None, 5000 ),     # Diss WB
                "connection_distance": (10000, None ),
                #"dni_threshold": (None, 3.0 ),
                "elevation_threshold": (1500, None ),
                #"ghi_threshold": (None, 3.0 ),
                "industrial_proximity": (None, 250 ),  # Diss Wingenbach / UBA 2013
                "lake_proximity": (None, 0 ),
                "mining_proximity": (None, 100 ),
                "ocean_proximity": (None, 10 ),
                "power_line_proximity": (None, 120 ),   # Diss WB
                "protected_biosphere_proximity": (None, 5 ), # UBA 2013
                "protected_bird_proximity": (None, 200 ), # UBA 2013
                "protected_habitat_proximity": (None, 5 ), # UBA 2013
                "protected_landscape_proximity": (None, 5 ), # UBA 2013
                "protected_natural_monument_proximity": (None, 200 ), # UBA 2013
                "protected_park_proximity": (None, 5 ), # UBA 2013
                "protected_reserve_proximity": (None, 200 ), # UBA 2013
                "protected_wilderness_proximity": (None, 200 ), # UBA 2013
                "camping_proximity": (None, 900),       # UBA 2013)
                #"touristic_proximity": (None, 800),
                #"leisure_proximity": (None, 1000),
                "railway_proximity": (None, 250 ),      # Diss WB
                "river_proximity": (None, 5 ),        # Abweichung vom standardwert (200)
                "roads_proximity": (None, 80 ),         # Diss WB
                "roads_main_proximity": (None, 80 ),    # Diss WB
                "roads_secondary_proximity": (None, 80 ),# Diss WB
                #"sand_proximity": (None, 5 ),
                "settlement_proximity": (None, 600 ),   # Diss WB
                "settlement_urban_proximity": (None, 1000 ),
                "slope_threshold": (10, None ),
                #"slope_north_facing_threshold": (3, None ),
                "wetland_proximity": (None, 5 ), # Diss WB / UBA 2013
                "waterbody_proximity": (None, 5 ), # Diss WB / UBA 2013
                "windspeed_100m_threshold": (None, 4.5 ),
                "windspeed_50m_threshold": (None, 4.5 ),
                "woodland_proximity": (None, 0 ),     # Abweichung vom standardwert (300) / Diss WB
                "woodland_coniferous_proximity": (None, 0 ), # Abweichung vom standardwert (300)
                "woodland_deciduous_proximity": (None, 0 ), # Abweichung vom standardwert (300)
                "woodland_mixed_proximity": (None, 0 ) # Abweichung vom standardwert (300)
                }

        # Apply selected exclusion criteria
        for key in selExlWind:
            ecWind.excludePrior(pr[key], value=ecWind.typicalExclusions[key])

        # Placement Algorithm
        ecWind.distributeItems(separation=separation, outputSRS=4326)

        # Extract and convert site coords of turbines
        site_coords = pd.DataFrame(ecWind.itemCoords)
        site_coords.columns = ['latitude','longitude']
        site_coords_gdf = geom.create_geo_df(site_coords, wkt_column=None, lon_column="longitude", lat_column='latitude')

        # Convert2epsg for plotting purposes
        if convert2epsg==True:
                trsf= site_coords_gdf["geometry"]
                site_coords_gdf_epsg3857 = trsf.to_crs(epsg=3857)

                # Save coords in EPSG3587 to hard disk
                site_coords_gdf_epsg3857.to_file("site_coordsWind_epsg3857_" + name + ".geojson", driver='GeoJSON')
                site_coords_gdf.to_file("site_coordsWind_WGS84_" + name + ".geojson", driver='GeoJSON')

        elif convert2epsg==False:
                site_coords_gdf.to_file("site_coordsWind_WGS84_" + name + ".geojson", driver='GeoJSON')

        # Write turbines to power plants df
        res_df_Wind = pd.DataFrame(columns=["energy_source_level_1", "energy_source_level_2", "technology",
                                "electrical_capacity", "lon", "lat", "data_source"])

        res_df_Wind["lon"] = site_coords["latitude"]
        res_df_Wind["lat"] = site_coords["longitude"]
        res_df_Wind["energy_source_level_1"] = 'Renewable energy'
        res_df_Wind["energy_source_level_2"] = 'Wind'
        res_df_Wind["technology"] = 'Onshore'
        res_df_Wind["electrical_capacity"] = 3.5
        res_df_Wind["data_source"] = 'GLAES'

        return res_df_Wind, ecWind
Ejemplo n.º 18
0
import glaes as gl
import pandas as pd
PARAMS = pd.read_csv('input_data/landEligibilityParameters.csv',
                     index_col='name')['value']
gl.Priors.loadDirectory("input_data")

# INPUTS
regionFile = "output_data/gadm36_DEU_1.shp"
regionID = int(PARAMS.loc['regionID'])
settlement_proximity = int(PARAMS.loc['exc_settlement_proximity'])

# OUTPUTS
outputFile = "output_data/eligibility_result.tif"

# Initiate Exclusion Calculator object
ec = gl.ExclusionCalculator(regionFile, where=regionID)

# Do a simple exclusion
ec.excludePrior("settlement_proximity",
                value=(0, settlement_proximity))  # Exclude urban areas

# TODO: Add into inputs
ec.excludePrior("roads_main_proximity", value=(0, 200))  # Exclude urban areas
ec.excludePrior("roads_secondary_proximity",
                value=(0, 200))  # Exclude urban areas
ec.excludePrior("protected_landscape_proximity",
                value=(0, 1000))  # Exclude urban areas

# Save result
ec.save(outputFile)
Ejemplo n.º 19
0
def calculate_wind_area(region):
    # Choose Region
    ecWind = gl.ExclusionCalculator(region,
                                    srs=3035,
                                    pixelSize=100,
                                    limitOne=False)

    # Define Exclusion Criteria
    selExlWind = {
        "access_distance": (5000, None),
        #"agriculture_proximity": (None, 50 ),
        #"agriculture_arable_proximity": (None, 50 ),
        #"agriculture_pasture_proximity": (None, 50 ),
        #"agriculture_permanent_crop_proximity": (None, 50 ),
        #"agriculture_heterogeneous_proximity": (None, 50 ),
        "airfield_proximity": (None, 1760),  # Diss WB
        "airport_proximity": (None, 5000),  # Diss WB
        "connection_distance": (10000, None),
        #"dni_threshold": (None, 3.0 ),
        "elevation_threshold": (1500, None),
        #"ghi_threshold": (None, 3.0 ),
        "industrial_proximity": (None, 250),  # Diss Wingenbach / UBA 2013
        "lake_proximity": (None, 0),
        "mining_proximity": (None, 100),
        "ocean_proximity": (None, 10),
        "power_line_proximity": (None, 120),  # Diss WB
        "protected_biosphere_proximity": (None, 5),  # UBA 2013
        "protected_bird_proximity": (None, 200),  # UBA 2013
        "protected_habitat_proximity": (None, 5),  # UBA 2013
        "protected_landscape_proximity": (None, 5),  # UBA 2013
        "protected_natural_monument_proximity": (None, 200),  # UBA 2013
        "protected_park_proximity": (None, 5),  # UBA 2013
        "protected_reserve_proximity": (None, 200),  # UBA 2013
        "protected_wilderness_proximity": (None, 200),  # UBA 2013
        "camping_proximity": (None, 900),  # UBA 2013)
        #"touristic_proximity": (None, 800),
        #"leisure_proximity": (None, 1000),
        "railway_proximity": (None, 250),  # Diss WB
        "river_proximity": (None, 5),  # Abweichung vom standardwert (200)
        "roads_proximity": (None, 80),  # Diss WB
        "roads_main_proximity": (None, 80),  # Diss WB
        "roads_secondary_proximity": (None, 80),  # Diss WB
        #"sand_proximity": (None, 5 ),
        "settlement_proximity": (None, 600),  # Diss WB
        "settlement_urban_proximity": (None, 1000),
        "slope_threshold": (10, None),
        #"slope_north_facing_threshold": (3, None ),
        "wetland_proximity": (None, 5),  # Diss WB / UBA 2013
        "waterbody_proximity": (None, 5),  # Diss WB / UBA 2013
        "windspeed_100m_threshold":
        (None, 5.5),  # Wert angepasst. Bei Nabenhöhe >100m realistisch?
        #"windspeed_50m_threshold": (None, 4.5),
        "woodland_proximity":
        (None, 0),  # Abweichung vom standardwert (300) / Diss WB
        "woodland_coniferous_proximity":
        (None, 0),  # Abweichung vom standardwert (300)
        "woodland_deciduous_proximity":
        (None, 0),  # Abweichung vom standardwert (300)
        "woodland_mixed_proximity": (None, 0
                                     )  # Abweichung vom standardwert (300)
    }

    # Apply selected exclusion criteria
    # for key in selExlWind:
    #     ecWind.excludePrior(pr[key], value=ecWind.typicalExclusions[key])

    for key in selExlWind.keys():
        ecWind.excludePrior(key, value=selExlWind[key])

    area = ecWind.areaAvailable

    return area
Ejemplo n.º 20
0
    def Holtinger2016_max(reg):
        """
        SOURCE: Holtinger2016

        EXCLUSIONS:
            - Areas above the alpine forest line
            - Maximum slope (11.3 degrees)
            - Water bodies
            - Settlement areas - 1000m buffer
            - Buildings outside of settlement areas - 750m buffer
            - Building land outside of settlement areas - 750m buffer
            - Built-up areas - 300m buffer
                * Industrial, commercial, and mining areas
            - Railways - 300m buffer
            - Motorways, primary, and secondary roads - 300m buffer
            - Airport public safety zones - 5100m buffer
            - Power grid( >110kV) - 250m buffer
            - National parks - 1000m buffer
            - Natura 2000 - habitats directive sites 
                * Potentially
            - Natura 2000 - birds directive sites
            - Other protected areas
                * Biosphere reserves, landscape protection areas, natural monuments and sites, 
            - Important birdlife areas
                * Potentially
            - Major migration routes for wild animals
                * Potentially
            - Lakes (> 50 ha) - 1000m buffer
        """
        ec = gl.ExclusionCalculator(reg)

        ##### do exclusions #####
        # "Areas above the alpine forest line
        ec.excludePrior("elevation_threshold",
                        value=(1750,
                               None))  # alpine forest line assumed at 1750 m

        # "maximum slope (degrees)"
        ec.excludePrior("slope_threshold", value=(11.3, None))

        # "water bodies"
        ec.excludePrior("river_proximity", value=0)
        #ec.excludePrior("lake_proximity", value=0 ) # commented out since it is included late with a buffer

        # "settlement areas - 1000m buffer"
        ec.excludePrior("settlement_proximity", value=(None, 1000))

        # "buildings outside of settlement areas - 750m buffer"

        # "building land outside of settlement areas - 750m buffer"

        # "built up areas - 300m buffer"
        # "  * industrial, commercial, and mining areas"
        ec.excludePrior("industrial_proximity", value=(None, 300))
        ec.excludePrior("mining_proximity", value=(None, 300))

        # "railways - 300m buffer"
        ec.excludePrior("railway_proximity", value=(None, 300))

        # "motorways, primary, and secondary roads - 300m buffer"
        ec.excludePrior("roads_main_proximity", value=(None, 300))
        ec.excludePrior("roads_secondary_proximity", value=(None, 300))

        # "airport public safety zones - 5100m buffer"
        ec.excludePrior("airport_proximity", value=(None, 5100))

        # "power grid( >110kV) - 250m buffer"
        ec.excludePrior("power_line_proximity", value=(None, 250))

        # "national parks - 1000m buffer"
        ec.excludePrior("protected_park_proximity", value=(None, 1000))

        # "Natura 2000 - habitats directive sites"
        # "*potentially"
        ec.excludePrior("protected_habitat_proximity", value=0)

        # "Natura 2000 - birds directive sites"
        ec.excludePrior("protected_bird_proximity", value=0)

        # "Other protected areas"
        # "*Biosphere reserves, landscape protection areas, natural monuments and sites,
        #   protected habitats, and landscape section"
        ec.excludePrior("protected_biosphere_proximity", value=0)
        ec.excludePrior("protected_landscape_proximity", value=0)
        ec.excludePrior("protected_natural_monument_proximity", value=0)

        # "important birdlife areas"
        # "*potentially"

        # "major migration routes for wild animals"
        # "*potentially"

        # "lakes (> 50 ha) - 1000m buffer"
        ec.excludePrior("lake_proximity", value=(None, 1000))

        # All done
        return ec
Ejemplo n.º 21
0
def compute_land_availability(shape: Union[Polygon, MultiPolygon]) -> float:
    """
    Compute land availability in (km2) of a geographical shape.

    Parameters
    ----------
    shape: Union[Polygon, MultiPolygon]
        Geographical shape
    Returns
    -------
    float
        Available area in (km2)
    Notes
    -----
    spatial_ref, filters, natura, clc and gebco must have been previously initialized as global variables

    """

    import matplotlib.pyplot as plt

    poly_wkt = shapely.wkt.dumps(shape)
    poly = ogr.CreateGeometryFromWkt(poly_wkt, spatial_ref_)

    # Compute rooftop area using ESM (European Settlement Map)
    if filters_.get("esm", 0):
        path_cop = f"{data_path}generation/vres/potentials/source/ESM/ESM_class50_100m/ESM_class50_100m.tif"
        ec = gl.ExclusionCalculator(poly, pixelRes=100, initialValue=path_cop)

        return ec.areaAvailable / 1e6

    ec = gl.ExclusionCalculator(poly, pixelRes=100)

    # GLAES priors
    if 'glaes_prior_defaults' in filters_:
        prior_defaults_params = filters_['glaes_prior_defaults']
        prior_config = prior_defaults_params["config"]
        priors = prior_defaults_params[
            "priors"] if 'priors' in prior_defaults_params else None
        filters_["glaes_priors"] = get_glaes_prior_defaults(
            prior_config, priors)

    if 'glaes_priors' in filters_:
        priors_filters = filters_["glaes_priors"]
        for prior_name in priors_filters.keys():
            prior_value = priors_filters[prior_name]
            if isinstance(prior_value, str):
                prior_value = literal_eval(prior_value)
            # Can receive a tuple or a list of tuples
            if not isinstance(prior_value, list):
                prior_value = [prior_value]
            for value in prior_value:
                ec.excludePrior(prior_name, value=value)

            #ec.draw()
            #plt.title(prior_name)
            #print(prior_name)
            #plt.show()

    # Exclude protected areas
    if 'natura' in filters_:
        ec.excludeRasterType(natura_, value=filters_["natura"])

    # Depth and altitude filters
    if 'depth_thresholds' in filters_:
        depth_thresholds = filters_["depth_thresholds"]
        # Keep points between two depth thresholds
        for gebco in gebcos_:
            ec.excludeRasterType(gebco, (-1e4, depth_thresholds["low"]))
            ec.excludeRasterType(gebco, (depth_thresholds["high"], 0))
    elif 'altitude_threshold' in filters_ and filters_[
            'altitude_threshold'] > 0.:
        for gebco in gebcos_:
            ec.excludeRasterType(gebco, (filters_['altitude_threshold'], 1e6))

    # Corine filters
    if 'clc' in filters_:
        clc_filters = filters_["clc"]

        if "remove_codes" in clc_filters and "remove_distance" in clc_filters and clc_filters[
                "remove_distance"] > 0.:
            # for remove_code in clc_filters["remove_codes"]:
            #    ec.excludeRasterType(clc_, value=remove_code, buffer=clc_filters["remove_distance"])
            ec.excludeRasterType(clc_,
                                 value=clc_filters["remove_codes"],
                                 buffer=clc_filters["remove_distance"])

        if "keep_codes" in clc_filters:
            # Invert True indicates code that need to be kept
            # for keep_code in clc_filters["keep_codes"]:
            #    ec.excludeRasterType(clc_, value=keep_code, mode='include')
            ec.excludeRasterType(clc_,
                                 value=clc_filters["keep_codes"],
                                 mode='include')

    if 'shipping' in filters_:
        value = filters_['shipping']
        value = literal_eval(value) if isinstance(value, str) else value
        ec.excludeRasterType(cargo_, value=value)
        ec.excludeRasterType(tanker_, value=value)

    if 'cables' in filters_:
        ec.excludeVectorType(cables_, buffer=filters_['cables'])

    if 'pipelines' in filters_:
        ec.excludeVectorType(pipelines_, buffer=filters_['pipelines'])

    # ax = ec.draw()
    # ec.pruneIsolatedAreas(0.9*1e6, 50)

    # ec.draw()
    # plt.show()
    # plt.savefig("test.png")

    return ec.areaAvailable / 1e6
Ejemplo n.º 22
0
def test_ExclusionCalculator_excludeRasterType():
    # exclude single value
    ec = gl.ExclusionCalculator(aachenShape)
    ec.excludeRasterType(clcRaster, 12)

    assert np.isclose(np.nanmean(ec.availability), 82.8033)
    assert np.isclose(np.nanstd(ec.availability), 37.73514175)

    # exclude value range
    ec = gl.ExclusionCalculator(aachenShape)
    ec.excludeRasterType(clcRaster, (5, 12))

    assert np.isclose(np.nanmean(ec.availability), 81.16260529)
    assert np.isclose(np.nanstd(ec.availability), 39.10104752)

    # Exclude iterable (should have the same result as the test above)
    ec = gl.ExclusionCalculator(gl._test_data_["aachenShapefile.shp"], srs=gk.srs.EPSG3035, pixelRes=100)
    ec.excludeRasterType(
        gl._test_data_['clc-aachen_clipped.tif'],
        value=[5, 6, 7, 8, 9, 10, 11, 12])

    assert np.isclose(np.nanmean(ec.availability), 81.16260529)
    assert np.isclose(np.nanstd(ec.availability), 39.10104752)

    # exclude value maximum
    ecMax12 = gl.ExclusionCalculator(aachenShape)
    ecMax12.excludeRasterType(clcRaster, (None, 12))

    assert np.isclose(np.nanmean(ecMax12.availability), 58.52362442)
    assert np.isclose(np.nanstd(ecMax12.availability), 49.26812363)

    # exclude value minimum
    ecMin13 = gl.ExclusionCalculator(aachenShape)
    ecMin13.excludeRasterType(clcRaster, (13, None))

    assert np.isclose(np.nanmean(ecMin13.availability), 41.47637558)
    assert np.isclose(np.nanstd(ecMin13.availability), 49.26812363)

    # Make sure min and max align
    s1 = ecMax12.availability[ecMax12.region.mask] > 0
    s2 = ecMin13.availability[ecMax12.region.mask] > 0
    assert np.logical_xor(s1, s2).all()

    # Test with a different projection system
    # exclude single value
    ec = gl.ExclusionCalculator(aachenShape, srs='latlon', pixelRes=0.005)
    ec.excludeRasterType(clcRaster, 12)
    print("AVAIL MEAN:", np.nanmean(ec.availability))

    assert np.isclose(np.nanmean(ec.availability), 82.95262909)
    assert np.isclose(np.nanstd(ec.availability), 32.26681137)

    # Test with complex value input
    ec = gl.ExclusionCalculator(gl._test_data_["aachenShapefile.shp"], srs='latlon', pixelRes=0.005)
    ec.excludeRasterType(
        gl._test_data_['clc-aachen_clipped.tif'],
        value="[-2),[5-7),12,(22-26],29,33,[40-]")

    assert np.isclose(np.nanmean(ec.availability), 49.5872573853)
    assert np.isclose(np.nanstd(ec.availability), 41.2754364014)

    # Test with intermediate functionaliy (creation and re-use)
    for i in range(2):
        ec = gl.ExclusionCalculator(
            gl._test_data_["aachenShapefile.shp"],
            srs='latlon',
            pixelRes=0.005,)
        ec.excludeRasterType(
            gl._test_data_['clc-aachen_clipped.tif'],
            value="[-2),[5-7),12,(22-26],29,33,[40-]",
            intermediate=join(RESULTDIR, "exclude_raster_intermediate.tif"))

        assert isfile(join(RESULTDIR, "exclude_raster_intermediate.tif"))
        assert np.isclose(np.nanmean(ec.availability), 49.5872573853)
        assert np.isclose(np.nanstd(ec.availability), 41.2754364014)
Ejemplo n.º 23
0
import glaes as gl
import geokit as gk
from os.path import join
from matplotlib import pyplot as plt


# Choose a region to operate on (Here, a predefined region for Aachen, Germany is used)
regionPath = '/home/dbeier/git-projects/glaes/glaes/test/data/aachenShapefile.shp' #['aachenShapefile.shp']
# Initialize ExclusionCalculator object
ec = gl.ExclusionCalculator(regionPath, srs=3035, pixelSize=100)
# Visualize avilability
plot = ec.draw()

# Set a path to a local copy of the CLC raster dataset (Here, a small sample is provided around Aachen)
clcRasterPath = gl._test_data_["clc-aachen_clipped.tif"]
# Apply exclusion
ec.excludeRasterType(clcRasterPath, value=(12,22))
# Visualize
ec.draw()

# Apply exclusion
ec.excludeRasterType(clcRasterPath, value=(1,2), buffer=1000)
# Visualize
ec.draw()

# Set a path to a local copy of the OSM roads dataset (Here, a small sample is provided around Aachen)
roadwaysPath = gl._test_data_["aachenRoads.shp"]
# Apply Exclusion
whereStatement = "type='motorway' OR type='primary' OR type='trunk'"
ec.excludeVectorType(roadwaysPath, where=whereStatement, buffer=200)
# Visualize