use of org.openmuc.openiec61850.Array in project s1tbx by senbox-org.
the class K5HDF method readBandRasterDataImpl.
public void readBandRasterDataImpl(int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, int sourceStepX, int sourceStepY, Band destBand, int destOffsetX, int destOffsetY, int destWidth, int destHeight, ProductData destBuffer, ProgressMonitor pm) throws IOException {
Guardian.assertTrue("sourceStepX == 1 && sourceStepY == 1", sourceStepX == 1 && sourceStepY == 1);
Guardian.assertTrue("sourceWidth == destWidth", sourceWidth == destWidth);
Guardian.assertTrue("sourceHeight == destHeight", sourceHeight == destHeight);
final int sceneHeight = product.getSceneRasterHeight();
final int sceneWidth = product.getSceneRasterWidth();
destHeight = Math.min(destHeight, sceneHeight - sourceOffsetY);
destWidth = Math.min(destWidth, sceneWidth - destOffsetX);
final int y0 = yFlipped ? (sceneHeight - 1) - sourceOffsetY : sourceOffsetY;
final Variable variable = bandMap.get(destBand);
final int rank = variable.getRank();
final int[] origin = new int[rank];
final int[] shape = new int[rank];
for (int i = 0; i < rank; i++) {
shape[i] = 1;
origin[i] = 0;
}
shape[0] = 1;
shape[1] = destWidth;
origin[1] = sourceOffsetX;
if (isComplex && destBand.getUnit().equals(Unit.IMAGINARY)) {
origin[2] = 1;
}
pm.beginTask("Reading data from band " + destBand.getName(), destHeight);
try {
for (int y = 0; y < destHeight; y++) {
origin[0] = yFlipped ? y0 - y : y0 + y;
final Array array;
synchronized (netcdfFile) {
array = variable.read(origin, shape);
}
if (destBand.getDataType() == ProductData.TYPE_FLOAT32) {
for (int x = 0; x < destWidth; x++) {
destBuffer.setElemFloatAt(y * destWidth + x, ArrayCopy.toFloat(array.getShort(x)));
}
} else {
System.arraycopy(array.getStorage(), 0, destBuffer.getElems(), y * destWidth, destWidth);
}
pm.worked(1);
}
} catch (InvalidRangeException e) {
throw new IOException(e.getMessage(), e);
} finally {
pm.done();
}
}
use of org.openmuc.openiec61850.Array in project s1tbx by senbox-org.
the class Sentinel1OCNReader method readDataForRank4Variable.
private synchronized void readDataForRank4Variable(int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, int sourceStepX, int sourceStepY, Variable var, int destWidth, int destHeight, ProductData destBuffer) {
final int[] shape0 = var.getShape();
// shape0[0] is height of "outer" grid.
// shape0[1] is width of "outer" grid.
// shape0[2] is height of "inner" grid.
// shape0[3] is width of "inner" grid.
final int[] origin = { sourceOffsetY / shape0[2], sourceOffsetX / shape0[3], 0, 0 };
// System.out.println("sourceOffsetY = " + sourceOffsetY + " shape0[2] = " + shape0[2] + " sourceOffsetX = " + sourceOffsetX + " shape0[3] = " + shape0[3]);
// System.out.println("origin " + origin[0] + " " + origin[1]);
final int outerYEnd = (sourceOffsetY + (sourceHeight - 1) * sourceStepY) / shape0[2];
final int outerXEnd = (sourceOffsetX + (sourceWidth - 1) * sourceStepX) / shape0[3];
// System.out.println("sourceHeight = " + sourceHeight + " sourceStepY = " + sourceStepY + " outerYEnd = " + outerYEnd);
// System.out.println("sourceWidth = " + sourceWidth + " sourceStepX = " + sourceStepX + " outerXEnd = " + outerXEnd);
final int[] shape = { outerYEnd - origin[0] + 1, outerXEnd - origin[1] + 1, shape0[2], shape0[3] };
try {
final Array srcArray = var.read(origin, shape);
final int[] idx = new int[4];
for (int i = 0; i < destHeight; i++) {
// srcY is wrt to what is read in srcArray
final int srcY = (sourceOffsetY - shape0[2] * origin[0]) + i * sourceStepY;
idx[0] = srcY / shape[2];
for (int j = 0; j < destWidth; j++) {
// srcX is wrt to what is read in srcArray
final int srcX = (sourceOffsetX - shape0[3] * origin[1]) + j * sourceStepX;
idx[1] = srcX / shape[3];
idx[2] = srcY - idx[0] * shape[2];
idx[3] = srcX - idx[1] * shape[3];
final int srcIdx = (idx[0] * shape[1] * shape[2] * shape[3]) + (idx[1] * shape[2] * shape[3]) + (idx[2] * shape[3]) + idx[3];
final int destIdx = i * destWidth + j;
destBuffer.setElemFloatAt(destIdx, srcArray.getFloat(srcIdx));
}
}
} catch (IOException e) {
SystemUtils.LOG.severe("Sentinel1OCNReader.readDataForRank4Variable: IOException when reading variable " + var.getFullName());
} catch (InvalidRangeException e) {
SystemUtils.LOG.severe("Sentinel1OCNReader.readDataForRank4Variable: InvalidRangeException when reading variable " + var.getFullName());
}
}
use of org.openmuc.openiec61850.Array in project s1tbx by senbox-org.
the class NetCDFUtils method createTiePointGrid.
public static TiePointGrid createTiePointGrid(final Variable variable, final int gridWidth, final int gridHeight, final int sceneWidth, final int sceneHeight) throws IOException {
final NcAttributeMap attMap = NcAttributeMap.create(variable);
final double subSamplingX = (double) sceneWidth / (double) (gridWidth - 1);
final double subSamplingY = (double) sceneHeight / (double) (gridHeight - 1);
final Array data = variable.read();
// (float[])data.copyTo1DJavaArray();
final float[] dataArray = new float[(int) data.getSize()];
for (int i = 0; i < data.getSize(); ++i) {
dataArray[i] = data.getFloat(i);
}
final TiePointGrid tpg = new TiePointGrid(variable.getShortName(), gridWidth, gridHeight, 0, 0, subSamplingX, subSamplingY, dataArray);
tpg.setDescription(getDescription(variable, attMap));
tpg.setUnit(getUnit(variable, attMap));
tpg.setScalingFactor(getScalingFactor(attMap));
tpg.setScalingOffset(getAddOffset(attMap));
final Number noDataValue = getNoDataValue(attMap);
if (noDataValue != null) {
tpg.setNoDataValue(noDataValue.doubleValue());
tpg.setNoDataValueUsed(true);
}
return tpg;
}
use of org.openmuc.openiec61850.Array in project s1tbx by senbox-org.
the class NetCDFUtils method createMapInfoX.
public static MapInfoX createMapInfoX(final Variable lonVar, final Variable latVar, final int sceneRasterWidth, final int sceneRasterHeight) throws IOException {
float pixelX;
float pixelY;
float easting;
float northing;
float pixelSizeX;
float pixelSizeY;
final NcAttributeMap lonAttrMap = NcAttributeMap.create(lonVar);
final Number lonValidMin = lonAttrMap.getNumericValue(NetcdfConstants.VALID_MIN_ATT_NAME);
final Number lonStep = lonAttrMap.getNumericValue(NetcdfConstants.STEP_ATT_NAME);
final NcAttributeMap latAttrMap = NcAttributeMap.create(latVar);
final Number latValidMin = latAttrMap.getNumericValue(NetcdfConstants.VALID_MIN_ATT_NAME);
final Number latStep = latAttrMap.getNumericValue(NetcdfConstants.STEP_ATT_NAME);
boolean yFlipped;
if (lonValidMin != null && lonStep != null && latValidMin != null && latStep != null) {
// COARDS convention uses 'valid_min' and 'step' attributes
pixelX = 0.5f;
pixelY = (sceneRasterHeight - 1.0f) + 0.5f;
easting = lonValidMin.floatValue();
northing = latValidMin.floatValue();
pixelSizeX = lonStep.floatValue();
pixelSizeY = latStep.floatValue();
// must flip
// todo - check
yFlipped = true;
} else {
// CF convention
final Array lonData = lonVar.read();
final Array latData = latVar.read();
final Index i0 = lonData.getIndex().set(0);
final Index i1 = lonData.getIndex().set(1);
pixelSizeX = lonData.getFloat(i1) - lonData.getFloat(i0);
easting = lonData.getFloat(i0);
final int latSize = (int) latVar.getSize();
final Index j0 = latData.getIndex().set(0);
final Index j1 = latData.getIndex().set(1);
pixelSizeY = latData.getFloat(j1) - latData.getFloat(j0);
pixelX = 0.5f;
pixelY = 0.5f;
// this should be the 'normal' case
if (pixelSizeY < 0) {
pixelSizeY *= -1;
yFlipped = false;
northing = latData.getFloat(latData.getIndex().set(0));
} else {
yFlipped = true;
northing = latData.getFloat(latData.getIndex().set(latSize - 1));
}
}
if (pixelSizeX <= 0 || pixelSizeY <= 0) {
return null;
}
final MapProjection projection = MapProjectionRegistry.getProjection(IdentityTransformDescriptor.NAME);
final MapInfo mapInfo = new MapInfo(projection, pixelX, pixelY, easting, northing, pixelSizeX, pixelSizeY, Datum.WGS_84);
mapInfo.setSceneWidth(sceneRasterWidth);
mapInfo.setSceneHeight(sceneRasterHeight);
return new MapInfoX(mapInfo, yFlipped);
}
use of org.openmuc.openiec61850.Array in project s1tbx by senbox-org.
the class CosmoSkymedReader method readBandRasterDataImpl.
/**
* {@inheritDoc}
*/
@Override
protected void readBandRasterDataImpl(int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, int sourceStepX, int sourceStepY, Band destBand, int destOffsetX, int destOffsetY, int destWidth, int destHeight, ProductData destBuffer, ProgressMonitor pm) throws IOException {
Guardian.assertTrue("sourceStepX == 1 && sourceStepY == 1", sourceStepX == 1 && sourceStepY == 1);
Guardian.assertTrue("sourceWidth == destWidth", sourceWidth == destWidth);
Guardian.assertTrue("sourceHeight == destHeight", sourceHeight == destHeight);
final int sceneHeight = product.getSceneRasterHeight();
final int sceneWidth = product.getSceneRasterWidth();
destHeight = Math.min(destHeight, sceneHeight - sourceOffsetY);
destWidth = Math.min(destWidth, sceneWidth - destOffsetX);
final int y0 = yFlipped ? (sceneHeight - 1) - sourceOffsetY : sourceOffsetY;
final Variable variable = bandMap.get(destBand);
final int rank = variable.getRank();
final int[] origin = new int[rank];
final int[] shape = new int[rank];
for (int i = 0; i < rank; i++) {
shape[i] = 1;
origin[i] = 0;
}
shape[0] = 1;
shape[1] = destWidth;
origin[1] = sourceOffsetX;
if (isComplex && destBand.getUnit().equals(Unit.IMAGINARY)) {
origin[2] = 1;
}
pm.beginTask("Reading data from band " + destBand.getName(), destHeight);
try {
for (int y = 0; y < destHeight; y++) {
origin[0] = yFlipped ? y0 - y : y0 + y;
final Array array;
synchronized (netcdfFile) {
array = variable.read(origin, shape);
}
System.arraycopy(array.getStorage(), 0, destBuffer.getElems(), y * destWidth, destWidth);
pm.worked(1);
}
} catch (InvalidRangeException e) {
final IOException ioException = new IOException(e.getMessage());
ioException.initCause(e);
throw ioException;
} finally {
pm.done();
}
}
Aggregations