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


Java Attribute类代码示例

本文整理汇总了Java中ucar.nc2.Attribute的典型用法代码示例。如果您正苦于以下问题:Java Attribute类的具体用法?Java Attribute怎么用?Java Attribute使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: createTimeVariable

import ucar.nc2.Attribute; //导入依赖的package包/类
/**
 * Creates a time dimension and variable.
 *
 * @param dataFile
 * @param timeCount      if timeCount is -1, then creates an unlimited timeDimension
 * @param timeUnitString
 * @return timeDimension
 */
public static Dimension createTimeVariable(NetcdfFileWriter dataFile, String timeVariableName, int timeCount, String timeUnitString) {
	//create time dimension.
	Dimension timeDimension;
	if (timeCount == -1 || timeCount == 0) {
		timeDimension = dataFile.addUnlimitedDimension(timeVariableName);
	} else {
		timeDimension = dataFile.addDimension(null,timeVariableName, timeCount);
	}

	//create time variable.
	Variable myVar = dataFile.addVariable(null,timeVariableName, ucar.ma2.DataType.DOUBLE, Arrays.asList(timeDimension) );
	dataFile.addVariableAttribute(myVar, new Attribute (STANDARD_NAME_ATTRIBUTE_NAME, TIME_VARIABLE_NAME) );
	dataFile.addVariableAttribute(myVar, new Attribute(LONG_NAME_ATTRIBUTE_NAME, TIME_VARIABLE_NAME));
	dataFile.addVariableAttribute(myVar, new Attribute(UNITS_ATTRIBUTE_NAME, timeUnitString));
	//use default calendar.
	dataFile.addVariableAttribute(myVar, new Attribute(CALENDAR_ATTRIBUTE_NAME, DEFAULT_CALENDAR_ATTRIBUTE_VALUE));
	dataFile.addVariableAttribute(myVar, new Attribute(AXIS_ATTRIBUTE_NAME, T_AXIS));
	return timeDimension;
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:28,代码来源:NetcdfUtils.java

示例2: getStringValue

import ucar.nc2.Attribute; //导入依赖的package包/类
/**
 * Reads the value of an attribute of a variable and returns its value as a string.
 * 
 * @param attribute a NetCDF attribute.
 * @param variable a NetCDF variable.
 * 
 * @return value of the attribute
 * 
 * @throws NetCdfAttributeException invalid request (see error message).
 */
public static String getStringValue(Variable variable, Attribute attribute) throws NetCdfAttributeException {
    String value = null;
    if (attribute == null) {
        return value;
    }

    if (!attribute.isString()) {
        throw new NetCdfAttributeException(
                variable,
                attribute,
                String.format("Error in getStringValue - Unable to get string value from attribute - Attribute type (%s) is not STRING ",
                              attribute.getDataType().toString()));
    }

    value = attribute.getStringValue();

    if (value == null) {
        throw new NetCdfAttributeException(variable, attribute, "Error in getStringValue - Unable to get string value from attribute");
    }
    return value;
}
 
开发者ID:clstoulouse,项目名称:motu,代码行数:32,代码来源:NetCdfReader.java

示例3: createAttribute

import ucar.nc2.Attribute; //导入依赖的package包/类
/**
 * Creates the attribute.
 * 
 * @param name the name
 * @param classType the class type
 * @param value the value
 * 
 * @return the attribute
 */
public static Attribute createAttribute(String name, Class<?> classType, Number value) {
    int[] shape = new int[1];
    shape[0] = 1;
    Array vala = Array.factory(classType, shape);
    Index ima = vala.getIndex();

    if ((classType == double.class) || (classType == Double.class)) {
        vala.setDouble(ima, value.doubleValue());
    } else if ((classType == float.class) || (classType == Float.class)) {
        vala.setFloat(ima, value.floatValue());
    } else if ((classType == long.class) || (classType == Long.class)) {
        vala.setLong(ima, value.longValue());
    } else if ((classType == int.class) || (classType == Integer.class)) {
        vala.setInt(ima, value.intValue());
    } else if ((classType == short.class) || (classType == Short.class)) {
        vala.setShort(ima, value.shortValue());
    } else if ((classType == byte.class) || (classType == Byte.class)) {
        vala.setByte(ima, value.byteValue());
    }

    return new Attribute(name, vala);
}
 
开发者ID:clstoulouse,项目名称:motu,代码行数:32,代码来源:NetCdfWriter.java

示例4: copyAttributes

import ucar.nc2.Attribute; //导入依赖的package包/类
/**
 * Copies attributes of a variable to another variable.
 *
 * @param src variable to copy from
 * @param dest variable to copy to
 * @param overwrite the overwrite
 */
public static void copyAttributes(Variable src, Variable dest, boolean overwrite) {

    if ((src == null) || (dest == null)) {
        return;
    }

    List<Attribute> attributes = src.getAttributes();
    for (Attribute att : attributes) {
        if (!overwrite) {
            if (dest.findAttributeIgnoreCase(att.getName()) == null) {
                continue;
            }
        }
        dest.addAttribute(new Attribute(att.getName(), att));
    }
}
 
开发者ID:clstoulouse,项目名称:motu,代码行数:24,代码来源:NetCdfWriter.java

示例5: addCoordinateTransformVariable

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

示例6: addVariables

import ucar.nc2.Attribute; //导入依赖的package包/类
@Override
void addVariables() {

	// mass_flux of surfaced gas in grid cell
	// float mass_flux (time, latitude, longitude)
	Variable myVar = writer.addVariable(null, MASS_FLUX, DataType.FLOAT,
			dims);
	writer.addVariableAttribute(myVar, new Attribute("long_name",
			"Flux of gas mass through sea surface"));
	writer.addVariableAttribute(myVar, new Attribute("units", "g/sqm/s"));
	addStandardAttributes(myVar);

	// mass_flux of surfaced gas in grid cell
	// float void_fraction (time, latitude, longitude)
	myVar = writer.addVariable(null, VOID_FRACTION, DataType.FLOAT, dims);
	writer.addVariableAttribute(myVar, new Attribute("long_name",
			"Void fraction at sea surface"));
	writer.addVariableAttribute(myVar, new Attribute("units", "%"));
	addStandardAttributes(myVar);
}
 
开发者ID:SINTEF-EnvironmentalTechnology,项目名称:GRF2NETCDF,代码行数:21,代码来源:SurfaceGridGasWriter.java

示例7: addVariables

import ucar.nc2.Attribute; //导入依赖的package包/类
@Override
void addVariables() {

	// concentration of dissolved matter in grid cell
	// float dissolved_concentration (time, depth, latitude, longitude)
	Variable myVar = writer.addVariable(null, DISSOLVED_CONCENTRATION,
			DataType.FLOAT, dims);
	writer.addVariableAttribute(myVar, new Attribute("long_name",
			"concentration of dissolved matter"));
	// writer.addVariableAttribute(myVar, new Attribute("standard_name",
	// "concentration_of_dissolved_suspended_matter_in_sea_water"));
	writer.addVariableAttribute(myVar, new Attribute("units", "ppb"));
	addStandardAttributes(myVar);

	// total hydrocarbon concentration in grid cell
	// float total_concentration (time, depth, latitude, longitude)
	myVar = writer.addVariable(null, TOTAL_CONCENTRATION, DataType.FLOAT,
			dims);
	writer.addVariableAttribute(myVar, new Attribute("long_name",
			"total hydrocarbon concentration"));
	// writer.addVariableAttribute(myVar, new Attribute("standard_name",
	// "concentration_of_suspended_matter_in_sea_water"));
	writer.addVariableAttribute(myVar, new Attribute("units", "ppb"));
	addStandardAttributes(myVar);
}
 
开发者ID:SINTEF-EnvironmentalTechnology,项目名称:GRF2NETCDF,代码行数:26,代码来源:ConcentrationGridWriter.java

示例8: createFile

import ucar.nc2.Attribute; //导入依赖的package包/类
/**
 * 
 * @param xDim
 * @param yDim
 * @param simulationStart
 * @param fileLocation
 * @throws IOException
 */
public void createFile(int xDim, int yDim, int zDim, Date simulationStart,
		String fileLocation) throws IOException {
	// create a new file for writing - from 2D Grid
	prepareFile(xDim, yDim, simulationStart, fileLocation);

	// insert dimension depth at position 1 => (time, depth, lat, lon)
	dims.add(1, writer.addDimension(null, DEPTH, zDim));

	// add coordinate variable for depth
	// float depth(depth)
	Variable myVar = writer.addVariable(null, DEPTH, DataType.FLOAT, DEPTH);
	writer.addVariableAttribute(myVar, new Attribute("long_name",
			"depth of grid cell center"));
	writer.addVariableAttribute(myVar, new Attribute("standard_name",
			"depth"));
	writer.addVariableAttribute(myVar, new Attribute("positive", "down"));
	writer.addVariableAttribute(myVar, new Attribute("axis", "Z"));

	addVariables();

	writer.create();
	writer.close();

}
 
开发者ID:SINTEF-EnvironmentalTechnology,项目名称:GRF2NETCDF,代码行数:33,代码来源:ThreeDGridWriter.java

示例9: addVariable

import ucar.nc2.Attribute; //导入依赖的package包/类
public <T> Var<T> addVariable(String shortName, Optional<String> longName,
        Optional<String> units, Optional<String> encoding, Class<T> cls, int numRecords) {
    Preconditions.checkNotNull(shortName);
    Preconditions.checkNotNull(longName);
    Preconditions.checkNotNull(units);
    Preconditions.checkNotNull(encoding);
    Preconditions.checkNotNull(cls);
    Dimension dimension = f.addDimension(null, shortName, numRecords);
    Variable variable = f.addVariable(null, shortName, toDataType(cls),
            Arrays.asList(dimension));
    if (longName.isPresent())
        variable.addAttribute(new Attribute("long_name", longName.get()));
    if (units.isPresent())
        variable.addAttribute(new Attribute("units", units.get()));
    if (encoding.isPresent())
        variable.addAttribute(new Attribute("encoding", encoding.get()));
    return new Var<T>(this, variable, cls);
}
 
开发者ID:amsa-code,项目名称:risky,代码行数:19,代码来源:NetCdfWriter.java

示例10: test

import ucar.nc2.Attribute; //导入依赖的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());
    }
}
 
开发者ID:amsa-code,项目名称:risky,代码行数:27,代码来源:NetCdfWriterTest.java

示例11: isUgrid

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

示例12: isSgrid

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

示例13: createTimeAxis

import ucar.nc2.Attribute; //导入依赖的package包/类
/**
 * Creates a time axis from the given {@link GridCoordSystem}
 *
 * @param coordSys
 *            the {@link CoordinateAxis1DTime} defining the axis
 * @return a new {@link TimeAxis}
 */
public static TimeAxis createTimeAxis(CoordinateAxis1DTime timeAxis) {
    if (timeAxis == null) {
        return null;
    }
    Attribute cal = timeAxis.findAttribute("calendar");
    String calString = cal == null ? null : cal.getStringValue().toLowerCase();

    Chronology chron = getChronologyForString(calString);
    if (chron == null) {
        throw new IllegalArgumentException("The calendar system " + cal.getStringValue()
                + " cannot be handled");
    }
    List<DateTime> timesteps = new ArrayList<DateTime>();
    for (CalendarDate date : timeAxis.getCalendarDates()) {
        timesteps.add(new DateTime(date.getMillis(), chron));
    }
    return new TimeAxisImpl("time", timesteps);
}
 
开发者ID:Reading-eScience-Centre,项目名称:edal-java,代码行数:26,代码来源:CdmUtils.java

示例14: getAttributeStringValue

import ucar.nc2.Attribute; //导入依赖的package包/类
/**
 * Returns the trimmed String value of the attribute with the given attributeName for the given variable.
 *
 * @param variable
 * @param attributeName
 * @return String or null.
 */
private static String getAttributeStringValue(Variable variable, String attributeName) {
	Attribute attribute = variable.findAttribute(attributeName);
	if (attribute == null) {
		return null;
	}

	String value = attribute.getStringValue();
	if (value == null) {
		return null;
	}

	return value.trim();
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:21,代码来源:NetcdfUtils.java

示例15: createDataVariable

import ucar.nc2.Attribute; //导入依赖的package包/类
private static void createDataVariable(NetcdfFileWriter netcdfFileWriter, IExchangeItem exchangeItem, Dimension timeDimension, Dimension realizationDimension, Dimension stationDimension,
			Map<IGeometryInfo, GridVariableProperties> geometryInfoGridVariablePropertiesMap) {
		List<Dimension> dimensions = new ArrayList<Dimension>();
		if (timeDimension != null) {
			dimensions.add(timeDimension);
		}
		if (realizationDimension != null) {
			dimensions.add(realizationDimension);
		}
		if (stationDimension != null) {
			dimensions.add(stationDimension);
		}
		if (geometryInfoGridVariablePropertiesMap != null) {
			GridVariableProperties gridVariableProperties = geometryInfoGridVariablePropertiesMap.get(exchangeItem.getGeometryInfo());
			if (gridVariableProperties != null) {
				dimensions.addAll(gridVariableProperties.getDimensions());
			}
		}

		DataType dataType = getDataType(exchangeItem.getValuesType());
		String variableName = getVariableName(exchangeItem);
		Variable myVar = netcdfFileWriter.addVariable(null,variableName, dataType, dimensions);
		//at this point standard_name of data is unknown, so cannot add the optional standard_name attribute here.
		netcdfFileWriter.addVariableAttribute(myVar, new Attribute(LONG_NAME_ATTRIBUTE_NAME, variableName));
		netcdfFileWriter.addVariableAttribute(myVar, new Attribute(UNITS_ATTRIBUTE_NAME, exchangeItem.getQuantityInfo().getUnit() ));
		netcdfFileWriter.addVariableAttribute(myVar, new Attribute(FILL_VALUE_ATTRIBUTE_NAME, DEFAULT_FILL_VALUE_DOUBLE));

		//TODO add grid mapping attribute. AK
//		if (gridVariableProperties != null) {
//			String gridMappingVariableName = gridVariableProperties.getGridMappingVariableName();
//			if (gridMappingVariableName != null) {
//				netcdfFile.addVariableAttribute(dataVariableName, GRID_MAPPING_ATTRIBUTE, gridMappingVariableName);
//			}
//		}
	}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:36,代码来源:NetcdfUtils.java


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