Example usage for org.apache.commons.math.linear ArrayRealVector setEntry

List of usage examples for org.apache.commons.math.linear ArrayRealVector setEntry

Introduction

In this page you can find the example usage for org.apache.commons.math.linear ArrayRealVector setEntry.

Prototype

public void setEntry(int index, double value) 

Source Link

Usage

From source file:edu.hawaii.soest.kilonalu.ctd.CTDConverter.java

private void convertTemperature(int temperatureVectorIndex) {

    // define the constants from the temperature conversion formulas
    double MV_CONSTANT_ONE = 524288d;
    double MV_CONSTANT_TWO = 1.6e+007;

    double R_CONSTANT_ONE = 2.900e+009;
    double R_CONSTANT_TWO = 1.024e+008;
    double R_CONSTANT_THREE = 2.048e+004;
    double R_CONSTANT_FOUR = 2.0e+005;

    double T_CONSTANT_ONE = 273.15d;

    //get the calibration coefficients from the CTDParser instance
    double temperatureCoefficientTA0 = this.ctdParser.getTemperatureCoefficientTA0();
    double temperatureCoefficientTA1 = this.ctdParser.getTemperatureCoefficientTA1();
    double temperatureCoefficientTA2 = this.ctdParser.getTemperatureCoefficientTA2();
    double temperatureCoefficientTA3 = this.ctdParser.getTemperatureCoefficientTA3();

    ArrayRealVector temperatureVector = (ArrayRealVector) this.dataValuesMatrix
            .getColumnVector(temperatureVectorIndex);

    ArrayRealVector convertedTemperatureVector = new ArrayRealVector(temperatureVector.getDimension());

    // iterate through the temperature values and apply the conversion
    for (int count = 0; count < temperatureVector.getDimension(); count++) {

        // calculate the temperature in degrees C from the calibration sheet formula
        // note: the mv, r, and tDegreesC variables come from the calibration sheet
        double countValue = temperatureVector.getEntry(count);
        double mv = (countValue - MV_CONSTANT_ONE) / MV_CONSTANT_TWO;

        double r = (mv * R_CONSTANT_ONE + R_CONSTANT_TWO) / (R_CONSTANT_THREE - mv * R_CONSTANT_FOUR);

        double tDegreesC = 1 / (temperatureCoefficientTA0 + temperatureCoefficientTA1 * (Math.log(r))
                + temperatureCoefficientTA2 * (Math.pow(Math.log(r), 2))
                + temperatureCoefficientTA3 * (Math.pow(Math.log(r), 3))) - T_CONSTANT_ONE;

        convertedTemperatureVector.setEntry(count, tDegreesC);

    }// ww  w  .  j a v  a2s. c o  m

    // set the new vector in the converted values matrix
    this.convertedDataValuesMatrix.setColumnVector(temperatureVectorIndex, convertedTemperatureVector);

}

From source file:edu.hawaii.soest.kilonalu.ctd.CTDConverter.java

private void convertConductivity(int conductivityVectorIndex, int temperatureVectorIndex,
        int pressureVectorIndex) {

    // define the constants from the conductivity conversion formulas
    double F_CONSTANT_ONE = 1000d;

    //get the calibration coefficients from the CTDParser instance
    double conductivityCoefficientG = this.ctdParser.getConductivityCoefficientG();
    double conductivityCoefficientH = this.ctdParser.getConductivityCoefficientH();
    double conductivityCoefficientI = this.ctdParser.getConductivityCoefficientI();
    double conductivityCoefficientJ = this.ctdParser.getConductivityCoefficientJ();
    double conductivityCoefficientCF0 = this.ctdParser.getConductivityCoefficientCF0();
    double conductivityCoefficientCPCOR = this.ctdParser.getConductivityCoefficientCPCOR();
    double conductivityCoefficientCTCOR = this.ctdParser.getConductivityCoefficientCTCOR();
    double conductivityCoefficientCSLOPE = this.ctdParser.getConductivityCoefficientCSLOPE();

    ArrayRealVector conductivityVector = (ArrayRealVector) this.dataValuesMatrix
            .getColumnVector(conductivityVectorIndex);

    ArrayRealVector convertedConductivityVector = new ArrayRealVector(conductivityVector.getDimension());

    ArrayRealVector convertedTemperatureVector = (ArrayRealVector) this.convertedDataValuesMatrix
            .getColumnVector(temperatureVectorIndex);

    ArrayRealVector convertedPressureVector = (ArrayRealVector) this.convertedDataValuesMatrix
            .getColumnVector(pressureVectorIndex);

    // iterate through the conductivity values and apply the conversion
    for (int count = 0; count < conductivityVector.getDimension(); count++) {

        // calculate the conductivity in Siemens/m from the calibration sheet formula
        double frequencyValue = conductivityVector.getEntry(count);
        double tDegreesC = convertedTemperatureVector.getEntry(count);
        double pressureDB = convertedPressureVector.getEntry(count);
        double f = frequencyValue / F_CONSTANT_ONE;
        double cSiemensPerM = (conductivityCoefficientG + (conductivityCoefficientH * Math.pow(f, 2))
                + (conductivityCoefficientI * Math.pow(f, 3)) + (conductivityCoefficientJ * Math.pow(f, 4)))
                / (1 + (conductivityCoefficientCTCOR * tDegreesC)
                        + (conductivityCoefficientCPCOR * pressureDB));
        convertedConductivityVector.setEntry(count, cSiemensPerM);

    }/*w  ww.  ja va  2s . c o  m*/

    // set the new vector in the converted values matrix
    this.convertedDataValuesMatrix.setColumnVector(conductivityVectorIndex, convertedConductivityVector);

}

From source file:edu.hawaii.soest.kilonalu.ctd.CTDConverter.java

private void convertPressure(int pressureVectorIndex, int pressureTempCompIndex) {

    double P_CONTSTANT_ONE = 14.7d; // atmospheric pressure influence
    double P_CONTSTANT_TWO = 0.689476d; // psia to decibars factor

    //get the calibration coefficients from the CTDParser instance
    double pressureCoefficientPA0 = this.ctdParser.getPressureCoefficientPA0();
    double pressureCoefficientPA1 = this.ctdParser.getPressureCoefficientPA1();
    double pressureCoefficientPA2 = this.ctdParser.getPressureCoefficientPA2();
    double pressureCoefficientPTCA0 = this.ctdParser.getPressureCoefficientPTCA0();
    double pressureCoefficientPTCA1 = this.ctdParser.getPressureCoefficientPTCA1();
    double pressureCoefficientPTCA2 = this.ctdParser.getPressureCoefficientPTCA2();
    double pressureCoefficientPTCB0 = this.ctdParser.getPressureCoefficientPTCB0();
    double pressureCoefficientPTCB1 = this.ctdParser.getPressureCoefficientPTCB1();
    double pressureCoefficientPTCB2 = this.ctdParser.getPressureCoefficientPTCB2();
    double pressureCoefficientPTEMPA0 = this.ctdParser.getPressureCoefficientPTEMPA0();
    double pressureCoefficientPTEMPA1 = this.ctdParser.getPressureCoefficientPTEMPA1();
    double pressureCoefficientPTEMPA2 = this.ctdParser.getPressureCoefficientPTEMPA2();
    double pressureOffsetCoefficient = this.ctdParser.getPressureOffsetCoefficient();

    // convert raw values ...
    ArrayRealVector pressureVector = (ArrayRealVector) this.dataValuesMatrix
            .getColumnVector(pressureVectorIndex);

    ArrayRealVector pressureTempCompVector = (ArrayRealVector) this.dataValuesMatrix
            .getColumnVector(pressureTempCompIndex);

    // to engineering values
    ArrayRealVector convertedPressureVector = new ArrayRealVector(pressureVector.getDimension());

    // iterate through the pressure values and apply the conversion
    for (int count = 0; count < pressureVector.getDimension(); count++) {

        // calculate the pressure in decibars from the calibration sheet formula
        double pressureValue = pressureVector.getEntry(count);
        double ptCompValue = pressureTempCompVector.getEntry(count);

        double t = pressureCoefficientPTEMPA0 + (pressureCoefficientPTEMPA1 * ptCompValue)
                + (pressureCoefficientPTEMPA2 * Math.pow(ptCompValue, 2));

        double x = pressureValue - pressureCoefficientPTCA0 - pressureCoefficientPTCA1 * t
                - pressureCoefficientPTCA2 * Math.pow(t, 2);

        double n = x * pressureCoefficientPTCB0 / (pressureCoefficientPTCB0 + pressureCoefficientPTCB1 * t
                + pressureCoefficientPTCB2 * Math.pow(t, 2));
        double pressurePSIA = pressureCoefficientPA0 + pressureCoefficientPA1 * n
                + pressureCoefficientPA2 * Math.pow(n, 2);

        // pressure (decibels) = [pressure (psia) - 14.7] * 0.689476 from the CTD manual
        double pressureDB = (pressurePSIA - P_CONTSTANT_ONE) * P_CONTSTANT_TWO;
        convertedPressureVector.setEntry(count, pressureDB);

    }/* ww w . j ava 2 s  .  c om*/

    // set the new vector in the converted values matrix
    this.convertedDataValuesMatrix.setColumnVector(pressureVectorIndex, convertedPressureVector);

}