-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextract_from_hydrolakes.py
executable file
·53 lines (46 loc) · 1.88 KB
/
extract_from_hydrolakes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
Author : Inne Vanderkelen ([email protected])
Institution : Vrije Universiteit Brussel (VUB)
Date : November 2019
Test script to extract shapefiles from Hydrolakes
"""
import os
import sys
import numpy as np
import xarray as xr
import geopandas as gpd
import shapely.geometry as sgeom
from shapely.geometry import box
sys.path.append(r'/home/inne/documents/phd/scripts/python/calc_lakeheat_isimip/lakeheat_isimip')
from dict_functions import *
def extract_from_hydrolakes(extend,extend_fname):
"""Script to extract the great polygon files from hydrolakes and GranD dataset
input= extend (array), extend_name (string including path)
filters lakes based on an area threshold """
area_threshold = 100 #in km^2
from shapely.geometry import box
if not os.path.isfile(extend_fname):
hydrolakes_dams_path = '/home/inne/documents/phd/data/HydroLAKES_polys_v10_shp/HydroLAKES_polys_v10_shp/HydroLAKES_polys_v10.shp'
print('Loading HydroLAKES ...')
lakes = gpd.read_file(hydrolakes_dams_path)
boundingbox = box(extend[0], extend[1], extend[2], extend[3])
print('Extracting lakes ...')
lakes_selected = lakes[lakes['Lake_area']>=area_threshold]
lakes_extracted = lakes_selected[lakes.geometry.intersects(boundingbox)]
lakes_extracted.to_file(extend_fname)
else:
print('Already extracted '+extend_fname)
#%%
# Settings
# Laurentian Great Lakes
extent_LGL = [-92.5,41,-75.5,49.5]
name_LGL = 'LaurentianGreatLakes'
lakes_path = '/home/inne/documents/phd/data/processed/lakes_shp/'
path_LGL = lakes_path+name_LGL+'.shp'
extract_from_hydrolakes(extent_LGL,path_LGL)
# African Great Lakes
extent_AGL = [28,-10,35.5,2.5]
name_AGL = 'AfricanGreatLakes'
lakes_path = '/home/inne/documents/phd/data/processed/lakes_shp/'
path_AGL = lakes_path+name_AGL+'.shp'
extract_from_hydrolakes(extent_AGL,path_AGL)