For the complete documentation index, see llms.txt. This page is also available as Markdown.

Code Examples

Setup

The following code examples require installation of certain packages and authentication from your ESS-DIVE account. Follow the instructions for setting up the Dataset API for your preferred coding language before trying out the search code examples:

Setup and Troubleshoot

Create Metadata

The metadata example provided here is from the ESS-DIVE sandbox site: https://data-sandbox.ess-dive.lbl.gov/#view/doi:10.3334/CDIAC/spruce.001.

Format JSON-LD Metadata in Python

Setup the JSON for the “provider”, which includes details about the project. Simply update the "value" to use the desired project identifier, lookup project identifiers via ESS-DIVE's project list: https://data.ess-dive.lbl.gov/projects. The project will be listed as the publisher in the citation.

provider_spruce = {
    "identifier": {
        "@type": "PropertyValue",
        "propertyID": "ess-dive",
        "value": "1e6d50d3-9532-43fb-a63f-bdcb4350bf0c"
    }
 }

Prepare the dataset authors in the order that you would like them to appear in the citation. Please add the ORCID for all authors, especially the first author, if possible.

creators =  [
   {
     "@id": "http://orcid.org/0000-0001-7293-3561",
     "givenName": "Paul J",
     "familyName": "Hanson",
     "affiliation": "Oak Ridge National Laboratory",
     "email": "hansonpj@ornl.gov"
   },
   {
     "givenName": "Jeffrey",
     "familyName": "Riggs",
     "affiliation": "Oak Ridge National Laboratory"
   },
   {
     "givenName": "C",
     "familyName": "Nettles",
     "affiliation": "Oak Ridge National Laboratory"
   },
   {
     "givenName": "William",
     "familyName": "Dorrance",
     "affiliation": "Oak Ridge National Laboratory"
   },
   {
     "givenName": "Les",
     "familyName": "Hook",
     "affiliation": "Oak Ridge National Laboratory"
   }
 ]

Create the rest of the JSON-LD object

Format JSON-LD Metadata in R

Due to R complex JSON-LD support limitations, you need to create a text file of your JSON-LD and add it’s directory in the following read_file function.

Here’s an example for a JSON-LD file located on our ESS-DIVE package service examples github repository.

Download the file and load it into your script.

Format JSON-LD Metadata in Java

Setup the JSON definitions to build your JSON_LD.

Now fill the details about the “provider”. This is the details about the project. The project will be listed as the publisher in the citation.

Prepare the dataset authors in the order that you would like them to appear in the citation. Please add the ORCID for all authors, especially the first author, if possible.

Initialize JSON_LD strings

Add nested information in JSON_objects.

Create the rest of the JSON-LD object

Submit Dataset

The following lines of code submits and validates JSON-LD metadata for a single dataset.

Metadata Only

Submit Metadata Only in Python

Submit the JSON-LD object with the Dataset API

Submit Metadata Only in R

Submit the JSON-LD object with the Dataset API

Review the results

Submit Metadata Only in Java

Submit the JSON-LD object with the Dataset API

Single Data File

Submit Metadata and Single Data File in Python

To submit the JSON-LD object along with data files, you need to create a folder named files and add your desired file to upload inside it.

Submit Metadata and Single Data File in R

To submit the JSON-LD object along with data files, you need to create a folder named files and add your desired file to upload inside it.

Review the results

Submit Metadata and Single Data File in Java

To submit the JSON-LD object along with data files, you need to create a folder named files and add your desired file to upload inside it.

Many Data Files

Submit Metadata and Many Data Files in Python

In case you have many files to be uploaded, you can place them all inside the files directory and use the following code:

Submit Metadata and Many Data Files in R

See our Dataset API GitHub repository for a complete example in R.

Currently there are no examples of this available in Java.


Edit Dataset

Metadata Only

Edit Metadata in Python

Use the PUT function to update the metadata of a dataset. This example updates the name of a dataset.

Check the results for the changed metadata attribute

Edit Metadata in R

Use the PUT function to update the metadata of a dataset. This example updates the name of a dataset.

NOTE: The body argument is a string not a file.

Transform the result into a data frame. (Ignore the warning message)

Check the results for the changed metadata attribute

Edit Metadata in Java

Use the PUT function to update the metadata of a dataset. This example updates the name of a dataset.

Metadata and Data

Edit Metadata and Data in Python

Use the PUT function to update a dataset. This example updates the date published to 2019 of a dataset and adds a new data file.

Check the results for the changed metadata attribute and newly uploaded file

Edit Metadata and Data in R

Use the PUT function to update a dataset. This example updates the date published to 2019 of a dataset and adds a new data file.

NOTE: The body argument is a string not a file.

Transform the result into a data frame. (Ignore the warning message)

Check the results for the changed metadata attribute and newly uploaded file

Check for errors and view the data frame on success

Edit Metadata and Data in Java

Use the PUT function to update a dataset. This example updates the date published to 2019 of a dataset and adds a new data file.

Check the results for the changed metadata attribute and newly uploaded file

At the end of the document, don’t forget to close the class and main function blocks by adding two curly braces (}}) if you hadn’t done that already!

To compile the code and run it, make sure you’re on the parent directory where the essdive.java file is not inside the lib folder.

Now assuming Java is already installed on your machine, we will start by compiling the java code you wrote using the following terminal command:

javac -cp .:"lib/*" essdive.java

This will create a new file that has the compiled code where it can run using the following command:

java -cp .:"lib/*" essdive

Last updated