当前位置: 首页>>代码示例>>Java>>正文


Java Variable.getDimensions方法代码示例

本文整理汇总了Java中ucar.nc2.Variable.getDimensions方法的典型用法代码示例。如果您正苦于以下问题:Java Variable.getDimensions方法的具体用法?Java Variable.getDimensions怎么用?Java Variable.getDimensions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ucar.nc2.Variable的用法示例。


在下文中一共展示了Variable.getDimensions方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: hasGeoYAxisWithLatEquivalence

import ucar.nc2.Variable; //导入方法依赖的package包/类
/**
 * Checks for geo Y axis with lat equivalence.
 * 
 * @return true if GeoX axis exists among coordinate axes and if there is a longitude variable equivalence
 *         (Variable whose name is 'longitude' and with at least two dimensions X/Y).
 * @throws MotuException
 */
public boolean hasGeoYAxisWithLatEquivalence() throws MotuException {
    CoordinateAxis coord = getGeoYAxis();
    if (coord == null) {
        return false;
    }

    Variable var = findLatitudeIgnoreCase();

    if (var == null) {
        return false;
    }

    List<Dimension> listDims = var.getDimensions();

    return hasGeoXYDimensions(listDims);
}
 
开发者ID:clstoulouse,项目名称:motu,代码行数:24,代码来源:NetCdfReader.java

示例2: hasGeoXAxisWithLonEquivalence

import ucar.nc2.Variable; //导入方法依赖的package包/类
/**
 * Checks for geo X axis with lon equivalence.
 * 
 * @return true if GeoX axis exists among coordinate axes and if there is a longitude variable
 *         equivalence) (Variable whose name isa longitude name' and with at least two dimensions X/Y).
 * @throws MotuException
 */
public boolean hasGeoXAxisWithLonEquivalence() throws MotuException {
    CoordinateAxis coord = getGeoXAxis();
    if (coord == null) {
        return false;
    }

    Variable var = findLongitudeIgnoreCase();

    if (var == null) {
        return false;
    }

    List<Dimension> listDims = var.getDimensions();

    return hasGeoXYDimensions(listDims);
}
 
开发者ID:clstoulouse,项目名称:motu,代码行数:24,代码来源:NetCdfReader.java

示例3: getCoordinateVariables

import ucar.nc2.Variable; //导入方法依赖的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

示例4: createGeometryInfo

import ucar.nc2.Variable; //导入方法依赖的package包/类
/**
 * Creates and returns an IGeometryInfo object for the given variable in the given netcdfFile.
 * If no geometry info available, then returns null.
 *
 * @param variable
 * @param netcdfFile
 * @return geometryInfo or null.
 */
public static IArrayGeometryInfo createGeometryInfo(Variable variable, NetcdfFile netcdfFile) {

	Variable latitudeVariable = findLatitudeVariableForVariable(variable, netcdfFile);
	Variable longitudeVariable = findLongitudeVariableForVariable(variable, netcdfFile);
	//currently only 2D grids are supported.
	if (latitudeVariable == null || longitudeVariable == null) {//if data does not depend on space.
		return null;
	}

	//if 2D grid.
	IQuantityInfo latitudeQuantityInfo = new QuantityInfo(LATITUDE_STANDARD_NAME, latitudeVariable.getUnitsString());
	IQuantityInfo longitudeQuantityInfo = new QuantityInfo(LONGITUDE_STANDARD_NAME, longitudeVariable.getUnitsString());
	List<Dimension> latitudeVariableDimensions = latitudeVariable.getDimensions();
	int[] latitudeValueIndices = new int[latitudeVariableDimensions.size()];
	for (int n = 0; n < latitudeValueIndices.length; n++) {
		latitudeValueIndices[n] = variable.findDimensionIndex(latitudeVariableDimensions.get(n).getShortName());
	}
	List<Dimension> longitudeVariableDimensions = longitudeVariable.getDimensions();
	int[] longitudeValueIndices = new int[longitudeVariableDimensions.size()];
	for (int n = 0; n < longitudeValueIndices.length; n++) {
		longitudeValueIndices[n] = variable.findDimensionIndex(longitudeVariableDimensions.get(n).getShortName());
	}
	IArray latitudeArray = (IArray) readData(latitudeVariable);
	IArray longitudeArray = (IArray) readData(longitudeVariable);
       //the latitude and longitude coordinates are stored in the same order as in the netcdf file.
	ArrayGeometryInfo geometryInfo = new ArrayGeometryInfo(latitudeArray, latitudeValueIndices,
			latitudeQuantityInfo, longitudeArray, longitudeValueIndices, longitudeQuantityInfo,null,null,null);
	return geometryInfo;
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:38,代码来源:NetcdfUtils.java

示例5: getLatitudeDimensionIndexForVariable

import ucar.nc2.Variable; //导入方法依赖的package包/类
public static int getLatitudeDimensionIndexForVariable(Variable variable, NetcdfFile netcdfFile) {
	Variable latitudeVariable = NetcdfUtils.findLatitudeVariableForVariable(variable, netcdfFile);
	if (latitudeVariable == null) {
		return -1;
	}

	List<Dimension> latitudeVariableDimensions = latitudeVariable.getDimensions();
	return variable.findDimensionIndex(latitudeVariableDimensions.get(0).getShortName());
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:10,代码来源:NetcdfUtils.java

示例6: setHasOutputDimension

import ucar.nc2.Variable; //导入方法依赖的package包/类
/**
 * Checks dimension in output.
 * 
 * @throws MotuException the net cdf variable not found exception
 * @throws NetCdfVariableNotFoundException the net cdf variable not found exception
 */
public void setHasOutputDimension() throws MotuException, NetCdfVariableNotFoundException {
    hasOutputTimeDimension = false;
    hasOutputLatDimension = false;
    hasOutputLonDimension = false;
    hasOutputZDimension = false;

    for (VarData varData : getRequestDownloadStatus().getRequestProduct().getRequestProductParameters().getVariables().values()) {
        Variable variable = getRequestDownloadStatus().getRequestProduct().getProduct().getNetCdfReader().getRootVariable(varData.getVarName());
        List<Dimension> dimsVar = variable.getDimensions();
        for (Dimension dim : dimsVar) {
            // ATESTER : changement de signature dans getCoordinateVariables entre netcdf-java 2.2.20 et
            // 2.2.22
            CoordinateAxis coord = getCoordinateVariable(dim);
            if (coord != null) {
                hasOutputTimeDimension |= coord.getAxisType() == AxisType.Time;
                hasOutputLatDimension |= coord.getAxisType() == AxisType.Lat;
                hasOutputLonDimension |= coord.getAxisType() == AxisType.Lon;
                if (getRequestDownloadStatus().getRequestProduct().getProduct().getNetCdfReader().hasGeoXYAxisWithLonLatEquivalence()) {
                    hasOutputLatDimension |= coord.getAxisType() == AxisType.GeoY;
                    hasOutputLonDimension |= coord.getAxisType() == AxisType.GeoX;
                }
                hasOutputZDimension |= (coord.getAxisType() == AxisType.GeoZ) || (coord.getAxisType() == AxisType.Height);
            }
        }
    }
}
 
开发者ID:clstoulouse,项目名称:motu,代码行数:33,代码来源:DatasetGridManager.java

示例7: findTimeVariableForVariable

import ucar.nc2.Variable; //导入方法依赖的package包/类
/**
 * Searches all the variables that the given variable depends on,
 * and returns the first variable that is a valid time variable.
 * If cannot find a valid time variable, then returns null.
 *
 * @param variable
 * @param netcdfFile
 * @return timeVariable or null.
 */
public static Variable findTimeVariableForVariable(Variable variable, NetcdfFile netcdfFile) {
	List<Dimension> dimensions = variable.getDimensions();
	for (Dimension dimension : dimensions) {
		Variable dimensionVariable = netcdfFile.findVariable(dimension.getShortName());
		if (dimensionVariable == null || !dimensionVariable.isCoordinateVariable()) {
			continue;
		}

		if(isTimeVariable(dimensionVariable)) {
			return dimensionVariable;
		}
	}

	//search auxiliary coordinate variables.
	//according to the CF-convention (see http://cf-pcmdi.llnl.gov/documents/cf-conventions/1.5/cf-conventions.html#coordinate-system):
	//"An application that is trying to find the latitude coordinate of a variable should always look first to see
	//if any of the variable's dimensions correspond to a latitude coordinate variable. If the latitude coordinate
	//is not found this way, then the auxiliary coordinate variables listed by the coordinates attribute should
	//be checked. Note that it is permissible, but optional, to list coordinate variables as well as auxiliary
	//coordinate variables in the coordinates attribute. The axis attribute is not allowed for auxiliary coordinate
	//variables. Auxiliary coordinate variables which lie on the horizontal surface can be identified as such by their
	//dimensions being horizontal. Horizontal dimensions are those whose coordinate variables have an axis attribute
	//of X or Y, or a units attribute indicating latitude and longitude (see Chapter 4, Coordinate Types ).
	String coordinates = getAttributeStringValue(variable, COORDINATES_ATTRIBUTE_NAME);
	if (coordinates != null) {
		String[] strings = coordinates.split("\\s+");
		for (String auxiliaryCoordinateVariableName : strings) {
			Variable auxiliaryCoordinateVariable = netcdfFile.findVariable(auxiliaryCoordinateVariableName);
			if (auxiliaryCoordinateVariable == null) {
				continue;
			}

			if (isTimeVariable(auxiliaryCoordinateVariable)) {
				return auxiliaryCoordinateVariable;
			}
		}
	}

	return null;
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:50,代码来源:NetcdfUtils.java

示例8: findLatitudeVariableForVariable

import ucar.nc2.Variable; //导入方法依赖的package包/类
/**
 * Searches all the variables that the given variable depends on,
 * and returns the first variable that is a valid latitude variable.
 * If cannot find a valid latitude variable, then returns null.
 *
 * @param variable
 * @param netcdfFile
 * @return latitudeVariable or null.
 */
private static Variable findLatitudeVariableForVariable(Variable variable, NetcdfFile netcdfFile) {
	//search coordinate variables.
	List<Dimension> dimensions = variable.getDimensions();
	for (Dimension dimension : dimensions) {
		Variable dimensionVariable = netcdfFile.findVariable(dimension.getShortName());
		if (dimensionVariable == null || !dimensionVariable.isCoordinateVariable()) {
			continue;
		}

		if (isLatitudeVariable(dimensionVariable)) {
			return dimensionVariable;
		}
	}

	//search auxiliary coordinate variables.
	//according to the CF-convention (see http://cf-pcmdi.llnl.gov/documents/cf-conventions/1.5/cf-conventions.html#coordinate-system):
	//"An application that is trying to find the latitude coordinate of a variable should always look first to see
	//if any of the variable's dimensions correspond to a latitude coordinate variable. If the latitude coordinate
	//is not found this way, then the auxiliary coordinate variables listed by the coordinates attribute should
	//be checked. Note that it is permissible, but optional, to list coordinate variables as well as auxiliary
	//coordinate variables in the coordinates attribute. The axis attribute is not allowed for auxiliary coordinate
	//variables. Auxiliary coordinate variables which lie on the horizontal surface can be identified as such by their
	//dimensions being horizontal. Horizontal dimensions are those whose coordinate variables have an axis attribute
	//of X or Y, or a units attribute indicating latitude and longitude (see Chapter 4, Coordinate Types ).
	String coordinates = getAttributeStringValue(variable, COORDINATES_ATTRIBUTE_NAME);
	if (coordinates != null) {
		String[] strings = coordinates.split("\\s+");
		for (String auxiliaryCoordinateVariableName : strings) {
			Variable auxiliaryCoordinateVariable = netcdfFile.findVariable(auxiliaryCoordinateVariableName);
			if (auxiliaryCoordinateVariable == null) {
				continue;
			}

			if (isLatitudeVariable(auxiliaryCoordinateVariable)) {
				return auxiliaryCoordinateVariable;
			}
		}
	}

	return null;
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:51,代码来源:NetcdfUtils.java

示例9: findLongitudeVariableForVariable

import ucar.nc2.Variable; //导入方法依赖的package包/类
/**
 * Searches all the variables that the given variable depends on,
 * and returns the first variable that is a valid longitude variable.
 * If cannot find a valid longitude variable, then returns null.
 *
 * @param variable
 * @param netcdfFile
 * @return longitudeVariable or null.
 */
private static Variable findLongitudeVariableForVariable(Variable variable, NetcdfFile netcdfFile) {
	//search coordinate variables.
	List<Dimension> dimensions = variable.getDimensions();
	for (Dimension dimension : dimensions) {
		Variable dimensionVariable = netcdfFile.findVariable(dimension.getShortName());
		if (dimensionVariable == null || !dimensionVariable.isCoordinateVariable()) {
			continue;
		}

		if (isLongitudeVariable(dimensionVariable)) {
			return dimensionVariable;
		}
	}

	//search auxiliary coordinate variables.
	//according to the CF-convention (see http://cf-pcmdi.llnl.gov/documents/cf-conventions/1.5/cf-conventions.html#coordinate-system):
	//"An application that is trying to find the latitude coordinate of a variable should always look first to see
	//if any of the variable's dimensions correspond to a latitude coordinate variable. If the latitude coordinate
	//is not found this way, then the auxiliary coordinate variables listed by the coordinates attribute should
	//be checked. Note that it is permissible, but optional, to list coordinate variables as well as auxiliary
	//coordinate variables in the coordinates attribute. The axis attribute is not allowed for auxiliary coordinate
	//variables. Auxiliary coordinate variables which lie on the horizontal surface can be identified as such by their
	//dimensions being horizontal. Horizontal dimensions are those whose coordinate variables have an axis attribute
	//of X or Y, or a units attribute indicating latitude and longitude (see Chapter 4, Coordinate Types ).
	String coordinates = getAttributeStringValue(variable, COORDINATES_ATTRIBUTE_NAME);
	if (coordinates != null) {
		String[] strings = coordinates.split("\\s+");
		for (String auxiliaryCoordinateVariableName : strings) {
			Variable auxiliaryCoordinateVariable = netcdfFile.findVariable(auxiliaryCoordinateVariableName);
			if (auxiliaryCoordinateVariable == null) {
				continue;
			}

			if (isLongitudeVariable(auxiliaryCoordinateVariable)) {
				return auxiliaryCoordinateVariable;
			}
		}
	}

	return null;
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:51,代码来源:NetcdfUtils.java

示例10: writeVariable

import ucar.nc2.Variable; //导入方法依赖的package包/类
/**
 * Add a Variable to the file. The data is also copied when finish() is called.
 *
 * @param var copy this Variable (not the data)
 * @param varAttrToRemove variable attribute to remove
 * @throws MotuException the motu exception
 */
public void writeVariable(Variable var, String[] varAttrToRemove) throws MotuException {

    // Dimension[] dims = new Dimension[oldVar.getRank()];
    List<Dimension> dims = new ArrayList<Dimension>();
    List<Dimension> dimvList = var.getDimensions();
    for (Dimension dim : dimvList) {
        Dimension dimToWrite = dimHash.get(dim.getName());
        if (dimToWrite == null) {
            throw new MotuException(
                    ErrorType.NETCDF_VARIABLE,
                    String.format("Error in NetCdfWriter writeVariable - Variable %s - Dimension %s must be added first",
                                  var.getName(),
                                  dim.getName()));

        }
        dims.add(dimToWrite);
    }

    long d1 = System.nanoTime();
    ncfile.addVariable(var.getName(), var.getDataType(), dims);
    long d2 = System.nanoTime();
    this.writingTime += (d2 - d1);

    boolean removeAttr = false;
    List<Attribute> attributeList = var.getAttributes();
    for (Attribute attribute : attributeList) {
        removeAttr = false;
        if (varAttrToRemove != null) {
            for (String attrToRemove : varAttrToRemove) {
                if (attrToRemove.equalsIgnoreCase(attribute.getName())) {
                    removeAttr = true;
                    break;
                }
            }
        }
        if (!removeAttr) {
            writeAttribute(var.getName(), attribute);
        }
    }
}
 
开发者ID:clstoulouse,项目名称:motu,代码行数:48,代码来源:NetCdfWriter.java


注:本文中的ucar.nc2.Variable.getDimensions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。