Skip to content

Commit

Permalink
DFLOW time series reference fix; IDF outlier tab retrieves CP-adj N d…
Browse files Browse the repository at this point in the history
…ay value

- both legacy and IDF DFLOW updated
  • Loading branch information
TongZhai committed Feb 5, 2020
1 parent 6fe1245 commit a482e76
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 31 deletions.
33 changes: 19 additions & 14 deletions DFLOW/DFLOWCalcs.vb
Original file line number Diff line number Diff line change
Expand Up @@ -662,11 +662,10 @@ Public Class DFLOWCalcs
Dim lHydrologicTS As atcTimeseries = aDataGroup(lDSIndex)
Dim lHydrologicTS2 As atcTimeseries = SubsetByDateBoundary(lHydrologicTS, lStartMonth, lStartDay, Nothing, lFirstyearDFLOW, lLastYearDFLOW, lEndMonthDFLOW, lEndDayDFLOW)
Dim lFirstDate As Double = lHydrologicTS2.Attributes.GetValue("start date")
Dim lHydrologicDS As atcDataSet = lHydrologicTS2
Dim lSYear As Integer = (lDateFormat.JDateToString(lHydrologicDS.Attributes.GetValue("start date"))).Substring(0, 4)
Dim lEYear As Integer = (lDateFormat.JDateToString(lHydrologicDS.Attributes.GetValue("end date"))).Substring(0, 4)
'Dim lHydrologicDS As atcDataSet = lHydrologicTS2
Dim lSYear As Integer = (lDateFormat.JDateToString(lHydrologicTS2.Attributes.GetValue("start date"))).Substring(0, 4)
Dim lEYear As Integer = (lDateFormat.JDateToString(lHydrologicTS2.Attributes.GetValue("end date"))).Substring(0, 4)
Dim lYears As Integer = lEYear - lSYear
Dim lTS As Double() = lHydrologicTS2.Values
lHydrologicTS.Attributes.SetValue("xBy start date", lFirstDate)

' ===== Calculate hydrologic design flow lxQy
Expand All @@ -677,7 +676,7 @@ Public Class DFLOWCalcs
If aShowProgress Then lfrmProgress.Label1.Text = (1 + lItemIdx) & " of " & lTotalItems & " - " & fAveragingPeriod & "Q" & fReturnPeriod
Application.DoEvents()
If lYears >= lReturnPeriod Then
lxQy = xQy(lAveragingPeriod, lReturnPeriod, lHydrologicDS, aInputs)
lxQy = xQy(lAveragingPeriod, lReturnPeriod, lHydrologicTS2, aInputs)
Else
lxQy = lNaN
End If
Expand All @@ -693,10 +692,11 @@ Public Class DFLOWCalcs
End Select

' ===== Create 4-day running average for start of xBy excursion analysis -
Dim lTimeSeries As atcTimeseries = aDataGroup(lDSIndex)
Dim lTimeSeries2 As atcTimeseries = SubsetByDateBoundary(lTimeSeries, lStartMonth, lStartDay, Nothing, lFirstyearDFLOW, lLastYearDFLOW, lEndMonthDFLOW, lEndDayDFLOW)
'Dim lTimeSeries As atcTimeseries = aDataGroup(lDSIndex)
'Dim lTimeSeries2 As atcTimeseries = SubsetByDateBoundary(lTimeSeries, lStartMonth, lStartDay, Nothing, lFirstyearDFLOW, lLastYearDFLOW, lEndMonthDFLOW, lEndDayDFLOW)
'lTS = lTimeSeries2.Values

lTS = lTimeSeries2.Values
Dim lTS As Double() = lHydrologicTS2.Values
lTS(0) = lNaN

Dim lTSN As Double()
Expand Down Expand Up @@ -761,7 +761,8 @@ Public Class DFLOWCalcs
Next

' ----- 2. Get initial guess
Dim lxBy As Double = xQy(lBioPeriod, lBioYears, aDataGroup(lDSIndex), aInputs)
'Dim lxBy As Double = xQy(lBioPeriod, lBioYears, aDataGroup(lDSIndex), aInputs)
Dim lxBy As Double = xQy(lBioPeriod, lBioYears, lHydrologicTS2, aInputs)

' ----- 3. Do xBy calculation
Dim lExcursionCount As Integer
Expand All @@ -784,7 +785,8 @@ Public Class DFLOWCalcs
End If
Application.DoEvents()

lEquivalentxQy = xQy(lAveragingPeriod, lYears, aDataGroup(lDSIndex), aInputs)
'lEquivalentxQy = xQy(lAveragingPeriod, lYears, aDataGroup(lDSIndex), aInputs)
lEquivalentxQy = xQy(lAveragingPeriod, lYears, lHydrologicTS2, aInputs)
If lEquivalentxQy > lxBy Then
lReturnPeriodTry = lYears
Else
Expand All @@ -796,7 +798,8 @@ Public Class DFLOWCalcs
lEquivalentxQy = lxBy
While lEquivalentxQy >= lxBy And lReturnPeriodTry < lYears
lReturnPeriodTry += 1
lEquivalentxQy = xQy(lAveragingPeriod, lReturnPeriodTry, aDataGroup(lDSIndex), aInputs)
'lEquivalentxQy = xQy(lAveragingPeriod, lReturnPeriodTry, aDataGroup(lDSIndex), aInputs)
lEquivalentxQy = xQy(lAveragingPeriod, lReturnPeriodTry, lHydrologicTS2, aInputs)
If aShowProgress Then
lfrmProgress.Label1.Text = (1 + lItemIdx) & " of " & lTotalItems & " - xQy (" & lReturnPeriodTry & " of up to " & lYears & ")"
End If
Expand Down Expand Up @@ -848,12 +851,12 @@ Public Class DFLOWCalcs
Next

' ===== Store results
ladsResults.CellValue(lItemIdx + 1, 0) = lHydrologicDS.Attributes.GetFormattedValue("Location") & " - " & lHydrologicDS.Attributes.GetFormattedValue("STANAM")
ladsResults.CellValue(lItemIdx + 1, 0) = lHydrologicTS2.Attributes.GetFormattedValue("Location") & " - " & lHydrologicTS2.Attributes.GetFormattedValue("STANAM")

' ----- Next three values are corrected by one day to account for current (3/2008) behavior of time series trimming

ladsResults.CellValue(lItemIdx + 1, 1) = lDateFormat.JDateToString(1 + lHydrologicDS.Attributes.GetValue("start date")) & " - " & _
lDateFormat.JDateToString(lHydrologicDS.Attributes.GetValue("end date"))
ladsResults.CellValue(lItemIdx + 1, 1) = lDateFormat.JDateToString(1 + lHydrologicTS2.Attributes.GetValue("start date")) & " - " &
lDateFormat.JDateToString(lHydrologicTS2.Attributes.GetValue("end date"))
ladsResults.CellValue(lItemIdx + 1, 2) = Format(UBound(lTS) - 1, "#,##0") & " "
ladsResults.Alignment(lItemIdx + 1, 2) = atcControls.atcAlignment.HAlignRight
ladsResults.CellValue(lItemIdx + 1, 3) = Format(lNZero, "#,##0") & "/" & Format(lNMiss - 1, "#,##0") & " "
Expand Down Expand Up @@ -901,6 +904,8 @@ Public Class DFLOWCalcs
ladsResults.CellValue(lItemIdx + 1, 14) = Format(lNExcHF / (UBound(lTS) - lNMiss), "percent")
ladsResults.Alignment(lItemIdx + 1, 14) = atcControls.atcAlignment.HAlignDecimal
lItemIdx = lItemIdx + 1

lHydrologicTS2.numValues = 0
Next

If aShowProgress Then
Expand Down
37 changes: 21 additions & 16 deletions atcIntegratedDesignFlow/DFLOWCalcs.vb
Original file line number Diff line number Diff line change
Expand Up @@ -726,9 +726,9 @@ Public Class DFLOWCalcs
Dim lHydrologicTS As atcTimeseries = aDataGroup(lDSIndex)
Dim lHydrologicTS2 As atcTimeseries = SubsetByDateBoundary(lHydrologicTS, lStartMonth, lStartDay, Nothing, lFirstyearDFLOW, lLastYearDFLOW, lEndMonthDFLOW, lEndDayDFLOW)
Dim lFirstDate As Double = lHydrologicTS2.Attributes.GetValue("start date")
Dim lHydrologicDS As atcTimeseries = lHydrologicTS2
Dim lSYear As Integer = (lDateFormat.JDateToString(lHydrologicDS.Attributes.GetValue("start date"))).Substring(0, 4)
Dim lEYear As Integer = (lDateFormat.JDateToString(lHydrologicDS.Attributes.GetValue("end date"))).Substring(0, 4)
'Dim lHydrologicDS As atcTimeseries = lHydrologicTS2
Dim lSYear As Integer = (lDateFormat.JDateToString(lHydrologicTS2.Attributes.GetValue("start date"))).Substring(0, 4)
Dim lEYear As Integer = (lDateFormat.JDateToString(lHydrologicTS2.Attributes.GetValue("end date"))).Substring(0, 4)
Dim lYears As Integer = lEYear - lSYear
lHydrologicTS.Attributes.SetValue("xBy start date", lFirstDate)
lHydrologicTS.Attributes.SetValue("xBy start year", lSYear)
Expand All @@ -746,7 +746,7 @@ Public Class DFLOWCalcs
If aShowProgress Then lfrmProgress.Label1.Text = (1 + lItemIdx) & " of " & lTotalItems & " - " & fAveragingPeriod & "Q" & fReturnPeriod
Application.DoEvents()
If lYears >= lReturnPeriod Then
lxQy = xQy(lAveragingPeriod, lReturnPeriod, lHydrologicDS, aInputs)
lxQy = xQy(lAveragingPeriod, lReturnPeriod, lHydrologicTS2, aInputs)
Else
lxQy = lNaN
End If
Expand All @@ -765,9 +765,10 @@ Public Class DFLOWCalcs
lHydrologicTS.Attributes.SetValue(lxQyKey, lxQy)

' ===== Create 4-day running average for start of xBy excursion analysis -
Dim lTimeSeries As atcTimeseries = SubsetByDateBoundary(aDataGroup(lDSIndex), lStartMonth, lStartDay, Nothing, lFirstyearDFLOW, lLastYearDFLOW, lEndMonthDFLOW, lEndDayDFLOW)
'Dim lTimeSeries As atcTimeseries = SubsetByDateBoundary(aDataGroup(lDSIndex), lStartMonth, lStartDay, Nothing, lFirstyearDFLOW, lLastYearDFLOW, lEndMonthDFLOW, lEndDayDFLOW)
'Dim lHydrologicTS2 As atcTimeseries = SubsetByDateBoundary(lHydrologicTS, lStartMonth, lStartDay, Nothing, lFirstyearDFLOW, lLastYearDFLOW, lEndMonthDFLOW, lEndDayDFLOW)

Dim lTS As Double() = lTimeSeries.Values
Dim lTS As Double() = lHydrologicTS2.Values
lTS(0) = lNaN

Dim lTSN As Double()
Expand Down Expand Up @@ -832,7 +833,8 @@ Public Class DFLOWCalcs
Next

' ----- 2. Get initial guess
Dim lxBy As Double = xQy(lBioPeriod, lBioYears, aDataGroup(lDSIndex), aInputs)
'Dim lxBy As Double = xQy(lBioPeriod, lBioYears, aDataGroup(lDSIndex), aInputs)
Dim lxBy As Double = xQy(lBioPeriod, lBioYears, lHydrologicTS2, aInputs)

' ----- 3. Do xBy calculation
Dim lExcursionCount As Integer
Expand All @@ -857,7 +859,8 @@ Public Class DFLOWCalcs
End If
Application.DoEvents()

lEquivalentxQy = xQy(lAveragingPeriod, lYears, aDataGroup(lDSIndex), aInputs)
'lEquivalentxQy = xQy(lAveragingPeriod, lYears, aDataGroup(lDSIndex), aInputs)
lEquivalentxQy = xQy(lAveragingPeriod, lYears, lHydrologicTS2, aInputs)
If lEquivalentxQy > lxBy Then
lReturnPeriodTry = lYears
Else
Expand All @@ -869,7 +872,8 @@ Public Class DFLOWCalcs
lEquivalentxQy = lxBy
While lEquivalentxQy >= lxBy And lReturnPeriodTry < lYears
lReturnPeriodTry += 1
lEquivalentxQy = xQy(lAveragingPeriod, lReturnPeriodTry, aDataGroup(lDSIndex), aInputs)
'lEquivalentxQy = xQy(lAveragingPeriod, lReturnPeriodTry, aDataGroup(lDSIndex), aInputs)
lEquivalentxQy = xQy(lAveragingPeriod, lReturnPeriodTry, lHydrologicTS2, aInputs)
If aShowProgress Then
lfrmProgress.Label1.Text = (1 + lItemIdx) & " of " & lTotalItems & " - xQy (" & lReturnPeriodTry & " of up to " & lYears & ")"
End If
Expand Down Expand Up @@ -931,12 +935,12 @@ Public Class DFLOWCalcs
Next

' ===== Store results
ladsResults.CellValue(lItemIdx + 1, 0) = lHydrologicDS.Attributes.GetFormattedValue("Location") & " - " & lHydrologicDS.Attributes.GetFormattedValue("STANAM")
ladsResults.CellValue(lItemIdx + 1, 0) = lHydrologicTS2.Attributes.GetFormattedValue("Location") & " - " & lHydrologicTS2.Attributes.GetFormattedValue("STANAM")

' ----- Next three values are corrected by one day to account for current (3/2008) behavior of time series trimming

ladsResults.CellValue(lItemIdx + 1, 1) = lDateFormat.JDateToString(1 + lHydrologicDS.Attributes.GetValue("start date")) & " - " &
lDateFormat.JDateToString(lHydrologicDS.Attributes.GetValue("end date"))
ladsResults.CellValue(lItemIdx + 1, 1) = lDateFormat.JDateToString(1 + lHydrologicTS2.Attributes.GetValue("start date")) & " - " &
lDateFormat.JDateToString(lHydrologicTS2.Attributes.GetValue("end date"))
ladsResults.CellValue(lItemIdx + 1, 2) = Format(UBound(lTS) - 1, "#,##0") & " "
ladsResults.Alignment(lItemIdx + 1, 2) = atcControls.atcAlignment.HAlignRight
ladsResults.CellValue(lItemIdx + 1, 3) = Format(lNZero, "#,##0") & "/" & Format(lNMiss - 1, "#,##0") & " "
Expand Down Expand Up @@ -1011,17 +1015,18 @@ Public Class DFLOWCalcs
lPct = lNExcHF / (UBound(lTS) - lNMiss)
ladsResults.CellValue(lItemIdx + 1, 15) = Format(lPct, "percent")
ladsResults.Alignment(lItemIdx + 1, 15) = atcControls.atcAlignment.HAlignDecimal
lHydrologicTS.Attributes.SetValue(lHMeanKey, lTimeSeries.Attributes.GetValue("Harmonic Mean") & vbTab & Format(lPct, "percent") & vbTab & "N/A")
lHydrologicTS.Attributes.SetValue(lHMeanKey, lHydrologicTS2.Attributes.GetValue("Harmonic Mean") & vbTab & Format(lPct, "percent") & vbTab & "N/A")
Dim lHMeanAdjKey As String = "NONBIOFLOW-Harmonic Mean Adj"
Dim lPctAdj As Double = lNExcHFAdj / (UBound(lTS) - lNMiss)
lHydrologicTS.Attributes.SetValue(lHMeanAdjKey, lTimeSeries.Attributes.GetValue("Harmonic Mean Adj") & vbTab & Format(lPctAdj, "percent") & vbTab & "N/A")
lHydrologicTS.Attributes.SetValue(lHMeanAdjKey, lHydrologicTS2.Attributes.GetValue("Harmonic Mean Adj") & vbTab & Format(lPctAdj, "percent") & vbTab & "N/A")

If lAddSeason Then
ladsResults.CellValue(lItemIdx + 1, 16) = lHydrologicTS.Attributes.GetValue("seasonname")
End If
lItemIdx = lItemIdx + 1
lHydrologicTS2.Clear() : lHydrologicTS2 = Nothing
lTimeSeries.Clear() : lTimeSeries = Nothing
'lHydrologicTS2.Clear()
'lHydrologicTS2 = Nothing
lHydrologicTS2.numValues = 0
Erase lTSN
GC.Collect()
Next 'lDSIndex}
Expand Down
8 changes: 7 additions & 1 deletion atcIntegratedDesignFlow/frmSWSTATmod.vb
Original file line number Diff line number Diff line change
Expand Up @@ -4703,7 +4703,13 @@ Public Class frmSWSTATmod
End If
.Item(4, I).Value = lFrom
.Item(5, I).Value = lTo
lStatVal = lTs.Attributes.GetValue(lOTStatName, Double.NaN)
With lTs.Attributes
If .ContainsAttribute(lOTStatName & "Adj") Then
lStatVal = .GetValue(lOTStatName & "Adj", Double.NaN)
Else
lStatVal = .GetValue(lOTStatName, Double.NaN)
End If
End With
If Not Double.IsNaN(lStatVal) Then
.Item(6, I).Value = DoubleToString(lStatVal, 15, "0.##########", aSignificantDigits:=8)
Else
Expand Down

0 comments on commit a482e76

Please sign in to comment.