@Test public void testReduce() throws IOException, InvalidRangeException { Dimension x = new Dimension("x", 20); Dimension y = new Dimension("y", 1); Variable.Builder<?> var = Variable.builder().setName("x").setDataType(DataType.INT) .setDimensions(ImmutableList.of(y, x)).addAttribute(new Attribute("name", "value")).setAutoGen(10, 2); Group g = Group.builder().addDimensions(ImmutableList.of(x, y)).addVariable(var).build(); Variable xvar = g.findVariableLocal("x"); assertThat(xvar).isNotNull(); Variable reduce = xvar.reduce(ImmutableList.of(y)); assertThat(reduce.getShape()).isEqualTo(new int[] {20}); Array data = reduce.read(); assertThat(MAMath.equals(data, Array.makeArray(DataType.INT, 20, 10, 2))).isTrue(); Array data2 = reduce.read(new Section(new int[] {1}, new int[] {10})); assertThat(MAMath.equals(data2, Array.makeArray(DataType.INT, 10, 12, 2))).isTrue(); }
public Variable reduce(List<Dimension> dims) { List<Integer> dimIdx = new ArrayList<>(dims.size()); for (Dimension d : dims) { assert dimensions.contains(d); assert d.getLength() == 1; dimIdx.add(dimensions.indexOf(d)); } Variable.Builder<?> sliceV = this.toBuilder(); sliceV.setProxyReader(new ReduceReader(this, dimIdx)); sliceV.resetCache(); sliceV.setIsCaching(false); for (Dimension d : dims) { sliceV.dimensions.remove(d); } return sliceV.build(getParentGroup()); }
Variable implements VariableSimpleIF, ProxyReader { public Variable reduce(List<Dimension> dims) { List<Integer> dimIdx = new ArrayList<>(dims.size()); for (Dimension d : dims) { assert dimensions.contains(d); assert d.getLength() == 1; dimIdx.add(dimensions.indexOf(d)); } Variable.Builder<?> sliceV = this.toBuilder(); sliceV.setProxyReader(new ReduceReader(this, dimIdx)); sliceV.resetCache(); sliceV.setIsCaching(false); for (Dimension d : dims) { sliceV.dimensions.remove(d); } return sliceV.build(getParentGroup()); } }
Variable implements VariableSimpleIF, ProxyReader { public Variable reduce(List<Dimension> dims) { List<Integer> dimIdx = new ArrayList<>(dims.size()); for (Dimension d : dims) { assert dimensions.contains(d); assert d.getLength() == 1; dimIdx.add(dimensions.indexOf(d)); } Variable.Builder<?> sliceV = this.toBuilder(); sliceV.setProxyReader(new ReduceReader(this, dimIdx)); sliceV.resetCache(); sliceV.setIsCaching(false); for (Dimension d : dims) { sliceV.dimensions.remove(d); } return sliceV.build(getParentGroup()); } protected  Variable(Builder<?> builder, Group parentGroup); }
Variable implements VariableSimpleIF, ProxyReader { public Variable reduce(List<Dimension> dims) { List<Integer> dimIdx = new ArrayList<>(dims.size()); for (Dimension d : dims) { assert dimensions.contains(d); assert d.getLength() == 1; dimIdx.add(dimensions.indexOf(d)); } Variable.Builder<?> sliceV = this.toBuilder(); sliceV.setProxyReader(new ReduceReader(this, dimIdx)); sliceV.resetCache(); sliceV.setIsCaching(false); for (Dimension d : dims) { sliceV.dimensions.remove(d); } return sliceV.build(getParentGroup()); } protected  Variable(Builder<?> builder, Group parentGroup); int findDimensionIndex(String name); String getDatasetLocation(); DataType getDataType(); String getDescription(); ImmutableList<Dimension> getDimensions(); Dimension getDimension(int i); String getDimensionsString(); int getElementSize(); @Nullable EnumTypedef getEnumTypedef(); @Nullable String getFileTypeId(); String getFullName(); @Nullable NetcdfFile getNetcdfFile(); Group getParentGroup(); @Nullable Structure getParentStructure(); ImmutableList<Range> getRanges(); int getRank(); int[] getShape(); int getShape(int index); Section getShapeAsSection(); String getShortName(); long getSize(); @Nullable String getUnitsString(); boolean isCoordinateVariable(); boolean isMemberOfStructure(); boolean isMetadata(); boolean isScalar(); boolean isUnlimited(); boolean isVariableLength(); @Nullable String lookupEnumString(int val); Variable section(List<Range> ranges); Variable section(Section subsection); Variable slice(int dim, int value); Variable reduce(List<Dimension> dims); long readToStream(Section section, OutputStream out); @Deprecated Array read(int[] origin, int[] shape); @Deprecated Array read(String sectionSpec); @Deprecated Array read(List<Range> ranges); @Deprecated Array read(ucar.ma2.Section section); @Deprecated Array read(); @Deprecated byte readScalarByte(); @Deprecated short readScalarShort(); @Deprecated int readScalarInt(); @Deprecated long readScalarLong(); @Deprecated float readScalarFloat(); @Deprecated double readScalarDouble(); @Deprecated String readScalarString(); ucar.array.Array<?> readArray(); ucar.array.Array<?> readArray(ucar.ma2.Section section); @Override @Deprecated Array reallyRead(Variable client, CancelTask cancelTask); @Override ucar.array.Array<?> proxyReadArray(Variable client, CancelTask cancelTask); @Override @Deprecated Array reallyRead(Variable client, Section section, CancelTask cancelTask); @Override ucar.array.Array<?> proxyReadArray(Variable client, Section section, CancelTask cancelTask); String getNameAndDimensions(); void getNameAndDimensions(Formatter buf, boolean useFullName, boolean strict); String toString(); String toStringDebug(); @Override boolean equals(Object oo); @Override int hashCode(); int compareTo(VariableSimpleIF o); @Override AttributeContainer attributes(); @Nullable Attribute findAttribute(String name); String findAttributeString(String attName, String defaultValue); @Deprecated void resetShape(); Object getSPobject(); int getSizeToCache(); void setCaching(boolean caching); boolean isCaching(); void invalidateCache(); boolean hasCachedData(); Builder<?> toBuilder(); static Builder<?> builder(); }
Variable implements VariableSimpleIF, ProxyReader { public Variable reduce(List<Dimension> dims) { List<Integer> dimIdx = new ArrayList<>(dims.size()); for (Dimension d : dims) { assert dimensions.contains(d); assert d.getLength() == 1; dimIdx.add(dimensions.indexOf(d)); } Variable.Builder<?> sliceV = this.toBuilder(); sliceV.setProxyReader(new ReduceReader(this, dimIdx)); sliceV.resetCache(); sliceV.setIsCaching(false); for (Dimension d : dims) { sliceV.dimensions.remove(d); } return sliceV.build(getParentGroup()); } protected  Variable(Builder<?> builder, Group parentGroup); int findDimensionIndex(String name); String getDatasetLocation(); DataType getDataType(); String getDescription(); ImmutableList<Dimension> getDimensions(); Dimension getDimension(int i); String getDimensionsString(); int getElementSize(); @Nullable EnumTypedef getEnumTypedef(); @Nullable String getFileTypeId(); String getFullName(); @Nullable NetcdfFile getNetcdfFile(); Group getParentGroup(); @Nullable Structure getParentStructure(); ImmutableList<Range> getRanges(); int getRank(); int[] getShape(); int getShape(int index); Section getShapeAsSection(); String getShortName(); long getSize(); @Nullable String getUnitsString(); boolean isCoordinateVariable(); boolean isMemberOfStructure(); boolean isMetadata(); boolean isScalar(); boolean isUnlimited(); boolean isVariableLength(); @Nullable String lookupEnumString(int val); Variable section(List<Range> ranges); Variable section(Section subsection); Variable slice(int dim, int value); Variable reduce(List<Dimension> dims); long readToStream(Section section, OutputStream out); @Deprecated Array read(int[] origin, int[] shape); @Deprecated Array read(String sectionSpec); @Deprecated Array read(List<Range> ranges); @Deprecated Array read(ucar.ma2.Section section); @Deprecated Array read(); @Deprecated byte readScalarByte(); @Deprecated short readScalarShort(); @Deprecated int readScalarInt(); @Deprecated long readScalarLong(); @Deprecated float readScalarFloat(); @Deprecated double readScalarDouble(); @Deprecated String readScalarString(); ucar.array.Array<?> readArray(); ucar.array.Array<?> readArray(ucar.ma2.Section section); @Override @Deprecated Array reallyRead(Variable client, CancelTask cancelTask); @Override ucar.array.Array<?> proxyReadArray(Variable client, CancelTask cancelTask); @Override @Deprecated Array reallyRead(Variable client, Section section, CancelTask cancelTask); @Override ucar.array.Array<?> proxyReadArray(Variable client, Section section, CancelTask cancelTask); String getNameAndDimensions(); void getNameAndDimensions(Formatter buf, boolean useFullName, boolean strict); String toString(); String toStringDebug(); @Override boolean equals(Object oo); @Override int hashCode(); int compareTo(VariableSimpleIF o); @Override AttributeContainer attributes(); @Nullable Attribute findAttribute(String name); String findAttributeString(String attName, String defaultValue); @Deprecated void resetShape(); Object getSPobject(); int getSizeToCache(); void setCaching(boolean caching); boolean isCaching(); void invalidateCache(); boolean hasCachedData(); Builder<?> toBuilder(); static Builder<?> builder(); static boolean permitCaching; }