/** * Read a section of the data for this Variable from the netcdf file and return a memory resident Array. * The Array has the same element type as the Variable, and the requested shape. * Note that this does not do rank reduction, so the returned Array has the same rank * as the Variable. Use Array.reduce() for rank reduction. * <p/> * If the Variable is a member of an array of Structures, this returns only the variable's data * in the first Structure, so that the Array shape is the same as the Variable. * To read the data in all structures, use ncfile.readSectionSpec(). * <p/> * Note this only allows you to specify a subset of this variable. * If the variable is nested in a array of structures and you want to subset that, use * NetcdfFile.read(String sectionSpec, boolean flatten); * * @param section list of Range specifying the section of data to read. * Must be null or same rank as variable. * If list is null, assume all data. * Each Range corresponds to a Dimension. If the Range object is null, it means use the entire dimension. * @return the requested data in a memory-resident Array * @throws IOException if error * @throws InvalidRangeException if section is invalid */ public Array read(ucar.ma2.Section section) throws java.io.IOException, ucar.ma2.InvalidRangeException { return (section == null) ? _read() : _read(Section.fill(section, shape)); }
/** * Read a section of the data for this Variable from the netcdf file and return a memory resident Array. * The Array has the same element type as the Variable, and the requested shape. * Note that this does not do rank reduction, so the returned Array has the same rank * as the Variable. Use Array.reduce() for rank reduction. * <p/> * If the Variable is a member of an array of Structures, this returns only the variable's data * in the first Structure, so that the Array shape is the same as the Variable. * To read the data in all structures, use ncfile.readSectionSpec(). * <p/> * Note this only allows you to specify a subset of this variable. * If the variable is nested in a array of structures and you want to subset that, use * NetcdfFile.read(String sectionSpec, boolean flatten); * * @param section list of Range specifying the section of data to read. * Must be null or same rank as variable. * If list is null, assume all data. * Each Range corresponds to a Dimension. If the Range object is null, it means use the entire dimension. * @return the requested data in a memory-resident Array * @throws IOException if error * @throws InvalidRangeException if section is invalid */ public Array read(ucar.ma2.Section section) throws java.io.IOException, ucar.ma2.InvalidRangeException { return (section == null) ? _read() : _read(Section.fill(section, shape)); }
/** * Read a section of the data for this Variable from the netcdf file and return a memory resident Array. * The Array has the same element type as the Variable, and the requested shape. * Note that this does not do rank reduction, so the returned Array has the same rank * as the Variable. Use Array.reduce() for rank reduction. * <p/> * If the Variable is a member of an array of Structures, this returns only the variable's data * in the first Structure, so that the Array shape is the same as the Variable. * To read the data in all structures, use ncfile.readSectionSpec(). * <p/> * Note this only allows you to specify a subset of this variable. * If the variable is nested in a array of structures and you want to subset that, use * NetcdfFile.read(String sectionSpec, boolean flatten); * * @param section list of Range specifying the section of data to read. * Must be null or same rank as variable. * If list is null, assume all data. * Each Range corresponds to a Dimension. If the Range object is null, it means use the entire dimension. * @return the requested data in a memory-resident Array * @throws IOException if error * @throws InvalidRangeException if section is invalid */ public Array read(ucar.ma2.Section section) throws java.io.IOException, ucar.ma2.InvalidRangeException { return (section == null) ? _read() : _read(Section.fill(section, shape)); }
wantSection = Section.fill(wantSection, v2.getShape());
if (indexSelect != null) { section = new Section(indexSelect); section = Section.fill(section, v.getShape()); // Check section has no nulls, set from shape array. } else {
if (indexSelect != null) { section = new Section(indexSelect); section = Section.fill(section, v.getShape()); // Check section has no nulls, set from shape array. } else {
if (indexSelect != null) { section = new Section(indexSelect); section = Section.fill(section, v.getShape()); // Check section has no nulls, set from shape array. } else {
public Array readData(ucar.nc2.Variable v2, Section section) throws IOException, InvalidRangeException { // subset List<Range> ranges = Section.fill(section, v2.getShape()).getRanges(); Giniheader.Vinfo vinfo = (Giniheader.Vinfo) v2.getSPobject(); int[] levels = vinfo.levels; if (vinfo.compression == 0) return readData(v2, vinfo.begin, ranges, levels); else if (vinfo.compression == 2) return readCompressedData(v2, vinfo.begin, ranges, levels); else if (vinfo.compression == 1) return readCompressedZlib(v2, vinfo.begin, vinfo.nx, vinfo.ny, ranges, levels); else return null; }
@Override public Array readData(Variable v2, Section section) throws IOException, InvalidRangeException { long start = System.currentTimeMillis(); // see if its time2D - then generate data on the fly if (v2.getSPobject() instanceof Time2Dinfo) { Time2Dinfo info = (Time2Dinfo) v2.getSPobject(); Array data = makeLazyCoordinateData(v2, info); assert data != null; Section sectionFilled = Section.fill(section, v2.getShape()); return data.sectionNoReduce(sectionFilled.getRanges()); } try { Array result; GribCollectionImmutable.VariableIndex vindex = (GribCollectionImmutable.VariableIndex) v2.getSPobject(); GribDataReader dataReader = GribDataReader.factory(gribCollection, vindex); SectionIterable sectionIter = new SectionIterable(section, v2.getShape()); result = dataReader.readData(sectionIter); long took = System.currentTimeMillis() - start; if (debugTime) System.out.println(" read data took=" + took + " msec "); return result; } catch (IOException ioe) { logger.error("Failed to readData ", ioe); throw ioe; } }
wantSection = Section.fill(wantSection, v2.getShape());
wantSection = Section.fill(wantSection, v2.getShape());
/** * Create a new Variable that is a logical subsection of this Variable. * No data is read until a read method is called on it. * * @param subsection Section of this variable. * Each Range in the section corresponds to a Dimension, and specifies the section of data to read in that Dimension. * A Range object may be null, which means use the entire dimension. * @return a new Variable which is a logical section of this Variable. * @throws InvalidRangeException if section not compatible with shape */ public Variable section(Section subsection) throws InvalidRangeException { subsection = Section.fill(subsection, shape); // create a copy of this variable with a proxy reader Variable sectionV = copy(); // subclasses must override sectionV.setProxyReader( new SectionReader(this, subsection)); sectionV.shape = subsection.getShape(); sectionV.createNewCache(); // dont share the cache sectionV.setCaching(false); // dont cache // replace dimensions if needed !! LOOK not shared sectionV.dimensions = new ArrayList<Dimension>(); for (int i = 0; i < getRank(); i++) { Dimension oldD = getDimension(i); Dimension newD = (oldD.getLength() == sectionV.shape[i]) ? oldD : new Dimension(oldD.getShortName(), sectionV.shape[i], false); newD.setUnlimited(oldD.isUnlimited()); sectionV.dimensions.add(newD); } sectionV.resetShape(); return sectionV; }
/** * Create a new Variable that is a logical subsection of this Variable. * No data is read until a read method is called on it. * * @param subsection Section of this variable. * Each Range in the section corresponds to a Dimension, and specifies the section of data to read in that Dimension. * A Range object may be null, which means use the entire dimension. * @return a new Variable which is a logical section of this Variable. * @throws InvalidRangeException if section not compatible with shape */ public Variable section(Section subsection) throws InvalidRangeException { subsection = Section.fill(subsection, shape); // create a copy of this variable with a proxy reader Variable sectionV = copy(); // subclasses must override sectionV.setProxyReader(new SectionReader(this, subsection)); sectionV.shape = subsection.getShape(); sectionV.createNewCache(); // dont share the cache sectionV.setCaching(false); // dont cache // replace dimensions if needed !! LOOK not shared sectionV.dimensions = new ArrayList<>(); for (int i = 0; i < getRank(); i++) { Dimension oldD = getDimension(i); Dimension newD = (oldD.getLength() == sectionV.shape[i]) ? oldD : new Dimension(oldD.getShortName(), sectionV.shape[i], false); newD.setUnlimited(oldD.isUnlimited()); sectionV.dimensions.add(newD); } sectionV.resetShape(); return sectionV; }
/** * Create a new Variable that is a logical subsection of this Variable. * No data is read until a read method is called on it. * * @param subsection Section of this variable. * Each Range in the section corresponds to a Dimension, and specifies the section of data to read in that Dimension. * A Range object may be null, which means use the entire dimension. * @return a new Variable which is a logical section of this Variable. * @throws InvalidRangeException if section not compatible with shape */ public Variable section(Section subsection) throws InvalidRangeException { subsection = Section.fill(subsection, shape); // create a copy of this variable with a proxy reader Variable sectionV = copy(); // subclasses must override sectionV.setProxyReader(new SectionReader(this, subsection)); sectionV.shape = subsection.getShape(); sectionV.createNewCache(); // dont share the cache sectionV.setCaching(false); // dont cache // replace dimensions if needed !! LOOK not shared sectionV.dimensions = new ArrayList<>(); for (int i = 0; i < getRank(); i++) { Dimension oldD = getDimension(i); Dimension newD = (oldD.getLength() == sectionV.shape[i]) ? oldD : new Dimension(oldD.getShortName(), sectionV.shape[i], false); newD.setUnlimited(oldD.isUnlimited()); sectionV.dimensions.add(newD); } sectionV.resetShape(); return sectionV; }
wantSection = Section.fill(wantSection, v2.getShape());
wantSection = Section.fill(wantSection, v2.getShape());
wantSection = Section.fill(wantSection, v2.getShape());
section = Section.fill(section, v.getShape());
section = Section.fill(section, v.getShape());
section = Section.fill(section, v.getShape());