This repository has been archived by the owner on May 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
95 lines (73 loc) · 3.15 KB
/
test.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import gc
import time
import sys
from sklearn.model_selection import train_test_split
from Hazard_Estimates.Model import *
import multiprocessing
hucNumber = 'huc12110202'
n_jobs = -1
def create_y(df, YColumn, category):
return (df[YColumn] / df['no_of_structures']).where(df[category] == 'RES3', df[YColumn])
def rescale_y(y, x, category):
return ((y) * x['no_of_structures']).where(x[category] == 'RES3', y)
files_hazard = [
'dem',
'TWI',
'hand',
'Distance2Coast',
'Distance2Streams',
'Distance2Lakes',
'FlowAccumulation',
'AverageKSAT',
'Precip25_12ha',
'Precip25_60ma',
'Precip100_12ha',
'Precip100_60ma',
'Precip500_12ha',
'Precip500_60ma'
]
dynamic_raster = [
{'filename':'AverageRoughness',
'time':[2001,2016]},
{'filename': 'impervious',
'time': [2016]},
]
file_location = r"H:\HDM_Data\Spatial_Index"
flood_hazard = model_framework( 'rf', "huc8",'adj_damage',files_hazard, file_location )
flood_hazard.load_model( r'D:\OneDrive_Tamu\OneDrive - Texas A&M University\NED\GLO\GLO_M3FR\Python\LargeModel.rf')
flood_hazard.max = 2017
flood_hazard.min = 1976
flood_hazard.Dynamic_rasters = dynamic_raster
for y_column, storm, model in [( 'sum_17', 'Hanna',r'D:\OneDrive_Tamu\OneDrive - Texas A&M University\NED\GLO\GLO_M3FR\Python\LargeModel.rf')] :
print(hucNumber)
# if os.path.exists(f"harvey/flood_hazard{hucNumber}.tif"): exit()
raster_sets = flood_hazard.locate_and_load(hucNumber)
for r in raster_sets.rasters:
if r.fileName =='hand':
r.asciiFile = np.where(r.asciiFile==r.src._nodatavals, -9999, r.asciiFile)
r.asciiFile = np.nan_to_num(r.asciiFile, nan=0)
print(r.fileName)
gc.collect()
raster_sets.Convert_Dimensions()
starti = time.time()
flood_hazard.model.n_jobs = n_jobs
raster_sets.rasters.append(raster_sets.generate_probability_raster(flood_hazard,
location=f"{storm}/FP_a_{hucNumber[3:]}",
ignore_column='hand',
nodata=-9999
,
file=f"{hucNumber}/dem.tfw",
annualize = False
),
)
gc.collect()
# if os.path.exists(f"harvey/{hucNumber}.tif"): exit()
# raster_sets.rasters[-1].fileName = "flood_prob"
# raster_sets.rasters[-1].make_dataset_1D()
# raster_sets.generate_probability_raster(flood_event,
# location=f"{storm}/{storm}_{hucNumber[3:]}",
# ignore_column='demFill',
# nodata=32767
# , file=f"{hucNumber}/demFill.tfw")
gc.collect()
print(f"{hucNumber} minutes: {(time.time() - starti) / 60}")