root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / statisticalMethods / pdfChiSquared / PDFChiSquaredAlgorithm.java @ 59
History | View | Annotate | Download (2.71 KB)
1 |
package es.unex.sextante.statisticalMethods.pdfChiSquared; |
---|---|
2 |
|
3 |
import es.unex.sextante.additionalInfo.AdditionalInfoNumericalValue; |
4 |
import es.unex.sextante.core.GeoAlgorithm; |
5 |
import es.unex.sextante.core.AnalysisExtent; |
6 |
import es.unex.sextante.core.Sextante; |
7 |
import es.unex.sextante.dataObjects.IRasterLayer; |
8 |
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException; |
9 |
import es.unex.sextante.exceptions.RepeatedParameterNameException; |
10 |
import es.unex.sextante.math.pdf.PDF; |
11 |
|
12 |
public class PDFChiSquaredAlgorithm |
13 |
extends
|
14 |
GeoAlgorithm { |
15 |
|
16 |
@Override
|
17 |
public void defineCharacteristics() { |
18 |
|
19 |
setName(Sextante.getText("Chi_squared_probability_distribution"));
|
20 |
setGroup(Sextante.getText("Statistical_methods"));
|
21 |
setUserCanDefineAnalysisExtent(false);
|
22 |
|
23 |
try {
|
24 |
m_Parameters.addInputRasterLayer("INPUT", Sextante.getText("Raster_layer"), true); |
25 |
m_Parameters.addNumericalValue("DEGREES", Sextante.getText("Degrees_of_freedom"), |
26 |
AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER, 2, 0, Integer.MAX_VALUE); |
27 |
m_Parameters.addBoolean("CDF", Sextante.getText("Accumulated_probability"), false); |
28 |
addOutputRasterLayer("PROBABILITY", Sextante.getText("Result")); |
29 |
} |
30 |
catch (final RepeatedParameterNameException e) { |
31 |
Sextante.addErrorToLog(e); |
32 |
} |
33 |
|
34 |
} |
35 |
|
36 |
|
37 |
@Override
|
38 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
39 |
|
40 |
int x, y;
|
41 |
int iNX, iNY;
|
42 |
double dValue;
|
43 |
int iDegrees;
|
44 |
boolean bCDF;
|
45 |
|
46 |
final IRasterLayer window = m_Parameters.getParameterValueAsRasterLayer("INPUT"); |
47 |
bCDF = m_Parameters.getParameterValueAsBoolean("CDF");
|
48 |
iDegrees = m_Parameters.getParameterValueAsInt("DEGREES");
|
49 |
window.setFullExtent(); |
50 |
final AnalysisExtent gridExtent = new AnalysisExtent(window); |
51 |
final IRasterLayer result = getNewRasterLayer("PROBABILITY", Sextante.getText("Probability__chi_squared"), |
52 |
IRasterLayer.RASTER_DATA_TYPE_DOUBLE, gridExtent); |
53 |
|
54 |
iNX = window.getNX(); |
55 |
iNY = window.getNY(); |
56 |
|
57 |
for (y = 0; y < iNY && setProgress(y, iNY); y++) { |
58 |
for (x = 0; x < iNX; x++) { |
59 |
dValue = window.getCellValueAsDouble(x, y); |
60 |
if (!window.isNoDataValue(dValue)) {
|
61 |
if (bCDF) {
|
62 |
result.setCellValue(x, y, PDF.chiSquareCDF(dValue, iDegrees)); |
63 |
} |
64 |
else {
|
65 |
result.setCellValue(x, y, PDF.chiSquare(dValue, iDegrees)); |
66 |
} |
67 |
} |
68 |
else {
|
69 |
result.setNoData(x, y); |
70 |
} |
71 |
} |
72 |
} |
73 |
|
74 |
return !m_Task.isCanceled();
|
75 |
|
76 |
} |
77 |
|
78 |
} |