WMS:WMLib: Difference between revisions
No edit summary |
No edit summary |
||
(12 intermediate revisions by 2 users not shown) | |||
Line 7: | Line 7: | ||
Writing code to run an HEC-1 analysis using WMLib is a simple process. Using any .NET-based programming language, you do the following to run an HEC-1 analysis and read the HEC-1 solution file: | Writing code to run an HEC-1 analysis using WMLib is a simple process. Using any .NET-based programming language, you do the following to run an HEC-1 analysis and read the HEC-1 solution file: | ||
# | #Either manually build a hydrologic tree, specifying sub-basin and outlet hydrologic and geometric parameters, or read a hydrologic tree from a WMS Tree (*.tre) file. | ||
# | #Run HEC-1 and read the HEC-1 output hydrographs. | ||
# | #Write the hydrographs to a file that can be read into the Time Series Editor (*.ts). The Time Series Editor is shipped with WMS and a license to the editor is included with a license of WMS. (optional) | ||
# | #Lag all the hydrographs in the hydrologic tree. (optional) | ||
# | #Get peak flows and/or times of peak flows. (optional) | ||
For example, if you want to do all of the above and you have a WMS tree file, you could write the following C# code: | For example, if you want to do all of the above and you have a WMS tree file, you could write the following C# code: | ||
Line 33: | Line 33: | ||
DateTime peakTime = hydroTree.GetPeakTime(); | DateTime peakTime = hydroTree.GetPeakTime(); | ||
// Write the hydrographs to a file that can be used by the time series editor | // Write the hydrographs to a file that can be used by the time series editor | ||
hydroTree.WriteTreeToTsFile("C:\\timeSeriesFilePath\\hydrographs.ts"); | |||
// Lag all hydrographs in the hydrologic tree | // Lag all hydrographs in the hydrologic tree | ||
hydroTree.ApplyLagTimes(); | hydroTree.ApplyLagTimes(); | ||
Line 60: | Line 60: | ||
List<TimeSeriesPoint> rainfallCurve = new List<TimeSeriesPoint>(); | List<TimeSeriesPoint> rainfallCurve = new List<TimeSeriesPoint>(); | ||
DateTime currTime = new DateTime(2010, 5, 1, 0, 0, 0); | DateTime currTime = new DateTime(2010, 5, 1, 0, 0, 0); | ||
HydroTree | HydroTree hydroTree = new HydroTree(currTime, 15, 300); | ||
// Setup some default rainfall data | |||
TimeSpan span = new TimeSpan(0, 1, 0); | TimeSpan span = new TimeSpan(0, 1, 0); | ||
int i = 0; | int i = 0; | ||
Line 69: | Line 70: | ||
} | } | ||
RainfallData myRainfall = new RainfallData(5.0, rainfallCurve); | RainfallData myRainfall = new RainfallData(5.0, rainfallCurve); | ||
OutletPoint myOutlet1 = new OutletPoint( | OutletPoint myOutlet1 = new OutletPoint(hydroTree, null, 0.0, "1A"); | ||
OutletPoint myOutlet2 = new OutletPoint( | OutletPoint myOutlet2 = new OutletPoint(hydroTree, myOutlet1, 200.0, "2A"); | ||
OutletPoint myOutlet3 = new OutletPoint( | OutletPoint myOutlet3 = new OutletPoint(hydroTree, myOutlet1, 10.0, "3A"); | ||
OutletPoint myOutlet4 = new OutletPoint( | OutletPoint myOutlet4 = new OutletPoint(hydroTree, myOutlet1, 80.0, "4A"); | ||
OutletPoint myOutlet5 = new OutletPoint( | OutletPoint myOutlet5 = new OutletPoint(hydroTree, myOutlet2, 100.0, "5A"); | ||
OutletPoint myOutlet6 = new OutletPoint( | OutletPoint myOutlet6 = new OutletPoint(hydroTree, myOutlet4, 60.0, "6A"); | ||
OutletPoint myOutlet7 = new OutletPoint( | OutletPoint myOutlet7 = new OutletPoint(hydroTree, myOutlet5, 10.0, "7A"); | ||
SubBasin myBasin8 = new SubBasin(myOutlet1, 10.0, 10.0, myRainfall, 70.0, "8B"); | SubBasin myBasin8 = new SubBasin(myOutlet1, 10.0, 10.0, myRainfall, 70.0, "8B"); | ||
SubBasin myBasin9 = new SubBasin(myOutlet1, 10.0, 10.0, myRainfall, 70.0, "9B"); | SubBasin myBasin9 = new SubBasin(myOutlet1, 10.0, 10.0, myRainfall, 70.0, "9B"); | ||
Line 84: | Line 85: | ||
SubBasin myBasin14 = new SubBasin(myOutlet6, 10.0, 10.0, myRainfall, 70.0, "14B"); | SubBasin myBasin14 = new SubBasin(myOutlet6, 10.0, 10.0, myRainfall, 70.0, "14B"); | ||
SubBasin myBasin15 = new SubBasin(myOutlet7, 10.0, 10.0, myRainfall, 70.0, "15B"); | SubBasin myBasin15 = new SubBasin(myOutlet7, 10.0, 10.0, myRainfall, 70.0, "15B"); | ||
fileName = "C:\\hec1OutputPath\\WMLib.hc1"; | string fileName = "C:\\hec1OutputPath\\WMLib.hc1"; | ||
const string hec1FileName = "C:\\hec1ExePath\\hec1.exe"; | const string hec1FileName = "C:\\hec1ExePath\\hec1.exe"; | ||
// Run HEC-1 and read the HEC-1 output hydrographs | // Run HEC-1 and read the HEC-1 output hydrographs | ||
Line 93: | Line 94: | ||
DateTime peakTime = hydroTree.GetPeakTime(); | DateTime peakTime = hydroTree.GetPeakTime(); | ||
// Write the hydrographs to a file that can be used by the time series editor | // Write the hydrographs to a file that can be used by the time series editor | ||
hydroTree.WriteTreeToTsFile("C:\\timeSeriesFilePath\\hydrographs.ts"); | |||
// Lag all hydrographs in the hydrologic tree | // Lag all hydrographs in the hydrologic tree | ||
hydroTree.ApplyLagTimes(); | hydroTree.ApplyLagTimes(); | ||
Line 110: | Line 111: | ||
} | } | ||
</pre> | </pre> | ||
== WMLib Classes == | |||
Help pages are available for understanding how each of the classes in WMLib are used. The following classes are available in WMLib: | |||
*[[WMS:WMLibFileIo|public class FileIo]] | |||
*[[WMS:WMLibHydroTree|public class HydroTree]] | |||
*[[WMS:WMLibOutletPoint|public class OutletPoint]] | |||
*[[WMS:WMLibRainfallData|public class RainfallData]] | |||
*[[WMS:WMLibSubBasin|public class SubBasin]] | |||
*[[WMS:WMLibTimeSeriesPoint|public class TimeSeriesPoint]] | |||
Contact the WMS developers for more information about and for and sample applications using the WMLib. | |||
{{WMLibMain}} | |||
[[Category:WMLib]] |
Latest revision as of 15:07, 16 June 2014
About WMLib
WMLib is a library of ".NET-based" DLL API functions that allows you to call some of the WMS functionality from other .NET-based applications from outside of WMS. You can send the API watershed parameters from either a WMS tree file or code-based hydrologic tree information. After the watershed parameters have been set up, the API can be used to write an HEC-1 input file and to run HEC-1. The API can then read the HEC-1 output hydrographs for each sub-basin and lag the hydrographs based on specified lag times at each outlet point. The HEC-1-computed hydrographs and/or peak flows can be obtained for each outlet and sub-basin in the hydrologic tree.
How WMLib Works
Writing code to run an HEC-1 analysis using WMLib is a simple process. Using any .NET-based programming language, you do the following to run an HEC-1 analysis and read the HEC-1 solution file:
- Either manually build a hydrologic tree, specifying sub-basin and outlet hydrologic and geometric parameters, or read a hydrologic tree from a WMS Tree (*.tre) file.
- Run HEC-1 and read the HEC-1 output hydrographs.
- Write the hydrographs to a file that can be read into the Time Series Editor (*.ts). The Time Series Editor is shipped with WMS and a license to the editor is included with a license of WMS. (optional)
- Lag all the hydrographs in the hydrologic tree. (optional)
- Get peak flows and/or times of peak flows. (optional)
For example, if you want to do all of the above and you have a WMS tree file, you could write the following C# code:
try { // Set the job control start time and build the tree from a file string fileName = "C:\\treeFilePath\\wmsTreeFile.tre"; DateTime currTime = new DateTime(2010, 5, 1, 0, 0, 0); HydroTree hydroTree = new HydroTree(currTime, 15, 300); if (FileIo.ReadTreeFile(fileName, hydroTree)) { fileName = "C:\\hec1OutputPath\\WMLib.hc1"; const string hec1FileName = "C:\\hec1ExePath\\hec1.exe"; // Run HEC-1 and read the HEC-1 output hydrographs if (hydroTree.RunHec1(fileName, hec1FileName)) { // Get the peak flow and time before lagging double peakFlow = hydroTree.GetPeakFlow(); DateTime peakTime = hydroTree.GetPeakTime(); // Write the hydrographs to a file that can be used by the time series editor hydroTree.WriteTreeToTsFile("C:\\timeSeriesFilePath\\hydrographs.ts"); // Lag all hydrographs in the hydrologic tree hydroTree.ApplyLagTimes(); // Get the peak flow and time after lagging peakFlow = hydroTree.GetPeakFlow(); peakTime = hydroTree.GetPeakTime(); } else { MessageBox.Show("Unable to run HEC-1"); } } } catch (Exception ex) { MessageBox.Show("An Exception Occurred: " + ex.Message); }
Alternatively, if you want to build a tree from scratch, you would change the code as follows:
try { // Set the job control start time and build the tree from code List<TimeSeriesPoint> rainfallCurve = new List<TimeSeriesPoint>(); DateTime currTime = new DateTime(2010, 5, 1, 0, 0, 0); HydroTree hydroTree = new HydroTree(currTime, 15, 300); // Setup some default rainfall data TimeSpan span = new TimeSpan(0, 1, 0); int i = 0; for (;i<5;i++) { rainfallCurve.Add(new TimeSeriesPoint(currTime, i/4.0)); currTime += span; } RainfallData myRainfall = new RainfallData(5.0, rainfallCurve); OutletPoint myOutlet1 = new OutletPoint(hydroTree, null, 0.0, "1A"); OutletPoint myOutlet2 = new OutletPoint(hydroTree, myOutlet1, 200.0, "2A"); OutletPoint myOutlet3 = new OutletPoint(hydroTree, myOutlet1, 10.0, "3A"); OutletPoint myOutlet4 = new OutletPoint(hydroTree, myOutlet1, 80.0, "4A"); OutletPoint myOutlet5 = new OutletPoint(hydroTree, myOutlet2, 100.0, "5A"); OutletPoint myOutlet6 = new OutletPoint(hydroTree, myOutlet4, 60.0, "6A"); OutletPoint myOutlet7 = new OutletPoint(hydroTree, myOutlet5, 10.0, "7A"); SubBasin myBasin8 = new SubBasin(myOutlet1, 10.0, 10.0, myRainfall, 70.0, "8B"); SubBasin myBasin9 = new SubBasin(myOutlet1, 10.0, 10.0, myRainfall, 70.0, "9B"); SubBasin myBasin10 = new SubBasin(myOutlet2, 10.0, 10.0, myRainfall, 70.0, "10B"); SubBasin myBasin11 = new SubBasin(myOutlet3, 10.0, 10.0, myRainfall, 70.0, "11B"); SubBasin myBasin12 = new SubBasin(myOutlet4, 10.0, 10.0, myRainfall, 70.0, "12B"); SubBasin myBasin13 = new SubBasin(myOutlet5, 10.0, 10.0, myRainfall, 70.0, "13B"); SubBasin myBasin14 = new SubBasin(myOutlet6, 10.0, 10.0, myRainfall, 70.0, "14B"); SubBasin myBasin15 = new SubBasin(myOutlet7, 10.0, 10.0, myRainfall, 70.0, "15B"); string fileName = "C:\\hec1OutputPath\\WMLib.hc1"; const string hec1FileName = "C:\\hec1ExePath\\hec1.exe"; // Run HEC-1 and read the HEC-1 output hydrographs if (hydroTree.RunHec1(fileName, hec1FileName)) { // Get the peak flow and time before lagging double peakFlow = hydroTree.GetPeakFlow(); DateTime peakTime = hydroTree.GetPeakTime(); // Write the hydrographs to a file that can be used by the time series editor hydroTree.WriteTreeToTsFile("C:\\timeSeriesFilePath\\hydrographs.ts"); // Lag all hydrographs in the hydrologic tree hydroTree.ApplyLagTimes(); // Get the peak flow and time after lagging peakFlow = hydroTree.GetPeakFlow(); peakTime = hydroTree.GetPeakTime(); } else { MessageBox.Show("Unable to run HEC-1"); } } catch (Exception ex) { MessageBox.Show("An Exception Occurred: " + ex.Message); }
WMLib Classes
Help pages are available for understanding how each of the classes in WMLib are used. The following classes are available in WMLib:
- public class FileIo
- public class HydroTree
- public class OutletPoint
- public class RainfallData
- public class SubBasin
- public class TimeSeriesPoint
Contact the WMS developers for more information about and for and sample applications using the WMLib.