/** * Returns the value as an <code>double</code>. <p>The method assumes that this value is a scalar and therefore * simply returns <code>getElemDoubleAt(0)</code>. * * @see #getElemDoubleAt(int index) */ public double getElemDouble() { return getElemDoubleAt(0); }
@Override public double evalD(final EvalEnv env) throws EvalException { final int elemIndex = ((RasterDataEvalEnv) env).getElemIndex(); return data.getElemDoubleAt(elemIndex); }
@Override public final double getDouble(int index) { return scale(_buffer.getElemDoubleAt(index)); } }
/** * Gets the field element with the given index as a <code>double</code>. * * @param index the field index, must be <code>>=0</code> and <code><getNumDataElems()</code> * * @throws java.lang.IndexOutOfBoundsException * if the index is out of bounds */ public double getElemDouble(int index) { return getData().getElemDoubleAt(index); }
@Override public boolean evalB(final EvalEnv env) throws EvalException { final int elemIndex = ((RasterDataEvalEnv) env).getElemIndex(); return Term.toB(data.getElemDoubleAt(elemIndex)); }
/** * Gets the <code>double</code> value of the parameter with the given key. The method performs a case-insensitive * search. * * @param key the parameter key * * @return the parameter value * * @throws HeaderEntryNotFoundException if an entry with the given key could not be found in the header */ public double getParamDouble(String key, int elemIndex) throws HeaderEntryNotFoundException { return getParamImpl(key).getData().getElemDoubleAt(elemIndex); }
/** * Gets the sample for the pixel located at (x,y) as a double value. * * @param x The X co-ordinate of the pixel location * @param y The Y co-ordinate of the pixel location * @throws NullPointerException if this band has no raster data * @throws java.lang.ArrayIndexOutOfBoundsException * if the co-ordinates are not in bounds */ @Override public double getPixelDouble(int x, int y) { if (isScalingApplied()) { return scale(getRasterData().getElemDoubleAt(getRasterWidth() * y + x)); } else { return getRasterData().getElemDoubleAt(getRasterWidth() * y + x); } }
@Override public double getSampleDouble(int x, int y) { double sample = dataBuffer.getElemDoubleAt(index(x, y)); // handle unsigned data types, see also [BEAM-1147] (nf - 20100527) if (signedByte) { //noinspection SillyAssignment sample = (byte) sample; } if (scaled) { sample = toGeoPhysical(sample); } return sample; }
private void read(ProductFile file, String datasetName, String fieldName, double[][] fieldData) throws IOException { final RecordReader recordReader = file.getRecordReader(datasetName + "_" + resolution.name()); for (int b = 0; b < B; b++) { final Record record = recordReader.readRecord(b); final ProductData productData = record.getField(fieldName).getData(); for (int i = 0; i < resolution.getPixelCount(); i++) { fieldData[b][i] = productData.getElemDoubleAt(i); } } }
/** * Gets the sample for the pixel located at (x,y) as an integer value. * * @param x The X co-ordinate of the pixel location * @param y The Y co-ordinate of the pixel location * @throws NullPointerException if this band has no raster data * @throws java.lang.ArrayIndexOutOfBoundsException * if the co-ordinates are not in bounds */ @Override public int getPixelInt(int x, int y) { if (isScalingApplied()) { return (int) Math.round(scale(getRasterData().getElemDoubleAt(getRasterWidth() * y + x))); } else { return getRasterData().getElemIntAt(getRasterWidth() * y + x); } }
private static void addOneSetDopplerCentroidCoefficients( MetadataElement dopplerCentroidSrc, MetadataElement dopplerCentroidCoeffsListElem, int listCnt) { final ArrayList<Double> coefList = new ArrayList<Double>(5); ProductData.UTC utcTime; double origin; try { utcTime = dopplerCentroidSrc.getAttributeUTC("zero_doppler_time"); origin = dopplerCentroidSrc.getAttributeDouble("slant_range_time"); final MetadataAttribute dopCoefAttrib = dopplerCentroidSrc.getAttribute("dop_coef"); final ProductData data = dopCoefAttrib.getData(); final int numElems = data.getNumElems(); for (int i = 0; i < numElems; ++i) { coefList.add(data.getElemDoubleAt(i)); } } catch (Exception e) { System.out.println(e.getMessage()); return; } final MetadataElement dopElem = new MetadataElement("dop_coef_list." + listCnt); dopplerCentroidCoeffsListElem.addElement(dopElem); addAbstractedAttribute("zero_doppler_time", utcTime, dopElem, ""); addAbstractedAttribute("slant_range_time", origin, "ns", dopElem, ""); int coefCnt = 1; for (Double value : coefList) { final MetadataElement coefElem = new MetadataElement("coefficient." + coefCnt); ++coefCnt; dopElem.addElement(coefElem); addAbstractedAttribute("dop_coef", value, "", coefElem, ""); } }
if (scaled) { for (int i = 0; i < size; i++) { samples[i] = toGeoPhysical(data.getElemDoubleAt(i)); samples[i] = data.getElemDoubleAt(i);
private static void addOneSetSRGRCoefficients(MetadataElement srgrSrc, MetadataElement srgrListElem, int listCnt) { final ArrayList<Double> coefList = new ArrayList<Double>(5); ProductData.UTC utcTime; double origin; try { utcTime = srgrSrc.getAttributeUTC("zero_doppler_time"); origin = srgrSrc.getAttributeDouble("ground_range_origin"); final MetadataAttribute srgrCoefAttrib = srgrSrc.getAttribute("srgr_coeff"); final ProductData data = srgrCoefAttrib.getData(); final int numElems = data.getNumElems(); for (int i = 0; i < numElems; ++i) { coefList.add(data.getElemDoubleAt(i)); } } catch (Exception e) { System.out.println(e.getMessage()); return; } final MetadataElement srgrElem = new MetadataElement("srgr_coef_list." + listCnt); srgrListElem.addElement(srgrElem); addAbstractedAttribute("zero_doppler_time", utcTime, srgrElem, ""); addAbstractedAttribute("ground_range_origin", origin, "m", srgrElem, ""); int coefCnt = 1; for (Double value : coefList) { final MetadataElement coefElem = new MetadataElement("coefficient." + coefCnt); ++coefCnt; srgrElem.addElement(coefElem); addAbstractedAttribute("srgr_coef", value, "", coefElem, ""); } }
/** * Gets the sample for the pixel located at (x,y) as a float value. * * @param x The X co-ordinate of the pixel location * @param y The Y co-ordinate of the pixel location * @throws NullPointerException if this band has no raster data * @throws java.lang.ArrayIndexOutOfBoundsException * if the co-ordinates are not in bounds */ @Override public float getPixelFloat(int x, int y) { if (isScalingApplied()) { return (float) scale(getRasterData().getElemDoubleAt(getRasterWidth() * y + x)); } else { return getRasterData().getElemFloatAt(getRasterWidth() * y + x); } }
public void testDirectInstantiation() throws IOException, OperatorException { Product a = new Product("a", "T", 2, 2); a.addBand(new VirtualBand("x", ProductData.TYPE_FLOAT64, 2, 2, "5.2")); Product b = new Product("b", "T", 2, 2); b.addBand(new VirtualBand("x", ProductData.TYPE_FLOAT64, 2, 2, "4.8")); // Directly instantiate AddOp Operator op1 = new AddOp(a, b); // Initializes op1 Product p1 = op1.getTargetProduct(); // Directly instantiate MulConstOp Operator op2 = new MulConstOp(p1, 2.5); // Initializes op2 Product product = op2.getTargetProduct(); Band xBand = product.getBand("x"); ProductData rasterData = xBand.createCompatibleRasterData(); xBand.readRasterData(0, 0, 2, 2, rasterData, ProgressMonitor.NULL); assertEquals(2.5 * (5.2 + 4.8), rasterData.getElemDoubleAt(0), 1e-10); assertEquals(2.5 * (5.2 + 4.8), rasterData.getElemDoubleAt(1), 1e-10); assertEquals(2.5 * (5.2 + 4.8), rasterData.getElemDoubleAt(2), 1e-10); assertEquals(2.5 * (5.2 + 4.8), rasterData.getElemDoubleAt(3), 1e-10); }
@Override public void writeBandRasterData(Band sourceBand, int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, ProductData sourceBuffer, ProgressMonitor pm) throws IOException { final String variableName = ReaderUtils.getVariableName(sourceBand); if (shallWriteVariable(variableName)) { ProductData scaledBuffer; if (convertLogScaledBands && sourceBand.isLog10Scaled()) { scaledBuffer = ProductData.createInstance(ProductData.TYPE_FLOAT32, sourceBuffer.getNumElems()); for (int i = 0; i < sourceBuffer.getNumElems(); i++) { double elemDoubleAt = sourceBuffer.getElemDoubleAt(i); scaledBuffer.setElemDoubleAt(i, sourceBand.scale(elemDoubleAt)); } } else { scaledBuffer = sourceBuffer; } synchronized (writeable) { NVariable variable = getVariable(variableName); variable.write(sourceOffsetX, sourceOffsetY, sourceWidth, sourceHeight, isYFlipped, scaledBuffer); } } }
if (scaled) { for (int i = 0; i < size; i++) { samples[i] = toGeoPhysical(data.getElemDoubleAt(i)); samples[i] = data.getElemDoubleAt(i);
assertEquals(65.0F, instance.getElemFloatAt(1), 0.0e-12F); assertEquals(101.0F, instance.getElemFloatAt(2), 0.0e-12F); assertEquals(97.0D, instance.getElemDoubleAt(0), 0.0e-12D); assertEquals(65.0D, instance.getElemDoubleAt(1), 0.0e-12D); assertEquals(101.0D, instance.getElemDoubleAt(2), 0.0e-12D); assertEquals("a", instance.getElemStringAt(0)); assertEquals("A", instance.getElemStringAt(1));
assertEquals(127.0F, instance.getElemFloatAt(1), 0.0e-12F); assertEquals(128.0F, instance.getElemFloatAt(2), 0.0e-12F); assertEquals(255.0D, instance.getElemDoubleAt(0), 0.0e-12D); assertEquals(127.0D, instance.getElemDoubleAt(1), 0.0e-12D); assertEquals(128.0D, instance.getElemDoubleAt(2), 0.0e-12D); assertEquals("255", instance.getElemStringAt(0)); assertEquals("127", instance.getElemStringAt(1));
assertEquals(32767.0F, instance.getElemFloatAt(1), 0.0e-12F); assertEquals(32768.0F, instance.getElemFloatAt(2), 0.0e-12F); assertEquals(65535.0D, instance.getElemDoubleAt(0), 0.0e-12D); assertEquals(32767.0D, instance.getElemDoubleAt(1), 0.0e-12D); assertEquals(32768.0D, instance.getElemDoubleAt(2), 0.0e-12D); assertEquals("65535", instance.getElemStringAt(0)); assertEquals("32767", instance.getElemStringAt(1));