The official Python library for Nortech AI.
You can install using pip:
pip install nortech
Or if you are using poetry:
poetry add nortech
Setup your environment variables with the CUSTOMER_API_TOKEN
provided to you:
export CUSTOMER_API_TOKEN="<CUSTOMER_API_TOKEN>"
To get a DataFrame with the requested signals:
- Go to your
Signal Search
interface. - Select the desired signals.
- Select the
DataTools
exported columns and copy the resultingsearch_json
. - Use the
search_json
and speficy aTimeWindow
as in the examples bellow.
In order to get a pandas DataFrame use the get_df
:
from datetime import datetime
from nortech.datatools import get_df, TimeWindow
search_json = """[
{
"name": "signal_1",
"dataType": "float",
"alias": 0,
"asset": {
"name": "asset_1"
},
"division": {
"name": "division_1"
},
"unit": {
"name": "unit_1"
},
"storage": {
"bucket": "nortech-test",
"path": "scope_1_group_0"
}
},
{
"name": "signal_2",
"dataType": "float",
"alias": 1,
"asset": {
"name": "asset_1"
},
"division": {
"name": "division_1"
},
"unit": {
"name": "unit_1"
},
"storage": {
"bucket": "nortech-test",
"path": "scope_1_group_0"
}
},
{
"name": "signal_3",
"dataType": "float",
"alias": 0,
"asset": {
"name": "asset_2"
},
"division": {
"name": "division_2"
},
"unit": {
"name": "unit_2"
},
"storage": {
"bucket": "nortech-test",
"path": "scope_1_group_1"
}
}
]"""
time_window = TimeWindow(
start=datetime(2020, 1, 1),
end=datetime(2020, 1, 5),
)
df = get_df(search_json=search_json, time_window=time_window)
assert list(df.columns) == [
'asset_1/division_1/unit_1/signal_1',
'asset_1/division_1/unit_1/signal_2',
'asset_2/division_2/unit_2/signal_3'
]
In order to get a polars DataFrame use the get_polars_df
:
from datetime import datetime
from nortech.datatools import get_polars_df, TimeWindow
search_json = """[
{
"name": "signal_1",
"dataType": "float",
"alias": 0,
"asset": {
"name": "asset_1"
},
"division": {
"name": "division_1"
},
"unit": {
"name": "unit_1"
},
"storage": {
"bucket": "nortech-test",
"path": "scope_1_group_0"
}
},
{
"name": "signal_2",
"dataType": "float",
"alias": 1,
"asset": {
"name": "asset_1"
},
"division": {
"name": "division_1"
},
"unit": {
"name": "unit_1"
},
"storage": {
"bucket": "nortech-test",
"path": "scope_1_group_0"
}
},
{
"name": "signal_3",
"dataType": "float",
"alias": 0,
"asset": {
"name": "asset_2"
},
"division": {
"name": "division_2"
},
"unit": {
"name": "unit_2"
},
"storage": {
"bucket": "nortech-test",
"path": "scope_1_group_1"
}
}
]"""
time_window = TimeWindow(
start=datetime(2020, 1, 1),
end=datetime(2020, 1, 5),
)
polars_df = get_polars_df(search_json=search_json, time_window=time_window)
assert polars_df.columns == [
'timestamp',
'asset_1/division_1/unit_1/signal_1',
'asset_1/division_1/unit_1/signal_2',
'asset_2/division_2/unit_2/signal_3'
]
In order to get a polars LazyFrame use the get_lazy_polars_df
:
from datetime import datetime
from nortech.datatools import get_lazy_polars_df, TimeWindow
search_json = """[
{
"name": "signal_1",
"dataType": "float",
"alias": 0,
"asset": {
"name": "asset_1"
},
"division": {
"name": "division_1"
},
"unit": {
"name": "unit_1"
},
"storage": {
"bucket": "nortech-test",
"path": "scope_1_group_0"
}
},
{
"name": "signal_2",
"dataType": "float",
"alias": 1,
"asset": {
"name": "asset_1"
},
"division": {
"name": "division_1"
},
"unit": {
"name": "unit_1"
},
"storage": {
"bucket": "nortech-test",
"path": "scope_1_group_0"
}
},
{
"name": "signal_3",
"dataType": "float",
"alias": 0,
"asset": {
"name": "asset_2"
},
"division": {
"name": "division_2"
},
"unit": {
"name": "unit_2"
},
"storage": {
"bucket": "nortech-test",
"path": "scope_1_group_1"
}
}
]"""
time_window = TimeWindow(
start=datetime(2020, 1, 1),
end=datetime(2020, 1, 5),
)
lazy_polars_df = get_lazy_polars_df(search_json=search_json, time_window=time_window)
assert lazy_polars_df.columns == [
'timestamp',
'asset_1/division_1/unit_1/signal_1',
'asset_1/division_1/unit_1/signal_2',
'asset_2/division_2/unit_2/signal_3'
]