| 1 | import nixio |
| 2 | import numpy as np |
| 3 | from collections import OrderedDict |
| 4 | |
| 5 | |
| 6 | def main(): |
| 7 | nixfile = nixio.File.open("dataframe.nix", nixio.FileMode.Overwrite) |
| 8 | block = nixfile.create_block("test block", "recordingsession") |
| 9 | column_definitions = OrderedDict([('name', str), ('id', str), ('time', float), |
| 10 | ('amplitude', np.float64), ('frequency', np.float64)]) |
| 11 | |
| 12 | column_units = ["", "", "s", "mV", "Hz"] |
| 13 | column_data = [("alpha", nixio.util.create_id()[:10], 20.18, 5.0, 100), |
| 14 | ("beta", nixio.util.create_id()[:10], 20.09, 5.5, 101), |
| 15 | ("gamma", nixio.util.create_id()[:10], 20.05, 5.1, 100), |
| 16 | ("delta", nixio.util.create_id()[:10], 20.15, 5.3, 150), |
| 17 | ("epsilon", nixio.util.create_id()[:10], 20.23, 5.7, 200), |
| 18 | ("fi", nixio.util.create_id()[:10], 20.07, 5.2, 300), |
| 19 | ("zeta", nixio.util.create_id()[:10], 20.12, 5.1, 39), |
| 20 | ("eta", nixio.util.create_id()[:10], 20.27, 5.1, 600), |
| 21 | ("theta", nixio.util.create_id()[:10], 20.15, 5.6, 400), |
| 22 | ("iota", nixio.util.create_id()[:10], 20.08, 5.1, 200)] |
| 23 | |
| 24 | data_frame = block.create_data_frame("test data frame", "signal1", |
| 25 | data=column_data, col_dict=column_definitions) |
| 26 | data_frame.units = column_units |
| 27 | |
| 28 | data_frame.print_table() |
| 29 | |
| 30 | print("size, aka number of rows: ", data_frame.size) |
| 31 | print("column names: ", data_frame.column_names) |
| 32 | print("column definition: ", data_frame.columns) |
| 33 | print("column units: ", data_frame.units) |
| 34 | |
| 35 | print("single cell by position: ", data_frame.read_cell(position=(0, 0))) |
| 36 | print("single cell by name and row index: ", data_frame.read_cell(col_name="name", row_idx=[0])) |
| 37 | |
| 38 | print("Entire ID column: ", data_frame.read_columns(name="id")) |
| 39 | print("Two columns, id and name, joined: ", data_frame.read_columns(name=["id", "name"])) |
| 40 | |
| 41 | print("Entire rows with indices 0 and 2: ", data_frame.read_rows([0, 2])) |
| 42 | |
| 43 | nixfile.close() |
| 44 | |
| 45 | |
| 46 | if __name__ == "__main__": |
| 47 | main() |