热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ucar.nc2.dataset.VariableDS.read()方法的使用及代码示例

本文整理了Java中ucar.nc2.dataset.VariableDS.read()方法的一些代码示例,展示了VariableDS.read()

本文整理了Java中ucar.nc2.dataset.VariableDS.read()方法的一些代码示例,展示了VariableDS.read()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。VariableDS.read()方法的具体详情如下:
包路径:ucar.nc2.dataset.VariableDS
类名称:VariableDS
方法名:read

VariableDS.read介绍

暂无

代码示例

代码示例来源:origin: geotools/geotools

private synchronized Array readSection(VariableAdapter wrapper, Section section)
throws IIOException, IOException {
try {
// Due to underlying NetCDF file system access (RAF based)
// and internal caching we do this call within a
// synchronized block
return wrapper.variableDS.read(section);
} catch (InvalidRangeException e) {
throw netcdfFailure(e);
}
}

代码示例来源:origin: edu.ucar/cdm

/**
* Constructor.
* @param v get data from this Variable
* @param type how to use the parameter
* @param param optional parameter
*/
public JoinArray(VariableDS v, Type type, int param) {
this.v = v;
this.type = type;
this.param = param;
try {
data = v.read();
} catch (IOException e) {
throw new RuntimeException(e);
}
}

代码示例来源:origin: edu.ucar/netcdf

/**
* Constructor.
* @param v get data from this Variable
* @param type how to use the parameter
* @param param optional parameter
*/
public JoinArray(VariableDS v, Type type, int param) {
this.v = v;
this.type = type;
this.param = param;
try {
data = v.read();
} catch (IOException e) {
throw new RuntimeException(e);
}
}

代码示例来源:origin: Unidata/thredds

/**
* Constructor.
* @param v get data from this Variable
* @param type how to use the parameter
* @param param optional parameter
*/
public JoinArray(VariableDS v, Type type, int param) {
this.v = v;
this.type = type;
this.param = param;
try {
data = v.read();
} catch (IOException e) {
throw new RuntimeException(e);
}
}

代码示例来源:origin: org.geotools/gt-netcdf

private synchronized Array readSection(VariableAdapter wrapper, Section section)
throws IIOException, IOException {
try {
// Due to underlying NetCDF file system access (RAF based)
// and internal caching we do this call within a
// synchronized block
return wrapper.variableDS.read(section);
} catch (InvalidRangeException e) {
throw netcdfFailure(e);
}
}

代码示例来源:origin: Unidata/thredds

private List makeTimesFromStrings( VariableDS org, Formatter errMessages) throws IOException {
int ncoords = (int) org.getSize();
List result = new ArrayList<>(ncoords);
ArrayObject data = (ArrayObject) org.read();
IndexIterator ii = data.getIndexIterator();
for (int i = 0; i String coordValue = (String) ii.getObjectNext();
CalendarDate cd = makeCalendarDateFromStringCoord( coordValue, org, errMessages);
result.add(cd);
}
return result;
}

代码示例来源:origin: edu.ucar/netcdf

private List makeTimesFromStrings( VariableDS org, Formatter errMessages) throws IOException {
int ncoords = (int) org.getSize();
List result = new ArrayList(ncoords);
ArrayObject data = (ArrayObject) org.read();
IndexIterator ii = data.getIndexIterator();
for (int i = 0; i String coordValue = (String) ii.getObjectNext();
CalendarDate cd = makeCalendarDateFromStringCoord( coordValue, org, errMessages);
result.add(cd);
}
return result;
}

代码示例来源:origin: edu.ucar/cdm

private List makeTimesFromStrings( VariableDS org, Formatter errMessages) throws IOException {
int ncoords = (int) org.getSize();
List result = new ArrayList<>(ncoords);
ArrayObject data = (ArrayObject) org.read();
IndexIterator ii = data.getIndexIterator();
for (int i = 0; i String coordValue = (String) ii.getObjectNext();
CalendarDate cd = makeCalendarDateFromStringCoord( coordValue, org, errMessages);
result.add(cd);
}
return result;
}

代码示例来源:origin: edu.ucar/netcdf

private List makeTimesFromChar(VariableDS org, Formatter errMessages) throws IOException {
int ncoords = (int) org.getSize();
int rank = org.getRank();
int strlen = org.getShape(rank - 1);
ncoords /= strlen;
List result = new ArrayList(ncoords);
ArrayChar data = (ArrayChar) org.read();
ArrayChar.StringIterator ii = data.getStringIterator();
ArrayObject.D1 sdata = new ArrayObject.D1(String.class, ncoords);
for (int i = 0; i String coordValue = ii.next();
CalendarDate cd = makeCalendarDateFromStringCoord(coordValue, org, errMessages);
sdata.set(i, coordValue);
result.add( cd);
}
setCachedData(sdata, true);
return result;
}

代码示例来源:origin: edu.ucar/cdm

private List makeTimesFromChar(VariableDS org, Formatter errMessages) throws IOException {
int ncoords = (int) org.getSize();
int rank = org.getRank();
int strlen = org.getShape(rank - 1);
ncoords /= strlen;
List result = new ArrayList<>(ncoords);
ArrayChar data = (ArrayChar) org.read();
ArrayChar.StringIterator ii = data.getStringIterator();
ArrayObject.D1 sdata = new ArrayObject.D1(String.class, ncoords);
for (int i = 0; i String coordValue = ii.next();
CalendarDate cd = makeCalendarDateFromStringCoord(coordValue, org, errMessages);
sdata.set(i, coordValue);
result.add( cd);
}
setCachedData(sdata, true);
return result;
}

代码示例来源:origin: Unidata/thredds

private List makeTimesFromChar(VariableDS org, Formatter errMessages) throws IOException {
int ncoords = (int) org.getSize();
int rank = org.getRank();
int strlen = org.getShape(rank - 1);
ncoords /= strlen;
List result = new ArrayList<>(ncoords);
ArrayChar data = (ArrayChar) org.read();
ArrayChar.StringIterator ii = data.getStringIterator();
ArrayObject.D1 sdata = (ArrayObject.D1) Array.factory(DataType.STRING, new int[] {ncoords});
for (int i = 0; i String coordValue = ii.next();
CalendarDate cd = makeCalendarDateFromStringCoord(coordValue, org, errMessages);
sdata.set(i, coordValue);
result.add( cd);
}
setCachedData(sdata, true);
return result;
}

代码示例来源:origin: Unidata/thredds

@Test
public void testUnsignedOffsetAttribute() throws IOException, URISyntaxException {
File testResource = new File(getClass().getResource("testScaleOffsetMissingUnsigned.ncml").toURI());

try (NetcdfDataset ncd = NetcdfDataset.openDataset(testResource.getAbsolutePath(), true, null)) {
VariableDS var = (VariableDS) ncd.findVariable("unsignedOffsetAttribute");

Assert.assertEquals(156, var.getOffset(), 0);
Assert.assertEquals(DataType.BYTE, var.getDataType()); // No change to data type.

Assert.assertEquals(106, var.read().getByte(0)); // -50 + 156 == 106
}
}
}

代码示例来源:origin: Unidata/thredds

@Test
public void testScaleValidRange() throws IOException, URISyntaxException {
File testResource = new File(getClass().getResource("testScaleOffsetMissingUnsigned.ncml").toURI());
try (NetcdfDataset ncd = NetcdfDataset.openDataset(testResource.getAbsolutePath(), true, null)) {
VariableDS var = (VariableDS) ncd.findVariable("scaleValidRange");
var.addEnhancement(Enhance.ConvertMissing);
Assert2.assertNearlyEquals(9.9f, (float) var.getValidMin());
Assert2.assertNearlyEquals(10.1f, (float) var.getValidMax());
Assert.assertEquals(DataType.FLOAT, var.getDataType()); // scale_factor is float.
float[] expecteds = new float[] { Float.NaN, 9.9f, 10.0f, 10.1f, Float.NaN };
float[] actuals = (float[]) var.read().getStorage();
Assert2.assertArrayNearlyEquals(expecteds, actuals);
}
}

代码示例来源:origin: Unidata/thredds

@Test
@Ignore("Does this file exist in a shared location?")
public void testAaron() throws Exception{
// different scale/offset in aggregation
try (GridDataset dataset = GridDataset.open("G:/work/braekel/dataset.ncml" )) {
GridDatatype grid = null;
for (GridDatatype thisGrid : dataset.getGrids()) {
if (thisGrid.getName().equals("cref")) {
grid = thisGrid;
}
}
List ranges = new ArrayList();
ranges.add(new Range(0, 0));
ranges.add(new Range(0, 0));
ranges.add(new Range(638, 638));
ranges.add(new Range(3750, 4622));
Array arr = grid.getVariable().read(ranges);
Index index = arr.getIndex();
index.set(new int[]{0, 0, 0, 834});
logger.debug("index {} value {}", index.currentElement(), arr.getDouble(index));
}
}

代码示例来源:origin: Unidata/thredds

@Test
public void testScaling() throws Exception {
String xml = "\n" +
"\n" +
" \n" +
" " +
"
\n" +
"
";
NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(xml), location, null);
// make sure that scaling is applied
VariableDS vs = (VariableDS) ncfile.findVariable("hs");
Array data = vs.read("0,1,:,:)");
while (data.hasNext()) {
float val = data.nextFloat();
if (!vs.isMissing(val))
assert (val <10.0) : val;
//System.out.printf("%f %n",val);
}
ncfile.close();
}

代码示例来源:origin: Unidata/thredds

@Test
public void testMissingUnsigned() throws URISyntaxException, IOException {
File testResource = new File(getClass().getResource("testScaleOffsetMissingUnsigned.ncml").toURI());
try (NetcdfDataset ncd = NetcdfDataset.openDataset(testResource.getAbsolutePath(), true, null)) {
VariableDS var = (VariableDS) ncd.findVariable("missingUnsigned");

// Packed valid_min == -106. Interpreting bit pattern as unsigned, we get 150.
Assert2.assertNearlyEquals(150, var.getValidMin());

// Packed valid_min == -6. Interpreting bit pattern as unsigned, we get 250.
Assert2.assertNearlyEquals(250, var.getValidMax());

// Packed _FillValue and missing_value are -1. Interpreting bit pattern as unsigned, we get 255.
Assert2.assertNearlyEquals(255, var.getFillValue());
Assert2.assertNearlyEquals(255, var.getMissingValues()[0]);

// "missingUnsigned" was originally UBYTE, but was widened to accommodate unsigned conversion.
Assert.assertEquals(DataType.USHORT, var.getDataType());

// Packed values are: -107, -106, -6, -5, -1, 80. Interpreting them as unsigned yields:
short[] expecteds = new short[] { 149, 150, 250, 251, 255, 80 };
short[] actuals = (short[]) var.read().getStorage();
Assert.assertArrayEquals(expecteds, actuals);
}
}

代码示例来源:origin: Unidata/thredds

public void readDoubleMissing() throws Exception {
VariableDS v = null;
assert( null != (v = (VariableDS) dsRead.findVariable("m1")));
assert( v.getDataType() == DataType.DOUBLE);
Array A = v.read();
Index ima = A.getIndex();
double val = A.getFloat(ima.set(1,1));
assert Double.isNaN(val);
assert v.isMissing(val);
// Reread without converting missing values to NaNs.
v.removeEnhancement(NetcdfDataset.Enhance.ConvertMissing);
v.createNewCache();
A = v.read();
ima = A.getIndex();
val = A.getFloat(ima.set(1,1));
Assert2.assertNearlyEquals(val, -999.99);
assert v.isMissing(val);
}

代码示例来源:origin: Unidata/thredds

public void testByteAttribute() throws IOException {
String filename = TestOnLocalServer.withHttpPath("dodsC/scanCdmUnitTests/ft/stationProfile/PROFILER_wind_06min_20091030_2330.nc");
NetcdfDataset ncd = NetcdfDataset.openDataset(filename, true, null);
assert ncd != null;
VariableDS v = (VariableDS) ncd.findVariable("uvQualityCode");
assert v != null;
assert v.hasMissing();
int count = 0;
Array data = v.read();
IndexIterator ii = data.getIndexIterator();
while (ii.hasNext()) {
byte val = ii.getByteNext();
if (v.isMissing(val)) count++;
if (val == (byte)-1)
assert v.isMissing(val);
}
System.out.println("size = "+v.getSize()+" missing= "+count);
}
}

代码示例来源:origin: Unidata/thredds

@Test
public void testScaling2() throws Exception {
DatasetUrl durl = DatasetUrl.findDatasetUrl(location+"fine.ncml");
NetcdfFile ncfile = NetcdfDataset.acquireFile(durl, null);
// make sure that scaling is applied
VariableDS vs = (VariableDS) ncfile.findVariable("hs");
Array data = vs.read("0,1,:,:)");
while (data.hasNext()) {
float val = data.nextFloat();
if (!vs.isMissing(val))
assert (val <10.0) : val;
//System.out.printf("%f %n",val);
}
ncfile.close();
}

代码示例来源:origin: Unidata/thredds

@Test
public void testByteAttribute() throws IOException {
String filename = TestOnLocalServer.withHttpPath("dodsC/scanCdmUnitTests/ft/stationProfile/PROFILER_wind_06min_20091030_2330.nc");
NetcdfDataset ncd = NetcdfDataset.openDataset(filename, true, null);
assert ncd != null;
VariableDS v = (VariableDS) ncd.findVariable("uvQualityCode");
assert v != null;
assert v.hasMissing();
int count = 0;
Array data = v.read();
IndexIterator ii = data.getIndexIterator();
while (ii.hasNext()) {
byte val = ii.getByteNext();
if (v.isMissing(val)) count++;
if (val == (byte)-1)
assert v.isMissing(val);
}
System.out.println("size = "+v.getSize()+" missing= "+count);
}
}

推荐阅读
author-avatar
强压谷攻
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有