Skip to content

Commit

Permalink
Work on issue #21
Browse files Browse the repository at this point in the history
  • Loading branch information
lbross committed Nov 12, 2015
1 parent a0f473f commit 3a65801
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/BAGIS_ClassLibrary/ConstantsModule.vb
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
Public Const BA_JH_Coef_Jul_Tmin As String = "JH_Coef_Jul_Tmin"

'Constant parameter names for parameters calculated at the AOI-level
Public Const BA_Aoi_Parameter_JH_Coef As String = "Aoi_Parameter_JH_Coef"
Public Const BA_Aoi_Parameter_jh_coef As String = "jh_coef"
Public Const BA_Aoi_Parameter_SR_Obs As String = "SR_Obs"
Public Const BA_Aoi_Parameter_PE_Obs As String = "PE_Obs"

Expand Down
3 changes: 2 additions & 1 deletion src/BAGIS_P/Forms/FrmExportParametersEwsf.vb
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,8 @@ Public Class FrmExportParametersEwsf
' 7. find jh_coeff column in nmonths table and overwrite with calculated jh_coeff value
Dim nmonthsTable As ParameterTable = m_tablesTable(NMONTHS)
If nmonthsTable IsNot Nothing Then
BA_UpdateJHCoefInTable(nmonthsTable, jhcoeffValue)
'BA_UpdateJHCoefInTable(nmonthsTable, jhcoeffValue)
BA_UpdateParametersInNmonthsTable(nmonthsTable, aoiParamTable)
m_tablesTable(NMONTHS) = nmonthsTable
End If

Expand Down
12 changes: 5 additions & 7 deletions src/BAGIS_P/Forms/FrmPEandSRObs.vb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Imports ESRI.ArcGIS.Geometry
Public Class FrmPEandSRObs

Private Const SR_COLUMN_PREFIX As String = "SR"
Private Const MISSING_VALUE As String = "-99"
Dim m_aoiParamTable As IDictionary(Of String, AoiParameter)

Public Sub New()
Expand Down Expand Up @@ -267,33 +266,32 @@ Public Class FrmPEandSRObs
fClass = BA_OpenFeatureClassFromFile(parentPath, fileName)
End If
Dim srValues As List(Of String) = New List(Of String)
Dim numMonths As Short = 12
If fClass IsNot Nothing Then
pQF.WhereClause = BA_FIELD_OBJECT_ID & " = " & oid
fCursor = fClass.Search(pQF, False)
pFeature = fCursor.NextFeature
If pFeature IsNot Nothing Then
Dim srFields As IFields = pFeature.Fields
Dim idxSR As Integer
For i As Short = 1 To numMonths
For i As Short = 1 To NUM_MONTHS
Dim fieldName As String = SR_COLUMN_PREFIX & i.ToString("D2")
idxSR = srFields.FindField(fieldName)
If idxSR > -1 Then
srValues.Add(Convert.ToString(pFeature.Value(idxSR)))
Else
srValues.Add(MISSING_VALUE)
srValues.Add(BA_9999)
missingValues += 1
End If
Next
End If
End If
Dim returnObj As AoiParameter = New AoiParameter(BA_Aoi_Parameter_SR_Obs)
'Populate srValues with default values if there was an error
If srValues.Count < numMonths Then
If srValues.Count < NUM_MONTHS Then
missingValues = 0
srValues.Clear()
For i As Short = 1 To numMonths
srValues.Add(MISSING_VALUE)
For i As Short = 1 To NUM_MONTHS
srValues.Add(BA_9999)
missingValues += 1
Next
End If
Expand Down
50 changes: 49 additions & 1 deletion src/BAGIS_P/MethodModule.vb
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,9 @@ Module MethodModule
Public Sub BA_UpdateJHCoefInTable(ByRef nmonthsTable As ParameterTable, ByVal jh_coeff As Double)
Dim idxCol As Short = -1
For i As Short = 0 To nmonthsTable.Headers.GetUpperBound(0)
If nmonthsTable.Headers(i).Equals(JH_COEF_HEADER) Then
If nmonthsTable.Headers(i).Equals(BA_Aoi_Parameter_jh_coef) Then
idxCol = i
Exit For
End If
Next
If idxCol > -1 Then
Expand All @@ -686,6 +687,53 @@ Module MethodModule
End If
End Sub

Public Sub BA_UpdateParametersInNmonthsTable(ByRef nmonthsTable As ParameterTable, ByVal updateTable As IDictionary(Of String, AoiParameter))
For Each pName As String In updateTable.Keys
Dim nextParam As AoiParameter = updateTable(pName)
Dim idxCol As Short = -1
'Looking for the column existing in the table
For i As Short = 0 To nmonthsTable.Headers.GetUpperBound(0)
If nmonthsTable.Headers(i).Equals(pName) Then
idxCol = i
Exit For
End If
Next
'Add the column header if we didn't find it
If idxCol = -1 Then
System.Array.Resize(nmonthsTable.Headers, nmonthsTable.Headers.Length + 2)
nmonthsTable.Headers(nmonthsTable.Headers.Length - 1) = pName
idxCol = nmonthsTable.Headers.Length - 1
End If
'Copy the values into a 2D list so we can manipulate the length if we need to
Dim parentList As IList(Of List(Of String)) = New List(Of List(Of String))
For i As Integer = 0 To nmonthsTable.Values.GetUpperBound(0)
Dim childList As IList(Of String) = New List(Of String)
For j As Integer = 0 To nmonthsTable.Values.GetUpperBound(1)
childList.Add(nmonthsTable.Values(i, j))
Next
parentList.Add(childList)
Next

'We found the column
If idxCol > -1 Then
Dim columnToUpdate As IList(Of String) = parentList(idxCol)
'The parameter is a single value and should be populated to all months
If Not String.IsNullOrEmpty(nextParam.Value) Then
Dim nextParamValue As Double = Convert.ToDouble(nextParam.Value)
For j As Integer = 0 To columnToUpdate.Count - 1
'nmonthsTable.Values(j, idxCol) = nextParamValue
columnToUpdate(j) = nextParamValue
Next
ElseIf nextParam.ValuesList IsNot Nothing AndAlso nextParam.ValuesList.Count = NUM_MONTHS Then
For j As Integer = 0 To columnToUpdate.Count - 1
'nmonthsTable.Values(j, idxCol) = Convert.ToDouble(nextParam.ValuesList(j))
columnToUpdate(j) = Convert.ToDouble(nextParam.ValuesList(j))
Next
End If
End If
Next
End Sub

Public Function BA_LoadAoiParameters(ByVal settingsPath As String) As IDictionary(Of String, AoiParameter)
Dim pSettings As Settings = BA_CreateOrLoadSettingsFile(settingsPath)
Dim paramTable As IDictionary(Of String, AoiParameter) = New Dictionary(Of String, AoiParameter)
Expand Down
3 changes: 1 addition & 2 deletions src/BAGIS_P/ParameterModule.vb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ Module ParameterModule
Public BASIN_LAT As String = "basin_lat"
Public HEADER_KEY As String = "header_key"
Public MISSING_VALUE As String = "missing_value"
Public JH_COEF_HEADER As String = "jh_coef"

Public NUM_MONTHS As Short = 12

'Retrieves the single dimension parameters from the parameter file and populates selected parameters from
'the hru dataset
Expand Down

0 comments on commit 3a65801

Please sign in to comment.