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 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.
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"}]
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.
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
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
Make sure to enter your own file path.
E.g. C:\\User\\Files\API_Tutorial.json for Windows & /Users/Files/API_Tutorial.json for Mac
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.
Remember to change the file directories & file names to your actual names. The directory variable can be left blank if yourAPI is already located in the same directory as your file.
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.
json_ld = {
"@context": "http://schema.org/",
"@type": "Dataset",
"@id": "http://dx.doi.org/10.3334/CDIAC/spruce.001",
"name": "SPRUCE S1 Bog Environmental Monitoring Data: 2010-2016",
"description": [
"This data set reports selected ambient environmental monitoring data from the S1 bog in Minnesota for the period June 2010 through December 2016. Measurements of the environmental conditions at these stations will serve as a pre-treatment baseline for experimental treatments and provide driver data for future modeling activities.",
"The site is the S1 bog, a Picea mariana [black spruce] - Sphagnum spp. bog forest in northern Minnesota, 40 km north of Grand Rapids, in the USDA Forest Service Marcell Experimental Forest (MEF). There are/were three monitoring sites located in the bog: Stations 1 and 2 are co-located at the southern end of the bog and Station 3 is located north central and adjacent to an existing U.S. Forest Service monitoring well.",
"There are eight data files with selected results of ambient environmental monitoring in the S1 bog for the period June 2010 through December 2016. One file has the ",
"other seven have the available data for a given calendar year. Not all measurements started in June 2010 and EM3 measurements ended in May 2014.",
"Further details about the data package are in the attached pdf file (SPRUCE_EM_DATA_2010_2016_20170620)."
],
"creator": creators,
"datePublished": "2015",
"keywords": [
"EARTH SCIENCE > BIOSPHERE > VEGETATION",
"Climate Change"
],
"variableMeasured": [
"EARTH SCIENCE > ATMOSPHERE > ATMOSPHERIC TEMPERATURE > SURFACE TEMPERATURE > AIR TEMPERATURE",
"EARTH SCIENCE > ATMOSPHERE > ATMOSPHERIC WATER VAPOR > WATER VAPOR INDICATORS > HUMIDITY > RELATIVE HUMIDITY",
"EARTH SCIENCE > ATMOSPHERE > ATMOSPHERIC PRESSURE > SEA LEVEL PRESSURE",
"EARTH SCIENCE > ATMOSPHERE > ATMOSPHERIC TEMPERATURE > SURFACE TEMPERATURE > DEW POINT TEMPERATURE > DEWPOINT DEPRESSION",
"EARTH SCIENCE > ATMOSPHERE > ATMOSPHERIC WINDS > SURFACE WINDS > WIND SPEED",
"EARTH SCIENCE > ATMOSPHERE > ATMOSPHERIC WINDS > SURFACE WINDS > WIND DIRECTION",
"EARTH SCIENCE > BIOSPHERE > VEGETATION > PHOTOSYNTHETICALLY ACTIVE RADIATION",
"EARTH SCIENCE > ATMOSPHERE > ATMOSPHERIC RADIATION > NET RADIATION",
"EARTH SCIENCE > LAND SURFACE > SURFACE RADIATIVE PROPERTIES > ALBEDO",
"EARTH SCIENCE > LAND SURFACE > SOILS > SOIL TEMPERATURE",
"Precipitation (Total)",
"Irradiance",
"Groundwater Temperature",
"Groundwater Level",
"Volumetric Water Content",
"surface_albedo"
],
"license": "http://creativecommons.org/licenses/by/4.0/",
"spatialCoverage": [
{
"description": "Site ID: S1 Bog Site name: S1 Bog, Marcell Experimental Forest Description: The site is the 8.1-ha S1 bog, a Picea mariana [black spruce] - Sphagnum spp. ombrotrophic bog forest in northern Minnesota, 40 km north of Grand Rapids, in the USDA Forest Service Marcell Experimental Forest (MEF). The S1 bog was harvested in successive strip cuts in 1969 and 1974 and the cut areas were allowed to naturally regenerate. Stations 1 and 2 are located in a 1974 strip that is characterized by a medium density of 3-5 meter black spruce and larch trees with an open canopy. The area was suitable for siting a monitoring station for representative meteorological conditions on the S1 bog. Station 3 is located in a 1969 harvest strip that is characterized by a higher density of 3-5 meter black spruce and larch trees with a generally closed canopy. Measurements at this station represent conditions in the surrounding stand. Site Photographs are in the attached document",
"geo": [
{
"name": "Northwest",
"latitude": 47.50285,
"longitude": -93.48283
},
{
"name": "Southeast",
"latitude": 47.50285,
"longitude": -93.48283
}
]
}
],
"funder": {
"@id": "http://dx.doi.org/10.13039/100006206",
"name": "U.S. DOE > Office of Science > Biological and Environmental Research (BER)"
},
"temporalCoverage": {
"startDate": "2010-07-16",
"endDate": "2016-12-31"
},
"editor": {
"@id": "http://orcid.org/0000-0001-7293-3561",
"givenName": "Paul J",
"familyName": "Hanson",
"email": "[email protected]"
},
"provider": provider_spruce,
"measurementTechnique": [
"The stations are equipped with standard sensors for measuring meteorological parameters, solar radiation, soil temperature and moisture, and groundwater temperature and elevation. Note that some sensor locations are relative to nearby vegetation and bog microtopographic features (i.e., hollows and hummocks). See Table 1 in the attached pdf (SPRUCE_EM_DATA_2010_2016_20170620) for a list of measurements and further details. Sensors and data loggers were initially installed and became operational in June, July, and August of 2010. Additional sensors were added in September 2011. Station 3 was removed from service on May 12, 2014.",
"These data are considered at Quality Level 1. Level 1 indicates an internally consistent data product that has been subjected to quality checks and data management procedures. Established calibration procedures were followed."
]
}
//JSON objects variables
JSONObject provider_spruce_json = new JSONObject();
JSONObject member = new JSONObject();
JSONObject funder = new JSONObject();
JSONObject temporalCoverage = new JSONObject();
JSONObject editor = new JSONObject();
JSONObject spatial_coverage_json = new JSONObject();
JSONObject primary_Creator = new JSONObject();
JSONObject secondary_Creator = new JSONObject();
JSONObject geo_northwest = new JSONObject();
JSONObject geo_southeast = new JSONObject();
JSONObject JSON_LD = new JSONObject();
JSONArray creators_json = new JSONArray();
JSONArray spatial_coverage_array = new JSONArray();
JSONArray geo = new JSONArray();
JSONArray measurementTechnique = new JSONArray();
JSONArray JSON_LD_Description = new JSONArray();
JSONArray keywords = new JSONArray();
JSONArray variableMeasured = new JSONArray();
// JSON_LD primary creator assignment
primary_Creator.put("@id","http://orcid.org/0000-0001-7293-3561");
primary_Creator.put("givenName","Paul J");
primary_Creator.put("familyName","Hanson");
primary_Creator.put("affiliation","Oak Ridge National Laboratory");
primary_Creator.put("email","[email protected]");
// JSON_LD secondary creator assignment
secondary_Creator.put("givenName","Jeffrey");
secondary_Creator.put("familyName","Riggs");
secondary_Creator.put("affiliation","Oak Ridge National Laboratory");
// Define as many creators as you need into newer JSON Objects and add them to the creators_json_array
creators_json.add(primary_Creator);
creators_json.add(secondary_Creator);
// JSON_LD Strings arrays
variableMeasured.add("EARTH SCIENCE > ATMOSPHERE > ATMOSPHERIC TEMPERATURE > SURFACE TEMPERATURE > AIR TEMPERATURE");
variableMeasured.add("EARTH SCIENCE > ATMOSPHERE > ATMOSPHERIC WATER VAPOR > WATER VAPOR INDICATORS > HUMIDITY > RELATIVE HUMIDITY");
variableMeasured.add("EARTH SCIENCE > ATMOSPHERE > ATMOSPHERIC PRESSURE > SEA LEVEL PRESSURE");
variableMeasured.add("EARTH SCIENCE > ATMOSPHERE > ATMOSPHERIC TEMPERATURE > SURFACE TEMPERATURE > DEW POINT TEMPERATURE > DEWPOINT DEPRESSION");
variableMeasured.add("EARTH SCIENCE > ATMOSPHERE > ATMOSPHERIC WINDS > SURFACE WINDS > WIND SPEED");
variableMeasured.add("EARTH SCIENCE > ATMOSPHERE > ATMOSPHERIC WINDS > SURFACE WINDS > WIND DIRECTION");
variableMeasured.add("EARTH SCIENCE > BIOSPHERE > VEGETATION > PHOTOSYNTHETICALLY ACTIVE RADIATION");
variableMeasured.add("EARTH SCIENCE > ATMOSPHERE > ATMOSPHERIC RADIATION > NET RADIATION");
variableMeasured.add("EARTH SCIENCE > LAND SURFACE > SURFACE RADIATIVE PROPERTIES > ALBEDO");
variableMeasured.add("EARTH SCIENCE > LAND SURFACE > SOILS > SOIL TEMPERATURE");
variableMeasured.add("Precipitation (Total)");
variableMeasured.add("Irradiance");
variableMeasured.add("Groundwater Temperature");
variableMeasured.add("Groundwater Level");
variableMeasured.add("Volumetric Water Content");
variableMeasured.add("surface_albedo");
measurementTechnique.add("The stations are equipped with standard sensors for measuring meteorological parameters, solar radiation, soil temperature and moisture, and groundwater temperature and elevation. Note that some sensor locations are relative to nearby vegetation and bog microtopographic features (i.e., hollows and hummocks). See Table 1 in the attached pdf (SPRUCE_EM_DATA_2010_2016_20170620) for a list of measurements and further details. Sensors and data loggers were initially installed and became operational in June, July, and August of 2010. Additional sensors were added in September 2011. Station 3 was removed from service on May 12, 2014.");
measurementTechnique.add("These data are considered at Quality Level 1. Level 1 indicates an internally consistent data product that has been subjected to quality checks and data management procedures. Established calibration procedures were followed.");
JSON_LD_Description.add("This data set reports selected ambient environmental monitoring data from the S1 bog in Minnesota for the period June 2010 through December 2016. Measurements of the environmental conditions at these stations will serve as a pre-treatment baseline for experimental treatments and provide driver data for future modeling activities.");
JSON_LD_Description.add("The site is the S1 bog, a Picea mariana [black spruce] - Sphagnum spp. bog forest in northern Minnesota, 40 km north of Grand Rapids, in the USDA Forest Service Marcell Experimental Forest (MEF). There are/were three monitoring sites located in the bog: Stations 1 and 2 are co-located at the southern end of the bog and Station 3 is located north central and adjacent to an existing U.S. Forest Service monitoring well.");
JSON_LD_Description.add("There are eight data files with selected results of ambient environmental monitoring in the S1 bog for the period June 2010 through December 2016. One file has the ");
JSON_LD_Description.add("other seven have the available data for a given calendar year. Not all measurements started in June 2010 and EM3 measurements ended in May 2014.");
JSON_LD_Description.add("Further details about the data package are in the attached pdf file (SPRUCE_EM_DATA_2010_2016_20170620).");
keywords.add("EARTH SCIENCE > BIOSPHERE > VEGETATION");
keywords.add("Climate Change");
// JSON_LD spatial coverage assignment
spatial_coverage_json.put("description","Site ID: S1 Bog Site name: S1 Bog, Marcell Experimental Forest Description: The site is the 8.1-ha S1 bog, a Picea mariana [black spruce] - Sphagnum spp. ombrotrophic bog forest in northern Minnesota, 40 km north of Grand Rapids, in the USDA Forest Service Marcell Experimental Forest (MEF). The S1 bog was harvested in successive strip cuts in 1969 and 1974 and the cut areas were allowed to naturally regenerate. Stations 1 and 2 are located in a 1974 strip that is characterized by a medium density of 3-5 meter black spruce and larch trees with an open canopy. The area was suitable for siting a monitoring station for representative meteorological conditions on the S1 bog. Station 3 is located in a 1969 harvest strip that is characterized by a higher density of 3-5 meter black spruce and larch trees with a generally closed canopy. Measurements at this station represent conditions in the surrounding stand. Site Photographs are in the attached document");
spatial_coverage_json.put("geo", geo);
spatial_coverage_array.add(spatial_coverage_json);
// JSON_LD funder assignment
funder.put("@id", "http://dx.doi.org/10.13039/100006206");
funder.put("name", "U.S. DOE > Office of Science > Biological and Environmental Research (BER)");
// JSON_LD temporalCoverage assignment
temporalCoverage.put("startDate","2010-07-16");
temporalCoverage.put("endDate","2016-12-31");
// JSON_LD editor assignment
editor.put("@id", "http://orcid.org/0000-0001-7293-3561");
editor.put("givenName", "Paul J");
editor.put("familyName", "Hanson");
editor.put("email", "[email protected]");
// JSON_LD geo variables assignments
geo_northwest.put("name","Northwest");
geo_northwest.put("latitude",47.50285);
geo_northwest.put("longitude",-93.48283);
geo_southeast.put("name","Southeast");
geo_southeast.put("latitude",47.50285);
geo_southeast.put("longitude",-93.48283);
geo.add(geo_northwest);
geo.add(geo_southeast);
# Check for errors
if put_package_response.status_code == 200:
# Success
response=put_package_response.json()
print(f"View URL:{response['viewUrl']}")
print(f"Name:{response['dataset']['name']}")
else:
# There was an error
print(put_package_response.text)
# Check for errors
if put_package_response.status_code == 200:
# Success
response=put_package_response.json()
print(f"View URL:{response['viewUrl']}")
print(f"Date Published:{response['dataset']['datePublished']}")
print(f"Files In Dataset:{response['dataset']['distribution']}")
else:
# There was an error
print(put_package_response.text)
get_packages_url = "{}{}".format(base,endpoint)
get_packages_response = requests.get(get_packages_url,
headers={"Authorization":header_authorization})
if get_packages_response.status_code == 200:
#Success
print(get_packages_response.json())
else:
# There was an error
print(get_packages_response.text)