def _get_document(self, doc_uid, doc_type, row, mappings): """Returns a CIM document from a spreadsheet row. """ # Create document. doc = pyesdoc.create(doc_type, project=_DOC_PROJECT, source=_DOC_SOURCE, version=1, uid=doc_uid) # Assign document dates. try: doc.meta except AttributeError: pass else: doc.meta.create_date = _DOC_CREATE_DATE doc.meta.update_date = _DOC_UPDATE_DATE # Assign document author. try: doc.meta.author = _DOC_AUTHOR_REFERENCE except AttributeError: pass # Set document attributes from mapped worksheet cells. for mapping in mappings: self._set_document_attribute(doc, row, mapping) return doc
def _create_doc(ontology=_CIM, version=_CIM_V1, package=_CIM_PACKAGE, typeof=_CIM_TYPE): """Creates a test document.""" type_key = ".".join([ontology, version, package, typeof]) return pyesdoc.create(type_key, _INSTITUTE, _PROJECT)
def _set_test_document(): """Returns a test document. """ global _DOC _DOC = pyesdoc.create( cim.v2.NumericalExperiment, project="test-project", source="unit-test") _DOC.canonical_name = "anexp" _DOC.name = "an experiment" _DOC.long_name = "yet another experiment" _DOC.rationale = "to state the bleeding obvious" _DOC.meta.id = unicode(_DOC.meta.id) _DOC.meta.version += 1 _DOC.required_period = pyesdoc.create( cim.v2.TemporalConstraint, project="test-project", source="unit-test") _DOC.required_period.is_conformance_requested = False _DOC.required_period.meta.id = unicode(_DOC.required_period.meta.id) _DOC.required_period.name = "too long" pyesdoc.extend(_DOC)
def _map_realm(specialization, accessor): """Maps a specialization to a realm. """ r = pyesdoc.create(cim.Realm, project='CMIP6', source='spreadsheet', version=1) r.description = specialization.description or specialization.name_camel_case_spaced r.name = specialization.name_camel_case_spaced r.specialization_id = specialization.id r.key_properties = _map_topic(specialization['keyprops'], accessor) r.grid = _map_topic(specialization['grid'], accessor) r.processes = _map_topics(specialization['process'], accessor) return r if (r.key_properties or r.grid or r.processes) else None
def _map_model(i, s, accessors): """Returns a mapped model CIM document. """ m = pyesdoc.create(cim.Model, project='CMIP6', source='spreadsheet', version=1, institute=i.canonical_name) m.activity_properties = _map_model_activity_properties(accessors) or [] m.canonical_id = s.canonical_name m.key_properties = _map_model_key_properties(accessors) m.model_type = 'GCM' m.name = s.canonical_name.upper() m.realms = _map_realms(accessors) return m if (m.activity_properties or m.key_properties or m.realms) else None
def init_machine_cim(set_partition=False, two_compute_pools=True, two_storage_pools=True, online_docs_given=True): """Initialise the CIM document for a CMIP6 Machine. Only up to two compute pools and storage pools may be specified. """ kwargs = { "project": "CMIP6", "source": "spreadsheet", "version": 1, "institute": INSTITUTE } # Define the overall document which will be populated below machine_cim = pyesdoc.create(cim.Machine, **kwargs) # Connect the first-level properties to the top-level machine document if set_partition: machine_cim.partition = pyesdoc.create(cim.Partition, **kwargs) # TODO: list of given length, for now groups have all given len 1 answer if online_docs_given: machine_cim.online_documentation = [pyesdoc.create(cim.OnlineResource)] # Add pools based on the number required (max. two based on spreadsheet): if two_compute_pools: machine_cim.compute_pools = [ pyesdoc.create(cim.ComputePool, **kwargs), pyesdoc.create(cim.ComputePool, **kwargs) ] else: machine_cim.compute_pools = [pyesdoc.create(cim.ComputePool, **kwargs)] if two_storage_pools: machine_cim.storage_pools = [ pyesdoc.create(cim.StoragePool, **kwargs), pyesdoc.create(cim.StoragePool, **kwargs) ] else: machine_cim.storage_pools = [ pyesdoc.create(cim.StoragePool, **kwargs), ] return machine_cim
def _map_model(i, s, accessors): """Returns a mapped model CIM document. """ m = pyesdoc.create(cim.Model, project='CMIP6', source='spreadsheet', version=1, institute=i.canonical_name) m.activity_properties = _map_model_activity_properties(accessors) or [] m.canonical_id = s.canonical_name m.key_properties = _map_model_key_properties(accessors) m.model_type = _map_model_type(i, s) m.name = s.canonical_name.upper() m.realms = _map_realms(accessors) return m if (m.activity_properties or m.key_properties or m.realms) else None
_WS_MULTI_ENSEMBLE, _WS_START_DATE_ENSEMBLE, _WS_CITATIONS, _WS_PARTY, _WS_URL ] # Default document project code. _DOC_PROJECT = 'CMIP6-DRAFT' # Default document source. _DOC_SOURCE = 'spreadsheet' # Default document author. _DOC_AUTHOR = pyesdoc.create(cim.v2.Party, source=_DOC_SOURCE, uid=u'253825f3-fbc8-43fb-b1f6-cc575dc693eb', version=1) _DOC_AUTHOR.email = u"*****@*****.**" _DOC_AUTHOR.name = u"Charlotte Pascoe" # Default document author reference. _DOC_AUTHOR_REFERENCE = cim.v2.DocReference() _DOC_AUTHOR_REFERENCE.uid = _DOC_AUTHOR.meta.id _DOC_AUTHOR_REFERENCE.version = _DOC_AUTHOR.meta.version # Default document create / update dates. _DOC_CREATE_DATE = dt.strptime("2016-07-04 13:00:00", "%Y-%m-%d %H:%M:%S") _DOC_UPDATE_DATE = _DOC_CREATE_DATE
:synopsis: Executes pyesdoc non-ascii document content tests. .. moduleauthor:: Earth System Documentation (ES-DOC) <*****@*****.**> """ # Module imports. import pyesdoc import pyesdoc.ontologies.cim as cim import test_utils as tu import test_types as tt # Create test model component. _MODEL = pyesdoc.create(cim.v1.ModelComponent, "cmip5", "mohc") _MODEL.long_name = "Atmosphere" _MODEL.short_name = "Atmosphere" _MODEL.type = "model" def _get_description(text_type): """Returns model description with non-ascii characters.""" if text_type == str: return ("{AS PARENT with differences as indicated}\r\n" "The horizontal resolution is 0.44\xc2\xb0 x 0.44\xc2\xb0, which gives " "a minimum resolution of ~50 km at the Equator of the rotated " "grid. Due to its fine resolution, the model requires a timestep " "of 5 minutes to maintain numerical stability." ) elif text_type == unicode:
def _test_create_03(): """Test creating documents - 3.""" for doc_type in pyesdoc.get_types(): doc = pyesdoc.create(doc_type, _INSTITUTE, _PROJECT) _assert_doc(doc, doc_type)
:license: GPL / CeCILL :platform: Unix, Windows :synopsis: Executes pyesdoc non-ascii document content tests. .. moduleauthor:: Earth System Documentation (ES-DOC) <*****@*****.**> """ # Module imports. import pyesdoc import pyesdoc.ontologies.cim as cim import test_utils as tu import test_types as tt # Create test model component. _MODEL = pyesdoc.create(cim.v1.ModelComponent, "cmip5", "mohc") _MODEL.long_name = "Atmosphere" _MODEL.short_name = "Atmosphere" _MODEL.type = "model" def _get_description(text_type): """Returns model description with non-ascii characters.""" if text_type == str: return ( "{AS PARENT with differences as indicated}\r\n" "The horizontal resolution is 0.44\xc2\xb0 x 0.44\xc2\xb0, which gives " "a minimum resolution of ~50 km at the Equator of the rotated " "grid. Due to its fine resolution, the model requires a timestep " "of 5 minutes to maintain numerical stability.") elif text_type == unicode:
def _test_create_02(): """Test creating documents - 3.""" for doc_type in pyesdoc.get_types(): doc = pyesdoc.create(doc_type, institute=_INSTITUTE, project=_PROJECT) _assert_doc(doc, doc_type)
def _create_doc(doc_type=cim.v1.ModelComponent): """Creates a test document.""" return pyesdoc.create(doc_type, _INSTITUTE, _PROJECT)