/** * 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; }
public Section mapIndex(Variable targetVar, Variable fromVar, int[] fromIndex) throws InvalidRangeException { List<Dimension> toDims = targetVar.getDimensions(); List<Dimension> fromDims = fromVar.getDimensions(); Section result = new Section(); // each dimension in the target must be present in the source for (int i=0; i<toDims.size(); i++) { Dimension dim = toDims.get(i); int varIndex = fromDims.indexOf(toDims.get(i)); if (varIndex < 0) throw new IllegalArgumentException("Dimension "+dim+" does not exist"); result.appendRange(fromIndex[varIndex], fromIndex[varIndex]); } return result; } }
public Section mapIndex(Variable targetVar, Variable fromVar, int[] fromIndex) throws InvalidRangeException { List<Dimension> toDims = targetVar.getDimensions(); List<Dimension> fromDims = fromVar.getDimensions(); Section result = new Section(); // each dimension in the target must be present in the source for (int i=0; i<toDims.size(); i++) { Dimension dim = toDims.get(i); int varIndex = fromDims.indexOf(toDims.get(i)); if (varIndex < 0) throw new IllegalArgumentException("Dimension "+dim+" does not exist"); result.appendRange(fromIndex[varIndex], fromIndex[varIndex]); } return result; } }
/** * Create a new CoordinateAxis1D as a section of this CoordinateAxis1D. * * @param r the section range * @return a new CoordinateAxis1D as a section of this CoordinateAxis1D * @throws InvalidRangeException if IllegalRange */ public CoordinateAxis1D section(Range r) throws InvalidRangeException { Section section = new Section().appendRange(r); return (CoordinateAxis1D) section(section); }
public StructureDataIterator getStructureDataIterator(Cursor cursor, int bufferSize) throws IOException { int recnum = cursor.getParentRecnum(); try { Section section = new Section().appendRange(recnum, recnum); int count = 1; while (count++ < struct.getRank()) // handles multidim case section.appendRange(null); ArrayStructure data = (ArrayStructure) struct.read(section); // read all the data for a fixed outer index return data.getStructureDataIterator(); } catch (InvalidRangeException e) { throw new IllegalStateException(e); } }
public StructureDataIterator getStructureDataIterator(Cursor cursor, int bufferSize) throws IOException { int recnum = cursor.getParentRecnum(); try { Section section = new Section().appendRange(recnum, recnum); int count = 1; while (count++ < struct.getRank()) // handles multidim case section.appendRange(null); ArrayStructure data = (ArrayStructure) struct.read(section); // read all the data for a fixed outer index return data.getStructureDataIterator(); } catch (InvalidRangeException e) { throw new IllegalStateException(e); } }
@Override public StructureDataIterator getStructureDataIterator(Cursor cursor) throws IOException { int recnum = cursor.getParentRecnum(); try { Section section = new Section().appendRange(recnum, recnum); int count = 1; while (count++ < struct.getRank()) // handles multidim case section.appendRange(null); ArrayStructure data = (ArrayStructure) struct.read(section); // read all the data for a fixed outer index return data.getStructureDataIterator(); } catch (InvalidRangeException e) { throw new IllegalStateException(e); } }
private StructureData nextStructureData() throws IOException { StructureDataW sdata = new StructureDataW(members); for (Variable var : vars) { Section s = new Section(); try { s.appendRange(outerIndex, outerIndex); s.appendRange(count, count); for (int i = 2; i < var.getRank(); i++) s.appendRange(null); Array data = var.read(s); sdata.setMemberData(var.getShortName(), data); } catch (InvalidRangeException e) { e.printStackTrace(); } } return sdata; }
private StructureData nextStructureData() throws IOException { StructureDataW sdata = new StructureDataW(members); for (Variable var : vars) { Section s = new Section(); try { s.appendRange(outerIndex, outerIndex); s.appendRange(count, count); for (int i = 2; i < var.getRank(); i++) s.appendRange(null); Array data = var.read(s); sdata.setMemberData(var.getShortName(), data); } catch (InvalidRangeException e) { e.printStackTrace(); } } return sdata; }
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; }
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 = r.setName(rangeNames.get(count++)); result.appendRange(nr); } return result; }
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; } }
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; } }
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; } }
static public Section decodeSection(NcStreamProto.Section proto) { Section section = new Section(); for (ucar.nc2.stream.NcStreamProto.Range pr : proto.getRangeList()) { try { section.appendRange((int) pr.getStart(), (int) (pr.getStart() + pr.getSize() - 1)); } catch (InvalidRangeException e) { e.printStackTrace(); return null; //throw new RuntimeException(e); } } return section; }
static public Section decodeSection(NcStreamProto.Section proto) { Section section = new Section(); for (ucar.nc2.stream.NcStreamProto.Range pr : proto.getRangeList()) { try { section.appendRange((int) pr.getStart(), (int) (pr.getStart() + pr.getSize() - 1)); } catch (InvalidRangeException e) { e.printStackTrace(); return null; //throw new RuntimeException(e); } } return section; }
private void doSubset(String filename) throws IOException, InvalidRangeException { // read the packed form, enhance using scale/offset, compare to original try (NetcdfDataset ncd = NetcdfDataset.openDataset(filename)) { Variable vs = ncd.findVariable("packed"); assert vs != null; Section s = new Section().appendRange(1, 1).appendRange(1, 1); Array readEnhanced = vs.read(s); logger.debug(NCdumpW.toString(readEnhanced)); Variable sec = vs.section(s); Array readSection = sec.read(); logger.debug(NCdumpW.toString(readSection)); ucar.unidata.util.test.CompareNetcdf.compareData(readEnhanced, readSection); } }
private void decodeMemberData(StructureMembers members, NcStreamProto.DataCol memberData, Section parentSection) throws IOException { String name = memberData.getName(); DataType dataType = NcStream.convertDataType(memberData.getDataType()); Section section = NcStream.decodeSection(memberData.getSection()); if (!memberData.getIsVlen()) { assert memberData.getNelems() == section.computeSize(); } // the dproto section includes parents, remove them Section msection = section.removeFirst(parentSection); if (memberData.getIsVlen()) msection = msection.appendRange(Range.VLEN); StructureMembers.Member result = members.addMember(name, null, null, dataType, msection.getShape()); Array data = decode(memberData, parentSection); result.setDataArray(data); }
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; }