-
Notifications
You must be signed in to change notification settings - Fork 5
Introduction to pyesdoc
Mark A. Greenslade edited this page Nov 14, 2018
·
1 revision
pip install pyesdoc
# Import library.
import pyesdoc
# Import cim v2 schema.
import pyesdoc.ontologies.cim.v2 as cim
# Search remote archive: CMIP6 experiments.
experiments = pyesdoc.search('cmip6', 'experiment')
# Search result is iterable.
for i in experiments:
print i.name
# Load a document from remote archive.
e = experiments.load_document('1pctCO2')
as_json = pyesdoc.encode(e, 'json')
assert isinstance(as_json, basestring)
as_xml = pyesdoc.encode(e, 'xml')
assert isinstance(as_xml, basestring)
# Is a document valid or not.
pyesdoc.is_valid(e)
# Get validation errors.
pyesdoc.validate(e)
# Temporal constraint information is missing.
tc = pyesdoc.create(cim.TemporalConstraint, 'cmip6')
tc.description = 'Historical, pre-Industrial to present'
tc.name = '1850-2014 165yrs'
tc.canonical_name = '165yrs1850-2014'
tc.is_conformance_info_required = False
tc.is_conformance_requested = True
# Update experiment.
e.required_period = tc
# Revalidate
pyesdoc.is_valid(e)
# Set file path.
FPATH = '~/1pctCO2.json'
# Write to file system.
pyesdoc.write(e, FPATH)
# Read from file system.
e = pyesdoc.read(FPATH)