Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISO xml without THREDDs #58

Open
theobarnhart-USGS opened this issue Nov 5, 2021 · 12 comments
Open

ISO xml without THREDDs #58

theobarnhart-USGS opened this issue Nov 5, 2021 · 12 comments

Comments

@theobarnhart-USGS
Copy link

Is there a way to generate an ISO metadata xml file from a ncml and/or a netCDF file without access to a THREDDs server? For example, I have several hundred CF-compliant netCDF files on a HPC that I would like to publish, but the repository requires an ISO metadata file for each file.

Thank you!

@desruisseaux
Copy link

While waiting for an answer from THREDDs experts, just note that it is possible to do that with a combination of Unidata UCAR library + Apache SIS (Java code) as a fallback. I will let experts said if there is a pure THREDDs solution (it would guarantee to provide the exact same metadata), if not I can provide more details.

@theobarnhart-USGS
Copy link
Author

Thank you @desruisseaux, could you please expand on that a bit? Ideally, I would like to generate ISO xml metadata from the netCDF files without having to move them to a THREDDs server.

@zdefne-usgs
Copy link

zdefne-usgs commented Nov 5, 2021

@DennisHeimbigner
Copy link

There is an option to the ncdump program in the netcdf-c library.

-x
Output XML (NcML) instead of CDL. The NcML does not include data values.
The NcML output option currently only works for netCDF classic model data.

It is seriously out-of-date and would presumably need extension to whatever features of netcdf-4 that you use.

@theobarnhart-USGS
Copy link
Author

Thanks @DennisHeimbigner , I've used that and successfully produced a ncml file; however, I have not been able to successfully validate that file against ISO 19115. I could be very wrong, but I think ncml is different from ISO xml metadata.

@theobarnhart-USGS
Copy link
Author

@zdefne-usgs Thanks, I saw that; however, it only functions if the data are on a THREDDs server, which I do not have.

@DennisHeimbigner
Copy link

How close is ISO metadata XML elements to ncml?

@zdefne-usgs
Copy link

Have you tried pointing to a local folder instead of a URL? You can download the JAR file here.

@zdefne-usgs Thanks, I saw that; however, it only functions if the data are on a THREDDs server, which I do not have.

@theobarnhart-USGS
Copy link
Author

I have not tried that yet but I can next week. My understanding is that the ncISO tool needs the THREDDs server to fill in some of the ISO metadata that is not captured in the ncml. NOAA-PMEL/uafnciso#20

@ethanrd
Copy link
Member

ethanrd commented Nov 5, 2021

I seem to recall some discussion of a stand-alone, command line tool for some aspect of ncISO but not sure about the details. Perhaps @noaaroland or @kevin-obrien have some thoughts on this.

@geoneubie
Copy link
Contributor

geoneubie commented Nov 5, 2021 via email

@desruisseaux
Copy link

Hello @theobarnhart-USGS

You can use the following. It uses the UCAR library for opening netCDF and ncml files and querying their attributes. Then those information are assembled in Java objects and marshalled by Apache SIS. You can create a Maven project with the following dependencies:

<project>
  <!-- Standard Maven verbiage omitted on this line for brevity -->
  <dependencies>
    <dependency>
      <groupId>org.apache.sis.storage</groupId>
      <artifactId>sis-netcdf</artifactId>
      <version>1.1</version>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jaxb</groupId>
      <artifactId>jaxb-runtime</artifactId>
      <version>2.3.3</version>
    </dependency>
    <dependency>
      <groupId>edu.ucar</groupId>
      <artifactId>cdm-core</artifactId>
      <version>5.4.2</version>
    </dependency>
  </dependencies>
  <repositories>
    <repository>
      <id>UCAR</id>
      <name>UCAR repository</name>
      <url>https://artifacts.unidata.ucar.edu/repository/unidata-releases</url>
    </repository>
  </repositories>
</project>

And following Java code (replace "GEBCO_2020.bc" by the path to the file to open):

import java.io.File;
import java.util.Map;
import javax.xml.transform.stream.StreamResult;
import org.apache.sis.storage.DataStore;
import org.apache.sis.storage.DataStores;
import org.apache.sis.xml.XML;
import org.opengis.metadata.Metadata;

public class Test {
    public static void main(String[] args) throws Exception {
        try (DataStore ds = DataStores.open(new File("GEBCO_2020.nc"))) {
            Metadata md = ds.getMetadata();

            // Quick look
            System.out.println(md);

            // ISO 19115-3 by default
            String xml = XML.marshal(md);
            System.out.println(xml);

            // ISO 19139:2007 (not nicely formatted)
            XML.marshal(md, new StreamResult(System.out), Map.of(XML.METADATA_VERSION, "2007"));
        }
    }
}

It works for GeoTIFF as well (with some more modules added in Maven dependencies). It is possible to query and modify the metadata in Java code if desired. Read-only example (writing is possible but require an extra-step):

Identification info = md.getIdentificationInfo().iterator().next();
Citation citation = info.getCitation();
InternationalString title = citation.getTitle();
System.out.println(title);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants