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"))
Neat Engine 2.0.3 loaded.
Success: Read UnverifiedDMSModel
We have now downloaded the CogniteCore
model, and need to run Neat
's verification on it
neat.verify()
Success: UnverifiedDMSModel → VerifiedDMSModel
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"])
Success: VerifiedDMSModel → VerifiedDMSModel
Next we will turn the CogniteCore
model into the basis for our new model Enterprise
model. This means
we are creating an extension from the CogniteCore
.
neat.prepare.data_model.to_enterprise(
data_model_id=("sp_doctrino_space", "ExtensionCore", "v1"), org_name="MyOrg", move_connections=True
)
Success: VerifiedDMSModel → VerifiedDMSModel
Note that we set move_connections=True
. This repeats all connections in the CogniteCore
model and updates the value type to match our new types.
We can show the results by using the show.data_model()
method.
neat.show.data_model()
http_purl.org_cognite_neat_data-model_verified_physical_sp_doctrino_space_ExtensionCore_v1.html
The new enterprise model is now ready. We can now publish it to CDF
neat.to.cdf.data_model()
You can inspect the details with the .inspect.outcome.data_model(...) method.
name | unchanged | |
---|---|---|
0 | spaces | 1 |
1 | containers | 11 |
2 | views | 11 |
3 | data_models | 1 |
4 | nodes | 0 |
Or we can dump it a spreadsheet and work on it from there.
neat.to.excel("my_extension.xlsx", include_reference=True)
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 Engine 2.0.3 loaded.
neat.read.excel("my_extension.xlsx")
Success: Read UnverifiedDMSModel
neat.verify()
Success: UnverifiedDMSModel → VerifiedDMSModel
neat.to.cdf.data_model(existing="force", drop_data=True)
You can inspect the details with the .inspect.outcome.data_model(...) method.
name | unchanged | changed | created | deleted | |
---|---|---|---|---|---|
0 | spaces | 1 | 0 | 0 | 0 |
1 | containers | 10 | 1 | 0 | 0 |
2 | views | 10 | 1 | 0 | 0 |
3 | data_models | 0 | 0 | 1 | 1 |
4 | nodes | 0 | 0 | 0 | 0 |
This new model is now published to CDF with the two extra properties
Deleted space []