Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Snippets/LoopThroughInputsToOutput.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This is a snippet to include in another script that loops through input data locations does a transform, and writes to an output data location with the same name. The Scripting Alternative must be configured with these data locations having identical names.

from hec.hecmath import TimeSeriesMath

def createDailyAverageForForecasts(alt, opts):
"""
"""
for inputLoc in alt.getInputDataLocations():
inputTSM = TimeSeriesMath(alt.loadTimeSeries(inputLoc))
# see https://www.hec.usace.army.mil/confluence/dssdocs/dssvueum/scripting/math-functions
# Computes daily average anchored at midnight end-of-day. offsetString can be used to shift the calculation, but leaving blank.
offsetString = ""
dailyTSM = inputTSM.transformTimeSeries(alt.getTimeStep(), offsetString, "AVE")
# this ensures the output data location is used.
outputLoc = currentAlternative.getOutputDataLocation(inputLoc.getName(), inputLoc.getParameter())
dailyTSM.setPathname(outputLoc.getDssPath())
alt.writeTimeSeries(dailyTSM.getData())