root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / hydrology / createHyetogram / CreateHyetogramAlgorithm.java @ 59
History | View | Annotate | Download (5.51 KB)
1 |
package es.unex.sextante.hydrology.createHyetogram; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.StringTokenizer; |
5 |
|
6 |
import es.unex.sextante.additionalInfo.AdditionalInfoNumericalValue; |
7 |
import es.unex.sextante.core.GeoAlgorithm; |
8 |
import es.unex.sextante.core.Sextante; |
9 |
import es.unex.sextante.dataObjects.ITable; |
10 |
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException; |
11 |
import es.unex.sextante.exceptions.RepeatedParameterNameException; |
12 |
import es.unex.sextante.exceptions.UnsupportedOutputChannelException; |
13 |
import es.unex.sextante.hydrology.modelling.Hyetograph; |
14 |
|
15 |
public class CreateHyetogramAlgorithm |
16 |
extends
|
17 |
GeoAlgorithm { |
18 |
|
19 |
public static final String RETURNS = "RETURNS"; |
20 |
public static final String HYETOGRAPHLENGTH = "HYETOGRAPHLENGTH"; |
21 |
public static final String TIMETOPEAK = "TIMETOPEAK"; |
22 |
public static final String INTERVAL = "INTERVAL"; |
23 |
public static final String AVERAGE = "AVERAGE"; |
24 |
public static final String STDDEV = "STDDEV"; |
25 |
public static final String HYETOGRAPH = "HYETOGRAPH"; |
26 |
|
27 |
private int m_iInterval; |
28 |
private int m_iPeakTime; |
29 |
private int m_iHyetoLength; |
30 |
private final int m_iRatioI1 = 10; //TODO cambiar esto |
31 |
private ArrayList m_Returns; |
32 |
private double m_dMean; |
33 |
private double m_dStdDev; |
34 |
|
35 |
|
36 |
@Override
|
37 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
38 |
|
39 |
m_iInterval = m_Parameters.getParameterValueAsInt(INTERVAL) * 60;
|
40 |
m_iHyetoLength = m_Parameters.getParameterValueAsInt(HYETOGRAPHLENGTH) * 60;
|
41 |
m_iPeakTime = m_Parameters.getParameterValueAsInt(TIMETOPEAK) * 60;
|
42 |
m_dMean = m_Parameters.getParameterValueAsDouble(AVERAGE); |
43 |
m_dStdDev = m_Parameters.getParameterValueAsDouble(STDDEV); |
44 |
|
45 |
m_Returns = new ArrayList(); |
46 |
final String sReturns = m_Parameters.getParameterValueAsString(RETURNS); |
47 |
final StringTokenizer st = new StringTokenizer(sReturns); |
48 |
while (st.hasMoreTokens()) {
|
49 |
try {
|
50 |
final String token = st.nextToken(); |
51 |
final Integer value = Integer.valueOf(token); |
52 |
m_Returns.add(value); |
53 |
} |
54 |
catch (final NumberFormatException e) {} |
55 |
} |
56 |
|
57 |
createTable(); |
58 |
|
59 |
return true; |
60 |
} |
61 |
|
62 |
|
63 |
private void createTable() throws UnsupportedOutputChannelException { |
64 |
|
65 |
int i, j;
|
66 |
int iReturn;
|
67 |
final String sFields[] = new String[m_Returns.size() + 1]; |
68 |
final Object values[] = new Object[m_Returns.size() + 1]; |
69 |
final Class types[] = new Class[m_Returns.size() + 1]; |
70 |
final Hyetograph hyetos[] = new Hyetograph[m_Returns.size()]; |
71 |
ITable driver; |
72 |
|
73 |
types[0] = Double.class; |
74 |
sFields[0] = "T"; |
75 |
for (i = 0; i < m_Returns.size(); i++) { |
76 |
types[i + 1] = Double.class; |
77 |
sFields[i + 1] = "P_" + ((Integer) m_Returns.get(i)).toString(); |
78 |
} |
79 |
|
80 |
driver = getNewTable(HYETOGRAPH, Sextante.getText("Hietograma"), types, sFields);
|
81 |
|
82 |
for (i = 0; i < m_Returns.size(); i++) { |
83 |
iReturn = ((Integer) m_Returns.get(i)).intValue();
|
84 |
hyetos[i] = getHyetograph(iReturn); |
85 |
} |
86 |
|
87 |
for (j = 0; j < hyetos[0].getIntervals(); j++) { |
88 |
values[0] = new Double(j * hyetos[0].getTimeInterval()); |
89 |
for (int k = 0; k < hyetos.length; k++) { |
90 |
values[k + 1] = new Double(hyetos[k].getRainfallAtInterval(j)); |
91 |
} |
92 |
driver.addRecord(values); |
93 |
} |
94 |
|
95 |
} |
96 |
|
97 |
|
98 |
private Hyetograph getHyetograph(final int iReturn) { |
99 |
|
100 |
final double dAlpha = Math.sqrt(Math.pow(3.141592, 2.0) / 6.0 / m_dStdDev); |
101 |
final double dMu = m_dMean - (0.5772 / dAlpha); |
102 |
|
103 |
final double dFx = 1.0 - (1.0 / iReturn); |
104 |
double dP24 = (float) -Math.log(Math.log(1.0 / dFx)); |
105 |
dP24 = dP24 / dAlpha + dMu; |
106 |
|
107 |
return new Hyetograph(dP24, m_iHyetoLength, m_iInterval, m_iPeakTime, iReturn, m_iRatioI1); |
108 |
|
109 |
} |
110 |
|
111 |
|
112 |
@Override
|
113 |
public void defineCharacteristics() { |
114 |
|
115 |
setName(Sextante.getText("Create_synthetic_hyetograph"));
|
116 |
setGroup(Sextante.getText("Indices_and_other_hydrological_parameters"));
|
117 |
setUserCanDefineAnalysisExtent(false);
|
118 |
|
119 |
try {
|
120 |
m_Parameters.addString(RETURNS, Sextante.getText("Return_periods"), "5 10 25 50 100"); |
121 |
m_Parameters.addNumericalValue(HYETOGRAPHLENGTH, Sextante.getText("Total_length__minutes"),
|
122 |
AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER, 180, Integer.MIN_VALUE, Integer.MAX_VALUE); |
123 |
m_Parameters.addNumericalValue(TIMETOPEAK, Sextante.getText("Time_to_peak__minutes"),
|
124 |
AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER, 120, Integer.MIN_VALUE, Integer.MAX_VALUE); |
125 |
m_Parameters.addNumericalValue(INTERVAL, Sextante.getText("Interval__minutes"),
|
126 |
AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER, 10, 1, Integer.MAX_VALUE); |
127 |
m_Parameters.addNumericalValue(AVERAGE, Sextante.getText("Rainfall_mean"),
|
128 |
AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE, 0, 0, Double.MAX_VALUE); |
129 |
m_Parameters.addNumericalValue(STDDEV, Sextante.getText("Standard_deviation"),
|
130 |
AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE, 0, 0, Double.MAX_VALUE); |
131 |
addOutputTable(HYETOGRAPH, Sextante.getText("Hietograma"));
|
132 |
} |
133 |
catch (final RepeatedParameterNameException e) { |
134 |
Sextante.addErrorToLog(e); |
135 |
} |
136 |
|
137 |
} |
138 |
|
139 |
} |