本文整理汇总了Java中ucar.ma2.IndexIterator类的典型用法代码示例。如果您正苦于以下问题:Java IndexIterator类的具体用法?Java IndexIterator怎么用?Java IndexIterator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IndexIterator类属于ucar.ma2包,在下文中一共展示了IndexIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTimeAxisDataAsString
import ucar.ma2.IndexIterator; //导入依赖的package包/类
/**
* Gets time axis data values.
*
* @return a list constains time axis data values
* @throws MotuException the motu exception
* @throws NetCdfVariableException the net cdf variable exception
*/
public List<String> getTimeAxisDataAsString() throws MotuException {
List<String> list = new ArrayList<String>();
Array array = getTimeAxisData();
if (array == null) {
return list;
}
double datetime = 0.0;
for (IndexIterator it = array.getIndexIterator(); it.hasNext();) {
datetime = it.getDoubleNext();
list.add(0, NetCdfReader.getDateAsGMTNoZeroTimeString(datetime, productMetaData.getTimeAxis().getUnitsString()));
}
return list;
}
示例2: getZAxisDataAsString
import ucar.ma2.IndexIterator; //导入依赖的package包/类
/**
* Gets Z (depth) axis data values.
*
* @return a list constains depth axis data values
* @throws MotuException the motu exception
* @throws NetCdfVariableException the net cdf variable exception
*/
public List<String> getZAxisDataAsString() throws MotuException, NetCdfVariableException {
if (LOG.isDebugEnabled()) {
LOG.debug("getZAxisDataAsString() - entering");
}
List<String> list = new ArrayList<String>();
Array array = getZAxisData();
double depth = 0.0;
for (IndexIterator it = array.getIndexIterator(); it.hasNext();) {
depth = it.getDoubleNext();
list.add(NetCdfReader.getStandardZAsString(depth));
}
if (LOG.isDebugEnabled()) {
LOG.debug("getZAxisDataAsString() - exiting");
}
return list;
}
示例3: getZAxisDataAsDouble
import ucar.ma2.IndexIterator; //导入依赖的package包/类
/**
* Gets the z axis data as double.
*
* @return the z axis data as string
*
* @throws MotuException the motu exception
* @throws NetCdfVariableException the net cdf variable exception
*/
public List<Double> getZAxisDataAsDouble() throws MotuException, NetCdfVariableException {
if (LOG.isDebugEnabled()) {
LOG.debug("getZAxisDataAsDouble() - entering");
}
List<Double> list = new ArrayList<Double>();
Array array = getZAxisData();
double depth = 0.0;
for (IndexIterator it = array.getIndexIterator(); it.hasNext();) {
depth = it.getDoubleNext();
list.add(depth);
}
if (LOG.isDebugEnabled()) {
LOG.debug("getZAxisDataAsDouble() - exiting");
}
return list;
}
示例4: readXY_1
import ucar.ma2.IndexIterator; //导入依赖的package包/类
private void readXY_1(Range yRange, Range xRange, IndexIterator ii) throws IOException {
byte[] imageBytes = getIamgeData();
//Get grid data
int i, j;
int xNum = (int) _width;
int yNum = (int) _height;
float[] data = new float[yNum * xNum];
for (i = 0; i < yNum; i++) {
for (j = 0; j < xNum; j++) {
data[(yNum - i - 1) * xNum + j] = DataConvert.byte2Int(imageBytes[i * xNum + j]);
}
}
for (int y = yRange.first(); y <= yRange.last();
y += yRange.stride()) {
for (int x = xRange.first(); x <= xRange.last();
x += xRange.stride()) {
int index = y * xNum + x;
ii.setFloatNext(data[index]);
}
}
}
示例5: read
import ucar.ma2.IndexIterator; //导入依赖的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(yRange, xRange, ii);
return dataArray;
} catch (InvalidRangeException ex) {
Logger.getLogger(MICAPS4DataInfo.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
}
示例6: read
import ucar.ma2.IndexIterator; //导入依赖的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;
}
}
示例7: read
import ucar.ma2.IndexIterator; //导入依赖的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 = 0;
Range yRange = section.getRange(rangeIdx++);
Range xRange = section.getRange(rangeIdx);
IndexIterator ii = dataArray.getIndexIterator();
readXY(yRange, xRange, ii);
return dataArray;
} catch (InvalidRangeException ex) {
Logger.getLogger(SurferGridDataInfo.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
}
示例8: identity
import ucar.ma2.IndexIterator; //导入依赖的package包/类
/**
* Return the identity array - a square array with ones on the main
* diagonal.
*
* @param n Number of rows (and columns) in n x n output.
* @param dtype Data type
* @return Identity array
*/
public static Array identity(int n, String dtype) {
DataType dt = toDataType(dtype);
int[] shape = new int[]{n, n};
Array a = Array.factory(dt, shape);
IndexIterator index = a.getIndexIterator();
int[] current;
while (index.hasNext()) {
index.next();
current = index.getCurrentCounter();
if (current[0] == current[1]) {
index.setObjectCurrent(1);
} else {
index.setObjectCurrent(0);
}
}
return a;
}
示例9: eye
import ucar.ma2.IndexIterator; //导入依赖的package包/类
/**
* Return a 2-D array with ones on the diagonal and zeros elsewhere.
*
* @param n Number of rows in the output.
* @param m Number of columns in the output.
* @param k Index of the diagonal: 0 (the default) refers to the main
* diagonal, a positive value refers to an upper diagonal, and a negative
* value to a lower diagonal.
* @param dtype Data type
* @return Created array
*/
public static Array eye(int n, int m, int k, String dtype) {
DataType dt = toDataType(dtype);
int[] shape = new int[]{n, m};
Array a = Array.factory(dt, shape);
IndexIterator index = a.getIndexIterator();
int[] current;
int i, j;
while (index.hasNext()) {
index.next();
current = index.getCurrentCounter();
i = current[0];
j = current[1] - k;
if (i == j) {
index.setObjectCurrent(1);
} else {
index.setObjectCurrent(0);
}
}
return a;
}
示例10: trapz
import ucar.ma2.IndexIterator; //导入依赖的package包/类
/**
* Integrate vector array using the composite trapezoidal rule.
*
* @param y Vecotr array
* @param dx Spacing between all y elements
* @param ranges
* @return Definite integral as approximated by trapezoidal rule
* @throws ucar.ma2.InvalidRangeException
*/
public static double trapz(Array y, double dx, List<Range> ranges) throws InvalidRangeException {
int n = 1;
for (Range range : ranges) {
n = n * range.length();
}
n -= 1;
double a = 1;
double b = n * dx + a;
double r = 0;
double v;
IndexIterator ii = y.getRangeIterator(ranges);
int i = 0;
while (ii.hasNext()) {
v = ii.getDoubleNext();
r += v;
if (i > 0 && i < n) {
r += v;
}
i += 1;
}
r = r * ((b - a) / (2 * n));
return r;
}
示例11: setSection
import ucar.ma2.IndexIterator; //导入依赖的package包/类
/**
* Set section
*
* @param a Array a
* @param ranges Ranges
* @param v Array value
* @return Result array
* @throws InvalidRangeException
*/
public static Array setSection(Array a, List<Range> ranges, Array v) throws InvalidRangeException {
Array r = a.section(ranges);
IndexIterator iter = r.getIndexIterator();
//int[] current;
Index index = v.getIndex();
while (iter.hasNext()) {
iter.next();
//current = iter.getCurrentCounter();
//index.set(current);
iter.setObjectCurrent(v.getObject(index));
index.incr();
}
r = Array.factory(a.getDataType(), a.getShape(), r.getStorage());
return r;
}
示例12: getMinimum
import ucar.ma2.IndexIterator; //导入依赖的package包/类
/**
* Get minimum value
*
* @param a Array a
* @return Minimum value
*/
public static double getMinimum(Array a) {
IndexIterator iter = a.getIndexIterator();
double min = 1.7976931348623157E+308D;
while (iter.hasNext()) {
double val = iter.getDoubleNext();
if (!Double.isNaN(val)) {
if (val < min) {
min = val;
}
}
}
if (min == 1.7976931348623157E+308D) {
return Double.NaN;
} else {
return min;
}
}
示例13: getMaximum
import ucar.ma2.IndexIterator; //导入依赖的package包/类
/**
* Get maximum value
*
* @param a Array a
* @return Maximum value
*/
public static double getMaximum(Array a) {
IndexIterator iter = a.getIndexIterator();
double max = -1.797693134862316E+307D;
while (iter.hasNext()) {
double val = iter.getDoubleNext();
if (!Double.isNaN(val)) {
if (val > max) {
max = val;
}
}
}
if (max == -1.797693134862316E+307D) {
return Double.NaN;
} else {
return max;
}
}
示例14: sum
import ucar.ma2.IndexIterator; //导入依赖的package包/类
/**
* Compute sum value of an array
*
* @param a Array a
* @param ranges Range list
* @return Sum value
* @throws ucar.ma2.InvalidRangeException
*/
public static double sum(Array a, List<Range> ranges) throws InvalidRangeException {
double s = 0.0, v;
int n = 0;
IndexIterator ii = a.getRangeIterator(ranges);
while (ii.hasNext()) {
v = ii.getDoubleNext();
if (!Double.isNaN(v)) {
s += v;
n += 1;
}
}
if (n == 0) {
s = Double.NaN;
}
return s;
}
示例15: aveDouble
import ucar.ma2.IndexIterator; //导入依赖的package包/类
/**
* Average array
*
* @param a Array a
* @return Average value
*/
public static double aveDouble(Array a) {
double sum = 0.0D;
double v;
int n = 0;
IndexIterator iterA = a.getIndexIterator();
while (iterA.hasNext()) {
v = iterA.getDoubleNext();
if (!Double.isNaN(v)) {
sum += v;
n += 1;
}
}
if (n == 0) {
return Double.NaN;
} else {
return sum / n;
}
}