Extending Data Model¶
Prerequisite:
- Access to a CDF Project.
- Know how to install and setup Python.
- Launch a Python notebook.
In this tutorial, we will show you how to extend a data model using the CogniteCore
model as an example.
Creating the Base Model¶
The CogniteCore
model is an immutable model versioned by Cognite
. To extend this model we first create a copy of it
in our own space, such that we can start to do modifications to it.
from cognite.neat import NeatSession, get_cognite_client
client = get_cognite_client(".env")
Found .env file in repository root. Loaded variables from .env file.
neat = NeatSession(client, verbose=True)
neat.read.cdf.data_model(("cdf_cdm", "CogniteCore", "v1"))
CDF <class 'tuple'> ('cdf_cdm', 'CogniteCore', 'v1') read successfully
'No issues found'
We have now downloaded the CogniteCore
model, and need to run Neat
's verification on it
issues = neat.verify()
The CogniteCore
model consists of 33 views, including views for 3D, Annotation, as well as several views that are used as interfaces.
We simpliy the core model by dropping these views.
neat.prepare.data_model.reduce(drop=["3D", "Annotation", "BaseViews"])
Next we will turn the CogniteCore
model into the basis for our new model ExtensionCore
neat.prepare.data_model.to_extension(new_data_model_id=("sp_doctrino_space", "ExtensionCore", "v1"), prefix="MyOrg")
The new base model is now ready. We can now directly publish it to CDF
neat.to.cdf.data_model()
name | created | |
---|---|---|
0 | spaces | 1.0 |
1 | containers | NaN |
2 | views | 11.0 |
3 | data_models | 1.0 |
Or we can dump it a spreadsheet and work on it from there.
neat.to.excel("my_extension.xlsx")
Adding New Properties¶
In the spreadsheet, we have added the two properties location
and subLocation
to the Asset
view. In addition, we have added our on container myContainer
in the container sheet.
We start a new NeatSession
to load this new model publish it to CDF
neat = NeatSession(client)
neat.read.excel("my_extension.xlsx")
Excel <class 'str'> my_extension.xlsx read successfully
'No issues found'
neat.verify()
'No issues found'
neat.to.cdf.data_model()
name | created | |
---|---|---|
0 | spaces | 1 |
1 | containers | 1 |
2 | views | 11 |
3 | data_models | 1 |
This new model is now published to CDF with the two extra properties