|
1 | | -# coding: utf-8 |
2 | | - |
3 | | -''' |
4 | | -Goals of step 01-drainage : |
5 | | - - Get a clean Flow Accumulation raster in km2 |
6 | | - - |
7 | | -''' |
| 1 | +import os |
| 2 | +from fct.config import config |
| 3 | +from multiprocessing import cpu_count |
| 4 | +p = cpu_count()/2 |
8 | 5 |
|
9 | 6 | # Create your tileset |
10 | | - |
11 | 7 | from fct.cli import Tiles |
12 | | -Tiles.CreateTileset('dem', 10000.0, |
13 | | - tileset1 = '/data/sdunesme/fct/tests_1m/fct_workdir/10k_tileset.gpkg', |
14 | | - tileset2 = '/data/sdunesme/fct/tests_1m/fct_workdir/10kbis_tileset.gpkg') |
| 8 | +Tiles.CreateTileset('dem5m', 30000.0, |
| 9 | + tileset1 = os.path.join(config.workdir, 'default_tileset.gpkg'), |
| 10 | + tileset2 = os.path.join(config.workdir, 'aux_tileset.gpkg')) |
15 | 11 |
|
16 | | -# Prepare the DEM tiles and VRT |
| 12 | +# ATTENTION : Bien vérifier que les tilesets couvrent bien tout le DEM avant de continuer |
| 13 | + |
| 14 | +# Copy the Hydrographic Reference to outputs/GLOBAL/REFHYDRO |
| 15 | +if not os.path.isdir(os.path.join(config.workdir, 'GLOBAL/REFHYDRO/')): |
| 16 | + os.makedirs(os.path.join(config.workdir, 'GLOBAL/REFHYDRO/')) |
17 | 17 |
|
| 18 | +# COPY input REFHYDRO to /local/sdunesme/run_rmc_5m/GLOBAL/REFHYDRO/REFERENTIEL_HYDRO.shp |
| 19 | + |
| 20 | +# Prepare the DEM tiles and VRT |
18 | 21 | from fct.cli import Tiles |
19 | | -Tiles.DatasourceToTiles('dem', '10k', 'dem', processes=32) |
20 | | -Tiles.DatasourceToTiles('dem', '10kbis', 'dem', processes=32) |
| 22 | +Tiles.DatasourceToTiles('dem5m', 'default', 'dem', processes=p) # Environ 120G pour 32*20km |
| 23 | +Tiles.DatasourceToTiles('dem5m', 'aux', 'dem', processes=p) |
21 | 24 |
|
22 | 25 | from fct.tileio import buildvrt |
23 | | -buildvrt('10k', 'dem') |
24 | | -buildvrt('10kbis', 'dem') |
| 26 | +buildvrt('default', 'dem') |
| 27 | +buildvrt('aux', 'dem') |
25 | 28 |
|
26 | | -# If you have two different scales DEM, you can fill the precise one with the less precise |
27 | 29 | # First step when you have only one DEM : Smoothing |
28 | 30 | from fct.drainage import PrepareDEM |
29 | 31 | params = PrepareDEM.SmoothingParameters() |
30 | | -params.window=15 |
| 32 | +#params.window=15 # Uncomment for 1m resolution DEM |
31 | 33 |
|
32 | | -PrepareDEM.MeanFilter(params, overwrite=True, processes=32, tileset='10k') |
33 | | -PrepareDEM.MeanFilter(params, overwrite=True, processes=32, tileset='10kbis') |
| 34 | +PrepareDEM.MeanFilter(params, overwrite=True, processes=p, tileset='default') |
| 35 | +PrepareDEM.MeanFilter(params, overwrite=True, processes=p, tileset='aux') |
| 36 | + |
| 37 | +from fct.tileio import buildvrt |
| 38 | +buildvrt('default', 'smoothed') |
| 39 | +buildvrt('aux', 'smoothed') |
| 40 | + |
| 41 | +# Drape hydrography network |
| 42 | +from fct.drainage import Drape |
| 43 | +params = Drape.Parameters() |
| 44 | +#params.elevations = 'smoothed' |
| 45 | +params.stream_network = 'network-cartography-ready' |
| 46 | +params.draped = 'stream-network-draped' |
| 47 | +Drape.DrapeNetworkAndAdjustElevations(params) |
| 48 | +Drape.SplitStreamNetworkIntoTiles(params, tileset='default') |
| 49 | +Drape.SplitStreamNetworkIntoTiles(params, tileset='aux') |
34 | 50 |
|
35 | 51 | # Fill sinks |
36 | 52 | from fct.drainage import DepressionFill |
37 | 53 | params = DepressionFill.Parameters() |
38 | | -params.elevations = 'smoothed' |
39 | | -params.offset = -1.0 # burn offset in meters |
| 54 | +#params.elevations = 'smoothed' |
| 55 | +params.offset = 1.0 # burn offset in meters |
40 | 56 | params.exterior_data = 9000.0 # exterior value |
41 | 57 |
|
42 | | -DepressionFill.LabelWatersheds(params, overwrite=True, processes=32) |
43 | | -DepressionFill.LabelWatersheds(params, overwrite=True, processes=32, tileset='10kbis') |
| 58 | +DepressionFill.LabelWatersheds(params, overwrite=True, processes=p) |
| 59 | +DepressionFill.LabelWatersheds(params, overwrite=True, processes=p, tileset='aux') |
44 | 60 |
|
45 | 61 | from fct.tileio import buildvrt |
46 | | -buildvrt('10k', 'dem-watershed-labels') |
47 | | -buildvrt('10kbis', 'dem-watershed-labels') |
| 62 | +buildvrt('default', 'dem-watershed-labels') |
| 63 | +buildvrt('aux', 'dem-watershed-labels') |
48 | 64 |
|
49 | 65 | DepressionFill.ResolveWatershedSpillover(params, overwrite=True) |
50 | | -DepressionFill.ResolveWatershedSpillover(params, overwrite=True, tileset='10kbis') |
| 66 | +DepressionFill.ResolveWatershedSpillover(params, overwrite=True, tileset='aux') |
51 | 67 |
|
52 | | -DepressionFill.DispatchWatershedMinimumZ(params, overwrite=True, processes=32) |
53 | | -DepressionFill.DispatchWatershedMinimumZ(params, overwrite=True, processes=32, tileset='10kbis') |
| 68 | +DepressionFill.DispatchWatershedMinimumZ(params, overwrite=True, processes=p) |
| 69 | +DepressionFill.DispatchWatershedMinimumZ(params, overwrite=True, processes=p, tileset='aux') |
54 | 70 |
|
55 | 71 | from fct.tileio import buildvrt |
56 | | -buildvrt('10k', 'dem-filled-resolved') |
57 | | -buildvrt('10kbis', 'dem-filled-resolved') |
| 72 | +buildvrt('default', 'dem-filled-resolved') |
| 73 | +buildvrt('aux', 'dem-filled-resolved') |
58 | 74 |
|
59 | 75 | # Resolve flats |
60 | 76 | from fct.drainage import BorderFlats |
61 | 77 | params = BorderFlats.Parameters() |
62 | | -BorderFlats.LabelBorderFlats(params=params, processes=32) |
63 | | -BorderFlats.LabelBorderFlats(params=params, processes=32, tileset='10kbis') |
| 78 | +BorderFlats.LabelBorderFlats(params=params, processes=p) |
| 79 | +BorderFlats.LabelBorderFlats(params=params, processes=p, tileset='aux') |
64 | 80 |
|
65 | 81 | from fct.tileio import buildvrt |
66 | | -buildvrt('10k', 'dem-flat-labels') |
67 | | -buildvrt('10kbis', 'dem-flat-labels') |
| 82 | +buildvrt('default', 'dem-flat-labels') |
| 83 | +buildvrt('aux', 'dem-flat-labels') |
68 | 84 |
|
69 | 85 | BorderFlats.ResolveFlatSpillover(params=params) |
70 | | -BorderFlats.ResolveFlatSpillover(params=params, tileset='10kbis') |
| 86 | +BorderFlats.ResolveFlatSpillover(params=params, tileset='aux') |
71 | 87 |
|
72 | | -BorderFlats.DispatchFlatMinimumZ(params=params, overwrite=True, processes=32) |
73 | | -BorderFlats.DispatchFlatMinimumZ(params=params, overwrite=True, processes=32, tileset='10kbis') |
| 88 | +BorderFlats.DispatchFlatMinimumZ(params=params, overwrite=True, processes=p) |
| 89 | +BorderFlats.DispatchFlatMinimumZ(params=params, overwrite=True, processes=p, tileset='aux') |
74 | 90 |
|
75 | 91 | from fct.tileio import buildvrt |
76 | | -buildvrt('10k', 'dem-drainage-resolved') |
77 | | -buildvrt('10kbis', 'dem-drainage-resolved') |
| 92 | +buildvrt('default', 'dem-drainage-resolved') |
| 93 | +buildvrt('aux', 'dem-drainage-resolved') |
78 | 94 |
|
79 | 95 | # FlatMap.DepressionDepthMap is useful if you want to check which flat areas have been resolved |
80 | 96 |
|
81 | 97 | # Flow direction |
82 | 98 | from fct.drainage import FlowDirection |
83 | 99 | params = FlowDirection.Parameters() |
84 | 100 | params.exterior = 'off' |
85 | | -FlowDirection.FlowDirection(params=params, overwrite=True, processes=32) |
86 | | -FlowDirection.FlowDirection(params=params, overwrite=True, processes=32, tileset='10kbis') |
| 101 | +FlowDirection.FlowDirection(params=params, overwrite=True, processes=p) |
| 102 | +FlowDirection.FlowDirection(params=params, overwrite=True, processes=p, tileset='aux') |
87 | 103 |
|
88 | 104 | from fct.tileio import buildvrt |
89 | | -buildvrt('10k', 'flow') |
90 | | -buildvrt('10kbis', 'flow') |
| 105 | +buildvrt('default', 'flow') |
| 106 | +buildvrt('aux', 'flow') |
91 | 107 |
|
92 | 108 | # Flow tiles inlets/outlets graph |
93 | 109 | from fct.drainage import Accumulate |
94 | 110 | params = Accumulate.Parameters() |
95 | 111 | params.elevations = 'dem-drainage-resolved' |
96 | 112 |
|
97 | | -Accumulate.Outlets(params=params, processes=32) |
98 | | -Accumulate.Outlets(params=params, processes=32, tileset='10kbis') |
| 113 | +Accumulate.Outlets(params=params, processes=p) |
| 114 | +Accumulate.Outlets(params=params, processes=p, tileset='aux') |
99 | 115 |
|
100 | 116 | Accumulate.AggregateOutlets(params) |
101 | | -Accumulate.AggregateOutlets(params, tileset='10kbis') |
| 117 | +Accumulate.AggregateOutlets(params, tileset='aux') |
102 | 118 |
|
103 | 119 | # Resolve inlets/outlets graph |
104 | 120 | Accumulate.InletAreas(params=params) |
105 | | -Accumulate.InletAreas(params=params, tileset='10kbis') |
| 121 | +Accumulate.InletAreas(params=params, tileset='aux') |
106 | 122 |
|
107 | 123 | # Flow accumulation |
108 | | -Accumulate.FlowAccumulation(params=params, overwrite=True, processes=32) |
109 | | -Accumulate.FlowAccumulation(params=params, overwrite=True, processes=32, tileset='10kbis') |
| 124 | +Accumulate.FlowAccumulation(params=params, overwrite=True, processes=p) |
| 125 | +Accumulate.FlowAccumulation(params=params, overwrite=True, processes=p, tileset='aux') |
110 | 126 |
|
111 | 127 | from fct.tileio import buildvrt |
112 | | -buildvrt('10k', 'acc') |
113 | | -buildvrt('10kbis', 'acc') |
| 128 | +buildvrt('default', 'acc') |
| 129 | +buildvrt('aux', 'acc') |
114 | 130 |
|
115 | 131 | # Stream Network from sources |
116 | 132 | from fct.drainage import StreamSources |
117 | 133 |
|
118 | 134 | StreamSources.InletSources(params) |
119 | | -StreamSources.InletSources(params, tileset='10kbis') |
| 135 | +StreamSources.InletSources(params, tileset='aux') |
120 | 136 |
|
121 | | -StreamSources.StreamToFeatureFromSources(min_drainage=500, processes=32) |
122 | | -StreamSources.StreamToFeatureFromSources(min_drainage=500, processes=32, tileset='10kbis') |
| 137 | +StreamSources.StreamToFeatureFromSources(min_drainage=500, processes=p) |
| 138 | +StreamSources.StreamToFeatureFromSources(min_drainage=500, processes=p, tileset='aux') |
123 | 139 |
|
124 | 140 | StreamSources.AggregateStreamsFromSources() |
125 | | -StreamSources.AggregateStreamsFromSources(tileset='10kbis') |
| 141 | +StreamSources.AggregateStreamsFromSources(tileset='aux') |
126 | 142 |
|
127 | 143 | # Find NoFlow pixels from RHTS |
128 | 144 | from fct.drainage import FixNoFlow |
|
131 | 147 | params.noflow = 'noflow' |
132 | 148 | params.fixed = 'noflow-targets' |
133 | 149 |
|
134 | | -FixNoFlow.DrainageRaster(params=params, processes=32) |
135 | | -FixNoFlow.DrainageRaster(params=params, processes=32, tileset='10kbis') |
| 150 | +FixNoFlow.DrainageRaster(params=params, processes=p) |
| 151 | +FixNoFlow.DrainageRaster(params=params, processes=p, tileset='aux') |
136 | 152 |
|
137 | 153 | from fct.tileio import buildvrt |
138 | | -buildvrt('10k', 'drainage-raster-from-sources') |
139 | | -buildvrt('10kbis', 'drainage-raster-from-sources') |
| 154 | +buildvrt('default', 'drainage-raster-from-sources') |
| 155 | +buildvrt('aux', 'drainage-raster-from-sources') |
140 | 156 |
|
141 | | -FixNoFlow.NoFlowPixels(params=params, processes=32) |
142 | | -FixNoFlow.NoFlowPixels(params=params, processes=32, tileset='10kbis') |
| 157 | +FixNoFlow.NoFlowPixels(params=params, processes=p) |
| 158 | +FixNoFlow.NoFlowPixels(params=params, processes=p, tileset='aux') |
143 | 159 |
|
144 | 160 | FixNoFlow.AggregateNoFlowPixels(params) |
145 | | -FixNoFlow.AggregateNoFlowPixels(params, tileset='10kbis') |
| 161 | +FixNoFlow.AggregateNoFlowPixels(params, tileset='aux') |
146 | 162 |
|
147 | 163 | # Fix NoFlow (create TARGETS shapefile and fix Flow Direction data) |
148 | | -FixNoFlow.FixNoFlow(params, tileset1='10k', tileset2='10kbis', fix=True) |
| 164 | +FixNoFlow.FixNoFlow(params, tileset1='default', tileset2='aux', fix=True) |
| 165 | +FixNoFlow.FixNoFlow(params, tileset1='aux', tileset2='default', fix=True) |
149 | 166 |
|
150 | 167 | # Remake FlowAccumulation with NoFlow pixels fixed |
| 168 | +# Il est possible de déplacer un peu les sources à la main et relancer à partir d'ici pour recalculer le RHTS |
151 | 169 | from fct.drainage import Accumulate |
152 | 170 | params = Accumulate.Parameters() |
153 | 171 | params.elevations = 'dem-drainage-resolved' |
| 172 | +# params.exterior_flow = 'exterior-inlet' # Uncomment this if you have exterior EXTERIOR INLET points |
154 | 173 |
|
155 | | -Accumulate.Outlets(params=params, processes=32) |
156 | | -Accumulate.AggregateOutlets(params) |
157 | | -Accumulate.InletAreas(params=params) |
158 | | -Accumulate.FlowAccumulation(params=params, overwrite=True, processes=32) |
| 174 | +Accumulate.Outlets(params=params, processes=p, tileset='default') |
| 175 | +Accumulate.AggregateOutlets(params, tileset='default') |
| 176 | +Accumulate.InletAreas(params=params, tileset='default') |
| 177 | +Accumulate.FlowAccumulation(params=params, overwrite=True, processes=p, tileset='default') |
159 | 178 |
|
160 | 179 | # Remake stream Network from sources with NoFlow pixels fixed |
| 180 | +from fct.drainage import Accumulate |
| 181 | +params = Accumulate.Parameters() |
| 182 | +params.elevations = 'dem-drainage-resolved' |
| 183 | +# params.exterior_flow = 'exterior-inlet' # Uncomment this if you have exterior EXTERIOR INLET points |
161 | 184 | from fct.drainage import StreamSources |
162 | 185 |
|
163 | | -StreamSources.InletSources(params) |
164 | | -StreamSources.StreamToFeatureFromSources(min_drainage=500, processes=32) |
165 | | -StreamSources.AggregateStreamsFromSources() |
| 186 | +StreamSources.InletSources(params, tileset='default') |
| 187 | +StreamSources.StreamToFeatureFromSources(min_drainage=500, processes=p, tileset='default') |
| 188 | +StreamSources.AggregateStreamsFromSources(tileset='default') |
| 189 | + |
| 190 | +# IF NETWORK IS DISCONNECTED, TRY TO RESTART THE WORKFLOW FROM "Remake flow accumulation" WITH THE OTHER TILESET |
166 | 191 |
|
167 | 192 | # Identify network nodes |
168 | 193 | from fct.drainage import IdentifyNetworkNodes |
169 | 194 | params = IdentifyNetworkNodes.Parameters() |
170 | 195 |
|
171 | | -IdentifyNetworkNodes.IdentifyNetworkNodes(params) |
172 | | -IdentifyNetworkNodes.JoinSourcesAttributes(params) |
173 | | - |
174 | | -# Sur le réseau hydro => rang de Hack => Créer champ AXIS = 16 derniers caractères de liens_vers_coursd_eau => extraction des sources |
| 196 | +IdentifyNetworkNodes.IdentifyNetworkNodes(params, tileset='default') |
| 197 | +IdentifyNetworkNodes.JoinSourcesAttributes(params, tileset='default') |
175 | 198 |
|
| 199 | +# Join network attributes and aggregate by axis |
176 | 200 | import os |
177 | | -if not os.path.isdir('/data/sdunesme/fct/tests_1m/fct_workdir/GLOBAL/MEASURE'): |
178 | | - os.mkdir('/data/sdunesme/fct/tests_1m/fct_workdir/GLOBAL/MEASURE') |
| 201 | +if not os.path.isdir(f'{config.workdir}/GLOBAL/MEASURE'): |
| 202 | + os.mkdir(f'{config.workdir}/GLOBAL/MEASURE') |
179 | 203 |
|
180 | 204 | from fct.drainage import JoinNetworkAttributes |
181 | | -JoinNetworkAttributes.JoinNetworkAttributes('/data/sdunesme/fct/tests_1m/fct_workdir/GLOBAL/DEM/SOURCES_IDENTIFIED_10K.shp', '/data/sdunesme/fct/tests_1m/fct_workdir/GLOBAL/DEM/NETWORK_IDENTIFIED_10K.shp', '/data/sdunesme/fct/tests_1m/fct_workdir/GLOBAL/DEM/RHTS.shp') |
182 | | -# JoinNetworkAttributes.UpdateLengthOrder('/data/sdunesme/fct/tests_1m/fct_workdir/GLOBAL/DEM/RHTS.shp', '/data/sdunesme/fct/tests_1m/fct_workdir/GLOBAL/DEM/RHTS.shp') |
183 | | -JoinNetworkAttributes.AggregateByAxis('/data/sdunesme/fct/tests_1m/fct_workdir/GLOBAL/DEM/RHTS.shp', '/data/sdunesme/fct/tests_1m/fct_workdir/GLOBAL/MEASURE/REFAXIS.shp') |
| 205 | +JoinNetworkAttributes.JoinNetworkAttributes(f'{config.workdir}/GLOBAL/DEM/SOURCES_IDENTIFIED_DEFAULT.shp', f'{config.workdir}/GLOBAL/DEM/NETWORK_IDENTIFIED_DEFAULT.shp', f'{config.workdir}/GLOBAL/DEM/RHTS.shp') |
| 206 | +# JoinNetworkAttributes.UpdateLengthOrder(f'{config.workdir}/GLOBAL/DEM/RHTS.shp', f'{config.workdir}/GLOBAL/DEM/RHTS.shp') |
| 207 | +JoinNetworkAttributes.AggregateByAxis(f'{config.workdir}/GLOBAL/DEM/RHTS.shp', f'{config.workdir}/GLOBAL/MEASURE/REFAXIS.shp') |
0 commit comments