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 TroubleshootCreate 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
Please refer to the API documentation to understand the schema and navigate through any errors: https://api-sandbox.ess-dive.lbl.gov
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.
To make sure your file is properly saved in the JSON-LD format, consider using the Atom text editor (https://atom.io)
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
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.
Remember to change the file directories & file names to your actual names. The directory variable can be left blank if your API is already located in the same directory as your file.
Many Data Files
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
Metadata and Data
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.
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
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