本文整理汇总了Java中ucar.ma2.DataType类的典型用法代码示例。如果您正苦于以下问题:Java DataType类的具体用法?Java DataType怎么用?Java DataType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DataType类属于ucar.ma2包,在下文中一共展示了DataType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mutipleLineRegress_OLS
import ucar.ma2.DataType; //导入依赖的package包/类
/**
* Implements ordinary least squares (OLS) to estimate the parameters of a
* multiple linear regression model.
* @param y Y sample data - one dimension array
* @param x X sample data - two dimension array
* @return Estimated regression parameters and residuals
*/
public static Array[] mutipleLineRegress_OLS(Array y, Array x) {
OLSMultipleLinearRegression regression = new OLSMultipleLinearRegression();
double[] yy = (double[])ArrayUtil.copyToNDJavaArray(y);
double[][] xx = (double[][])ArrayUtil.copyToNDJavaArray(x);
regression.newSampleData(yy, xx);
double[] para = regression.estimateRegressionParameters();
double[] residuals = regression.estimateResiduals();
int k = para.length;
int n = residuals.length;
Array aPara = Array.factory(DataType.DOUBLE, new int[]{k});
Array aResiduals = Array.factory(DataType.DOUBLE, new int[]{n});
for (int i = 0; i < k; i++){
aPara.setDouble(i, para[i]);
}
for (int i = 0; i < k; i++){
aResiduals.setDouble(i, residuals[i]);
}
return new Array[]{aPara, aResiduals};
}
示例2: writeEmpty
import ucar.ma2.DataType; //导入依赖的package包/类
public void writeEmpty (String netcdfFilename) throws Exception {
ArrayList<Dimension> dimList = new ArrayList<Dimension>();
IntermediateNetcdfFile nfile;
try {
nfile = new IntermediateNetcdfFile(netcdfFilename, false);
} catch (LASException e) {
throw new Exception("Cannot create empty file.");
}
NetcdfFileWriteable netcdfFile = nfile.getNetcdfFile();
Dimension index = netcdfFile.addDimension("index", 1);
dimList.add(index);
netcdfFile.addVariable(time, DataType.DOUBLE, dimList);
ArrayDouble.D1 data = new ArrayDouble.D1(1);
Double d = new Double("-9999.");
data.set(0, d);
netcdfFile.addGlobalAttribute("query_result", "No data found to match this request.");
netcdfFile.create();
netcdfFile.write(time, data);
}
示例3: getElementBlockSize
import ucar.ma2.DataType; //导入依赖的package包/类
/**
* Computes the element block size for data processing.
*
* Returns (max. size of a block in bytes to be process / (byte size of the variable datatype) * number of
* dimension).
*
* The max. size of a block in Kilo-bytes to be process is in the Motu configuration file (dataBlocksize
* attribute of MotuConfig) For variable whose datatype size is not known, byte size is set tot 1.
*
* @param varShape variable's shape to process.
* @param datatype variable's data type to process
* @return element block size
* @throws MotuException the motu exception
* @throws MotuNotImplementedException the motu not implemented exception
*/
private static int getElementBlockSize(int[] varShape, DataType datatype) throws MotuException, MotuNotImplementedException {
double maxDataToUse = countMaxElementData(varShape, datatype);
double elementBlockSize = 1;
if ((varShape.length <= 0) || (varShape.length > 4)) {
// throw new MotuNotImplementedException(String
// .format("Error in NetCdfWriter.getElementBlockSize - Processing for %d-dimension is not
// implemented",
// varShape.length));
}
double pow = 1.0 / varShape.length;
elementBlockSize = Math.pow(maxDataToUse, pow);
return (int) elementBlockSize;
}
示例4: fmin
import ucar.ma2.DataType; //导入依赖的package包/类
/**
* Element-wise minimum of array elements, ignores NaNs.
*
* @param x1 Array 1
* @param x2 Array 2
* @return The minimum of x1 and x2, element-wise.
*/
public static Array fmin(Array x1, Array x2) {
DataType dt = commonType(x1.getDataType(), x2.getDataType());
Array r = Array.factory(dt, x1.getShape());
for (int i = 0; i < r.getSize(); i++) {
if (Double.isNaN(x1.getDouble(i))) {
r.setObject(i, x2.getDouble(i));
} else if (Double.isNaN(x2.getDouble(i))) {
r.setObject(i, x1.getDouble(i));
} else {
r.setObject(i, Math.min(x1.getDouble(i), x2.getDouble(i)));
}
}
return r;
}
示例5: SEOF
import ucar.ma2.DataType; //导入依赖的package包/类
/**
* EOF algorithm
*
* @param N Station or grid number
* @param LL Time dimension number
* @param f Origin data
* @param method Method
* @return Eigen vector, time factor, accumulated explained variance,
* ordered eigen value
*/
public static Object[] SEOF(int N, int LL, Array f, DataProMethod method) {
Array H = Array.factory(DataType.DOUBLE, f.getShape());
switch (method) {
case NONE:
for (int i = 0; i < H.getSize(); i++) {
H.setDouble(i, f.getDouble(i));
}
break;
case DEPARTURE:
H = dep(N, LL, f);
break;
default:
H = nor(N, LL, f);
break;
}
return SEOF(N, LL, f, H);
}
示例6: nor
import ucar.ma2.DataType; //导入依赖的package包/类
static Array nor(int N, int LL, Array f) {
Array H = Array.factory(DataType.DOUBLE, f.getShape());
double[] Std = new double[N];
double[] Aver = average(N, LL, f);
for (int j = 0; j < N; j++) {
Std[j] = 0;
for (int i = 0; i < LL; i++) {
Std[j] += (f.getDouble(i * N + j) - Aver[j]) * (f.getDouble(i * N + j) - Aver[j]);
}
Std[j] = Math.sqrt(Std[j] / LL);
}
for (int j = 0; j < N; j++) {
for (int i = 0; i < LL; i++) {
H.setDouble(i * N + j, (f.getDouble(i * N + j) - Aver[j]) / Std[j]);
}
}
return H;
}
示例7: cholesky
import ucar.ma2.DataType; //导入依赖的package包/类
/**
* Calculates the Cholesky decomposition of a matrix. The Cholesky
* decomposition of a real symmetric positive-definite matrix A consists of
* a lower triangular matrix L with same size such that: A = LLT. In a
* sense, this is the square root of A.
*
* @param a The given matrix.
* @return Result array.
*/
public static Array cholesky(Array a) {
Array r = Array.factory(DataType.DOUBLE, a.getShape());
double[][] aa = (double[][]) ArrayUtil.copyToNDJavaArray(a);
RealMatrix matrix = new Array2DRowRealMatrix(aa, false);
CholeskyDecomposition decomposition = new CholeskyDecomposition(matrix);
RealMatrix L = decomposition.getL();
int n = L.getColumnDimension();
int m = L.getRowDimension();
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
r.setDouble(i * n + j, L.getEntry(i, j));
}
}
return r;
}
示例8: pow
import ucar.ma2.DataType; //导入依赖的package包/类
/**
* Array pow function
*
* @param a Number a
* @param b Array b
* @return Result array
*/
public static Array pow(Array a, Array b) {
DataType type = ArrayMath.commonType(a.getDataType(), b.getDataType());
switch (type) {
case SHORT:
case INT:
return ArrayMath.powInt(a, b);
case FLOAT:
case DOUBLE:
return ArrayMath.powDouble(a, b);
case OBJECT:
if (isComplex(a) || isComplex(b)) {
return ArrayMath.powComplex(a, b);
}
break;
}
return null;
}
示例9: inv
import ucar.ma2.DataType; //导入依赖的package包/类
/**
* Calculate inverse matrix
*
* @param a The matrix
* @return Inverse matrix array
*/
public static Array inv(Array a) {
double[][] aa = (double[][]) ArrayUtil.copyToNDJavaArray(a);
RealMatrix matrix = new Array2DRowRealMatrix(aa, false);
RealMatrix invm = MatrixUtils.inverse(matrix);
if (invm == null) {
return null;
}
int m = invm.getRowDimension();
int n = invm.getColumnDimension();
Array r = Array.factory(DataType.DOUBLE, new int[]{m, n});
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
r.setDouble(i * n + j, invm.getEntry(i, j));
}
}
return r;
}
示例10: sin
import ucar.ma2.DataType; //导入依赖的package包/类
/**
* Sine function
*
* @param a Array a
* @return Result array
*/
public static Array sin(Array a) {
Array r;
if (isComplex(a)) {
r = Array.factory(DataType.OBJECT, a.getShape());
for (int i = 0; i < a.getSize(); i++) {
r.setObject(i, ((Complex) a.getObject(i)).sin());
}
} else {
r = Array.factory(a.getDataType() == DataType.DOUBLE ? DataType.DOUBLE : DataType.FLOAT, a.getShape());
for (int i = 0; i < a.getSize(); i++) {
r.setDouble(i, Math.sin(a.getDouble(i)));
}
}
return r;
}
示例11: read
import ucar.ma2.DataType; //导入依赖的package包/类
/**
* Read array data of the variable
*
* @param varName Variable name
* @param origin The origin array
* @param size The size array
* @param stride The stride array
* @return Array data
*/
@Override
public Array read(String varName, int[] origin, int[] size, int[] stride) {
try {
Section section = new Section(origin, size, stride);
Array dataArray = Array.factory(DataType.FLOAT, section.getShape());
int rangeIdx = 2;
Range yRange = section.getRange(rangeIdx++);
Range xRange = section.getRange(rangeIdx);
IndexIterator ii = dataArray.getIndexIterator();
readXY(varName, yRange, xRange, ii);
return dataArray;
} catch (InvalidRangeException ex) {
Logger.getLogger(MICAPS4DataInfo.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
}
示例12: read
import ucar.ma2.DataType; //导入依赖的package包/类
/**
* Read array data of the variable
*
* @param varName Variable name
* @param origin The origin array
* @param size The size array
* @param stride The stride array
* @return Array data
*/
@Override
public Array read(String varName, int[] origin, int[] size, int[] stride) {
int varIdx = this._fieldList.indexOf(varName);
if (varIdx < 0) {
return null;
}
int[] shape = new int[1];
shape[0] = this.stNum;
DataType dt = DataType.FLOAT;
if (varName.equals("Stid"))
dt = DataType.STRING;
Array r = Array.factory(dt, shape);
List<String> dataList;
for (int i = 0; i < _dataList.size(); i++) {
dataList = _dataList.get(i);
r.setFloat(i, Float.parseFloat(dataList.get(varIdx)));
}
return r;
}
示例13: toGridArray
import ucar.ma2.DataType; //导入依赖的package包/类
/**
* Convert to GridArray object
*
* @return GridArray object
*/
@Override
public GridArray toGridArray() {
Array a = Array.factory(DataType.DOUBLE, new int[]{this.getYNum(), this.getXNum()});
int idx = 0;
for (int i = 0; i < this.getYNum(); i++) {
for (int j = 0; j < this.getXNum(); j++) {
a.setDouble(idx, this.data[i][j]);
idx += 1;
}
}
GridArray r = new GridArray();
r.data = a;
r.xArray = this.xArray;
r.yArray = this.yArray;
r.projInfo = this.projInfo;
r.missingValue = this.missingValue;
return r;
}
示例14: hcurl
import ucar.ma2.DataType; //导入依赖的package包/类
/**
* Calculates the vertical component of the curl (ie, vorticity)
*
* @param uData U component
* @param vData V component
* @param xx X dimension value
* @param yy Y dimension value
* @return Curl
*/
public static Array hcurl(Array uData, Array vData, List<Number> xx, List<Number> yy) {
int rank = uData.getRank();
int[] shape = uData.getShape();
Array lonData = Array.factory(DataType.DOUBLE, shape);
Array latData = Array.factory(DataType.DOUBLE, shape);
Index index = lonData.getIndex();
int[] current;
for (int i = 0; i < lonData.getSize(); i++) {
current = index.getCurrentCounter();
lonData.setDouble(index, xx.get(current[rank - 1]).doubleValue());
latData.setDouble(index, yy.get(current[rank - 2]).doubleValue());
index.incr();
}
Array dv = cdiff(vData, rank - 1);
Array dx = mul(cdiff(lonData, rank - 1), Math.PI / 180);
Array du = cdiff(mul(uData, cos(mul(latData, Math.PI / 180))), rank - 2);
Array dy = mul(cdiff(latData, rank - 2), Math.PI / 180);
Array gData = div(sub(div(dv, dx), div(du, dy)), mul(cos(mul(latData, Math.PI / 180)), 6.37e6));
return gData;
}
示例15: equal
import ucar.ma2.DataType; //导入依赖的package包/类
/**
* Array equal
*
* @param a Array a
* @param b Number b
* @return Result array
*/
public static Array equal(Array a, Number b) {
Array r = Array.factory(DataType.INT, a.getShape());
double v = b.doubleValue();
if (Double.isNaN(v)) {
for (int i = 0; i < a.getSize(); i++) {
if (Double.isNaN(a.getDouble(i))) {
r.setDouble(i, 1);
} else {
r.setDouble(i, 0);
}
}
} else {
for (int i = 0; i < a.getSize(); i++) {
if (a.getDouble(i) == v) {
r.setDouble(i, 1);
} else {
r.setDouble(i, 0);
}
}
}
return r;
}