Skip to content

Introduction to pyesdoc

Mark A. Greenslade edited this page Nov 14, 2018 · 1 revision

Installation

pip install pyesdoc

Setup

# Import library.
import pyesdoc

# Import cim v2 schema.
import pyesdoc.ontologies.cim.v2 as cim

Search

# 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')

Encoding

as_json = pyesdoc.encode(e, 'json')
assert isinstance(as_json, basestring)

as_xml = pyesdoc.encode(e, 'xml')
assert isinstance(as_xml, basestring)

Creation & Validation

# 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)

I/O

# Set file path.
FPATH = '~/1pctCO2.json'

# Write to file system.
pyesdoc.write(e, FPATH)

# Read from file system.
e = pyesdoc.read(FPATH)
Clone this wiki locally