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
52 changes: 52 additions & 0 deletions ARF/reduce-rainfall
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import random
from com.rma.io import DssFileManagerImpl
from com.rma.io import DssFileManagerImpl
from hec.hecmath import TimeSeriesMath

##
#
# computeAlternative function is called when the ScriptingAlternative is computed.
# Arguments:
# currentAlternative - the ScriptingAlternative. hec2.wat.plugin.java.impl.scripting.model.ScriptPluginAlt
# computeOptions - the compute options. hec.wat.model.ComputeOptions
#
# return True if the script was successful, False if not.
# no explicit return will be treated as a successful return
#
##
def computeAlternative(currentAlternative, computeOptions):
output = None
currentAlternative.addComputeMessage("Computing ScriptingAlternative:" + currentAlternative.getName() )

for loc in currentAlternative.getInputDataLocations():
currentAlternative.addComputeMessage(loc.getName())

# 1. read time series
tsc = currentAlternative.loadTimeSeries(loc)
hm = TimeSeriesMath(tsc)

#2. Choose a reduction factor
arf = selectArf()

# 3. multily time series by randomly selected areal reduction factor
hm = hm.multiply(arf)
currentAlternative.addComputeMessage("reduced")

# 4. add to output
output = hm


# write output
dfm = DssFileManagerImpl.getDssFileManager()
odl = currentAlternative.getOutputDataLocations()[0]
output.setPathname(odl.getDssPath())
currentAlternative.writeTimeSeries(output.getData())
currentAlternative.addComputeMessage("saved output")

return True

def selectArf():
# Reduction values to select. Update values for your storm
numbers = [.87, .813, .824, .904, .919, .903, .842, .915]
arf = random.choice(numbers)
return arf