本文整理汇总了Java中ucar.nc2.dataset.NetcdfDataset类的典型用法代码示例。如果您正苦于以下问题:Java NetcdfDataset类的具体用法?Java NetcdfDataset怎么用?Java NetcdfDataset使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NetcdfDataset类属于ucar.nc2.dataset包,在下文中一共展示了NetcdfDataset类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getCoordinateVariable
import ucar.nc2.dataset.NetcdfDataset; //导入依赖的package包/类
/**
* Gets the coordinate variable.
*
* @param dim the dim
* @param ds the ds
*
* @return the coordinate variable
* @throws MotuException
*
*/
public static CoordinateAxis getCoordinateVariable(Dimension dim, NetcdfDataset ds) throws MotuException {
Variable variable = null;
try {
variable = NetCdfReader.getVariable(dim.getName(), ds);
} catch (NetCdfVariableNotFoundException e) {
throw new MotuException(
ErrorType.NETCDF_LOADING,
String.format("Error in getCoordinateVariable - Unable to get variable '%s'", dim.getName()),
e);
}
if (variable == null) {
return null;
}
if (!variable.isCoordinateVariable()) {
return null;
}
if (!(variable instanceof CoordinateAxis)) {
return null;
}
return (CoordinateAxis) variable;
}
开发者ID:clstoulouse,项目名称:motu,代码行数:35,代码来源:NetCdfReader.java
示例2: getCoordinateVariables
import ucar.nc2.dataset.NetcdfDataset; //导入依赖的package包/类
/**
* Gets the coordinate variables.
*
* @param var the var
* @param ds the net cdf dataset
*
* @return the coordinate variables
*
* @throws MotuNotImplementedException the motu not implemented exception
* @throws MotuException the net cdf variable not found exception
*/
public static List<Variable> getCoordinateVariables(Variable var, NetcdfDataset ds) throws MotuNotImplementedException, MotuException {
List<Variable> listCoordVars = new ArrayList<Variable>();
if (var instanceof CoordinateAxis) {
return listCoordVars;
}
List<Dimension> listDims = var.getDimensions();
for (Dimension dim : listDims) {
Variable dimCoordVars = NetCdfReader.getCoordinateVariable(dim, ds);
listCoordVars.add(dimCoordVars);
}
return listCoordVars;
}
开发者ID:clstoulouse,项目名称:motu,代码行数:28,代码来源:NetCdfReader.java
示例3: addCoordinateTransformVariable
import ucar.nc2.dataset.NetcdfDataset; //导入依赖的package包/类
/**
* Adds the coordinate transform variable to the dataset.
*
* @param ds modify this dataset
* @param coordTransName coordinate systèem variable name
* @param listNewAxes Axes (Variables) of the new coordinate system.
* @param listOriginAxes Axes (Variables) of the original coordinate system.
* @throws MotuNotImplementedException
* @throws MotuException
*/
private void addCoordinateTransformVariable(NetcdfDataset ds,
String coordTransName,
List<CoordinateAxis> listNewAxes,
List<CoordinateAxis> listOriginAxes) throws MotuNotImplementedException, MotuException {
if (coordinateTransformContainsKey(coordTransName)) {
return;
}
ProjectionCT projCT = null;
ProjectionImpl proj = new LatLonProjection();
projCT = new ProjectionCT(coordTransName, "", proj);
VariableDS v = makeCoordinateTransformVariable(ds, projCT);
putCoordinateTransform(coordTransName, v);
String coordinateAxesName = CoordinateSystem.makeName(listNewAxes);
ds.addVariable(null, v);
v.addAttribute(new Attribute(_Coordinate.Axes, coordinateAxesName));
addCoordinateSystemsAttr(ds, coordTransName, listOriginAxes);
}
开发者ID:clstoulouse,项目名称:motu,代码行数:36,代码来源:CoordSysBuilderYXLatLon.java
示例4: testGetObservationIoosNetCDFEncoding
import ucar.nc2.dataset.NetcdfDataset; //导入依赖的package包/类
@Test
public void testGetObservationIoosNetCDFEncoding() throws OwsExceptionReport, XmlException, IOException {
// check for netcdf lib before test is run. on debian/ubuntu the package is libnetcdf-dev
// TODO shouldn't netcdf3 response formats work without this library?
try {
Native.loadLibrary("netcdf", Nc4prototypes.class);
} catch (UnsatisfiedLinkError e) {
Assume.assumeNoException("netcdf library not detected, skipping test", e);
}
InputStream getObsResponse = sendGetObservation1RequestViaPox(NETWORK_OFFERING, IoosNetcdfEncoder.CONTENT_TYPE_NETCDF.toString(),
ImmutableList.of(STATION_ASSET.getAssetId()), ImmutableList.of(OBS_PROP),null).asInputStream();
File tempNetcdfFile = File.createTempFile("i52n-sos-netcdf-test", ".nc");
FileOutputStream fileOutputStream = new FileOutputStream(tempNetcdfFile);
IOUtils.copy(getObsResponse, fileOutputStream);
getObsResponse.close();
fileOutputStream.close();
NetcdfDataset netcdfDataset = NetcdfDataset.openDataset(tempNetcdfFile.getAbsolutePath());
assertThat(netcdfDataset, notNullValue());
//TODO validate
}
开发者ID:ioos,项目名称:i52n-sos,代码行数:23,代码来源:IoosGetObservationIntegrationTest.java
示例5: verifyHeightAxis
import ucar.nc2.dataset.NetcdfDataset; //导入依赖的package包/类
private void verifyHeightAxis(NetcdfFile netcdfFile, int size, double minHeight, double maxHeight) throws IOException {
NetcdfDataset netcdfDataset = NetcdfDataset.wrap(netcdfFile, Sets.newHashSet(Enhance.CoordSystems));
assertNotNull(netcdfDataset);
List<CoordinateSystem> coordinateSystems = netcdfDataset.getCoordinateSystems();
// assertEquals(1, coordinateSystems.size());
boolean heightAxisFound = false;
for (CoordinateSystem coordinateSystem : coordinateSystems) {
CoordinateAxis heightAxis = coordinateSystem.getHeightAxis();
if (heightAxis != null) {
heightAxisFound = true;
assertEquals(size, heightAxis.getSize());
assertEquals(maxHeight, heightAxis.getMaxValue(), 0.0);
assertEquals(minHeight, heightAxis.getMinValue(), 0.0);
}
}
assertTrue("Height axis not found in any coordinate system", heightAxisFound);
}
开发者ID:ioos,项目名称:i52n-sos,代码行数:18,代码来源:AbstractIoosNetcdfEncoderTest.java
示例6: releaseDataset
import ucar.nc2.dataset.NetcdfDataset; //导入依赖的package包/类
/**
* Mark a {@link NetcdfDataset} as inactive. This means that it may be
* removed from the cache in the event that the cache fills up. Reacquiring
* the dataset with {@link NetcdfDatasetAggregator#getDataset(String)} will
* mark it as active again.
*
* @param dataset
* The {@link NetcdfDataset} which is no longer (immediately)
* required.
*/
public static synchronized void releaseDataset(NetcdfDataset dataset) {
if (activeDatasets.containsKey(dataset)) {
Integer count = activeDatasets.get(dataset);
if (count == 1) {
activeDatasets.remove(dataset);
log.debug(dataset.getLocation() + " has no active connections");
} else {
activeDatasets.put(dataset, count - 1);
log.debug(dataset.getLocation() + " has " + activeDatasets.get(dataset)
+ " active connections");
}
} else {
if (dataset != null) {
log.warn("Dataset " + dataset.getLocation()
+ " is not in active dataset list but has been asked to be released! This is not harmful in itself but may indicate a coding error whereby a dataset has been marked to be released from the cache multiple times.");
}
}
}
开发者ID:Reading-eScience-Centre,项目名称:edal-java,代码行数:29,代码来源:NetcdfDatasetAggregator.java
示例7: isUgrid
import ucar.nc2.dataset.NetcdfDataset; //导入依赖的package包/类
/**
* Looks inside a NetCDF dataset to determine whether it follows the UGRID
* conventions.
*
* @param nc
* The dataset
* @return <code>true</code> if this is a UGRID dataset
*/
private static boolean isUgrid(NetcdfDataset nc) {
/*
* First find the variable containing the "cf_role = mesh_topology"
* attribute. This is what defines that we are working with a UGRID
* dataset.
*/
List<Variable> variables = nc.getVariables();
Variable meshTopology = null;
for (Variable var : variables) {
Attribute cfRole = var.findAttribute("cf_role");
if (cfRole != null && cfRole.isString()
&& cfRole.getStringValue().equalsIgnoreCase("mesh_topology")) {
meshTopology = var;
break;
}
}
return meshTopology != null;
}
开发者ID:Reading-eScience-Centre,项目名称:edal-java,代码行数:27,代码来源:CdmGridDatasetFactory.java
示例8: isSgrid
import ucar.nc2.dataset.NetcdfDataset; //导入依赖的package包/类
/**
* Looks inside a NetCDF dataset to determine whether it follows the SGRID
* conventions.
*
* @param nc
* The dataset
* @return <code>true</code> if this is a SGRID dataset
*/
private static boolean isSgrid(NetcdfDataset nc) {
/*
* First find the variable containing the "cf_role = grid_topology"
* attribute. This is what defines that we are working with a UGRID
* dataset.
*/
List<Variable> variables = nc.getVariables();
Variable gridTopology = null;
for (Variable var : variables) {
Attribute cfRole = var.findAttribute("cf_role");
if (cfRole != null && cfRole.isString()
&& cfRole.getStringValue().equalsIgnoreCase("grid_topology")) {
gridTopology = var;
break;
}
}
return gridTopology != null;
}
开发者ID:Reading-eScience-Centre,项目名称:edal-java,代码行数:27,代码来源:CdmGridDatasetFactory.java
示例9: openDataSource
import ucar.nc2.dataset.NetcdfDataset; //导入依赖的package包/类
@Override
protected GridDataSource openDataSource() throws DataReadingException {
NetcdfDataset nc = null;
try {
nc = CdmGridDatasetFactory.this.getNetcdfDatasetFromLocation(location, false);
synchronized (this) {
/*
* If the getGridDataset method runs concurrently on the
* same object, we can get a
* ConcurrentModificationException, so we synchronise this
* action to avoid the issue.
*/
return new CdmGridDataSource(nc);
}
} catch (EdalException | IOException e) {
if (nc != null) {
NetcdfDatasetAggregator.releaseDataset(nc);
}
throw new DataReadingException("Problem aggregating datasets", e);
}
}
开发者ID:Reading-eScience-Centre,项目名称:edal-java,代码行数:22,代码来源:CdmGridDatasetFactory.java
示例10: createXMLfromNetcdfDataset
import ucar.nc2.dataset.NetcdfDataset; //导入依赖的package包/类
public org.jdom.Document createXMLfromNetcdfDataset(NetcdfDataset
ncds,
String url) {
DatasetsGridsAxesBean beans = createBeansFromNetcdfDataset(url, false, null);
if ( beans == null ) {
System.err.println("Unable to create XML for "+url);
return null;
}
DatasetBean dataset = (DatasetBean) beans.getDatasets().get(0);
List<GridBean> GridBeans = beans.getGrids();
List<AxisBean> AxisBeans = beans.getAxes();
Document doc = new Document();
Element lasdata = new Element("lasdata");
doc.setRootElement(lasdata);
Element datasetsElement = new Element("datasets");
Element thisDataset = dataset.toXml();
datasetsElement.addContent(thisDataset);
lasdata.addContent(datasetsElement);
Element gridsElement = new Element("grids");
Iterator git = GridBeans.iterator();
while (git.hasNext()) {
GridBean gb = (GridBean) git.next();
Element gridElement = gb.toXml();
gridsElement.addContent(gridElement);
}
lasdata.addContent(gridsElement);
Element axesElement = new Element("axes");
Iterator ait = AxisBeans.iterator();
while (ait.hasNext()) {
AxisBean ab = (AxisBean) ait.next();
Element axisElement = ab.toXml();
axesElement.addContent(axisElement);
}
lasdata.addContent(axesElement);
return doc;
}
开发者ID:NOAA-PMEL,项目名称:LAS,代码行数:41,代码来源:ADDXMLProcessor.java
示例11: testNYHOPS
import ucar.nc2.dataset.NetcdfDataset; //导入依赖的package包/类
@Test
public final void testNYHOPS() {
// This data set is a high frequency (possibly irregular) time series an therefore should have the irregular flag applied.
// New code attempts to detect the need for this automatically. If the auto detection would fail the units would be "seconds"
// which LAS does not support. If it works the units are hours (as asserted below).
String url = DODSNetcdfFile.canonicalURL("http://colossus.dl.stevens-tech.edu:8080/thredds/dodsC/fmrc/NYBight/NYHOPS_Forecast_Collection_for_the_New_York_Bight_best.ncd");
NetcdfDataset ncds;
try {
ADDXMLProcessor addxml = new ADDXMLProcessor();
HashMap<String, String> options= new HashMap<String, String>();
addxml.setOptions(options);
ncds = ucar.nc2.dataset.NetcdfDataset.openDataset(url);
Document nyhops = addxml.createXMLfromNetcdfDataset(ncds , url);
Element axes = nyhops.getRootElement().getChild("axes");
List<Element> axisList = axes.getChildren();
assertTrue(axisList.size() > 0);
for (Iterator axisIt = axisList.iterator(); axisIt.hasNext();) {
Element axis = (Element) axisIt.next();
String type = axis.getAttributeValue("type");
if ( type.equals("t") ) {
assertTrue(axis.getAttributeValue("units").contains("hour"));
}
}
} catch (IOException e) {
fail("Unable to connect to OPeNDAP server.");
}
}
开发者ID:NOAA-PMEL,项目名称:LAS,代码行数:28,代码来源:TestNYHOPS.java
示例12: testGFDL
import ucar.nc2.dataset.NetcdfDataset; //导入依赖的package包/类
@Test
public final void testGFDL() {
// Test to make sure variables with names that start with u or v but aren't vectors don't get included. There should only be one composite.
String url = DODSNetcdfFile.canonicalURL("http://data1.gfdl.noaa.gov:8080/thredds/dodsC/CM2.1U_CDFef_v1.0_r1ocean");
String[] name = new String[]{"Vector of "};
String[] units = new String[]{"m s-1"};
NetcdfDataset ncds;
try {
ADDXMLProcessor addxml = new ADDXMLProcessor();
HashMap<String, String> options= new HashMap<String, String>();
addxml.setOptions(options);
ncds = ucar.nc2.dataset.NetcdfDataset.openDataset(url);
// Test from COADS, which tests the new vectors capability
Document leetmaa = addxml.createXMLfromNetcdfDataset(ncds , url);
Iterator compIt = leetmaa.getRootElement().getDescendants(new ElementFilter("composite"));
assertTrue(compIt.hasNext());
int index = 0;
while ( compIt.hasNext() ) {
Element composite = (Element) compIt.next();
List children = composite.getChildren();
assertTrue(children.size() == 1);
Element variable = (Element) children.get(0);
assertTrue(variable != null);
String vname = variable.getAttributeValue("name");
String vunits = variable.getAttributeValue("units");
assertTrue(vname.contains(name[index]));
assertTrue(vunits.equals(units[index]));
index++;
}
assertTrue(index == 1);
} catch (IOException e) {
fail("Unable to connect to OPeNDAP server.");
}
}
开发者ID:NOAA-PMEL,项目名称:LAS,代码行数:35,代码来源:TestGFDL.java
示例13: testNGDC
import ucar.nc2.dataset.NetcdfDataset; //导入依赖的package包/类
@Test
public final void testNGDC() {
// The sole purpose of this test it to check the starting hour of the time axis.
// The time axis is regular with an interval of 1 day, but for some strange reason the times are recorded at 17:00
// so the hour needs to be included in the start string.
String url = DODSNetcdfFile.canonicalURL("http://www.ngdc.noaa.gov/thredds/dodsC/sst-100km-aggregation");
NetcdfDataset ncds;
try {
ADDXMLProcessor addxml = new ADDXMLProcessor();
HashMap<String, String> options= new HashMap<String, String>();
options.put("force","t");
addxml.setOptions(options);
ncds = ucar.nc2.dataset.NetcdfDataset.openDataset(url);
Document ngdc = addxml.createXMLfromNetcdfDataset(ncds , url);
Iterator<Element> arangeIt = ngdc.getDescendants(new ElementFilter("arange"));
assertTrue(arangeIt.hasNext());
while ( arangeIt.hasNext() ) {
Element arange = (Element) arangeIt.next();
String start = arange.getAttributeValue("start");
if ( start.length() > 6) {
Pattern pattern = Pattern.compile(".*[0-9][0-9]:[0-9][0-9]:[0-9][0-9]");
Matcher matcher = pattern.matcher(start);
assertTrue(matcher.matches());
}
}
} catch (IOException e) {
fail("Unable to connect to OPeNDAP server.");
}
}
开发者ID:NOAA-PMEL,项目名称:LAS,代码行数:30,代码来源:TestNGDC.java
示例14: testOISST
import ucar.nc2.dataset.NetcdfDataset; //导入依赖的package包/类
@Test
public final void testOISST() {
// This is a test of the hack in the code to identify an climatology from ESRL/PSD. There should be a modulo=true attribute
// on the time axis.
String url = DODSNetcdfFile.canonicalURL("http://ferret.pmel.noaa.gov/thredds/dodsC/data/PMEL/sst.ltm.1971-2000.nc");
NetcdfDataset ncds;
try {
ADDXMLProcessor addxml = new ADDXMLProcessor();
HashMap<String, String> options= new HashMap<String, String>();
addxml.setOptions(options);
ncds = ucar.nc2.dataset.NetcdfDataset.openDataset(url);
Document coads = addxml.createXMLfromNetcdfDataset(ncds , url);
Element axes = coads.getRootElement().getChild("axes");
List<Element> axisList = axes.getChildren();
assertTrue(axisList.size() > 0);
for (Iterator axisIt = axisList.iterator(); axisIt.hasNext();) {
Element axis = (Element) axisIt.next();
String type = axis.getAttributeValue("type");
if ( type.equals("t") ) {
String mod = axis.getAttributeValue("modulo");
assertTrue(mod != null);
assertTrue(mod.equals("true"));
}
}
} catch (IOException e) {
fail("Unable to connect to OPeNDAP server.");
}
}
开发者ID:NOAA-PMEL,项目名称:LAS,代码行数:29,代码来源:TestOISST.java
示例15: initOriginalVariables
import ucar.nc2.dataset.NetcdfDataset; //导入依赖的package包/类
/**
* Inits the original variables.
*
* @param ds the ds
*/
private void initOriginalVariables(NetcdfDataset ds) {
orignalVariables.clear();
for (Variable var : ds.getVariables()) {
orignalVariables.put(var.getName(), var);
}
}
开发者ID:clstoulouse,项目名称:motu,代码行数:13,代码来源:NetCdfReader.java
示例16: getNetCdfReaderDataset
import ucar.nc2.dataset.NetcdfDataset; //导入依赖的package包/类
/**
* Gets the net cdf reader dataset.
*
* @return the NetCdfDataset object of the NetCdfReader object.
*/
public NetcdfDataset getNetCdfReaderDataset() {
if (getNetCdfReader() == null) {
return null;
}
return getNetCdfReader().getNetcdfDataset();
}
开发者ID:clstoulouse,项目名称:motu,代码行数:12,代码来源:Product.java
示例17: makeCoordinateTransformVariable
import ucar.nc2.dataset.NetcdfDataset; //导入依赖的package包/类
/**
* @see ucar.nc2.dataset.CoordSysBuilder#makeCoordinateTransformVariable(ucar.nc2.dataset.NetcdfDataset,
* ucar.nc2.dataset.CoordinateTransform)
* @param ds dataset
* @param ct coordiante transform
* @return coordinate transfrom variable.
*/
@Override
protected VariableDS makeCoordinateTransformVariable(NetcdfDataset ds, CoordinateTransform ct) {
VariableDS v = new VariableDS(ds, null, null, ct.getName(), DataType.CHAR, "", null, null);
// fake data
Array data = Array.factory(DataType.CHAR.getPrimitiveClassType(), new int[] {}, new char[] { ' ' });
v.setCachedData(data, true);
return v;
}
开发者ID:clstoulouse,项目名称:motu,代码行数:19,代码来源:CoordSysBuilderYXLatLon.java
示例18: readDataInfo
import ucar.nc2.dataset.NetcdfDataset; //导入依赖的package包/类
@Override
public void readDataInfo(String fileName) {
this.setFileName(fileName);
try {
//ncfile = NetcdfFile.open(fileName);
ncfile = NetcdfDataset.openFile(fileName, null);
readDataInfo();
} catch (IOException ex) {
Logger.getLogger(NetCDFDataInfo.class.getName()).log(Level.SEVERE, null, ex);
}
}
开发者ID:meteoinfo,项目名称:MeteoInfoLib,代码行数:12,代码来源:NetCDFDataInfo.java
示例19: verifyNetcdfFile
import ucar.nc2.dataset.NetcdfDataset; //导入依赖的package包/类
private FeatureDataset verifyNetcdfFile(File netcdfFile, FeatureType featureType) throws IOException {
FeatureDataset featureDataset = null;
Formatter errlog = new Formatter();
try {
featureDataset = FeatureDatasetFactoryManager.open(featureType, netcdfFile.getAbsolutePath(), null, errlog);
} catch (IOException e) {
LOGGER.error(errlog.toString());
throw e;
}
if (!errlog.toString().trim().isEmpty()) {
fail(errlog.toString());
}
assertTrue(featureDataset.getFeatureType().equals(featureType));
assertThat(featureDataset, instanceOf(FeatureDatasetPoint.class));
NetcdfDataset netcdfDataset = NetcdfDataset.wrap(featureDataset.getNetcdfFile(), Sets.newHashSet(Enhance.CoordSystems));
//make sure that the feature type found by FDFM (via cdm_feature_type) is the same as the expected feature type
assertEquals(featureType, FeatureDatasetFactoryManager.findFeatureType(netcdfDataset));
//verify that axes is increasing
List<CoordinateSystem> coordinateSystems = netcdfDataset.getCoordinateSystems();
// assertEquals(1, coordinateSystems.size());
for (CoordinateSystem coordinateSystem : coordinateSystems) {
for (CoordinateAxis axis : coordinateSystem.getCoordinateAxes()) {
verifyAxisIsMonotonic(axis);
}
}
return featureDataset;
}
开发者ID:ioos,项目名称:i52n-sos,代码行数:32,代码来源:AbstractIoosNetcdfEncoderTest.java
示例20: testCreateFile
import ucar.nc2.dataset.NetcdfDataset; //导入依赖的package包/类
@Test
public void testCreateFile() {
try {
tester.createFile(5, 2, Calendar.getInstance().getTime(), CREATE_TESTFILE);
//TODO implement test criteria:
// all variables
// correct dimensions
// correct attributes
NetcdfFile data = NetcdfDataset.open(CREATE_TESTFILE);
List<Variable> vars = data.getVariables();
assertTrue(vars.size() == 8);
List<Dimension> dims = data.getDimensions();
assertTrue(dims.size() == 3);
assertNotNull(data.findVariable(SurfaceGridOilWriter.TIME));
assertNotNull(data.findVariable(SurfaceGridOilWriter.LATITUDE));
assertNotNull(data.findVariable(SurfaceGridOilWriter.LONGITUDE));
assertNotNull(data.findVariable(SurfaceGridOilWriter.COVERAGE));
assertNotNull(data.findVariable(SurfaceGridOilWriter.EMULSIONVISCOSITY));
assertNotNull(data.findVariable(SurfaceGridOilWriter.EMULSIONWATCONT));
assertNotNull(data.findVariable(SurfaceGridOilWriter.THICKNESS));
assertNotNull(data.findVariable(SurfaceGridOilWriter.GRIDMAPPING));
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
}
}
开发者ID:SINTEF-EnvironmentalTechnology,项目名称:GRF2NETCDF,代码行数:31,代码来源:SurfaceGridOilWriterTest.java
注:本文中的ucar.nc2.dataset.NetcdfDataset类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论