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": "[email protected]"
   },
   {
     "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

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

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.

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:


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

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

Last updated