Class HecMath
- All Implemented Interfaces:
Constants
- Direct Known Subclasses:
PairedDataMath
,TextMath
,TimeSeriesMath
HecMath
class together with the TimeSeriesMath
and
PairedDataMath
subclasses provide the user with a method to manipulate
an entire time series or paired data set with simple function calls. For example, each
value in a time series may be scaled by the value 3.0 using:
- ts.multiply( 3.0 ) where
ts
is aTimeSeriesMath
object
HecMath
class provides the math functions in an abstract form. The
actual function operations are overriden and performed in the TimeSeriesMath
and
PairedDataMath
subclasses.
TimeSeriesMath
and PairedDataMath
essentially wrap around
the hec.io.TimeSeriesContainer
(time series data) and
hec.io.PairedDataContainer
(paired data) classes and have no data
of their own. The TimeSeriesMath
class provides the user a way of
manipulating time series data. Similarly, PairedDataMath
class provides
the user with functions to manipulate paired data.
The static method HecMath.createInstance( DataContainer dc )
can be used to create
the HecMath subclass appropriate to the data type. That is if dc
is of
type TimeSeriesContainer
, a TimeSeriesMath
object
will be created containing the TimeSeriesContainer
. Conversly,
if dc
is of type PairedDataContainer
,
a PairedDataMath
object will be created.
The HecMath
class provides several concrete methods which modify the
data in the DataContainer, and are thus common to both TimeSeriesContainer and
PairedDataContainer. These primarily concern the record path name and the
file name associated with the time series or paired data.
If errors in the processing and computation of the math functions occur,
such as the attempted operation on an empty data set or the use of invalid parameter values,
an HecMathException
will be thrown by the function and must be
caught by the caller. Runtime errors ( java.lang.RuntimeException )
are caught in HecMath, TimeSeriesMath and PairedDataMath
and
converted to an HecMathException
.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
protected DataContainer
protected DSSPathname
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
Fields inherited from interface hec.script.Constants
FALSE, ITS_DELETE_INSERT, ITS_MERGE, RTS_REPLACE_ALL, RTS_REPLACE_ALL_CREATE, RTS_REPLACE_ALL_DELETE, RTS_REPLACE_MISSING_VALUES_ONLY, RTS_REPLACE_WITH_NON_MISSING, TRUE, UNDEFINED, UNDEFINED_DOUBLE, UNDEFINED_FLOAT, UNDEFINED_INT, UNDEFINED_LONG, UNDEFINED_TIME
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabs()
add
(double constant) applyMultipleLinearRegression
(String startTimeString, String endTimeString, HecMath[] tsMathArray, double minimumLimit, double maximumLimit) protected static int
bisearch
(double[] xarray, double x, int n) bi-sectional search to find index location of x in xarray[]protected static int
bisearch
(int[] xarray, int x, int n) bi-sectional search to find index location of x in xarray[]abstract boolean
centeredMovingAverage
(int numberToAverageOver, boolean onlyValidValues, boolean useReduced) static boolean
Check ifdc
is null.conicInterpolation
(HecMath tsMath, String inputType, String outputType, double storageScaleFactor) abstract HecMath
convertToIrregular
(String timeIntervalString) abstract HecMath
abstract HecMath
copy()
correlationCoefficients
(HecMath tsMath) cos()
static HecMath
Static method to create an instance ofTimeSeriesMath
orPairedDataMath
depending upon the type ofDataContainer
.static HecMath
createInstance
(TSRecord tsRecord) Static method to create an instance ofTimeSeriesMath
from thehec.model.TSRecord
HecMath[]
decayingBasinWetnessParameter
(HecMath math, double decayRate) divide
(double constant) HecMath[]
durationAnalysis
(DurationPeriod[] durationPeriods) HecMath[]
durationAnalysis
(DurationPeriod[] durationPeriods, String plotScaleType, String plottingPointsType, int numberOfIntervals) HecMath[]
durationAnalysis
(String durationPeriodType) HecMath[]
durationAnalysis
(String durationPeriodType, String plotScaleType, String plottingPointsType, int numberOfIntervals) estimateForMissingPrecipValues
(int maxMissingAllowed) estimateForMissingValues
(int maxMissingAllowed) exponentiation
(double constant) extractTimeSeriesDataForTimeSpecification
(String timeLevelString, String rangeString, boolean isInclusive, int intervalWindow, boolean setAsIrregular) forwardMovingAverage
(int numberToAverageOver) generateDataPairs
(HecMath math, boolean sort) Deprecated.generateDataPairs
(HecMath math, double buffer) generatePairedData
(HecMath tsMath, boolean sort) static HecMath
generateRegularIntervalTimeSeries
(String startTimeString, String endTimeString, int timeIntervalMinutes, int timeOffsetMinutes, double initialValue) static HecMath
generateRegularIntervalTimeSeries
(String startTimeString, String endTimeString, String timeIntervalString, double initialValue) static HecMath
generateRegularIntervalTimeSeries
(String startTimeString, String endTimeString, String timeIntervalString, String timeOffsetString, double initialValue) abstract DataContainer
getData()
Copy the current DataContainer data in the HecMath object intocontainer
.abstract void
getData
(DataContainer container) Copy the current DataContainer data in the HecMath object intocontainer
.protected String
getFunctionName
(int functionType) getPath()
returns the DSS Path that this HecMath's DataContainer representsint
getUnits()
protected static int
hunt
(double[] xarray, double x, int istart) bi-sectional search to find index location of x in xarray[].interpolateDataAtRegularInterval
(String timeIntervalString, String timeOffsetString) inverse()
abstract boolean
abstract boolean
isMetric()
static boolean
isMissing
(double value) Check ifvalue
is set to the missing value(HecMath.UNDEFINED)
.static boolean
isValid
(byte[] bytes) boolean
isValid
(int index) double
int
double
log()
log10()
double
max()
int
maxDate()
double
mean()
double
med()
mergePairedDataSets
(HecMath math) mergeTimeSeries
(HecMath math) double
min()
int
minDate()
double
mode()
modifiedPulsRouting
(HecMath math, int numberSubreaches, double muskingumX) multipleLinearRegression
(HecMath[] tsMathArray, double minimumLimit, double maximumLimit) multipleRegression
(HecMath[] tsMathArray, double minimumLimit, double maximumLimit) multiply
(double constant) muskingumRouting
(int numberSubreaches, double muskingumK, double muskingumX) int
int
olympicSmoothing
(int numberToAverageOver, boolean onlyValidValues, boolean useReduced) double
p1()
double
p10()
double
p2()
double
p20()
double
p25()
double
p5()
double
p75()
double
p80()
double
p90()
double
p95()
double
p98()
double
p99()
periodConstants
(HecMath math) polynomialTransformation
(HecMath tsMath) ratingTableInterpolation
(HecMath tsMath) replaceSpecificValues
(HecDouble from, HecDouble to) replaceValuesInRange
(HecDouble min, HecDouble max, HecDouble to) round()
roundOff
(int digitsPrecision, int powerOfTensPlace) static double
roundOffValue
(double dvalue, int desiredPrecision, int powerOfTensPlace) round off an individual valuescreenWithForwardMovingAverage
(int numberToAverageOver, double changeLimit, boolean setInvalidToMissingValue, String qualityFlagForInvalidValue) screenWithMaxMin
(double minValueLimit, double maxValueLimit, double changeLimit, boolean setInvalidToreplacementValue, double replacementValue, String qualityFlagForInvalidValue) screenWithMaxMin
(double minValueLimit, double maxValueLimit, double changeLimit, boolean setInvalidToMissingValue, String qualityFlagForInvalidValue) void
setCurve
(int curveNumber) void
abstract void
setData
(DataContainer container) Set the DataContainer data for the current HecMath object.void
set the D part of the DSS Pathnamevoid
set the E part of the DSS Pathnamevoid
setLocation
(String location) set the Location part (B Part) of the DSS Pathnamevoid
setParameterPart
(String paramString) set the parameter type (C Part) of the DSS Pathnamevoid
setPathname
(String pathname) set the pathname for this HecMath objectvoid
setTimeInterval
(String timeInterval) set the Time Interval part (E Part) of the DSS Pathname.abstract void
void
setVersion
(String version) set the Version part (F Part) of the DSS Pathnamevoid
setWatershed
(String watershed) set the watershed part (A Part) of the DSS PathnameshiftAdjustment
(HecMath math) shiftInTime
(String timeShiftString) sin()
double
snapToRegularInterval
(String timeIntervalString, String timeOffsetString, String timeBackwardString, String timeForwardString) sqrt()
double
straddleStaggerRouting
(int numberToAverage, int numberToLag, int numberSubreaches) subtract
(double constant) double
sum()
tan()
transformTimeSeries
(HecMath math, String functionTypeString) transformTimeSeries
(HecMath math, String functionTypeString, boolean toIrregular) transformTimeSeries
(String timeIntervalString, String timeOffsetString, String functionTypeString) transformTimeSeries
(String timeIntervalString, String timeOffsetString, String functionTypeString, boolean toIrregular) transformWithFunction
(ScalarOperable transformer) truncate()
twoVariableRatingTableInterpolation
(HecMath tsMathX, HecMath tsMathZ)
-
Field Details
-
_dc
-
_dssPath
-
_curveNumber
protected int _curveNumber -
ADD
protected static final int ADD- See Also:
-
SUBTRACT
protected static final int SUBTRACT- See Also:
-
MULTIPLY
protected static final int MULTIPLY- See Also:
-
DIVIDE
protected static final int DIVIDE- See Also:
-
EXPONENTIATION
protected static final int EXPONENTIATION- See Also:
-
SQRT
protected static final int SQRT- See Also:
-
LOG10
protected static final int LOG10- See Also:
-
LOG
protected static final int LOG- See Also:
-
ABS
protected static final int ABS- See Also:
-
TRUNCATE
protected static final int TRUNCATE- See Also:
-
ROUND
protected static final int ROUND- See Also:
-
SIN
protected static final int SIN- See Also:
-
COS
protected static final int COS- See Also:
-
TAN
protected static final int TAN- See Also:
-
INVERSE
protected static final int INVERSE- See Also:
-
-
Constructor Details
-
HecMath
public HecMath()
-
-
Method Details
-
abs
- Throws:
HecMathException
-
accumulation
- Throws:
HecMathException
-
add
- Throws:
HecMathException
-
add
- Throws:
HecMathException
-
applyMultipleLinearRegression
public HecMath applyMultipleLinearRegression(String startTimeString, String endTimeString, HecMath[] tsMathArray, double minimumLimit, double maximumLimit) throws HecMathException - Throws:
HecMathException
-
centeredMovingAverage
public HecMath centeredMovingAverage(int numberToAverageOver, boolean onlyValidValues, boolean useReduced) throws HecMathException - Throws:
HecMathException
-
conicInterpolation
public HecMath conicInterpolation(HecMath tsMath, String inputType, String outputType, double storageScaleFactor) throws HecMathException - Throws:
HecMathException
-
correlationCoefficients
- Throws:
HecMathException
-
cos
- Throws:
HecMathException
-
cyclicAnalysis
- Throws:
HecMathException
-
decayingBasinWetnessParameter
public HecMath decayingBasinWetnessParameter(HecMath math, double decayRate) throws HecMathException - Throws:
HecMathException
-
divide
- Throws:
HecMathException
-
divide
- Throws:
HecMathException
-
durationAnalysis
- Throws:
HecMathException
-
durationAnalysis
public HecMath[] durationAnalysis(String durationPeriodType, String plotScaleType, String plottingPointsType, int numberOfIntervals) throws HecMathException - Throws:
HecMathException
-
durationAnalysis
- Throws:
HecMathException
-
durationAnalysis
public HecMath[] durationAnalysis(DurationPeriod[] durationPeriods, String plotScaleType, String plottingPointsType, int numberOfIntervals) throws HecMathException - Throws:
HecMathException
-
estimateForMissingPrecipValues
- Throws:
HecMathException
-
estimateForMissingValues
- Throws:
HecMathException
-
replaceSpecificValues
- Throws:
HecMathException
-
replaceValuesInRange
public HecMath replaceValuesInRange(HecDouble min, HecDouble max, HecDouble to) throws HecMathException - Throws:
HecMathException
-
exponentiation
- Throws:
HecMathException
-
extractTimeSeriesDataForTimeSpecification
public HecMath extractTimeSeriesDataForTimeSpecification(String timeLevelString, String rangeString, boolean isInclusive, int intervalWindow, boolean setAsIrregular) throws HecMathException - Throws:
HecMathException
-
flowAccumulatorGageProcessor
- Throws:
HecMathException
-
forwardMovingAverage
- Throws:
HecMathException
-
generateDataPairs
Deprecated.- Parameters:
math
-sort
-- Returns:
- Throws:
HecMathException
-
generatePairedData
- Throws:
HecMathException
-
generateDataPairs
- Throws:
HecMathException
-
getStandardUnits
-
getUnits
-
interpolateDataAtRegularInterval
public HecMath interpolateDataAtRegularInterval(String timeIntervalString, String timeOffsetString) throws HecMathException - Throws:
HecMathException
-
inverse
- Throws:
HecMathException
-
isValid
public boolean isValid(int index) -
lastValidDate
- Throws:
HecMathException
-
lastValidValue
- Throws:
HecMathException
-
log
- Throws:
HecMathException
-
transformWithFunction
- Throws:
HecMathException
-
log10
- Throws:
HecMathException
-
max
- Throws:
HecMathException
-
maxDate
- Throws:
HecMathException
-
mean
- Throws:
HecMathException
-
mergePairedDataSets
- Throws:
HecMathException
-
mergeTimeSeries
- Throws:
HecMathException
-
min
- Throws:
HecMathException
-
minDate
- Throws:
HecMathException
-
modifiedPulsRouting
public HecMath modifiedPulsRouting(HecMath math, int numberSubreaches, double muskingumX) throws HecMathException - Throws:
HecMathException
-
multipleLinearRegression
public HecMath multipleLinearRegression(HecMath[] tsMathArray, double minimumLimit, double maximumLimit) throws HecMathException - Throws:
HecMathException
-
multipleRegression
public HecMath multipleRegression(HecMath[] tsMathArray, double minimumLimit, double maximumLimit) throws HecMathException - Throws:
HecMathException
-
multiply
- Throws:
HecMathException
-
multiply
- Throws:
HecMathException
-
muskingumRouting
public HecMath muskingumRouting(int numberSubreaches, double muskingumK, double muskingumX) throws HecMathException - Throws:
HecMathException
-
numberMissingValues
- Throws:
HecMathException
-
numberValidValues
- Throws:
HecMathException
-
olympicSmoothing
public HecMath olympicSmoothing(int numberToAverageOver, boolean onlyValidValues, boolean useReduced) throws HecMathException - Throws:
HecMathException
-
periodConstants
- Throws:
HecMathException
-
polynomialTransformation
- Throws:
HecMathException
-
polynomialTransformationWithIntegral
- Throws:
HecMathException
-
ratingTableInterpolation
- Throws:
HecMathException
-
reverseRatingTableInterpolation
- Throws:
HecMathException
-
round
- Throws:
HecMathException
-
roundOff
- Throws:
HecMathException
-
screenWithForwardMovingAverage
public HecMath screenWithForwardMovingAverage(int numberToAverageOver, double changeLimit, boolean setInvalidToMissingValue, String qualityFlagForInvalidValue) throws HecMathException - Throws:
HecMathException
-
screenWithMaxMin
public HecMath screenWithMaxMin(double minValueLimit, double maxValueLimit, double changeLimit, boolean setInvalidToMissingValue, String qualityFlagForInvalidValue) throws HecMathException - Throws:
HecMathException
-
screenWithMaxMin
public HecMath screenWithMaxMin(double minValueLimit, double maxValueLimit, double changeLimit, boolean setInvalidToreplacementValue, double replacementValue, String qualityFlagForInvalidValue) throws HecMathException - Throws:
HecMathException
-
setCurve
- Throws:
HecMathException
-
setCurve
- Throws:
HecMathException
-
shiftAdjustment
- Throws:
HecMathException
-
shiftInTime
- Throws:
HecMathException
-
sin
- Throws:
HecMathException
-
skewCoefficient
- Throws:
HecMathException
-
kurtosisCoefficient
- Throws:
HecMathException
-
mode
- Throws:
HecMathException
-
med
- Throws:
HecMathException
-
p1
- Throws:
HecMathException
-
p2
- Throws:
HecMathException
-
p5
- Throws:
HecMathException
-
p10
- Throws:
HecMathException
-
p20
- Throws:
HecMathException
-
p25
- Throws:
HecMathException
-
p75
- Throws:
HecMathException
-
p80
- Throws:
HecMathException
-
p90
- Throws:
HecMathException
-
p95
- Throws:
HecMathException
-
p98
- Throws:
HecMathException
-
p99
- Throws:
HecMathException
-
snapToRegularInterval
public HecMath snapToRegularInterval(String timeIntervalString, String timeOffsetString, String timeBackwardString, String timeForwardString) throws HecMathException - Throws:
HecMathException
-
sqrt
- Throws:
HecMathException
-
standardDeviation
- Throws:
HecMathException
-
standardNormalDeviate
- Throws:
HecMathException
-
straddleStaggerRouting
public HecMath straddleStaggerRouting(int numberToAverage, int numberToLag, int numberSubreaches) throws HecMathException - Throws:
HecMathException
-
subtract
- Throws:
HecMathException
-
subtract
- Throws:
HecMathException
-
successiveDifferences
- Throws:
HecMathException
-
sum
- Throws:
HecMathException
-
tan
- Throws:
HecMathException
-
timeDerivative
- Throws:
HecMathException
-
transformTimeSeries
- Throws:
HecMathException
-
transformTimeSeries
public HecMath transformTimeSeries(HecMath math, String functionTypeString, boolean toIrregular) throws HecMathException - Throws:
HecMathException
-
transformTimeSeries
public HecMath transformTimeSeries(String timeIntervalString, String timeOffsetString, String functionTypeString, boolean toIrregular) throws HecMathException - Throws:
HecMathException
-
truncate
- Throws:
HecMathException
-
twoVariableRatingTableInterpolation
public HecMath twoVariableRatingTableInterpolation(HecMath tsMathX, HecMath tsMathZ) throws HecMathException - Throws:
HecMathException
-
convertToIrregular
- Throws:
HecMathException
-
transformTimeSeries
public HecMath transformTimeSeries(String timeIntervalString, String timeOffsetString, String functionTypeString) throws HecMathException - Throws:
HecMathException
-
setData
Set the DataContainer data for the current HecMath object. The current HecMath will use a copy ofcontainer
.- Parameters:
container
- The DataContainer data to be used by this HecMath object.- Throws:
HecMathException
- ifcontainer
is null or not the correct type of DataContainer.
-
getData
Copy the current DataContainer data in the HecMath object intocontainer
.- Parameters:
container
- The TimeSeriesContainer to receive the copy of data from this time series.- Throws:
HecMathException
-
getData
Copy the current DataContainer data in the HecMath object intocontainer
.- Returns:
- a copy of the DataContainer held in the current HecMath object.
- Throws:
HecMathException
-
getSelectedCurve
public int getSelectedCurve() -
convertToEnglishUnits
- Throws:
HecMathException
-
convertToMetricUnits
- Throws:
HecMathException
-
isMetric
- Throws:
HecMathException
-
isEnglish
- Throws:
HecMathException
-
canDetermineUnitSystem
public abstract boolean canDetermineUnitSystem() -
generateRegularIntervalTimeSeries
public static HecMath generateRegularIntervalTimeSeries(String startTimeString, String endTimeString, String timeIntervalString, String timeOffsetString, double initialValue) throws HecMathException - Throws:
HecMathException
-
generateRegularIntervalTimeSeries
public static HecMath generateRegularIntervalTimeSeries(String startTimeString, String endTimeString, String timeIntervalString, double initialValue) throws HecMathException - Throws:
HecMathException
-
generateRegularIntervalTimeSeries
public static HecMath generateRegularIntervalTimeSeries(String startTimeString, String endTimeString, int timeIntervalMinutes, int timeOffsetMinutes, double initialValue) throws HecMathException - Throws:
HecMathException
-
copy
- Throws:
HecMathException
-
setUnits
-
getFunctionName
-
createInstance
Static method to create an instance ofTimeSeriesMath
orPairedDataMath
depending upon the type ofDataContainer
. IfDataContainer
is anhec.io.TimeSeriesContainer
, aTimeSeriesMath
object will be returned. IfDataContainer
is anhec.io.PairedDataContainer
aPairedDataMath
object will be returned.- Returns:
- A
TimeSeriesMath
orPairedDataMath
. - Throws:
HecMathException
- ifDataContainer
is null or not aTimeSeriesContainer
or aPairedDataContainer
-
createInstance
Static method to create an instance ofTimeSeriesMath
from thehec.model.TSRecord
- Returns:
- A
TimeSeriesMath
- Throws:
HecMathException
- iftsRecord
is null
-
isValid
public static boolean isValid(byte[] bytes) -
checkContainer
Check ifdc
is null.- Returns:
- true if
dc
is not null. - Throws:
HecMathException
- ifdc
is null.
-
isMissing
public static boolean isMissing(double value) Check ifvalue
is set to the missing value(HecMath.UNDEFINED)
.- Parameters:
value
- value- Returns:
- true if
value
equalsHecMath.UNDEFINED
, otherwise returns false.
-
setPathname
set the pathname for this HecMath object- Parameters:
pathname
- the new pathname- Throws:
HecMathException
-
setWatershed
set the watershed part (A Part) of the DSS Pathname- Parameters:
watershed
- the new watershed part- Throws:
HecMathException
-
setLocation
set the Location part (B Part) of the DSS Pathname- Parameters:
location
- the new location part- Throws:
HecMathException
-
setTimeInterval
set the Time Interval part (E Part) of the DSS Pathname. No check is make to see if timeInterval is a valid DSS time interval string.- Parameters:
timeInterval
- the new Time Interval part- Throws:
HecMathException
-
setDPart
set the D part of the DSS Pathname- Parameters:
dPart
- the new version part- Throws:
HecMathException
-
setEPart
set the E part of the DSS Pathname- Parameters:
ePart
- the new version part- Throws:
HecMathException
-
setVersion
set the Version part (F Part) of the DSS Pathname- Parameters:
version
- the new version part- Throws:
HecMathException
-
setParameterPart
set the parameter type (C Part) of the DSS Pathname- Parameters:
paramString
- the new parameter type- Throws:
HecMathException
-
bisearch
protected static int bisearch(int[] xarray, int x, int n) bi-sectional search to find index location of x in xarray[] -
bisearch
protected static int bisearch(double[] xarray, double x, int n) bi-sectional search to find index location of x in xarray[] -
hunt
protected static int hunt(double[] xarray, double x, int istart) bi-sectional search to find index location of x in xarray[]. Will begin search at istart, and will expand search outwards if not found -
roundOffValue
public static double roundOffValue(double dvalue, int desiredPrecision, int powerOfTensPlace) round off an individual value -
getPath
returns the DSS Path that this HecMath's DataContainer represents- Returns:
- the DSS Path
-
generatePairedData(HecMath, boolean)