congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
ucar.nc2
Code IndexAdd Tabnine to your IDE (free)

How to use ucar.nc2

Best Java code snippets using ucar.nc2 (Showing top 20 results out of 486)

origin: geotools/geotools

/**
 * Get Z Dimension Lenght for standard CF variables
 *
 * @param var
 * @return
 */
public static int getZDimensionLength(Variable var) {
  final int rank = var.getRank();
  if (rank > 2) {
    return var.getDimension(rank - Z_DIMENSION).getLength();
  }
  // TODO: Should I avoid use this method in case of 2D Variables?
  return 0;
}
origin: geotools/geotools

public static int getDimensionLength(Variable var, final int dimensionIndex) {
  return var.getDimension(dimensionIndex).getLength();
}
origin: geotools/geotools

private String getCoordinatesForVariable(String shortName) {
  Variable var = dataset.findVariable(null, shortName);
  if (var != null) {
    // Getting the coordinates attribute
    Attribute attribute = var.findAttribute(NetCDFUtilities.COORDINATES);
    if (attribute != null) {
      return attribute.getStringValue();
    } else {
      return var.getDimensionsString();
    }
  }
  return null;
}
origin: apache/tika

NetcdfFile ncFile = NetcdfDataset.openFile(gribFile.getAbsolutePath(), null);
for (Attribute attr : ncFile.getGlobalAttributes()) {
  Property property = resolveMetadataKey(attr.getFullName());
  if (attr.getDataType().isString()) {
    metadata.add(property, attr.getStringValue());
  } else if (attr.getDataType().isNumeric()) {
    int value = attr.getNumericValue().intValue();
    metadata.add(property, String.valueOf(value));
xhtml.newline();
for (Dimension dim : ncFile.getDimensions()){
  xhtml.element("li", dim.getFullName() + "=" + String.valueOf(dim.getLength()) + ";");
  xhtml.newline();
xhtml.newline();
for (Variable var : ncFile.getVariables()){
  xhtml.element("p", String.valueOf(var.getDataType()) + var.getNameAndDimensions() + ";");
  for(Attribute element : var.getAttributes()){
    xhtml.element("li", " :" + element + ";");
    xhtml.newline();
origin: apache/tika

protected void unravelStringMet(NetcdfFile ncFile, Group group, Metadata met) {
  if (group == null) {
    group = ncFile.getRootGroup();
  }
  // get file type
  met.set("File-Type-Description", ncFile.getFileTypeDescription());
  // unravel its string attrs
  for (Attribute attribute : group.getAttributes()) {
    if (attribute.isString()) {
      met.add(attribute.getFullName(), attribute.getStringValue());
    } else {
      // try and cast its value to a string
      met.add(attribute.getFullName(), String.valueOf(attribute
          .getNumericValue()));
    }
  }
  for (Group g : group.getGroups()) {
    unravelStringMet(ncFile, g, met);
  }
}
origin: geotools/geotools

private static Variable getAuxiliaryCoordinate(
    NetcdfDataset dataset, Group group, Variable var, String dimName) {
  Variable coordinateVariable = null;
  Attribute attribute = var.findAttribute(NetCDFUtilities.COORDINATES);
  if (attribute != null) {
    String coordinates = attribute.getStringValue();
    String[] coords = coordinates.split(" ");
    for (String coord : coords) {
      Variable coordVar = dataset.findVariable(group, coord);
      List<Dimension> varDimensions = coordVar.getDimensions();
      if (varDimensions != null
          && varDimensions.size() == 1
          && varDimensions.get(0).getFullName().equalsIgnoreCase(dimName)) {
        coordinateVariable = coordVar;
        break;
      }
    }
  }
  return coordinateVariable;
}
origin: geotools/geotools

  return false;
} else if (checkType == CheckType.NOSCALARS) {
  List<Dimension> dimensions = var.getDimensions();
  if (dimensions.size() < 2) {
    return false;
  DataType dataType = var.getDataType();
  if (dataType == DataType.CHAR) {
    return false;
  return isVariableAccepted(var.getFullName(), CheckType.NONE);
} else if (checkType == CheckType.ONLYGEOGRIDS) {
  List<Dimension> dimensions = var.getDimensions();
  if (dimensions.size() < 2) {
    return false;
    String dimName = dimension.getFullName();
    Group group = dimension.getGroup();
    Variable dimVariable = group.findVariable(dimName);
    if (dimVariable == null && dataset != null) {
      AxisType axisType = axis.getAxisType();
      if (axisType == null) {
        return false;
  DataType dataType = var.getDataType();
  if (dataType == DataType.CHAR) {
origin: geotools/geotools

  /** Look for a Coordinate Reference System */
  private CoordinateReferenceSystem lookForCrs(
      CoordinateReferenceSystem crs, Attribute gridMappingAttribute, Variable var)
      throws FactoryException {
    if (gridMappingAttribute != null) {
      String gridMappingName = gridMappingAttribute.getStringValue();
      if (LOGGER.isLoggable(Level.FINE)) {
        LOGGER.fine("The variable refers to gridMapping: " + gridMappingName);
      }
      Variable mapping = dataset.findVariable(null, gridMappingName);
      if (mapping != null) {
        CoordinateReferenceSystem localCrs = NetCDFProjection.parseProjection(mapping);
        if (localCrs != null) {
          // lookup for a custom EPSG if any
          crs = NetCDFProjection.lookupForCustomEpsg(localCrs);
        }
      } else if (LOGGER.isLoggable(Level.WARNING)) {
        LOGGER.warning(
            "The specified variable "
                + var.getFullName()
                + " declares a gridMapping = "
                + gridMappingName
                + " but that mapping doesn't exist.");
      }
    }
    return crs;
  }
}
origin: geotools/geotools

double max = Double.NaN;
DataType dataType = null;
Attribute rangeAttribute = var.findAttribute(ACTUAL_RANGE);
if (rangeAttribute == null) {
  rangeAttribute = var.findAttribute(VALID_RANGE);
  dataType = rangeAttribute.getDataType();
  min = rangeAttribute.getNumericValue(0).doubleValue();
  max = rangeAttribute.getNumericValue(1).doubleValue();
} else {
  Attribute minAttribute = var.findAttribute(VALID_MIN);
  Attribute maxAttribute = var.findAttribute(VALID_MAX);
  if (minAttribute != null && maxAttribute != null) {
    dataType = minAttribute.getDataType();
    min = minAttribute.getNumericValue().doubleValue();
    max = maxAttribute.getNumericValue().doubleValue();
origin: geotools/geotools

Attribute coordinatesAttribute = var.findAttribute(NetCDFUtilities.COORDINATES);
boolean hasXLon = false;
boolean hasYLat = false;
if (coordinatesAttribute != null) {
  coordinates = coordinatesAttribute.getStringValue();
} else if (!(var instanceof CoordinateAxis)) {
  String dimensions = var.getDimensionsString();
  if (dimensions != null && !dimensions.isEmpty()) {
    coordinates = dimensions;
origin: geotools/geotools

/**
 * Utility method for getting NoData from an input {@link Variable}
 *
 * @param var Variable instance
 * @return a Number representing NoData
 */
public static Number getNodata(Variable var) {
  if (var != null) {
    // Getting all the Variable attributes
    List<Attribute> attributes = var.getAttributes();
    String fullName;
    // Searching for FILL_VALUE or MISSING_VALUE attributes
    for (Attribute attribute : attributes) {
      fullName = attribute.getFullName();
      if (fullName.equalsIgnoreCase(FILL_VALUE)
          || fullName.equalsIgnoreCase(MISSING_VALUE)) {
        return attribute.getNumericValue();
      }
    }
  }
  return null;
}
origin: geotools/geotools

Attribute semiMajorAxisAttribute = gridMappingVariable.findAttribute(CF.SEMI_MAJOR_AXIS);
if (semiMajorAxisAttribute != null) {
  semiMajorAxis = semiMajorAxisAttribute.getNumericValue();
  ellipsoidParams.put(NetCDFUtilities.SEMI_MAJOR, semiMajorAxis);
  semiMajorAxisAttribute = gridMappingVariable.findAttribute(CF.EARTH_RADIUS);
  if (semiMajorAxisAttribute != null) {
    semiMajorAxis = semiMajorAxisAttribute.getNumericValue();
    ellipsoidParams.put(NetCDFUtilities.SEMI_MAJOR, semiMajorAxis);
Attribute semiMinorAxisAttribute = gridMappingVariable.findAttribute(CF.SEMI_MINOR_AXIS);
if (semiMinorAxisAttribute != null) {
  semiMinorAxis = semiMinorAxisAttribute.getNumericValue();
  ellipsoidParams.put(NetCDFUtilities.SEMI_MINOR, semiMinorAxis);
      gridMappingVariable.findAttribute(CF.INVERSE_FLATTENING);
  if (inverseFlatteningAttribute != null) {
    inverseFlattening = inverseFlatteningAttribute.getNumericValue().doubleValue();
origin: geotools/geotools

/**
 * Adjust the mappingName if needed. This may happen for some projections where different
 * standard parallels may require _1SP or _2SP suffix.
 *
 * @param the input netCDF mappingName
 * @param var the gridMapping variable
 * @return
 */
private static String getProjectionName(String mappingName, Variable var) {
  String projectionName = mappingName;
  if (mappingName.equalsIgnoreCase(CF.LAMBERT_CONFORMAL_CONIC)) {
    Attribute standardParallel = var.findAttribute(CF.STANDARD_PARALLEL);
    // special Management for multiple standard parallels to use
    // the proper projection
    projectionName =
        CF.LAMBERT_CONFORMAL_CONIC
            + (standardParallel.getLength() == 1 ? "_1SP" : "_2SP");
  } else if (mappingName.equalsIgnoreCase(CF.MERCATOR)) {
    Attribute standardParallel = var.findAttribute(CF.STANDARD_PARALLEL);
    projectionName = CF.MERCATOR + (standardParallel == null ? "_2SP" : "_1SP");
  }
  return projectionName;
}
origin: geotools/geotools

/**
 * Extract the {@link CoordinateReferenceSystem} from a NetCDF attribute (if present)
 * containing a WKT String
 *
 * @param wktAttribute the NetCDF {@link Attribute} if any, containing WKT definition.
 * @return
 */
private static CoordinateReferenceSystem parseWKT(Attribute wktAttribute) {
  CoordinateReferenceSystem crs = null;
  if (wktAttribute != null) {
    String wkt = wktAttribute.getStringValue();
    try {
      crs = CRS.parseWKT(wkt);
    } catch (FactoryException e) {
      if (LOGGER.isLoggable(Level.WARNING)) {
        LOGGER.warning("Unable to setup a CRS from the specified WKT: " + wkt);
      }
    }
  }
  return crs;
}
origin: geotools/geotools

/**
 * Get a {@link Variable} by name.
 *
 * @param varName the name of the {@link Variable} to pick.
 * @return the variable or <code>null</code>.
 */
public Variable getVariableByName(final String varName) {
  final List<Variable> varList = dataset.getVariables();
  for (Variable var : varList) {
    if (var.getFullName().equals(varName)) return var;
  }
  return null;
}
origin: geotools/geotools

/**
 * Get a proper {@link CRSParser} for the input Variable.
 *
 * @param var
 * @return
 */
public static NetCDFProjection.CRSParser getCRSParser(Variable var) {
  if (var != null) {
    Attribute attr = null;
    // check on crs related attributes which may contain a fully
    // defined WKT or a grid mapping reference
    if ((attr = var.findAttribute(NetCDFUtilities.CERP_ESRI_PE_STRING)) != null) {
      return new WKTCRSParser(attr);
    } else if ((attr = var.findAttribute(NetCDFUtilities.SPATIAL_REF)) != null) {
      return new WKTCRSParser(attr);
    } else if ((attr = var.findAttribute(NetCDFUtilities.GRID_MAPPING_NAME)) != null) {
      return new GridMappingCRSParser(attr);
    }
  }
  return null;
}
origin: geotools/geotools

/** @throws Exception */
private void initSlicesInfo() throws Exception {
  int[] shape = variableDS.getShape();
  numberOfSlices = 1;
  for (int i = 0; i < variableDS.getShape().length - 2; i++) {
    if (!ignoredDimensions.contains(variableDS.getDimension(i).getFullName())) {
      numberOfSlices *= shape[i];
    }
  }
}
origin: geotools/geotools

public Map<String, Integer> mapIndex(int[] splittedIndex) {
  Map<String, Integer> resultIndex = new HashMap<String, Integer>();
  for (int n = 0; n < splittedIndex.length; n++) {
    if (nDimensionIndex[n] != -1) {
      resultIndex.put(
          variableDS.getDimension(nDimensionIndex[n]).getFullName(),
          splittedIndex[n]);
    }
  }
  return resultIndex;
}
origin: geotools/geotools

/**
 * Returns the data type which most closely represents the "raw" internal data of the variable.
 * This is the value returned by the default implementation of {@link
 * NetcdfImageReader#getRawDataType}.
 *
 * @param variable The variable.
 * @return The data type, or {@link DataBuffer#TYPE_UNDEFINED} if unknown.
 * @see NetcdfImageReader#getRawDataType
 */
public static int getRawDataType(final VariableIF variable) {
  VariableDS ds = (VariableDS) variable;
  final DataType type;
  if (Boolean.getBoolean(ENHANCE_SCALE_MISSING)) {
    type = ds.getDataType();
  } else {
    type = ds.getOriginalDataType();
  }
  return transcodeNetCDFDataType(type, variable.isUnsigned());
}
origin: geotools/geotools

/**
 * Return the value of a particular dimension.
 *
 * @param dimensionIndex the index of the dimension
 * @return the value
 */
@SuppressWarnings("unchecked")
private <T> T getValueByIndex(int dimensionIndex, final Map<String, Integer> mappedIndex) {
  final Dimension dimension = variableDS.getDimension(dimensionIndex);
  return (T)
      reader.georeferencing
          .getCoordinateVariable(dimension.getFullName())
          .read(mappedIndex);
}
ucar.nc2

Most used classes

  • Variable
    A Variable is a logical container for data. It has a dataType, a set of Dimensions that define its a
  • Attribute
    An Attribute has a name and a value, used for associating arbitrary metadata with a Variable or a Gr
  • NetcdfFile
    Read-only scientific datasets that are accessible through the netCDF API. Immutable after setImmutab
  • Dimension
    A Dimension is used to define the array shape of a Variable. It may be shared among Variables, which
  • NetcdfDataset
  • NetcdfFileWriter,
  • Structure,
  • CoordinateAxis1D,
  • CoordinateAxis,
  • CalendarDate,
  • AxisType,
  • FeatureType,
  • VariableDS,
  • GridDatatype,
  • GridDataset,
  • CalendarDateFormatter,
  • DateRange,
  • DebugFlags,
  • EscapeStrings
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now