/nortech-python

The official Python library for Nortech AI

Primary LanguagePythonApache License 2.0Apache-2.0

nortech-python

The official Python library for Nortech AI.

Install

You can install using pip:

pip install nortech

Or if you are using poetry:

poetry add nortech

nortech.datatools

Config

Setup your environment variables with the CUSTOMER_API_TOKEN provided to you:

export CUSTOMER_API_TOKEN="<CUSTOMER_API_TOKEN>"

Examples

To get a DataFrame with the requested signals:

  1. Go to your Signal Search interface.
  2. Select the desired signals.
  3. Select the DataTools exported columns and copy the resulting search_json.
  4. Use the search_json and speficy a TimeWindow as in the examples bellow.
Pandas DataFrame

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'
]
Polars DataFrame

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'
]
Polars LazyFrame

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'
]