/** * 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; }
final Section section = new Section(ranges);
/** * Read data section specified by a "section selector", and return a memory resident Array. Uses * Fortran 90 array section syntax. * * @param sectionSpec specification string, eg "1:2,10,:,1:100:10". May optionally have (). * @return the requested data in a memory-resident Array * @see ucar.ma2.Section for sectionSpec syntax */ public Array read(String sectionSpec) throws IOException, InvalidRangeException { return read(new Section(sectionSpec)); }
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 Section prepend(Section parentSection) { if (parentSection == null) return this; List<Range> ranges = new ArrayList<>(parentSection.getRanges()); ranges.addAll(getRanges()); return new Section(ranges); }
public Section shiftOrigin(int[] newOrigin) throws InvalidRangeException { if (newOrigin.length != getRank()) throw new InvalidRangeException("Invalid Section rank"); List<Range> results = new ArrayList<>(getRank()); for (int j = 0; j < list.size(); j++) { Range base = list.get(j); results.add(base.shiftOrigin(-newOrigin[j])); } return new Section(results); }
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; }
@Override Index reduce() { Section curr = new Section(shape); Section want = curr.reduce(); return new IndexConstant( want.getShape()); }
public void testIntersectWithStrides() throws InvalidRangeException { Section have = new Section("121:121:1,0:1919:1"); Section want = new Section("100:229:3,100:191:7"); Section intersectCorrect = new Section("121:121:3,100:191:7"); Section intersect = have.intersect( want); assert intersect.equals(intersectCorrect); int offset = want.offset( intersect); assert offset == 98 : offset; }
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); }
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; }
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 void main(String args[]) throws InvalidRangeException { long maxChunkElems = maxChunk / 4; int[] totalShape = new int[]{1, 40, 530, 240}; //int[] chunkShape = new int[] {1, 1, 530, 240}; FileWriter2.ChunkingIndex index = new FileWriter2.ChunkingIndex(totalShape); while (index.currentElement() < index.getSize()) { int[] chunkOrigin = index.getCurrentCounter(); int[] chunkShape = index.computeChunkShape(maxChunkElems); System.out.printf(" %s%n", new Section(chunkOrigin, chunkShape)); index.setCurrentCounter(index.currentElement() + (int) Index.computeSize(chunkShape)); } }
static public void main(String args[]) throws InvalidRangeException { long maxChunkElems = maxChunk / 4; int[] totalShape = new int[] {1, 40, 530, 240}; //int[] chunkShape = new int[] {1, 1, 530, 240}; FileWriter2.ChunkingIndex index = new FileWriter2.ChunkingIndex(totalShape); while (index.currentElement() < index.getSize()) { int[] chunkOrigin = index.getCurrentCounter(); int[] chunkShape = index.computeChunkShape(maxChunkElems); System.out.printf(" %s%n", new Section(chunkOrigin, chunkShape)); index.setCurrentCounter(index.currentElement() + (int) Index.computeSize(chunkShape)); } }
private void testOne(int[] shape, long maxChunkElems) { show("shape", shape); System.out.printf(" max = %d%n", maxChunkElems); FileWriter2.ChunkingIndex index = new FileWriter2.ChunkingIndex(shape); int[] result = index.computeChunkShape(maxChunkElems); show("chunk", result); long shapeSize = new Section(result).computeSize(); System.out.printf(" size = %d%n%n", shapeSize); assert shapeSize <= maxChunkElems; }
private Array read(TimeInventory.Instance timeInstance, String fullNameEsc, List<Range> innerSection, HashMap<String, NetcdfDataset> openFilesRead) throws IOException, InvalidRangeException { NetcdfFile ncfile = open(timeInstance.getDatasetLocation(), openFilesRead); if (ncfile == null) return null; // file might be deleted ?? Variable v = ncfile.findVariable(fullNameEsc); if (v == null) return null; // v could be missing, return missing data i think // assume time is first dimension LOOK: out of-order; ensemble; section different ?? Range timeRange = new Range(timeInstance.getDatasetIndex(), timeInstance.getDatasetIndex()); Section s = new Section(innerSection); s.insertRange(0, timeRange); return v.read(s); }
@Test public void testFull() throws InvalidRangeException { int[] shape = new int[] {123,22,92,12}; Section section = new Section(shape); IndexChunker index = new IndexChunker(shape, section); assert index.getTotalNelems() == section.computeSize(); IndexChunker.Chunk chunk = index.next(); assert chunk.getNelems() == section.computeSize(); assert !index.hasNext(); }