/** * Create an MAVector out of a double array */ public MAVector( double[] values) { this( Array.factory( values)); }
@Override public Array getCoordsAsArray() { double[] values = getValues(); return Array.factory(DataType.DOUBLE, shape, values); }
/** * Generate new Array with given dataType, shape, storage. * * @param dataType DataType, eg DataType.DOUBLE. * @param shape shape of the array. * @param storage primitive array of correct type * @return new Array<type> or Array<type>.D<rank> if 0 <= rank <= 7. * @throws ClassCastException wrong storage type */ static public Array factory(DataType dataType, int[] shape, Object storage) { return factory(dataType, Index.factory(shape), storage); }
private Array convertStringToChar(Array data, Variable ncVar) { String s = (String) data.getObject(Index.scalarIndexImmutable); int total = (int) ncVar.getSize(); char[] storage = new char[total]; int len = Math.min( s.length(), total); for (int k=0; k<len; k++) storage[k] = s.charAt(k); return Array.factory( DataType.CHAR, ncVar.getShape(), storage); }
public MAMath.MinMax getMinMaxData( float[] data) { int[] shape = new int[1]; shape[0] = data.length; Array a = Array.factory( DataType.FLOAT.getPrimitiveClassType(), shape, data); return MAMath.getMinMax( a); } int getGateDimsIndex(int cell, Dimension [] dList, int numSensor)
/** * Get the value as an Array. * * @return Array of values. */ public Array getValues() { if (values == null && svalue != null) { values = Array.factory(DataType.STRING, new int[]{1}); values.setObject(values.getIndex(), svalue); } return values; }
private Attribute readOpaqueAttValues(int grpid, int varid, String attname, int len, UserType userType) throws IOException { int total = len * userType.size; byte[] bb = new byte[total]; int ret = nc4.nc_get_att(grpid, varid, attname, bb); if (ret != 0) throw new IOException(ret + ": " + nc4.nc_strerror(ret)); return new Attribute(attname, Array.factory(DataType.BYTE, new int[]{total}, bb)); }
public ArrayDouble.D3 getCoordinateArray(int timeIndex) throws IOException, InvalidRangeException { Array data = readArray(existingData, timeIndex); // copy for now - better to just return Array, with promise its rank 3 int[] shape = data.getShape(); ArrayDouble.D3 ddata = (ArrayDouble.D3) Array.factory(double.class, shape); MAMath.copyDouble(ddata, data); return ddata; }
/** * Create a copy of this Array, copying the data so that physical order is the same as * logical order * * @return the new Array */ public Array copy() { Array newA = factory(getDataType(), getShape()); MAMath.copy(newA, this); return newA; }
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); }
/** * Add extra outermost dimension with len = 1. * * @param org original array * @return rank1 array of rank + 1 */ static public Array makeArrayRankPlusOne(Array org) { int[] shape = new int[org.getRank() + 1]; System.arraycopy(org.getShape(), 0, shape, 1, org.getRank()); shape[0] = 1; return factory(org.getDataType(), shape, org.getStorage()); }
/** * Create a copy of this Array, copying the data so that physical order is the same as * logical order * * @return the new Array */ public Array copy() { Array newA = factory(getElementType(), getShape()); MAMath.copy(newA, this); newA.setUnsigned(isUnsigned()); return newA; }
@Override public Array getCoordBoundsAsArray() { Array result = Array.factory(getDataType(), new int[]{ncoords, 2}); int count = 0; for (int i = 0; i < ncoords; i++) { result.setDouble(count++, getCoordEdge1(i)); result.setDouble(count++, getCoordEdge2(i)); } return result; }
public static Array convert2Unpacked(Array packed, ScaleOffset scaleOffset) { Array result = Array.factory(DataType.DOUBLE, packed.getShape()); IndexIterator riter = result.getIndexIterator(); while (packed.hasNext()) { riter.setDoubleNext( packed.nextDouble() * scaleOffset.scale + scaleOffset.offset); } return result; }
static public StructureData make(String name, Object value) { StructureMembers members = new StructureMembers(""); DataType dtype = DataType.getType(value.getClass()); StructureMembers.Member m = members.addMember(name, null, null, dtype, new int[]{1}); StructureDataW sw = new StructureDataW(members); Array dataArray = Array.factory(dtype, new int[]{1}); dataArray.setObject(dataArray.getIndex(), value); sw.setMemberData(m, dataArray); return sw; }
public static Array convert2packed(Array unpacked, double missingValue, int nbits, boolean isUnsigned, DataType packedType) { MAMath.ScaleOffset scaleOffset = calcScaleOffsetSkipMissingData(unpacked, missingValue, nbits, isUnsigned); Array result = Array.factory(packedType, unpacked.getShape()); IndexIterator riter = result.getIndexIterator(); while (unpacked.hasNext()) { double uv = unpacked.nextDouble(); double pv = (uv - scaleOffset.offset) / scaleOffset.scale; riter.setDoubleNext( pv); } return result; }
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; }
public Array readData2(Variable v2, Section section, double[] values) { Array data = Array.factory(v2.getDataType().getPrimitiveClassType(), section.getShape()); IndexIterator ii = data.getIndexIterator(); Range radialRange = section.getRange(0); for (int r = radialRange.first(); r <= radialRange.last(); r += radialRange.stride()) { ii.setDoubleNext(values[r]); } return data; }
public Array readData2(Variable v2, Section section, double[] values) { Array data = Array.factory(v2.getDataType().getPrimitiveClassType(), section.getShape()); IndexIterator ii = data.getIndexIterator(); Range radialRange = section.getRange(0); for (int r = radialRange.first(); r <= radialRange.last(); r += radialRange.stride()) { ii.setDoubleNext(values[r]); } return data; }