forked from initze/landsattrend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
07-02_LakeAnalysis_Z056_local.py
65 lines (51 loc) · 2.13 KB
/
07-02_LakeAnalysis_Z056_local.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
54
55
56
57
58
59
60
61
62
63
64
65
from landsattrend.lake_analysis import LakeMaker
import os, platform
import shutil
PROCESS_ROOT = os.getcwd()
def set_conda_gdal_paths():
if platform.system() == 'Windows':
os.environ['GDAL_BIN'] = os.path.join(os.environ['CONDA_PREFIX'], 'Library', 'bin')
os.environ['GDAL_PATH'] = os.path.join(os.environ['CONDA_PREFIX'], 'Scripts')
else:
os.environ['GDAL_BIN'] = os.path.join(os.environ['CONDA_PREFIX'], 'bin')
os.environ['GDAL_PATH'] = os.environ['GDAL_BIN']
process_dir = os.path.join(PROCESS_ROOT, 'process')
site_name = '32604'
CLASS_PERIOD = '2000-2020'
CLASS_MODEL = os.path.join(PROCESS_ROOT, 'models', 'PDG_6idx2feat_elslope_model_py38_sklearn0232_v04.z')
LAKE_FILTER_MODEL = os.path.join(PROCESS_ROOT, 'models', '20180820_lakefilter_12039samples_py3.z')
DEM_LOCATION = os.path.join(PROCESS_ROOT, r'aux_data', 'dem', 'DEM.vrt')
FOREST_LOCATION = os.path.join(PROCESS_ROOT, r'aux_data', 'forestfire', 'forestfire.vrt')
def main():
set_conda_gdal_paths()
tiles_directory = os.path.join(PROCESS_ROOT, 'data', site_name, CLASS_PERIOD, 'tiles')
tif_files = os.listdir(tiles_directory)
if '.DS_Store' in tif_files:
tif_files.remove('.DS_Store')
print('Available Images:\n')
for t in tif_files:
print(t)
l = LakeMaker(site_name, os.path.join(process_dir, site_name), tiles_directory, classperiod=CLASS_PERIOD)
print("\nStart Classification")
l.classify(CLASS_MODEL)
print("\nPreparing additional Data")
l.prepare_aux_data(DEM_LOCATION, FOREST_LOCATION)
print("\nCreating Masks")
l.make_masks()
print("\nCalculating Stats")
l.make_stats()
print("\nSaving DataFrame to Disk")
l.save_df()
# errors come somewhere here
print("\nFiltering non-lake objects")
l.filter_data(LAKE_FILTER_MODEL)
print("\nSaving DataFrame to Disk")
l.save_filtered_data()
print("\nTransforming data to metric values")
l.finalize_calculations()
print("\nSaving DataFrame to Disk")
l.save_results()
print("\nSaving ResultGrid at 3km resolution")
l.export_gridded_results([100, 250])
if __name__ == "__main__":
main()