|
| 1 | +"""Import an HDF5 file with the one-dimensional schema into Sift. |
| 2 | +
|
| 3 | +In this layout, each value channel is its own 1D dataset that pairs with a |
| 4 | +time dataset in the same group (or an ancestor group's time dataset, walking |
| 5 | +up to the root). Channel name, units, and description are read from the |
| 6 | +dataset's attributes when present. |
| 7 | +""" |
| 8 | + |
| 9 | +import os |
| 10 | + |
| 11 | +from dotenv import load_dotenv |
| 12 | +from sift_client import SiftClient |
| 13 | +from sift_client.sift_types.data_import import DataTypeKey |
| 14 | + |
| 15 | +if __name__ == "__main__": |
| 16 | + load_dotenv() |
| 17 | + |
| 18 | + grpc_uri = os.getenv("SIFT_GRPC_URI") |
| 19 | + assert grpc_uri, "expected 'SIFT_GRPC_URI' environment variable to be set" |
| 20 | + |
| 21 | + rest_uri = os.getenv("SIFT_REST_URI") |
| 22 | + assert rest_uri, "expected 'SIFT_REST_URI' environment variable to be set" |
| 23 | + |
| 24 | + apikey = os.getenv("SIFT_API_KEY") |
| 25 | + assert apikey, "expected 'SIFT_API_KEY' environment variable to be set" |
| 26 | + |
| 27 | + asset_name = os.getenv("ASSET_NAME") |
| 28 | + assert asset_name, "expected 'ASSET_NAME' environment variable to be set" |
| 29 | + |
| 30 | + client = SiftClient(api_key=apikey, grpc_url=grpc_uri, rest_url=rest_uri) |
| 31 | + |
| 32 | + # Auto-detect the config and import the file. HDF5 requires the layout |
| 33 | + # (data_type) to be specified since the extension alone is ambiguous. |
| 34 | + # HDF5 timestamps aren't self-describing, so time_format defaults to |
| 35 | + # TimeFormat.ABSOLUTE_UNIX_NANOSECONDS; override it if your timestamps |
| 36 | + # are in a different format. |
| 37 | + import_job = client.data_import.import_from_path( |
| 38 | + "sample_data.h5", |
| 39 | + asset=asset_name, |
| 40 | + data_type=DataTypeKey.HDF5_ONE_D, |
| 41 | + ) |
| 42 | + |
| 43 | + import_job.wait_until_complete() |
| 44 | + |
| 45 | + # If auto-detect doesn't quite match your file, inspect the config and patch |
| 46 | + # it before importing. Common fixes: change the time format, override a |
| 47 | + # channel's data type, or drop a channel that shouldn't be imported. |
| 48 | + # |
| 49 | + # from sift_client.sift_types.data_import import TimeFormat |
| 50 | + # |
| 51 | + # config = client.data_import.detect_config( |
| 52 | + # "sample_data.h5", |
| 53 | + # data_type=DataTypeKey.HDF5_ONE_D, |
| 54 | + # ) |
| 55 | + # print(config) # inspect what was auto-detected |
| 56 | + # |
| 57 | + # # Example: timestamps are ISO-8601 strings instead of unix nanoseconds |
| 58 | + # config.time_format = TimeFormat.ABSOLUTE_DATETIME |
| 59 | + # |
| 60 | + # # Example: drop a channel from the import |
| 61 | + # config.data = [d for d in config.data if d.name != "channel_0"] |
| 62 | + # |
| 63 | + # import_job = client.data_import.import_from_path( |
| 64 | + # "sample_data.h5", |
| 65 | + # asset=asset_name, |
| 66 | + # config=config, |
| 67 | + # ) |
| 68 | + # import_job.wait_until_complete() |
0 commit comments