/** * Returns the names of all global attributes found in the file. * * @return names of all global attributes in the file. */ @Override public Collection<String> getAttributeNames() { return VariableWrapper.toNames(file.getGlobalAttributes()); }
for (Attribute attr : ncFile.getGlobalAttributes()) { Property property = resolveMetadataKey(attr.getFullName()); if (attr.getDataType().isString()) {
/** * Returns the names of all global attributes found in the file. * * @return names of all global attributes in the file. */ @Override public Collection<String> getAttributeNames() { return VariableWrapper.toNames(file.getGlobalAttributes()); }
public SeadasFileReader(SeadasProductReader productReader) { this.productReader = productReader; ncFile = productReader.getNcfile(); globalAttributes = ncFile.getGlobalAttributes(); }
public static NcAttributeMap create(NetcdfFile file) { return new NcAttributeMap(file.getGlobalAttributes()); }
private static Map<String, String> readGlobalAttributes(NetcdfFile ncFile) { List<Attribute> globalNcAttributes = ncFile.getGlobalAttributes(); Map<String, String> globalAttributes = new TreeMap<String, String>(); for (Attribute attribute : globalNcAttributes) { globalAttributes.put(attribute.getShortName().trim(), attribute.getStringValue().trim()); } return globalAttributes; }
metadata.set("File-Type-Description", ncFile.getFileTypeDescription()); for (Attribute attr : ncFile.getGlobalAttributes()) { Property property = resolveMetadataKey(attr.getFullName()); if (attr.getDataType().isString()) {
/** * Returns all the metadata related with the experiments as key-value pairs. * * @return */ public Metadata getMetadata(){ HashMap<String, String> globalAttr = new HashMap<String, String>(); for (Attribute attr: inputFile.getGlobalAttributes()) globalAttr.put(attr.getFullName(), attr.getStringValue()); return new Metadata(globalAttr); } }
private String getCollectionShortName() throws ProductIOException { List<Attribute> gattr = ncFile.getGlobalAttributes(); for (Attribute attr : gattr) { if (attr.getShortName().endsWith("Collection_Short_Name")) { return attr.getStringValue(); } } throw new ProductIOException("Cannot find collection short name"); }
public List getMetadata() throws Exception { if (!isRoot()) { return null; } if (attributeList != null) { return attributeList; } NC2File theFile = (NC2File) getFileFormat(); NetcdfFile ncFile = theFile.getNetcdfFile(); List netcdfAttributeList = ncFile.getGlobalAttributes(); if (netcdfAttributeList == null) { return null; } int n = netcdfAttributeList.size(); attributeList = new Vector(n); ucar.nc2.Attribute netcdfAttr = null; for (int i = 0; i < n; i++) { netcdfAttr = (ucar.nc2.Attribute) netcdfAttributeList.get(i); attributeList.add(NC2File.convertAttribute(netcdfAttr)); } return attributeList; }
public static void main(String args[]) throws Exception, IOException, InstantiationException, IllegalAccessException { //String fileIn = "/home/yuanho/dev/netcdf-java-2.2/src/ucar/nc2/n0r_20040823_2215"; // uncompressed String fileIn = "c:/data/image/gini/n0r_20041013_1852"; ucar.nc2.NetcdfFile.registerIOProvider(ucar.nc2.iosp.gini.Giniiosp.class); ucar.nc2.NetcdfFile ncf = ucar.nc2.NetcdfFile.open(fileIn); List alist = ncf.getGlobalAttributes(); ucar.nc2.Variable v = ncf.findVariable("BaseReflectivity"); int[] origin = {0, 0}; int[] shape = {3000, 4736}; ArrayByte data = (ArrayByte) v.read(origin, shape); ncf.close(); }
public static void readNetcdfMetadata(NetcdfFile netcdfFile, MetadataElement root, int maxNumValuesRead) { root.addElement(readAttributeList(netcdfFile.getGlobalAttributes(), GLOBAL_ATTRIBUTES)); root.addElement(readVariableDescriptions(netcdfFile.getVariables(), VARIABLE_ATTRIBUTES, maxNumValuesRead)); }
private void addMetadataToProduct() throws IOException { try { final MetadataElement origMetadataRoot = AbstractMetadata.addOriginalProductMetadata(product.getMetadataRoot()); NetCDFUtils.addAttributes(origMetadataRoot, NetcdfConstants.GLOBAL_ATTRIBUTES_NAME, netcdfFile.getGlobalAttributes()); addAuxXML(product); for (final Variable variable : variableMap.getAll()) { NetCDFUtils.addAttributes(origMetadataRoot, variable.getShortName(), variable.getAttributes()); } //final Group rootGroup = netcdfFile.getRootGroup(); //NetCDFUtils.addGroups(product.getMetadataRoot(), rootGroup); addAbstractedMetadataHeader(product, product.getMetadataRoot()); } catch (Exception e) { SystemUtils.LOG.severe("Error reading metadata for " + product.getName() + ": " + e.getMessage()); } }
@Override public void decode(ProfileReadContext ctx, Product p) throws IOException { GeoCoding geoCoding = readConventionBasedMapGeoCoding(ctx, p); if (geoCoding == null) { geoCoding = readPixelGeoCoding(p); } // If there is still no geocoding, check special case of netcdf file which was converted // from hdf file and has 'StructMetadata.n' element. // In this case, the HDF 'elements' were put into a single Netcdf String attribute // todo: in fact this has been checked only for MODIS09 HDF-EOS product. Try to further generalize if (geoCoding == null && hasHdfMetadataOrigin(ctx.getNetcdfFile().getGlobalAttributes())) { hdfDecode(ctx, p); } if (geoCoding != null) { p.setGeoCoding(geoCoding); } }
@Test @Category(NeedsCdmUnitTest.class) public void testResolver() throws IOException { String remoteDataset = TestOnLocalServer.withProtocolAndPath( "thredds:resolve:http", "catalog/gribCollection/GFS_CONUS_80km/latest.xml"); try (NetcdfFile ncd = NetcdfDataset.openFile(remoteDataset, null)) { List<Attribute> globalAttrs = ncd.getGlobalAttributes(); String testMessage = ""; for (Attribute attr : globalAttrs) { testMessage = testMessage + "\n" + attr; } logger.debug(testMessage); } } }
private void readGlobalMetaData(File inFile) throws IOException { netCDFAttributes = new NetCDFAttributes(); netCDFAttributes.add(netcdfFile.getGlobalAttributes()); netCDFVariables = new NetCDFVariables(); netCDFVariables.add(netcdfFile.getVariables()); // check wheter daac or imapp if (isImappFormat()) { globalAttributes = new ImappAttributes(inFile, netCDFVariables, netCDFAttributes); } else { globalAttributes = new DaacAttributes(netCDFVariables); } }
private void hdfDecode(ProfileReadContext ctx, Product p) throws IOException { final CfHdfEosGeoInfoExtractor cfHdfEosGeoInfoExtractor = new CfHdfEosGeoInfoExtractor( ctx.getNetcdfFile().getGlobalAttributes()); cfHdfEosGeoInfoExtractor.extractInfo(); String projection = cfHdfEosGeoInfoExtractor.getProjection(); double upperLeftLon = cfHdfEosGeoInfoExtractor.getUlLon(); double upperLeftLat = cfHdfEosGeoInfoExtractor.getUlLat(); double lowerRightLon = cfHdfEosGeoInfoExtractor.getLrLon(); double lowerRightLat = cfHdfEosGeoInfoExtractor.getLrLat(); HdfEosGeocodingPart.attachGeoCoding(p, upperLeftLon, upperLeftLat, lowerRightLon, lowerRightLat, projection, null); }
int sizeHeader(boolean largeFile) { int size = 4; // magic number size += 4; // numrecs // dims size += 8; // magic, ndims for (Dimension dim : ncfile.getDimensions()) size += sizeString(dim.getShortName()) + 4; // name, len // global attributes size += sizeAtts(ncfile.getGlobalAttributes()); // variables size += 8; // magic, nvars for (Variable var : ncfile.getVariables()) { size += sizeString(var.getShortName()); // dimensions size += 4; // ndims size += 4 * var.getDimensions().size(); // dim id // variable attributes size += sizeAtts(var.getAttributes()); size += 8; // data type, variable size size += (largeFile) ? 8 : 4; } return size; }
private void addMetadataToProduct() throws IOException { final MetadataElement origMetadataRoot = AbstractMetadata.addOriginalProductMetadata(product.getMetadataRoot()); NetCDFUtils.addAttributes(origMetadataRoot, NetcdfConstants.GLOBAL_ATTRIBUTES_NAME, netcdfFile.getGlobalAttributes()); addDeliveryNote(product); for (final Variable variable : variableMap.getAll()) { NetCDFUtils.addAttributes(origMetadataRoot, variable.getShortName(), variable.getAttributes()); } //final Group rootGroup = netcdfFile.getRootGroup(); //NetCDFUtils.addGroups(product.getMetadataRoot(), rootGroup); addAbstractedMetadataHeader(product, product.getMetadataRoot()); }
@Override public void decode(ProfileReadContext ctx, Product p) throws IOException { NetcdfFile ncFile = ctx.getNetcdfFile(); MetadataElement root = p.getMetadataRoot(); root.addElement(MetadataUtils.readAttributeList(ncFile.getGlobalAttributes(), "MPH")); MetadataElement eosElem = new MetadataElement("EOS"); createMDE(HdfEosUtils.STRUCT_METADATA, ctx, eosElem); createMDE(HdfEosUtils.CORE_METADATA, ctx, eosElem); createMDE(HdfEosUtils.ARCHIVE_METADATA, ctx, eosElem); root.addElement(eosElem); List<Variable> ncVariables = ncFile.getVariables(); filterVariableList(ncVariables); root.addElement(MetadataUtils.readVariableDescriptions(ncVariables, "DSD")); }