model module¶
The FLDPLN model module. This module implements the FLDPLN singleton class which exposes the MATLAB functions in the fldpln_model package (created by MATLAB) as methods. In essence, the FLDPLN class hides the conversion from Python variables to MATLAB data types used in those MATLAB generated functions.
Compared with the non-singleton implementation in model0.py, a singleton class has the following advantages:¶
1. It hide the package handle variable inside the instance instead of exposing it as a module variable which can reduce potential conflict and over-writing¶
2. It hides the initialization and termination steps in the constructor and destructor so that the object behaviors more like a typical Python object¶
FLDPLN
¶
A singleton class for using the functions in the fldpln_model package generated by MATLAB.
CreateSegmentLibrary(self, bildir, segdir, filmskfile, segshpfile, fldmn, fldmx, dh, mxht, libdir, mtype, para)
¶
Create segment-based FLDPLN library
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bildir |
str |
BIL file directory |
required |
segdir |
str |
Segment file directory |
required |
filmskfile |
str |
Spatial mask BIL file path used to limit the modeling. If no mask, set to '' |
required |
segshpfile |
str |
A shapefile that contains the segments to be used in the library. If all segments are used, set to '' |
required |
segshpfile |
dict |
Dictionary containing the shapefile information file (str): Shapefile path that contains the select subset of segments, set to '' if all segments are used segid_field (str): Field name in the shapefile that contains the segment ID seg_fldmx_field (str): Field name in the shapefile that contains the fldmx value. Set to '' if all segments use the same fldmx |
required |
fldmn |
float |
Minimum flood stage assumed, typically set to 1 centimeter or 0.0328084 foot depends on DEM's vertical unit |
required |
fldmx |
float |
Maximum stage modeled |
required |
dh |
float |
Vertical step size in DEM's vertical unit |
required |
mxht |
float |
max dem+flood height to cease flooding. Usually set 0 for no cap height |
required |
libdir |
str |
Output directory for the segment-based library |
required |
mtype |
str |
FLDPLN model type. Choose from {'hd', 'ram0', 'ram'} |
required |
para |
dict |
Dictionary containing parallelization settings when running the model. type (str): Parallelization type. Choose from {'none', 'parfor', 'parfeval'} numcores (int): Number of cores to use. Set to 0 to use all available cores worker_type (str): Type of workers, 'Processes' or 'Threads'. Default is 'Processes' as MATLAB Runtime does not support 'Threads' |
required |
Returns:
| Type | Description |
|---|---|
None |
No return value |
FormatSegmentLibrary(self, bildir, segdir, libdir, dirout)
¶
Reformat segment-based library for tiling and mapping
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bildir |
str |
BIL file directory |
required |
segdir |
str |
Segment file directory |
required |
libdir |
str |
Raw segment-based library directory |
required |
dirout |
str |
Output directory for the reformatted library |
required |
Returns:
| Type | Description |
|---|---|
None |
No return value |
GenerateSegments(self, fdrf, facf, strfac, segfac, seglen, segdir)
¶
Generate stream segments for building segment-based FLDPLN library
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fdrf |
str |
Flow direction BIL file path |
required |
facf |
str |
Flow accumulation BIL file path |
required |
strfac |
int |
Stream flow accumulation threshold (in sq. miles) for identifying stream networks |
required |
segfac |
int |
Stream flow accumulation threshold (in sq. miles) used for creating segments along stream networks |
required |
seglen |
int |
Segment length threshold (in miles) used for creating segments along stream networks |
required |
segdir |
str |
Output directory for segment files |
required |
Returns:
| Type | Description |
|---|---|
None |
No return value |
GenerateStageVolumeTable(self, libdir, stage_step, cell_size, segshpfile, dirout)
¶
Generate stage-volume table for the segments
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
libdir |
str |
Segment-based library directory |
required |
stage_step |
float |
Stage step size in DEM's vertical unit for generating stage-volume table |
required |
cell_size |
float |
Cell size of the DEM in the segment-based library in meters. It is used to convert the volume unit to cubic meters. |
required |
segshpfile |
dict |
A shapefile that contains the segments to be used for generating stage-volume table. If all segments are used, set to {'file': ''} file (str): Shapefile path that contains the select subset of segments, set to '' if all segments are used segid_field (str): Field name in the shapefile that contains the segment ID seg_adjust_field (str): Field name in the shapefile that contains the adjustment factor for the stage-volume table. Set to '' if no adjustment is needed. |
required |
dirout |
str |
Output directory for the stage-volume table |
required |
Returns:
| Type | Description |
|---|---|
None |
No return value |
GenerateStreamOrder(self, bildir, segdir, segshp)
¶
Generate stream order for the segments
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bildir |
str |
BIL file directory |
required |
segdir |
str |
Segment file directory |
required |
segshp |
str |
Selected segment shapefile |
required |
Returns:
| Type | Description |
|---|---|
None |
No return value |
WriteSegmentFspCsvFiles(self, bildir, segdir, seg_list, outdir=None, fileType='csv')
¶
Write segment and FSP as CSV files for viewing or creating segment shapefile
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bildir |
str |
BIL file directory |
required |
segdir |
str |
Segment file directory |
required |
seg_list |
list |
List of integer segment IDs to be exported. If empty, all segments will be exported |
required |
outdir |
str |
Output directory for the CSV files. If None, the output will be saved in the segment file directory |
None |
fileType |
str |
FSP output file type. Choose from {'mat', 'csv'}. default is 'csv' |
'csv' |
Returns:
| Type | Description |
|---|---|
None |
No return value |