diff --git a/ARF/reduce-rainfall b/ARF/reduce-rainfall new file mode 100644 index 0000000..a7f1f41 --- /dev/null +++ b/ARF/reduce-rainfall @@ -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