/** * Check whether the Y axis need to be flipped. Note that the method is synchronized since it * access the underlying Variable * * @param axis * @return * @throws IOException */ private synchronized boolean needFlipYAxis(CoordinateAxis axis) throws IOException { boolean flipYAxis = false; try { Array yAxisStart = axis.read(new Section().appendRange(2)); float y1 = yAxisStart.getFloat(0); float y2 = yAxisStart.getFloat(1); if (y2 > y1) { flipYAxis = true; } } catch (InvalidRangeException e) { throw new RuntimeException(e); } return flipYAxis; }
Cache(int[] shape, int[] newshape, DataType dataType) { this.shape = shape; this.newshape = newshape; this.result = Array.factory(dataType, newshape); nt = shape[0]; Section s = new Section(shape); chunksize = (int)(s.computeSize() / nt); // get view of result as a 2d array (any..., nt); int[] reshape = new int[] {chunksize, nt}; this.work = this.result.reshapeNoCopy(reshape); }
public boolean conformal(Section other) { if (computeSize() != other.computeSize()) return false; Section reduceThis = this.reduce(); Section reduceOther = other.reduce(); return reduceThis.equalShape(reduceOther); }
public Section addRangeNames(List<String> rangeNames) throws InvalidRangeException { if (rangeNames.size() != getRank()) throw new InvalidRangeException("Invalid number of Range Names"); int count = 0; Section result = new Section(); for (Range r : getRanges()) { Range nr = new Range(rangeNames.get(count++), r); result.appendRange(nr); } return result; }
Section makeVarSection(Variable mainv) { Section vSection = mainv.getShapeAsSection(); Section dataSection = new Section(); for (Range r : vSection.getRanges()) { Range rr = section.find(r.getName()); dataSection.appendRange(rr != null ? rr : r); } return dataSection; } }
@Override public Array reallyRead(Variable client, Section section, CancelTask cancelTask) throws IOException, InvalidRangeException { Section orgSection = new Section(section.getRanges()); orgSection.insertRange(sliceDim, slice.getRange(sliceDim)); Array data = orgClient._read( orgSection); data = data.reduce( sliceDim); return data; }
public Array readData(Variable v2, Section section) throws IOException, InvalidRangeException { Vgroup vgroup = (Vgroup) v2.getSPobject(); Range scanRange = section.getRange(0); Range radialRange = section.getRange(1); Range gateRange = section.getRange(2); Array data = Array.factory(v2.getDataType(), section.getShape()); IndexIterator ii = data.getIndexIterator(); for (int scanIdx : scanRange) { Level2Record[] mapScan = vgroup.map[scanIdx]; readOneScan(mapScan, radialRange, gateRange, vgroup.datatype, ii); } return data; }
/** * Create a new Section by compacting each Range. * first = first/stride, last=last/stride, stride=1. * * @return compacted Section * @throws InvalidRangeException elements must be nonnegative, 0 <= first <= last */ public Section compact() throws InvalidRangeException { List<Range> results = new ArrayList<>(getRank()); for (Range r : list) { results.add(r.compact()); } return new Section(results); }
@Override Index reduce(int dim) { if ((dim < 0) || (dim >= rank)) throw new IllegalArgumentException("illegal reduce dim " + dim); if (shape[dim] != 1) throw new IllegalArgumentException("illegal reduce dim " + dim + " : length != 1"); Section curr = new Section(shape); Section want = curr.removeRange(dim); return new IndexConstant( want.getShape()); }
private int writeEnumData(Variable v, UserType userType, int grpid, int varid, int typeid, Section section, Array values) throws IOException, InvalidRangeException { int ret = 0; SizeT[] origin = convertSizeT(section.getOrigin()); SizeT[] shape = convertSizeT(section.getShape()); boolean isUnsigned = isUnsigned(typeid); int sectionLen = (int) section.computeSize(); assert values.getSize() == sectionLen; int[] secStride = section.getStride(); boolean stride1 = isStride1(secStride); ByteBuffer bb = values.getDataAsByteBuffer(ByteOrder.nativeOrder()); byte[] data = bb.array(); if(stride1) { ret = nc4.nc_put_vara(grpid, varid, origin, shape, data); } else { SizeT[] stride = convertSizeT(secStride); ret = nc4.nc_put_vars(grpid, varid, origin, shape, stride, data); } return ret; }
private static Section randomSubset(Section all, int stride) throws InvalidRangeException { Section s = new Section(); for (Range r : all.getRanges()) { int first = random(r.first(), r.last() / 2); int last = random(r.last() / 2, r.last()); s.appendRange(first, last, stride); } return s; }
public Section removeFirst(Section parentSection) { int parentSize = parentSection.getRank(); assert parentSize <= list.size(); if (parentSize == list.size()) return new Section(); // scalar return subSection(parentSize, list.size()); }
public Array readData(ucar.nc2.Variable v2, Section section) throws IOException, InvalidRangeException { // subset int[] origin = section.getOrigin(); int[] shape = section.getShape(); int[] stride = section.getStride(); Giniheader.Vinfo vinfo = (Giniheader.Vinfo) v2.getSPobject(); int[] levels = vinfo.levels; if (headerParser.gini_GetCompressType() == 0) return readData(v2, vinfo.begin, origin, shape, stride, levels); else if (headerParser.gini_GetCompressType() == 2) return readCompressedData(v2, vinfo.begin, origin, shape, stride, levels); else if (headerParser.gini_GetCompressType() == 1) return readCompressedZlib(v2, vinfo.begin, vinfo.nx, vinfo.ny, origin, shape, stride, levels); else return null; }
@Override public Array reallyRead(Variable client, Section section, CancelTask cancelTask) throws IOException, InvalidRangeException { // see if its really a full read if ((null == section) || section.computeSize() == getSize()) return reallyRead(client, cancelTask); if (orgVar == null) return getMissingDataArray(section.getShape()); return orgVar.read(section); }
private void writeCompoundData(Structure s, UserType userType, int grpid, int varid, int typeid, Section section, ArrayStructure values) throws IOException, InvalidRangeException { SizeT[] origin = convertSizeT(section.getOrigin()); SizeT[] shape = convertSizeT(section.getShape()); SizeT[] stride = convertSizeT(section.getStride()); ArrayStructureBB valuesBB = StructureDataDeep.copyToArrayBB(s, values, ByteOrder.nativeOrder()); // LOOK embedded strings getting lost ?? ByteBuffer bbuff = valuesBB.getByteBuffer(); if (debugCompound) System.out.printf("writeCompoundData variable %s (grpid %d varid %d) %n", s.getShortName(), grpid, varid); // write the data // int ret = nc4.nc_put_var(grpid, varid, bbuff); int ret; if(section.isStrided()) ret = nc4.nc_put_vars(grpid, varid, origin, shape, stride, bbuff.array()); else ret = nc4.nc_put_vara(grpid, varid, origin, shape, bbuff.array()); if (ret != 0) throw new IOException(errMessage("nc_put_vars", ret, grpid, varid)); }