Example usage for java.lang Math log10

List of usage examples for java.lang Math log10

Introduction

In this page you can find the example usage for java.lang Math log10.

Prototype

@HotSpotIntrinsicCandidate
public static double log10(double a) 

Source Link

Document

Returns the base 10 logarithm of a double value.

Usage

From source file:org.broadinstitute.gatk.tools.walkers.genotyper.afcalc.AFCalculationUnitTest.java

@Test(enabled = true, dataProvider = "Models")
public void testNoPrior(final AFCalculator model) {
    for (int REF_PL = 10; REF_PL <= 20; REF_PL += 10) {
        final Genotype AB = makePL(Arrays.asList(A, C), REF_PL, 0, 10000);

        final double[] flatPriors = new double[] { 0.0, 0.0, 0.0 };
        // test that function computeAlleleFrequency correctly operates when the flat prior option is set
        // computeAlleleFrequencyPriors takes linear priors
        final ArrayList<Double> inputPrior = new ArrayList<Double>();
        inputPrior.add(1.0 / 3);//ww  w  .  java2  s .com
        inputPrior.add(1.0 / 3);
        final AFPriorProvider log10priorProvider = UnifiedGenotypingEngine
                .composeAlleleFrequencyPriorProvider(2, 0.0, inputPrior);
        final double[] noPriors = log10priorProvider.forTotalPloidy(2);

        GetGLsTest cfgFlatPrior = new GetGLsTest(model, 1, Arrays.asList(AB), flatPriors, "flatPrior");
        GetGLsTest cfgNoPrior = new GetGLsTest(model, 1, Arrays.asList(AB), noPriors, "noPrior");
        final AFCalculationResult resultTrackerFlat = cfgFlatPrior.execute();
        final AFCalculationResult resultTrackerNoPrior = cfgNoPrior.execute();

        final double pRefWithNoPrior = AB.getLikelihoods().getAsVector()[0];
        final double pHetWithNoPrior = AB.getLikelihoods().getAsVector()[1] - Math.log10(0.5);
        final double nonRefPost = Math.pow(10, pHetWithNoPrior)
                / (Math.pow(10, pRefWithNoPrior) + Math.pow(10, pHetWithNoPrior));
        final double log10NonRefPost = Math.log10(nonRefPost);

        if (!Double.isInfinite(log10NonRefPost)) {
            // check that the no-prior and flat-prior constructions yield same result
            Assert.assertEquals(resultTrackerFlat.getLog10PosteriorOfAFGT0(),
                    resultTrackerNoPrior.getLog10PosteriorOfAFGT0());
        }

    }
}

From source file:org.broadinstitute.gatk.tools.walkers.genotyper.afcalc.AFCalculationUnitTest.java

@Test(enabled = true && !DEBUG_ONLY, dataProvider = "Models")
public void testBiallelicPriors(final AFCalculator model) {

    for (int REF_PL = 10; REF_PL <= 20; REF_PL += 10) {
        final Genotype AB = makePL(Arrays.asList(A, C), REF_PL, 0, 10000);

        for (int log10NonRefPrior = 1; log10NonRefPrior < 10 * REF_PL; log10NonRefPrior += 1) {
            final double refPrior = 1 - QualityUtils.qualToErrorProb(log10NonRefPrior);
            final double nonRefPrior = (1 - refPrior) / 2;
            final double[] priors = MathUtils.normalizeFromLog10(
                    MathUtils.toLog10(new double[] { refPrior, nonRefPrior, nonRefPrior }), true);
            if (!Double.isInfinite(priors[1])) {
                GetGLsTest cfg = new GetGLsTest(model, 1, Arrays.asList(AB), priors,
                        "pNonRef" + log10NonRefPrior);
                final AFCalculationResult resultTracker = cfg.execute();
                final int actualAC = resultTracker.getAlleleCountsOfMLE()[0];

                final double pRefWithPrior = AB.getLikelihoods().getAsVector()[0] + priors[0];
                final double pHetWithPrior = AB.getLikelihoods().getAsVector()[1] + priors[1] - Math.log10(0.5);
                final double nonRefPost = Math.pow(10, pHetWithPrior)
                        / (Math.pow(10, pRefWithPrior) + Math.pow(10, pHetWithPrior));
                final double log10NonRefPost = Math.log10(nonRefPost);

                if (!Double.isInfinite(log10NonRefPost))
                    Assert.assertEquals(resultTracker.getLog10PosteriorOfAFGT0(), log10NonRefPost, 1e-2);

                if (nonRefPost >= 0.9)
                    Assert.assertTrue(resultTracker.isPolymorphic(C, -1));

                final int expectedMLEAC = 1; // the MLE is independent of the prior
                Assert.assertEquals(actualAC, expectedMLEAC, "actual AC with priors " + log10NonRefPrior
                        + " not expected " + expectedMLEAC + " priors " + Utils.join(",", priors));
            }/*from  w  w w  .  j a v  a  2 s .c om*/
        }
    }
}

From source file:org.esa.nest.gpf.ASARCalibrator.java

/**
 * Called by the framework in order to compute a tile for the given target band.
 * <p>The default implementation throws a runtime exception with the message "not implemented".</p>
 *
 * @param targetBand The target band./*from w ww.  ja va  2  s . c o  m*/
 * @param targetTile The current tile associated with the target band to be computed.
 * @param pm         A progress monitor which should be used to determine computation cancelation requests.
 * @throws org.esa.beam.framework.gpf.OperatorException If an error occurs during computation of the target raster.
 */
@Override

public void computeTile(Band targetBand, Tile targetTile, ProgressMonitor pm) throws OperatorException {

    final Rectangle targetTileRectangle = targetTile.getRectangle();
    final int x0 = targetTileRectangle.x;
    final int y0 = targetTileRectangle.y;
    final int w = targetTileRectangle.width;
    final int h = targetTileRectangle.height;
    //System.out.println("x0 = " + x0 + ", y0 = " + y0 + ", w = " + w + ", h = " + h);

    Band sourceBand1;
    Tile sourceRaster1;
    ProductData srcData1;
    ProductData srcData2 = null;

    final String[] srcBandNames = targetBandNameToSourceBandName.get(targetBand.getName());
    if (srcBandNames.length == 1) {
        sourceBand1 = sourceProduct.getBand(srcBandNames[0]);
        sourceRaster1 = calibrationOp.getSourceTile(sourceBand1, targetTileRectangle);
        srcData1 = sourceRaster1.getDataBuffer();
    } else {
        sourceBand1 = sourceProduct.getBand(srcBandNames[0]);
        final Band sourceBand2 = sourceProduct.getBand(srcBandNames[1]);
        sourceRaster1 = calibrationOp.getSourceTile(sourceBand1, targetTileRectangle);
        final Tile sourceRaster2 = calibrationOp.getSourceTile(sourceBand2, targetTileRectangle);
        srcData1 = sourceRaster1.getDataBuffer();
        srcData2 = sourceRaster2.getDataBuffer();
    }

    final Unit.UnitType bandUnit = Unit.getUnitType(sourceBand1);

    // copy band if unit is phase
    if (bandUnit == Unit.UnitType.PHASE) {
        targetTile.setRawSamples(sourceRaster1.getRawSamples());
        return;
    }

    final String pol = OperatorUtils.getBandPolarization(srcBandNames[0], absRoot);
    int prodBand = 0;
    if (pol != null && mdsPolar[1] != null && mdsPolar[1].contains(pol)) {
        prodBand = 1;
    }

    final ProductData trgData = targetTile.getDataBuffer();
    final TileIndex srcIndex = new TileIndex(sourceRaster1);
    final TileIndex tgtIndex = new TileIndex(targetTile);

    final int maxY = y0 + h;
    final int maxX = x0 + w;

    final double[] incidenceAnglesArray = new double[w];
    final double[] slantRangeTimeArray = new double[w];

    double[][] targetTileOldAntPat = null; // old antenna pattern gains for row pixels in a tile, in linear scale
    double[][] targetTileNewAntPat = null; // new antenna pattern gains for row pixels in a tile, in linear scale
    double[][] targetTileSlantRange = null; // slant range for pixels in a tile, in m

    if (applyAntennaPatternCorr) {
        targetTileNewAntPat = new double[h][w];
        targetTileSlantRange = new double[h][w];
        if (retroCalibrationFlag) {
            targetTileOldAntPat = new double[h][w];
        }

        if (wideSwathProductFlag) {
            computeWideSwathAntennaPatternForCurrentTile(x0, y0, w, h, targetTileOldAntPat, targetTileNewAntPat,
                    targetTileSlantRange, slantRangeTPGInterp);
        } else {
            computeSingleSwathAntennaPatternForCurrentTile(x0, y0, w, h, targetTileOldAntPat,
                    targetTileNewAntPat, targetTileSlantRange, prodBand, slantRangeTPGInterp);
        }
    }

    double sigma, dn = 0, i, q;
    final double theCalibrationFactor = newCalibrationConstant[prodBand];

    int srcIdx, tgtIdx;
    for (int y = y0, yy = 0; y < maxY; ++y, ++yy) {
        srcIndex.calculateStride(y);
        tgtIndex.calculateStride(y);

        incidenceTPGInterp.getPixels(x0, y, w, 1, incidenceAnglesArray, pm,
                TiePointInterpolator.InterpMode.QUADRATIC);

        if (applyRangeSpreadingCorr) {
            slantRangeTPGInterp.getPixels(x0, y, w, 1, slantRangeTimeArray, pm,
                    TiePointInterpolator.InterpMode.QUADRATIC);
        }

        for (int x = x0, xx = 0; x < maxX; ++x, ++xx) {
            srcIdx = srcIndex.getIndex(x);
            tgtIdx = tgtIndex.getIndex(x);

            if (bandUnit == Unit.UnitType.AMPLITUDE) {
                dn = srcData1.getElemDoubleAt(srcIdx);
                sigma = dn * dn;
            } else if (bandUnit == Unit.UnitType.INTENSITY) {
                sigma = srcData1.getElemDoubleAt(srcIdx);
            } else if (bandUnit == Unit.UnitType.REAL || bandUnit == Unit.UnitType.IMAGINARY) {
                i = srcData1.getElemDoubleAt(srcIdx);
                q = srcData2.getElemDoubleAt(srcIdx);
                sigma = i * i + q * q;
            } else {
                throw new OperatorException("ASAR Calibration: unhandled unit");
            }

            if (retroCalibrationFlag) { // remove old antenna pattern gain
                sigma *= targetTileOldAntPat[yy][xx]; // see Andrea's email dated Nov. 11, 2008
            }

            // apply calibration constant and incidence angle corrections
            sigma *= FastMath.sin(incidenceAnglesArray[xx] * MathUtils.DTOR) / theCalibrationFactor;

            if (applyRangeSpreadingCorr && targetTileSlantRange != null) { // apply range spreading loss compensation
                /*
                time = slantRangeTimeArray[xx] / 1000000000.0; //convert ns to s
                sigma *= Math.pow(time * halfLightSpeedByRefSlantRange, rangeSpreadingCompPower);
                */
                sigma *= Math.pow(targetTileSlantRange[yy][xx] / refSlantRange800km, rangeSpreadingCompPower);
            }

            if (applyAntennaPatternCorr) { // apply antenna pattern correction
                sigma /= targetTileNewAntPat[yy][xx]; // see Andrea's email dated Nov. 11, 2008
            }

            if (outputImageScaleInDb) { // convert calibration result to dB
                if (sigma < underFlowFloat) {
                    sigma = -underFlowFloat;
                } else {
                    sigma = 10.0 * Math.log10(sigma);
                }
            }

            trgData.setElemDoubleAt(tgtIdx, sigma);
        }
    }
}

From source file:org.esa.s1tbx.calibration.gpf.ASARCalibrator.java

/**
 * Called by the framework in order to compute a tile for the given target band.
 * <p>The default implementation throws a runtime exception with the message "not implemented".</p>
 *
 * @param targetBand The target band./*from   w  ww  .  j  a  v  a  2 s  .c  o m*/
 * @param targetTile The current tile associated with the target band to be computed.
 * @param pm         A progress monitor which should be used to determine computation cancelation requests.
 * @throws org.esa.snap.framework.gpf.OperatorException If an error occurs during computation of the target raster.
 */
@Override

public void computeTile(Band targetBand, Tile targetTile, ProgressMonitor pm) throws OperatorException {

    final Rectangle targetTileRectangle = targetTile.getRectangle();
    final int x0 = targetTileRectangle.x;
    final int y0 = targetTileRectangle.y;
    final int w = targetTileRectangle.width;
    final int h = targetTileRectangle.height;
    //System.out.println("x0 = " + x0 + ", y0 = " + y0 + ", w = " + w + ", h = " + h);

    Band sourceBand1;
    Tile sourceRaster1;
    ProductData srcData1;
    ProductData srcData2 = null;

    final String[] srcBandNames = targetBandNameToSourceBandName.get(targetBand.getName());
    if (srcBandNames.length == 1) {
        sourceBand1 = sourceProduct.getBand(srcBandNames[0]);
        sourceRaster1 = calibrationOp.getSourceTile(sourceBand1, targetTileRectangle);
        srcData1 = sourceRaster1.getDataBuffer();
    } else {
        sourceBand1 = sourceProduct.getBand(srcBandNames[0]);
        final Band sourceBand2 = sourceProduct.getBand(srcBandNames[1]);
        sourceRaster1 = calibrationOp.getSourceTile(sourceBand1, targetTileRectangle);
        final Tile sourceRaster2 = calibrationOp.getSourceTile(sourceBand2, targetTileRectangle);
        srcData1 = sourceRaster1.getDataBuffer();
        srcData2 = sourceRaster2.getDataBuffer();
    }

    final Unit.UnitType bandUnit = Unit.getUnitType(sourceBand1);

    // copy band if unit is phase
    if (bandUnit == Unit.UnitType.PHASE) {
        targetTile.setRawSamples(sourceRaster1.getRawSamples());
        return;
    }

    final String pol = OperatorUtils.getBandPolarization(srcBandNames[0], absRoot);
    int prodBand = 0;
    if (pol != null && mdsPolar[1] != null && mdsPolar[1].contains(pol)) {
        prodBand = 1;
    }

    final ProductData trgData = targetTile.getDataBuffer();
    final TileIndex srcIndex = new TileIndex(sourceRaster1);
    final TileIndex tgtIndex = new TileIndex(targetTile);

    final int maxY = y0 + h;
    final int maxX = x0 + w;

    final double[] incidenceAnglesArray = new double[w];
    final double[] slantRangeTimeArray = new double[w];

    double[][] targetTileOldAntPat = null; // old antenna pattern gains for row pixels in a tile, in linear scale
    double[][] targetTileNewAntPat = null; // new antenna pattern gains for row pixels in a tile, in linear scale
    double[][] targetTileSlantRange = null; // slant range for pixels in a tile, in m

    if (applyAntennaPatternCorr) {
        targetTileNewAntPat = new double[h][w];
        targetTileSlantRange = new double[h][w];
        if (retroCalibrationFlag) {
            targetTileOldAntPat = new double[h][w];
        }

        if (wideSwathProductFlag) {
            computeWideSwathAntennaPatternForCurrentTile(x0, y0, w, h, targetTileOldAntPat, targetTileNewAntPat,
                    targetTileSlantRange, slantRangeTPGInterp);
        } else {
            computeSingleSwathAntennaPatternForCurrentTile(x0, y0, w, h, targetTileOldAntPat,
                    targetTileNewAntPat, targetTileSlantRange, prodBand, slantRangeTPGInterp);
        }
    }

    double sigma, dn = 0, i, q;
    final double theCalibrationFactor = newCalibrationConstant[prodBand];

    int srcIdx, tgtIdx;
    for (int y = y0, yy = 0; y < maxY; ++y, ++yy) {
        srcIndex.calculateStride(y);
        tgtIndex.calculateStride(y);

        incidenceTPGInterp.getPixels(x0, y, w, 1, incidenceAnglesArray, pm,
                TiePointInterpolator.InterpMode.QUADRATIC);

        if (applyRangeSpreadingCorr) {
            slantRangeTPGInterp.getPixels(x0, y, w, 1, slantRangeTimeArray, pm,
                    TiePointInterpolator.InterpMode.QUADRATIC);
        }

        for (int x = x0, xx = 0; x < maxX; ++x, ++xx) {
            srcIdx = srcIndex.getIndex(x);
            tgtIdx = tgtIndex.getIndex(x);

            if (bandUnit == Unit.UnitType.AMPLITUDE) {
                dn = srcData1.getElemDoubleAt(srcIdx);
                sigma = dn * dn;
            } else if (bandUnit == Unit.UnitType.INTENSITY) {
                sigma = srcData1.getElemDoubleAt(srcIdx);
            } else if (bandUnit == Unit.UnitType.REAL || bandUnit == Unit.UnitType.IMAGINARY) {
                i = srcData1.getElemDoubleAt(srcIdx);
                q = srcData2.getElemDoubleAt(srcIdx);
                sigma = i * i + q * q;
            } else {
                throw new OperatorException("ASAR Calibration: unhandled unit");
            }

            if (retroCalibrationFlag) { // remove old antenna pattern gain
                sigma *= targetTileOldAntPat[yy][xx]; // see Andrea's email dated Nov. 11, 2008
            }

            // apply calibration constant and incidence angle corrections
            sigma *= FastMath.sin(incidenceAnglesArray[xx] * Constants.DTOR) / theCalibrationFactor;

            if (applyRangeSpreadingCorr && targetTileSlantRange != null) { // apply range spreading loss compensation
                /*
                time = slantRangeTimeArray[xx] / 1000000000.0; //convert ns to s
                sigma *= Math.pow(time * halfLightSpeedByRefSlantRange, rangeSpreadingCompPower);
                */
                sigma *= FastMath.pow(targetTileSlantRange[yy][xx] / refSlantRange800km,
                        rangeSpreadingCompPower);
            }

            if (applyAntennaPatternCorr) { // apply antenna pattern correction
                sigma /= targetTileNewAntPat[yy][xx]; // see Andrea's email dated Nov. 11, 2008
            }

            if (outputImageScaleInDb) { // convert calibration result to dB
                if (sigma < underFlowFloat) {
                    sigma = -underFlowFloat;
                } else {
                    sigma = 10.0 * Math.log10(sigma);
                }
            }

            trgData.setElemDoubleAt(tgtIdx, sigma);
        }
    }
}

From source file:com.vonglasow.michael.satstat.MainActivity.java

/**
 * Gets the number of decimal digits to show when displaying sensor values, based on sensor accuracy.
 * @param sensor The sensor//w  w  w  .j a  va  2 s.  c  o  m
 * @param maxDecimals The maximum number of decimals to display, even if the sensor's accuracy is higher
 * @return
 */
public static byte getSensorDecimals(Sensor sensor, byte maxDecimals) {
    if (sensor == null)
        return 0;
    float res = sensor.getResolution();
    if (res == 0)
        return maxDecimals;
    return (byte) Math.min(maxDecimals,
            (sensor != null) ? (byte) Math.max(Math.ceil((float) -Math.log10(sensor.getResolution())), 0) : 0);
}

From source file:org.esa.s1tbx.calibration.gpf.calibrators.ASARCalibrator.java

/**
 * Called by the framework in order to compute a tile for the given target band.
 * <p>The default implementation throws a runtime exception with the message "not implemented".</p>
 *
 * @param targetBand The target band.//from w  ww  .  j a  v a2  s  .  c om
 * @param targetTile The current tile associated with the target band to be computed.
 * @param pm         A progress monitor which should be used to determine computation cancelation requests.
 * @throws OperatorException If an error occurs during computation of the target raster.
 */
@Override

public void computeTile(Band targetBand, Tile targetTile, ProgressMonitor pm) throws OperatorException {

    final Rectangle targetTileRectangle = targetTile.getRectangle();
    final int x0 = targetTileRectangle.x;
    final int y0 = targetTileRectangle.y;
    final int w = targetTileRectangle.width;
    final int h = targetTileRectangle.height;
    //System.out.println("x0 = " + x0 + ", y0 = " + y0 + ", w = " + w + ", h = " + h);

    Band sourceBand1;
    Tile sourceRaster1;
    ProductData srcData1;
    ProductData srcData2 = null;

    final String[] srcBandNames = targetBandNameToSourceBandName.get(targetBand.getName());
    if (srcBandNames.length == 1) {
        sourceBand1 = sourceProduct.getBand(srcBandNames[0]);
        sourceRaster1 = calibrationOp.getSourceTile(sourceBand1, targetTileRectangle);
        srcData1 = sourceRaster1.getDataBuffer();
    } else {
        sourceBand1 = sourceProduct.getBand(srcBandNames[0]);
        final Band sourceBand2 = sourceProduct.getBand(srcBandNames[1]);
        sourceRaster1 = calibrationOp.getSourceTile(sourceBand1, targetTileRectangle);
        final Tile sourceRaster2 = calibrationOp.getSourceTile(sourceBand2, targetTileRectangle);
        srcData1 = sourceRaster1.getDataBuffer();
        srcData2 = sourceRaster2.getDataBuffer();
    }

    final Unit.UnitType tgtBandUnit = Unit.getUnitType(targetBand);
    final Unit.UnitType srcBandUnit = Unit.getUnitType(sourceBand1);

    // copy band if unit is phase
    if (tgtBandUnit == Unit.UnitType.PHASE) {
        targetTile.setRawSamples(sourceRaster1.getRawSamples());
        return;
    }

    final String pol = OperatorUtils.getBandPolarization(srcBandNames[0], absRoot);
    int prodBand = 0;
    if (pol != null && mdsPolar[1] != null && mdsPolar[1].contains(pol)) {
        prodBand = 1;
    }

    final ProductData trgData = targetTile.getDataBuffer();
    final TileIndex srcIndex = new TileIndex(sourceRaster1);
    final TileIndex tgtIndex = new TileIndex(targetTile);

    final int maxY = y0 + h;
    final int maxX = x0 + w;

    final double[] incidenceAnglesArray = new double[w];
    final double[] slantRangeTimeArray = new double[w];

    double[][] targetTileOldAntPat = null; // old antenna pattern gains for row pixels in a tile, in linear scale
    double[][] targetTileNewAntPat = null; // new antenna pattern gains for row pixels in a tile, in linear scale
    double[][] targetTileSlantRange = null; // slant range for pixels in a tile, in m

    if (applyAntennaPatternCorr) {
        targetTileNewAntPat = new double[h][w];
        targetTileSlantRange = new double[h][w];
        if (retroCalibrationFlag) {
            targetTileOldAntPat = new double[h][w];
        }

        if (wideSwathProductFlag) {
            computeWideSwathAntennaPatternForCurrentTile(x0, y0, w, h, targetTileOldAntPat, targetTileNewAntPat,
                    targetTileSlantRange, slantRangeTPGInterp);
        } else {
            computeSingleSwathAntennaPatternForCurrentTile(x0, y0, w, h, targetTileOldAntPat,
                    targetTileNewAntPat, targetTileSlantRange, prodBand, slantRangeTPGInterp);
        }
    }

    double sigma, dn, dn2, i, q, phaseTerm = 0.0;
    final double theCalibrationFactor = newCalibrationConstant[prodBand];

    int srcIdx, tgtIdx;
    for (int y = y0, yy = 0; y < maxY; ++y, ++yy) {
        srcIndex.calculateStride(y);
        tgtIndex.calculateStride(y);

        incidenceTPGInterp.getPixels(x0, y, w, 1, incidenceAnglesArray, pm,
                TiePointInterpolator.InterpMode.QUADRATIC);

        if (applyRangeSpreadingCorr) {
            slantRangeTPGInterp.getPixels(x0, y, w, 1, slantRangeTimeArray, pm,
                    TiePointInterpolator.InterpMode.QUADRATIC);
        }

        for (int x = x0, xx = 0; x < maxX; ++x, ++xx) {
            srcIdx = srcIndex.getIndex(x);
            tgtIdx = tgtIndex.getIndex(x);

            if (srcBandUnit == Unit.UnitType.AMPLITUDE) {
                dn = srcData1.getElemDoubleAt(srcIdx);
                dn2 = dn * dn;
            } else if (srcBandUnit == Unit.UnitType.INTENSITY) {
                dn2 = srcData1.getElemDoubleAt(srcIdx);
            } else if (srcBandUnit == Unit.UnitType.REAL) {
                i = srcData1.getElemDoubleAt(srcIdx);
                q = srcData2.getElemDoubleAt(srcIdx);
                dn2 = i * i + q * q;
                if (tgtBandUnit == Unit.UnitType.REAL) {
                    phaseTerm = i / Math.sqrt(dn2);
                } else if (tgtBandUnit == Unit.UnitType.IMAGINARY) {
                    phaseTerm = q / Math.sqrt(dn2);
                }
            } else if (srcBandUnit == Unit.UnitType.INTENSITY_DB) {
                dn2 = FastMath.pow(10, srcData1.getElemDoubleAt(srcIdx) / 10.0); // convert dB to linear scale
            } else {
                throw new OperatorException("ASAR Calibration: unhandled unit");
            }

            double calFactor = 1.0;
            if (retroCalibrationFlag) { // remove old antenna pattern gain
                calFactor *= targetTileOldAntPat[yy][xx]; // see Andrea's email dated Nov. 11, 2008
            }

            // apply calibration constant and incidence angle corrections
            calFactor *= FastMath.sin(incidenceAnglesArray[xx] * Constants.DTOR) / theCalibrationFactor;

            if (applyRangeSpreadingCorr && targetTileSlantRange != null) { // apply range spreading loss compensation
                calFactor *= FastMath.pow(targetTileSlantRange[yy][xx] / refSlantRange800km,
                        rangeSpreadingCompPower);
            }

            if (applyAntennaPatternCorr) { // apply antenna pattern correction
                calFactor /= targetTileNewAntPat[yy][xx]; // see Andrea's email dated Nov. 11, 2008
            }

            sigma = dn2 * calFactor;

            if (isComplex && outputImageInComplex) {
                sigma = Math.sqrt(sigma) * phaseTerm;
            }

            if (outputImageScaleInDb) { // convert calibration result to dB
                if (sigma < underFlowFloat) {
                    sigma = -underFlowFloat;
                } else {
                    sigma = 10.0 * Math.log10(sigma);
                }
            }

            trgData.setElemDoubleAt(tgtIdx, sigma);
        }
    }
}

From source file:spectrogram.Spectrogram.java

/**
 * label the color map appropriately//w ww .  j a  v  a 2  s  .c  o m
 */
private void labelColorMapTics() {
    int mapWidth = (int) cmRect.getWidth();
    int mapHeight = (int) cmRect.getHeight();

    double imin = spectraCache.getiMin();
    double imax = spectraCache.getiMax();

    // add tick marks and labels to the color bar
    int y0 = (int) cmRect.getY();
    int x0 = (int) (cmRect.getX() + mapWidth - 4);
    grph.setFont(lblFont);
    grph.setColor(Color.BLACK);
    for (int p = 0; p <= 100; p++) {
        if ((p % 10 == 0 && p != 90) || (logIntensity && p < 10 && p % 2 == 0)) {
            int p1 = p;
            double p2; // actual value in the image
            p2 = p / 100. * (imax - imin) + imin;
            if (logIntensity) {
                p1 = p == 0 ? 0 : (int) (Math.log10((double) p) * 50);
                p2 = Math.pow(10, p2);
            }
            int y = mapHeight - Math.round(p1 * mapHeight / 100.f) + y0;
            grph.drawLine(x0, y, x0 + 6, y);
            String lbl;
            int exp = (int) Math.log10(p2);
            if (Math.abs(exp) < 4) {
                lbl = String.format("%1$4f", p2);
            } else {
                double p3 = p2 / Math.pow(10, exp) * 10;
                lbl = String.format("%1$.2fe%2$d", p3, exp);
            }

            grph.drawString(lbl, x0 + 8, y + lblHeight / 3);
        }
    }
}

From source file:com.actelion.research.table.view.JVisualization.java

private void updateColorIndices() {
    if (mMarkerColor.getColorColumn() == cColumnUnassigned) {
        for (int i = 0; i < mDataPoints; i++)
            mPoint[i].colorIndex = VisualizationColor.cDefaultDataColorIndex;
    } else if (CompoundTableHitlistHandler.isHitlistColumn(mMarkerColor.getColorColumn())) {
        int hitlistIndex = CompoundTableHitlistHandler.getHitlistFromColumn(mMarkerColor.getColorColumn());
        int flagNo = mTableModel.getHitlistHandler().getHitlistFlagNo(hitlistIndex);
        for (int i = 0; i < mDataPoints; i++)
            mPoint[i].colorIndex = (byte) (mPoint[i].record.isFlagSet(flagNo)
                    ? VisualizationColor.cSpecialColorCount
                    : VisualizationColor.cSpecialColorCount + 1);
    } else if (mTableModel.isDescriptorColumn(mMarkerColor.getColorColumn())) {
        setSimilarityColors(-1);/* www  .  j  ava  2  s.c o  m*/
    } else if (mMarkerColor.getColorListMode() == VisualizationColor.cColorListModeCategories) {
        for (int i = 0; i < mDataPoints; i++)
            mPoint[i].colorIndex = (byte) (VisualizationColor.cSpecialColorCount
                    + mTableModel.getCategoryIndex(mMarkerColor.getColorColumn(), mPoint[i].record));
    } else if (mTableModel.isColumnTypeDouble(mMarkerColor.getColorColumn())) {
        float min = Float.isNaN(mMarkerColor.getColorMin())
                ? mTableModel.getMinimumValue(mMarkerColor.getColorColumn())
                : (mTableModel.isLogarithmicViewMode(mMarkerColor.getColorColumn()))
                        ? (float) Math.log10(mMarkerColor.getColorMin())
                        : mMarkerColor.getColorMin();
        float max = Float.isNaN(mMarkerColor.getColorMax())
                ? mTableModel.getMaximumValue(mMarkerColor.getColorColumn())
                : (mTableModel.isLogarithmicViewMode(mMarkerColor.getColorColumn()))
                        ? (float) Math.log10(mMarkerColor.getColorMax())
                        : mMarkerColor.getColorMax();

        //   1. colorMin is explicitly set; max is real max, but lower than min
        // or 2. colorMax is explicitly set; min is real min, but larger than max
        // first case is OK, second needs adaption below to be handled as indented
        if (min >= max)
            if (!Float.isNaN(mMarkerColor.getColorMax()))
                min = Float.MIN_VALUE;

        for (int i = 0; i < mDataPoints; i++) {
            float value = mPoint[i].record.getDouble(mMarkerColor.getColorColumn());
            if (Float.isNaN(value))
                mPoint[i].colorIndex = VisualizationColor.cMissingDataColorIndex;
            else if (value <= min)
                mPoint[i].colorIndex = (byte) VisualizationColor.cSpecialColorCount;
            else if (value >= max)
                mPoint[i].colorIndex = (byte) (mMarkerColor.getColorList().length - 1);
            else
                mPoint[i].colorIndex = (byte) (0.5 + VisualizationColor.cSpecialColorCount
                        + (float) (mMarkerColor.getColorList().length - VisualizationColor.cSpecialColorCount
                                - 1) * (value - min) / (max - min));
        }
    }

    invalidateOffImage(true);
}

From source file:org.broadinstitute.gatk.utils.MathUtils.java

/**
 * Converts LN to LOG10/*from www  .  j  a  va 2 s .c om*/
 *
 * @param ln log(x)
 * @return log10(x)
 */
public static double lnToLog10(final double ln) {
    return ln * Math.log10(Math.E);
}

From source file:com.redsqirl.workflow.server.Workflow.java

public String generateNewId() throws RemoteException {
    boolean found = false;
    String newId = null;/*w  ww . j  a  v a2s .c  o  m*/
    int length = (int) (Math.log10(element.size() + 1) + 2);

    while (newId == null) {
        newId = "a" + RandomString.getRandomName(length, "1234567890");
        Iterator<DataFlowElement> itA = element.iterator();
        found = false;
        while (itA.hasNext() && !found) {
            found = itA.next().getComponentId().equals(newId);
        }
        if (found) {
            newId = null;
        }

    }
    return newId;
}