本文整理汇总了Java中ucar.ma2.InvalidRangeException类的典型用法代码示例。如果您正苦于以下问题:Java InvalidRangeException类的具体用法?Java InvalidRangeException怎么用?Java InvalidRangeException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InvalidRangeException类属于ucar.ma2包,在下文中一共展示了InvalidRangeException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: read
import ucar.ma2.InvalidRangeException; //导入依赖的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;
}
}
示例2: read
import ucar.ma2.InvalidRangeException; //导入依赖的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;
}
}
示例3: read
import ucar.ma2.InvalidRangeException; //导入依赖的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(this.dataType, section.getShape());
int rangeIdx = 0;
Range yRange = section.getRange(rangeIdx++);
Range xRange = section.getRange(rangeIdx);
//IndexIterator ii = dataArray.getIndexIterator();
readXY(yRange, xRange, dataArray);
return dataArray;
} catch (InvalidRangeException ex) {
Logger.getLogger(ASCIIGridDataInfo.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
}
示例4: read
import ucar.ma2.InvalidRangeException; //导入依赖的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;
}
}
示例5: project
import ucar.ma2.InvalidRangeException; //导入依赖的package包/类
/**
* Project grid data
*
* @param fromProj From projection
* @param toProj To projection
* @return Porjected grid data
* @throws ucar.ma2.InvalidRangeException
*/
public GridArray project(ProjectionInfo fromProj, ProjectionInfo toProj) throws InvalidRangeException {
//return project(fromProj, toProj, ResampleMethods.NearestNeighbor);
List<Number> xx = new ArrayList<>();
List<Number> yy = new ArrayList<>();
for (Double x : this.xArray) {
xx.add(x);
}
for (Double y : this.yArray) {
yy.add(y);
}
Object[] r = ArrayUtil.reproject(data, xx, yy, fromProj, toProj);
GridArray rdata = new GridArray((Array) r[0], (Array) r[1], (Array) r[2], missingValue);
rdata.projInfo = toProj;
return rdata;
}
示例6: trapz
import ucar.ma2.InvalidRangeException; //导入依赖的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;
}
示例7: setSection
import ucar.ma2.InvalidRangeException; //导入依赖的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;
}
示例8: sum
import ucar.ma2.InvalidRangeException; //导入依赖的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;
}
示例9: argMin
import ucar.ma2.InvalidRangeException; //导入依赖的package包/类
/**
* Get the index of the minimum value into the flattened array.
*
* @param a Array a
* @return Minimum value index
* @throws ucar.ma2.InvalidRangeException
*/
public static int argMin(Array a) throws InvalidRangeException {
double min = Double.MAX_VALUE, v;
int idx = 0;
IndexIterator iterator = a.getIndexIterator();
int i = 0;
while (iterator.hasNext()){
v = iterator.getDoubleNext();
if (!Double.isNaN(v)){
if (min > v){
min = v;
idx = i;
}
}
i += 1;
}
return idx;
}
示例10: argMax
import ucar.ma2.InvalidRangeException; //导入依赖的package包/类
/**
* Get the index of the maximum value into the flattened array.
*
* @param a Array a
* @return Maximum value index
* @throws ucar.ma2.InvalidRangeException
*/
public static int argMax(Array a) throws InvalidRangeException {
double max = Double.MIN_VALUE, v;
int idx = 0;
IndexIterator iterator = a.getIndexIterator();
int i = 0;
while (iterator.hasNext()){
v = iterator.getDoubleNext();
if (!Double.isNaN(v)){
if (max < v){
max = v;
idx = i;
}
}
i += 1;
}
return idx;
}
示例11: mean
import ucar.ma2.InvalidRangeException; //导入依赖的package包/类
/**
* Compute mean value of an array
*
* @param a Array a
* @param ranges Range list
* @return Mean value
* @throws ucar.ma2.InvalidRangeException
*/
public static double mean(Array a, List<Range> ranges) throws InvalidRangeException {
double mean = 0.0, v;
int n = 0;
IndexIterator ii = a.getRangeIterator(ranges);
while (ii.hasNext()) {
v = ii.getDoubleNext();
if (!Double.isNaN(v)) {
mean += v;
n += 1;
}
}
if (n > 0) {
mean = mean / n;
} else {
mean = Double.NaN;
}
return mean;
}
示例12: createFile
import ucar.ma2.InvalidRangeException; //导入依赖的package包/类
/**
*
* @param xDim
* @param yDim
* @param simulationStart
* @param fileLocation
* @throws IOException
*/
public void createFile(int xDim, int yDim, Date simulationStart,
String fileLocation) throws IOException {
prepareFile(xDim, yDim, simulationStart, fileLocation);
addVariables();
writer.create();
// write time = 0, as there will be an undefined value elsewise
Variable time = writer.findVariable(TIME);
int[] from_start = new int[] { 0 };
Array mytime = Array.factory(DataType.FLOAT, new int[] { 1 });
mytime.setFloat(0, 0f);
try {
writer.write(time, from_start, mytime);
} catch (InvalidRangeException e) {
throw new IOException(e.getMessage());
}
writer.close();
}
示例13: test
import ucar.ma2.InvalidRangeException; //导入依赖的package包/类
@Test
public void test() throws IOException, InvalidRangeException {
File file = new File("target/temp.nc");
file.delete();
NetCdfWriter n = new NetCdfWriter(file, "0.1");
Var<Long> v = n.addVariable("time", Long.class).longName("time in epoch milliseconds")
.units("epoch milliseconds").numRecords(2).build();
v.add(100L);
v.add(200L);
n.close();
// now read the file just written and assert
NetcdfFile nc = NetcdfFile.open(file.getCanonicalPath());
List<Attribute> attributes = nc.findGroup(null).getAttributes();
System.out.println(attributes);
assertFalse(attributes.isEmpty());
System.out.println(nc.getDimensions());
{
Array array = nc.readSection("time");
assertEquals(100, array.getLong(0));
assertEquals(200, array.getLong(1));
assertEquals(2, array.getSize());
}
}
示例14: getSpectrumById
import ucar.ma2.InvalidRangeException; //导入依赖的package包/类
/**
* Get spectrum using a spectrum id, gives the option to choose whether to use cache.
* This implementation provides a way of by passing the cache.
*
* @param id spectrum id
* @param useCache true means to use cache
* @return Spectrum spectrum object
*/
@Override
public Spectrum getSpectrumById(Comparable id, boolean useCache) {
Spectrum spectrum = super.getSpectrumById(id, useCache);
if (spectrum == null){
MsScan rawSpec;
try {
rawSpec = unmarshaller.getSpectrumById(Integer.parseInt(id.toString()));
spectrum = NetCDFTransformer.transformSpectrum(rawSpec);
if (useCache) {
getCache().store(CacheEntry.SPECTRUM, id, spectrum);
}
} catch (netCDFParsingException|InvalidRangeException|IOException e) {
String msg = "Error while trying to parse the NetCDF file";
logger.error(msg, e);
throw new DataAccessException(msg, e);
}
}
return spectrum;
}
示例15: writeArrayDataValues
import ucar.ma2.InvalidRangeException; //导入依赖的package包/类
private void writeArrayDataValues(int[] shape, Array arrayDataIdArray, int[] valuesOrigin, int[] arrayIdOrigin,
ArrayData arrayData) throws IOException, InvalidRangeException {
valuesOrigin[0] = getArrayDataOffset(arrayData);
if (!getArrayDataOffsets().containsKey(arrayData.getId())) {
arrayIdOrigin[0] = getArrayDataOffset(arrayData);
arrayDataIdArray.setLong(arrayDataIdArray.getIndex(), arrayData.getId());
writer.write(ARRAY_DATA_IDS_VARIABLE, arrayIdOrigin, arrayDataIdArray);
}
for (ArrayDataValueType valueType : values.getTypes()) {
Array valuesArray = Array.factory(valueType.getTypeClass(), shape);
Index valuesIndex = valuesArray.getIndex();
for (AbstractReporter reporter : values.getReporters()) {
valuesIndex.set(0, reporter.getDataStorageIndex());
setValue(valuesArray, valuesIndex, arrayData, reporter, valueType);
}
writer.write(valueType.name(), valuesOrigin, valuesArray);
}
}