use of com.beanit.openiec61850.Array in project ncWMS by Unidata.
the class PhaveosDataReader method read.
@Override
public List<Float> read(String filename, Layer layer, int tIndex, int zIndex, Domain<HorizontalPosition> targetDomain) throws IOException {
NetcdfDataset nc = null;
try {
nc = NetcdfDataset.openDataset(filename);
ucar.nc2.Variable var = nc.findVariable(layer.getId());
// We read in data using a "bounding box" strategy
PixelMap pm = new PixelMap(layer.getHorizontalGrid(), targetDomain);
int iSize = pm.getMaxIIndex() - pm.getMinIIndex() + 1;
int jSize = pm.getMaxJIndex() - pm.getMinJIndex() + 1;
int[] origin = new int[] { pm.getMinJIndex(), pm.getMinIIndex() };
int[] shape = new int[] { jSize, iSize };
Array data = var.read(origin, shape);
// Now copy the data to an array of floats
Index index = data.getIndex();
index.set(new int[index.getRank()]);
float[] arr = new float[(int) targetDomain.size()];
Arrays.fill(arr, Float.NaN);
for (PixelMapEntry pme : pm) {
int i = pme.getSourceGridIIndex() - pm.getMinIIndex();
int j = pme.getSourceGridJIndex() - pm.getMinJIndex();
index.set(new int[] { j, i });
float val = data.getFloat(index);
// Hack to deal with factor-1000 scale in L4 data
if ("mtci_l4".equals(layer.getId())) {
val /= 1000.0f;
}
for (int targetGridPoint : pme.getTargetGridPoints()) {
arr[targetGridPoint] = val > 0.0f ? val : Float.NaN;
}
}
return CdmUtils.wrap(arr);
} catch (InvalidRangeException ire) {
// Shouldn't happen: this would be a programming error
throw new RuntimeException(ire);
} finally {
if (nc != null) {
nc.close();
}
}
}
Aggregations