3@brief Python script providing the SDDS Python module.
5This module provides the `SDDS` class and associated methods to load, manipulate, and save SDDS files.
6It supports both ASCII and binary SDDS formats and provides functionality to read, write, and manipulate SDDS data.
13 from .
import sddsdata
18from dataclasses
import dataclass
19from typing
import Optional, Any
24 A class to represent and manipulate SDDS datasets.
26 This class provides methods to load, manipulate, and save SDDS data.
27 It supports ASCII and binary formats and facilitates operations on parameters, arrays, and columns.
30 index (int): The index of the SDDS dataset (integer from 0 to 1000).
31 description (list): List containing the description text and contents of the SDDS file.
32 parameterName (list): List of parameter names.
33 arrayName (list): List of array names.
34 columnName (list): List of column names.
35 parameterDefinition (list): List of parameter definitions.
36 arrayDefinition (list): List of array definitions.
37 arrayDimensions (list): List of array dimensions.
38 columnDefinition (list): List of column definitions.
39 parameterData (list): List of parameter data values.
40 arrayData (list): List of array data values.
41 columnData (list): List of column data values.
42 mode (int): The data storage mode (`SDDS_ASCII` or `SDDS_BINARY`).
46 SDDS_VERBOSE_PrintErrors = 1
47 SDDS_EXIT_PrintErrors = 2
51 SDDS_CHECK_NONEXISTENT = 1
52 SDDS_CHECK_WRONGTYPE = 2
53 SDDS_CHECK_WRONGUNITS = 3
87 Initializes a new SDDS object.
90 index (int, optional): Integer index of the SDDS object. If not provided, an available
91 index will be automatically assigned. Must be between 0 and 1000.
94 ValueError: If no index is provided and all indices are in use.
104 raise ValueError(
"All SDDS indices are in use. Cannot create a new SDDS object.")
107 raise ValueError(f
"Index {index} is already in use.")
111 raise ValueError(f
"Index {index} must be between 0 and {self._max_index}.")
130 Destructor to release the index when the object is deleted.
137 Loads an SDDS file into the SDDS object.
140 input (str): The input SDDS filename to load.
143 Exception: If unable to read the SDDS data.
145 This method reads the SDDS file specified by `input`, and populates the object's data structures
146 with the parameters, arrays, columns, and their respective data.
150 if sddsdata.InitializeInput(self.
index, input) != 1:
152 if sddsdata.InitializeInput(self.
index, input) != 1:
153 raise ValueError(
"Failed to initialize SDDS input.")
184 self.
arrayData = [[]
for _
in range(numberOfArrays)]
185 self.
columnData = [[]
for _
in range(numberOfColumns)]
189 page = sddsdata.ReadPage(self.
index)
191 raise Exception(
"Unable to read SDDS data for the first page")
194 for i
in range(numberOfParameters):
196 for i
in range(numberOfArrays):
199 rows = sddsdata.RowCount(self.
index)
201 for i
in range(numberOfColumns):
204 for i
in range(numberOfColumns):
206 page = sddsdata.ReadPage(self.
index)
209 if sddsdata.Terminate(self.
index) != 1:
210 raise ValueError(
"Failed to terminate SDDS input.")
218 Loads an SDDS file into the SDDS object with sparse data reading.
221 input (str): The input SDDS filename to load.
222 interval (int): Interval between pages to read.
223 offset (int): Offset to start reading from.
226 Exception: If unable to read the SDDS data.
228 This method reads every `interval` pages from the SDDS file, starting from the page at `offset`.
232 if sddsdata.InitializeInput(self.
index, input) != 1:
234 if sddsdata.InitializeInput(self.
index, input) != 1:
235 raise ValueError(
"Failed to initialize SDDS input.")
266 self.
arrayData = [[]
for _
in range(numberOfArrays)]
267 self.
columnData = [[]
for _
in range(numberOfColumns)]
271 page = sddsdata.ReadPageSparse(self.
index, interval, offset)
273 raise Exception(
"Unable to read SDDS data for the first page")
275 for i
in range(numberOfParameters):
277 for i
in range(numberOfArrays):
280 rows = sddsdata.RowCount(self.
index)
282 for i
in range(numberOfColumns):
285 for i
in range(numberOfColumns):
287 page = sddsdata.ReadPageSparse(self.
index, interval, offset)
290 if sddsdata.Terminate(self.
index) != 1:
291 raise ValueError(
"Failed to terminate SDDS input.")
299 Loads an SDDS file into the SDDS object, reading only the last few rows.
302 input (str): The input SDDS filename to load.
303 lastrows (int): Number of last rows to read.
306 Exception: If unable to read the SDDS data.
308 This method reads only the last `lastrows` rows from each page of the SDDS file.
312 if sddsdata.InitializeInput(self.
index, input) != 1:
314 if sddsdata.InitializeInput(self.
index, input) != 1:
315 raise ValueError(
"Failed to initialize SDDS input.")
346 self.
arrayData = [[]
for _
in range(numberOfArrays)]
347 self.
columnData = [[]
for _
in range(numberOfColumns)]
351 page = sddsdata.ReadPageLastRows(self.
index, lastrows)
353 raise Exception(
"Unable to read SDDS data for the first page")
355 for i
in range(numberOfParameters):
357 for i
in range(numberOfArrays):
360 rows = sddsdata.RowCount(self.
index)
362 for i
in range(numberOfColumns):
365 for i
in range(numberOfColumns):
367 page = sddsdata.ReadPageLastRows(self.
index, lastrows)
370 if sddsdata.Terminate(self.
index) != 1:
371 raise ValueError(
"Failed to terminate SDDS input.")
379 Saves the SDDS object's data to an SDDS file.
382 output (str): The output SDDS filename to save the data.
385 Exception: If unable to write the SDDS data.
387 This method writes the data stored in the SDDS object to the specified file, including the
388 parameters, arrays, columns, and their data.
398 raise Exception(
"Unmatched parameterName and parameterData")
399 if numberOfArrays != len(self.
arrayData):
400 raise Exception(
"Unmatched arrayName and arrayData")
402 raise Exception(
"Unmatched columnName and columnData")
404 raise Exception(
"Unmatched parameterName and parameterDefinition")
406 raise Exception(
"Unmatched arrayName and arrayDefinition")
408 raise Exception(
"Unmatched columnName and columnDefinition")
410 if numberOfParameters > 0:
412 elif numberOfColumns > 0:
414 elif numberOfArrays > 0:
417 for i
in range(numberOfParameters):
419 raise Exception(
"Unequal number of pages in parameter data")
420 for i
in range(numberOfArrays):
422 raise Exception(
"Unequal number of pages in array data")
424 raise Exception(
"Unequal number of pages in array dimension data")
425 for i
in range(numberOfColumns):
427 raise Exception(
"Unequal number of pages in column data")
428 for page
in range(pages):
430 if numberOfColumns > 0:
432 for i
in range(numberOfColumns):
434 raise Exception(
"Unequal number of rows in column data")
438 raise ValueError(
"Failed to initialize SDDS output.")
441 for i
in range(numberOfParameters):
442 if sddsdata.DefineParameter(
452 raise ValueError(
"Failed to define parameter.")
454 for i
in range(numberOfArrays):
455 if sddsdata.DefineArray(
467 raise ValueError(
"Failed to define array.")
469 for i
in range(numberOfColumns):
470 if sddsdata.DefineColumn(
480 raise ValueError(
"Failed to define column.")
483 if sddsdata.WriteLayout(self.
index) != 1:
484 raise ValueError(
"Failed to write SDDS layout.")
487 for page
in range(pages):
489 if numberOfColumns > 0:
491 if sddsdata.StartPage(self.
index, rows) != 1:
492 raise ValueError(
"Failed to start SDDS page.")
493 for i
in range(numberOfParameters):
495 raise ValueError(
"Failed to set parameter value.")
496 for i
in range(numberOfArrays):
497 if sddsdata.SetArray(
500 raise ValueError(
"Failed to set array value.")
501 for i
in range(numberOfColumns):
503 raise ValueError(
"Failed to set column value.")
504 if sddsdata.WritePage(self.
index) != 1:
505 raise ValueError(
"Failed to write SDDS page.")
508 if sddsdata.Terminate(self.
index) != 1:
509 raise ValueError(
"Failed to terminate SDDS output.")
516 Sets the description for the SDDS object.
519 text (str): Description text.
520 contents (str): Description contents.
524 def defineParameter(self, name, symbol="", units="", description="", formatString="", type=SDDS_DOUBLE, fixedValue=""):
526 Defines a parameter for the SDDS object.
529 name (str): Parameter name.
530 symbol (str, optional): Parameter symbol.
531 units (str, optional): Parameter units.
532 description (str, optional): Parameter description.
533 formatString (str, optional): Format string for the parameter.
534 type (int, optional): Data type of the parameter. Defaults to SDDS_DOUBLE. Valid options include:
535 - SDDS_SHORT: 16-bit signed integer.
536 - SDDS_USHORT: 16-bit unsigned integer.
537 - SDDS_LONG: 32-bit signed integer.
538 - SDDS_ULONG: 32-bit unsigned integer.
539 - SDDS_LONG64: 64-bit signed integer.
540 - SDDS_ULONG64: 64-bit unsigned integer.
541 - SDDS_FLOAT: Single-precision floating-point number.
542 - SDDS_DOUBLE: Double-precision floating-point number.
543 - SDDS_LONGDOUBLE: Long double-precision floating-point number.
544 - SDDS_STRING: String (textual data).
545 - SDDS_CHARACTER: Single character.
546 fixedValue (str, optional): Fixed value of the parameter.
548 This method adds a parameter definition to the SDDS object.
552 [symbol, units, description, formatString, type, fixedValue]
524 def defineParameter(self, name, symbol="", units="", description="", formatString="", type=SDDS_DOUBLE, fixedValue=""):
…
558 Defines a simple parameter with minimal information.
561 name (str): Parameter name.
562 type (int): Data type of the parameter. Valid options include:
563 - SDDS_SHORT: 16-bit signed integer.
564 - SDDS_USHORT: 16-bit unsigned integer.
565 - SDDS_LONG: 32-bit signed integer.
566 - SDDS_ULONG: 32-bit unsigned integer.
567 - SDDS_LONG64: 64-bit signed integer.
568 - SDDS_ULONG64: 64-bit unsigned integer.
569 - SDDS_FLOAT: Single-precision floating-point number.
570 - SDDS_DOUBLE: Double-precision floating-point number.
571 - SDDS_LONGDOUBLE: Long double-precision floating-point number.
572 - SDDS_STRING: String (textual data).
573 - SDDS_CHARACTER: Single character.
575 This method adds a parameter definition with default attributes.
581 def defineArray(self, name, symbol="", units="", description="", formatString="", group_name="", type=SDDS_DOUBLE, fieldLength=0, dimensions=1):
583 Defines an array for the SDDS object.
586 name (str): Array name.
587 symbol (str, optional): Array symbol.
588 units (str, optional): Array units.
589 description (str, optional): Array description.
590 formatString (str, optional): Format string for the array.
591 group_name (str, optional): Group name for the array.
592 type (int, optional): Data type of the array. Defaults to SDDS_DOUBLE, Valid options include:
593 - SDDS_SHORT: 16-bit signed integer.
594 - SDDS_USHORT: 16-bit unsigned integer.
595 - SDDS_LONG: 32-bit signed integer.
596 - SDDS_ULONG: 32-bit unsigned integer.
597 - SDDS_LONG64: 64-bit signed integer.
598 - SDDS_ULONG64: 64-bit unsigned integer.
599 - SDDS_FLOAT: Single-precision floating-point number.
600 - SDDS_DOUBLE: Double-precision floating-point number.
601 - SDDS_LONGDOUBLE: Long double-precision floating-point number.
602 - SDDS_STRING: String (textual data).
603 - SDDS_CHARACTER: Single character.
604 fieldLength (int, optional): Field length for the array.
605 dimensions (int, optional): Number of dimensions of the array. Defaults to 1
607 This method adds an array definition to the SDDS object.
611 [symbol, units, description, formatString, group_name, type, fieldLength, dimensions]
581 def defineArray(self, name, symbol="", units="", description="", formatString="", group_name="", type=SDDS_DOUBLE, fieldLength=0, dimensions=1):
…
618 Defines a simple array with minimal information.
621 name (str): Array name.
622 type (int): Data type of the array. Valid options include:
623 - SDDS_SHORT: 16-bit signed integer.
624 - SDDS_USHORT: 16-bit unsigned integer.
625 - SDDS_LONG: 32-bit signed integer.
626 - SDDS_ULONG: 32-bit unsigned integer.
627 - SDDS_LONG64: 64-bit signed integer.
628 - SDDS_ULONG64: 64-bit unsigned integer.
629 - SDDS_FLOAT: Single-precision floating-point number.
630 - SDDS_DOUBLE: Double-precision floating-point number.
631 - SDDS_LONGDOUBLE: Long double-precision floating-point number.
632 - SDDS_STRING: String (textual data).
633 - SDDS_CHARACTER: Single character.
634 dimensions (int): Number of dimensions of the array.
636 This method adds an array definition with default attributes.
643 def defineColumn(self, name, symbol="", units="", description="", formatString="", type=SDDS_DOUBLE, fieldLength=0):
645 Defines a column for the SDDS object.
648 name (str): Column name.
649 symbol (str, optional): Column symbol.
650 units (str, optional): Column units.
651 description (str, optional): Column description.
652 formatString (str, optional): Format string for the column.
653 type (int, optional): Data type of the column. Defaults to SDDS_DOUBLE. Valid options include:
654 - SDDS_SHORT: 16-bit signed integer.
655 - SDDS_USHORT: 16-bit unsigned integer.
656 - SDDS_LONG: 32-bit signed integer.
657 - SDDS_ULONG: 32-bit unsigned integer.
658 - SDDS_LONG64: 64-bit signed integer.
659 - SDDS_ULONG64: 64-bit unsigned integer.
660 - SDDS_FLOAT: Single-precision floating-point number.
661 - SDDS_DOUBLE: Double-precision floating-point number.
662 - SDDS_LONGDOUBLE: Long double-precision floating-point number.
663 - SDDS_STRING: String (textual data).
664 - SDDS_CHARACTER: Single character.
665 fieldLength (int, optional): Field length for the column.
667 This method adds a column definition to the SDDS object.
671 [symbol, units, description, formatString, type, fieldLength]
643 def defineColumn(self, name, symbol="", units="", description="", formatString="", type=SDDS_DOUBLE, fieldLength=0):
…
677 Defines a simple column with minimal information.
680 name (str): Column name.
681 type (int): Data type of the column. Valid options include:
682 - SDDS_SHORT: 16-bit signed integer.
683 - SDDS_USHORT: 16-bit unsigned integer.
684 - SDDS_LONG: 32-bit signed integer.
685 - SDDS_ULONG: 32-bit unsigned integer.
686 - SDDS_LONG64: 64-bit signed integer.
687 - SDDS_ULONG64: 64-bit unsigned integer.
688 - SDDS_FLOAT: Single-precision floating-point number.
689 - SDDS_DOUBLE: Double-precision floating-point number.
690 - SDDS_LONGDOUBLE: Long double-precision floating-point number.
691 - SDDS_STRING: String (textual data).
692 - SDDS_CHARACTER: Single character.
694 This method adds a column definition with default attributes.
702 Sets the list of parameter values for a parameter. This can be used to set values for multiple pages at once.
705 name (str): Parameter name.
706 valueList (list): List of values for the parameter.
709 Exception: If the parameter name is invalid.
711 This method assigns a list of values to a parameter across pages.
717 msg =
"Invalid parameter name " + name
722 Gets the list of parameter values for a parameter. This can be used to get values for multiple pages at once.
725 name (str): Parameter name.
728 list: List of values for the parameter.
731 Exception: If the parameter name is invalid.
738 msg =
"Invalid parameter name " + name
743 Sets a single parameter value at a specific page.
746 name (str): Parameter name.
747 value: Parameter value.
748 page (int, optional): Page number (1-based index, defaults to 1).
751 Exception: If the parameter name or page is invalid.
753 This method sets the parameter value at the specified page.
762 msg =
"Invalid page " + str(page + 1)
767 msg =
"Invalid parameter name " + name
772 Gets a single parameter value at a specific page.
775 name (str): Parameter name.
776 page (int, optional): Page number (1-based index, defaults to 1).
779 value: Parameter value.
782 Exception: If the parameter name or page is invalid.
791 msg =
"Invalid page " + str(page + 1)
796 msg =
"Invalid parameter name " + name
801 Sets the nested list of array values and dimensions for a single array. This can be used to set values for multiple pages at once.
804 name (str): Array name.
805 valueList (list): Nested list of array values.
806 dimensionList (list): Nested list of array dimensions.
809 Exception: If the array name is invalid.
811 This method assigns values and dimensions to an array across pages.
819 msg =
"Invalid array name " + name
824 Gets the nested list of array values for a single array. This can be used to get values for multiple pages at once.
827 name (str): Array name.
830 list: Nested list of array values.
833 Exception: If the array name is invalid.
839 msg =
"Invalid array name " + name
844 Gets the nested list of array dimensions for a single array. This can be used to get dimensions for multiple pages at once.
847 name (str): Array name.
850 list: Nested list of array dimensions.
853 Exception: If the array name is invalid.
859 msg =
"Invalid array name " + name
864 Sets a single array value and dimension at a specific page.
867 name (str): Array name.
868 valueList (list): Array values.
869 dimensionList (list): Array dimensions.
870 page (int, optional): Page number (1-based index, defaults to 1).
873 Exception: If the array name or page is invalid.
875 This method sets the array values and dimensions at the specified page.
884 elif len(self.
arrayData[i]) < page
or page < 0:
885 msg =
"Invalid page " + str(page + 1)
891 msg =
"Invalid array name " + name
896 Gets a single array value at a specific page.
899 name (str): Array name.
900 page (int, optional): Page number (1-based index, defaults to 1).
906 Exception: If the array name or page is invalid.
914 elif len(self.
arrayData[i]) < page
or page < 0:
915 msg =
"Invalid page " + str(page + 1)
920 msg =
"Invalid array name " + name
925 Gets a single array dimension at a specific page.
928 name (str): Array name.
929 page (int, optional): Page number (1-based index, defaults to 1).
932 list: Array dimension.
935 Exception: If the array name or page is invalid.
943 elif len(self.
arrayData[i]) < page
or page < 0:
944 msg =
"Invalid page " + str(page + 1)
949 msg =
"Invalid array name " + name
954 Sets the nested list of column values for a single column. This can be used to set values for multiple pages at once.
957 name (str): Column name.
958 valueList (list): Nested list of column values.
961 Exception: If the column name is invalid.
963 This method assigns a list of values to a column across pages.
969 msg =
"Invalid column name " + name
974 Gets the nested list of column values for a single column. This can be used to get values for multiple pages at once.
977 name (str): Column name.
980 list: Nested list of column values.
983 Exception: If the column name is invalid.
989 msg =
"Invalid column name " + name
994 Sets a single column value list at a specific page.
997 name (str): Column name.
998 valueList (list): Column values.
999 page (int, optional): Page number (1-based index, defaults to 1).
1002 Exception: If the column name or page is invalid.
1004 This method sets the column values at the specified page.
1011 elif len(self.
columnData[i]) < page
or page < 0:
1012 msg =
"Invalid page " + str(page + 1)
1013 raise Exception(msg)
1017 msg =
"Invalid column name " + name
1018 raise Exception(msg)
1022 Gets a single column value list at a specific page.
1025 name (str): Column name.
1026 page (int, optional): Page number (1-based index, defaults to 1).
1029 list: Column values.
1032 Exception: If the column name or page is invalid.
1040 elif len(self.
columnData[i]) < page
or page < 0:
1041 msg =
"Invalid page " + str(page + 1)
1042 raise Exception(msg)
1046 msg =
"Invalid column name " + name
1047 raise Exception(msg)
1051 Sets a single column value at a specific page and row.
1054 name (str): Column name.
1055 value: Column value.
1056 page (int, optional): Page number (1-based index, defaults to 1).
1057 row (int, optional): Row number (1-based index, defaults to 1).
1060 Exception: If the column name, page, or row is invalid.
1062 This method sets the column value at the specified page and row.
1073 msg =
"Invalid row " + str(row + 1)
1074 raise Exception(msg)
1075 elif len(self.
columnData[i]) < page
or page < 0:
1076 msg =
"Invalid page " + str(page + 1)
1077 raise Exception(msg)
1081 elif len(self.
columnData[i][page]) < row
or row < 0:
1082 msg =
"Invalid row " + str(row + 1)
1083 raise Exception(msg)
1087 msg =
"Invalid column name " + name
1088 raise Exception(msg)
1092 Gets a single column value at a specific page and row.
1095 name (str): Column name.
1096 page (int, optional): Page number (1-based index, defaults to 1).
1097 row (int, optional): Row number (1-based index, defaults to 1).
1100 value: Column value.
1103 Exception: If the column name, page, or row is invalid.
1114 msg =
"Invalid row " + str(row + 1)
1115 raise Exception(msg)
1116 elif len(self.
columnData[i]) < page
or page < 0:
1117 msg =
"Invalid page " + str(page + 1)
1118 raise Exception(msg)
1122 elif len(self.
columnData[i][page]) < row
or row < 0:
1123 msg =
"Invalid row " + str(row + 1)
1124 raise Exception(msg)
1128 msg =
"Invalid column name " + name
1129 raise Exception(msg)
1133 Retrieves the number of parameters.
1136 int: The number of parameters.
1142 Retrieves the number of arrays.
1145 int: The number of arrays.
1151 Retrieves the number of columns.
1154 int: The number of columns.
1160 Retrieves a list of all parameter names.
1163 list: A list of parameter names as strings, or an empty list.
1169 Retrieves a list of all array names.
1172 list: A list of array names as strings, or an empty list.
1178 Retrieves a list of all column names.
1181 list: A list of column names as strings, or an empty list.
1187 Retrieves the data type of a parameter.
1190 name (str): Parameter name.
1193 int: Number representing the data type of the parameter.
1198 msg =
"Invalid parameter name " + name
1199 raise Exception(msg)
1203 Retrieves the data type of a array.
1206 name (str): Array name.
1209 int: Number representing the data type of the array.
1214 msg =
"Invalid array name " + name
1215 raise Exception(msg)
1219 Retrieves the data type of a column.
1222 name (str): Column name.
1225 int: Number representing the data type of the column.
1230 msg =
"Invalid column name " + name
1231 raise Exception(msg)
1235 Retrieves the units of a parameter.
1238 name (str): Parameter name.
1241 str: Units of the parameter.
1246 msg =
"Invalid parameter name " + name
1247 raise Exception(msg)
1251 Retrieves the units of a array.
1254 name (str): Array name.
1257 str: Units of the array.
1262 msg =
"Invalid array name " + name
1263 raise Exception(msg)
1267 Retrieves the units of a column.
1270 name (str): Column name.
1273 str: Units of the column.
1278 msg =
"Invalid column name " + name
1279 raise Exception(msg)
1283 Retrieves the number or loaded pages
1286 int: Number or loaded pages
1293SDDS_VERBOSE_PrintErrors = SDDS.SDDS_VERBOSE_PrintErrors
1294SDDS_EXIT_PrintErrors = SDDS.SDDS_EXIT_PrintErrors
1295SDDS_CHECK_OKAY = SDDS.SDDS_CHECK_OKAY
1296SDDS_CHECK_NONEXISTENT = SDDS.SDDS_CHECK_NONEXISTENT
1297SDDS_CHECK_WRONGTYPE = SDDS.SDDS_CHECK_WRONGTYPE
1298SDDS_CHECK_WRONGUNITS = SDDS.SDDS_CHECK_WRONGUNITS
1299SDDS_LONGDOUBLE = SDDS.SDDS_LONGDOUBLE
1300SDDS_DOUBLE = SDDS.SDDS_DOUBLE
1301SDDS_REAL64 = SDDS.SDDS_REAL64
1302SDDS_FLOAT = SDDS.SDDS_FLOAT
1303SDDS_REAL32 = SDDS.SDDS_REAL32
1304SDDS_LONG64 = SDDS.SDDS_LONG64
1305SDDS_INT64 = SDDS.SDDS_INT64
1306SDDS_ULONG64 = SDDS.SDDS_ULONG64
1307SDDS_UINT64 = SDDS.SDDS_UINT64
1308SDDS_LONG = SDDS.SDDS_LONG
1309SDDS_INT32 = SDDS.SDDS_INT32
1310SDDS_ULONG = SDDS.SDDS_ULONG
1311SDDS_UINT32 = SDDS.SDDS_UINT32
1312SDDS_SHORT = SDDS.SDDS_SHORT
1313SDDS_INT16 = SDDS.SDDS_INT16
1314SDDS_USHORT = SDDS.SDDS_USHORT
1315SDDS_UINT16 = SDDS.SDDS_UINT16
1316SDDS_STRING = SDDS.SDDS_STRING
1317SDDS_CHARACTER = SDDS.SDDS_CHARACTER
1318SDDS_NUM_TYPES = SDDS.SDDS_NUM_TYPES
1319SDDS_BINARY = SDDS.SDDS_BINARY
1320SDDS_ASCII = SDDS.SDDS_ASCII
1321SDDS_FLUSH_TABLE = SDDS.SDDS_FLUSH_TABLE
1323def load(input_file) -> SDDS:
1325 Loads an SDDS file into the SDDS object.
1328 input_file (str): The input SDDS filename to load.
1331 Exception: If unable to read the SDDS data.
1333 This method reads the SDDS file specified by `input`, and populates the object's data structures
1334 with the parameters, arrays, columns, and their respective data.
1342 sdds_obj.load(input_file)
1343 except Exception
as e:
1344 raise ValueError(f
"Failed to load the SDDS file: {e}")
1348def loadSparse(input_file, interval, offset) -> SDDS:
1350 Loads an SDDS file into the SDDS object with sparse data reading.
1353 input_file (str): The input SDDS filename to load.
1354 interval (int): Interval between pages to read.
1355 offset (int): Offset to start reading from.
1358 Exception: If unable to read the SDDS data.
1360 This method reads every `interval` pages from the SDDS file, starting from the page at `offset`.
1367 sdds_obj.loadSparse(input_file, interval, offset)
1368 except Exception
as e:
1369 raise ValueError(f
"Failed to load the SDDS file: {e}")
1375 Loads an SDDS file into the SDDS object, reading only the last few rows.
1378 input_file (str): The input SDDS filename to load.
1379 lastrows (int): Number of last rows to read.
1382 Exception: If unable to read the SDDS data.
1384 This method reads only the last `lastrows` rows from each page of the SDDS file.
1391 sdds_obj.loadLastRows(input_file, lastrows)
1392 except Exception
as e:
1393 raise ValueError(f
"Failed to load the SDDS file: {e}")
1397def save(sdds_obj : SDDS, output_file):
1399 Saves the SDDS object's data to an SDDS file.
1402 output (str): The output SDDS filename to save the data.
1405 Exception: If unable to write the SDDS data.
1407 This method writes the data stored in the SDDS object to the specified file, including the
1408 parameters, arrays, columns, and their data.
1412 sdds_obj.save(output_file)
1413 except Exception
as e:
1414 raise ValueError(f
"Failed to load the SDDS file: {e}")
1416def sdds_data_type_to_string(data_type_code):
1418 Converts a numeric SDDS data type code to its string representation.
1421 data_type_code (int): Numeric code of the SDDS data type.
1424 str: String representation of the SDDS data type.
1428 1:
"SDDS_LONGDOUBLE",
1438 11:
"SDDS_CHARACTER",
1440 return data_type_map.get(data_type_code,
"Unknown Data Type")
1442def sdds_data_type_to_short_string(data_type_code):
1444 Converts a numeric SDDS data type code to its short string representation.
1447 data_type_code (int): Numeric code of the SDDS data type.
1450 str: String representation of the SDDS data type.
1466 return data_type_map.get(data_type_code,
"Unknown Data Type")
1468def sdds_short_string_to_data_type(data_type_code):
1470 Converts a numeric SDDS data type code to its short string representation.
1473 data_type_code (string): String representation of the SDDS data type.
1476 int: Numeric code of the SDDS data type.
1492 return data_type_map.get(data_type_code,
"Unknown Data Type")
1496 Demonstrates how to save a demo SDDS file using the SDDS class.
1499 output (str): The output SDDS filename to save the demo data.
1501 This function creates an SDDS object, populates it with sample data, and saves it to the specified output file.
1504 x.description[0] =
"text"
1505 x.description[1] =
"contents"
1506 x.parameterName = [
"ShortP",
"LongP",
"FloatP",
"DoubleP",
"StringP",
"CharacterP"]
1507 x.parameterData = [[1, 6], [2, 7], [3.3, 8.8], [4.4, 9.8], [
"five",
"ten"], [
"a",
"b"]]
1508 x.parameterDefinition = [
1509 [
"",
"",
"",
"", x.SDDS_SHORT,
""],
1510 [
"",
"",
"",
"", x.SDDS_LONG,
""],
1511 [
"",
"",
"",
"", x.SDDS_FLOAT,
""],
1512 [
"",
"",
"",
"", x.SDDS_DOUBLE,
""],
1513 [
"",
"",
"",
"", x.SDDS_STRING,
""],
1514 [
"",
"",
"",
"", x.SDDS_CHARACTER,
""],
1517 x.arrayName = [
"ShortA",
"LongA",
"FloatA",
"DoubleA",
"StringA",
"CharacterA"]
1518 x.arrayDefinition = [
1519 [
"",
"",
"",
"",
"", x.SDDS_SHORT, 0, 1],
1520 [
"",
"",
"",
"",
"", x.SDDS_LONG, 0, 1],
1521 [
"",
"",
"",
"",
"", x.SDDS_FLOAT, 0, 2],
1522 [
"",
"",
"",
"",
"", x.SDDS_DOUBLE, 0, 1],
1523 [
"",
"",
"",
"",
"", x.SDDS_STRING, 0, 1],
1524 [
"",
"",
"",
"",
"", x.SDDS_CHARACTER, 0, 1],
1526 x.arrayDimensions = [
1535 [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6, 7, 8]],
1536 [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 6, 7]],
1537 [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6, 7, 8]],
1538 [[1, 2, 3, 4], [1, 2, 3, 4, 5]],
1539 [[
"one",
"two",
"three",
"four"], [
"five",
"six",
"seven",
"eight",
"nine"]],
1540 [[
"a",
"b",
"c",
"d"], [
"e",
"f",
"g",
"h",
"i"]],
1543 x.columnName = [
"ShortC",
"LongC",
"FloatC",
"DoubleC",
"StringC",
"CharacterC"]
1545 [[1, 2, 3], [-1, -2, -3, -4]],
1546 [[1, 2, 3], [-1, -2, -3, -4]],
1547 [[1, 2, 3], [-1, -2, -3.6, -4.4]],
1548 [[1, 2, 3], [-1, -2, -3.6, -4.4]],
1549 [[
"row 1",
"row 2",
"row 3"], [
"row 1",
"row 2",
"row 3",
"row 4"]],
1550 [[
"x",
"y",
"z"], [
"i",
"j",
"k",
"l"]],
1552 x.columnDefinition = [
1553 [
"",
"",
"",
"", x.SDDS_SHORT, 0],
1554 [
"",
"",
"",
"", x.SDDS_LONG, 0],
1555 [
"",
"",
"",
"", x.SDDS_FLOAT, 0],
1556 [
"",
"",
"",
"", x.SDDS_DOUBLE, 0],
1557 [
"",
"",
"",
"", x.SDDS_STRING, 0],
1558 [
"",
"",
"",
"", x.SDDS_CHARACTER, 0],
1567 Demonstrates how to save a demo SDDS file using the SDDS class with simplified definitions.
1570 output (str): The output SDDS filename to save the demo data.
1572 This function shows how to use simplified methods to define parameters, arrays, and columns.
1575 x.setDescription(
"text",
"contents")
1576 names = [
"Short",
"Long",
"Float",
"Double",
"String",
"Character"]
1577 types = [x.SDDS_SHORT, x.SDDS_LONG, x.SDDS_FLOAT, x.SDDS_DOUBLE, x.SDDS_STRING, x.SDDS_CHARACTER]
1579 x.defineSimpleParameter(names[i] +
"P", types[i])
1580 if types[i] == x.SDDS_FLOAT:
1581 x.defineSimpleArray(names[i] +
"A", types[i], 2)
1583 x.defineSimpleArray(names[i] +
"A", types[i], 1)
1584 x.defineSimpleColumn(names[i] +
"C", types[i])
1585 parameterData = [[1, 6], [2, 7], [3.3, 8.8], [4.4, 9.8], [
"five",
"ten"], [
"a",
"b"]]
1587 x.setParameterValueList(names[i] +
"P", parameterData[i])
1598 [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6, 7, 8]],
1599 [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 6, 7]],
1600 [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6, 7, 8]],
1601 [[1, 2, 3, 4], [1, 2, 3, 4, 5]],
1602 [[
"one",
"two",
"three",
"four"], [
"five",
"six",
"seven",
"eight",
"nine"]],
1603 [[
"a",
"b",
"c",
"d"], [
"e",
"f",
"g",
"h",
"i"]],
1606 x.setArrayValueLists(names[i] +
"A", arrayData[i], arrayDimensions[i])
1609 [[1, 2, 3], [-1, -2, -3, -4]],
1610 [[1, 2, 3], [-1, -2, -3, -4]],
1611 [[1, 2, 3], [-1, -2, -3.6, -4.4]],
1612 [[1, 2, 3], [-1, -2, -3.6, -4.4]],
1613 [[
"row 1",
"row 2",
"row 3"], [
"row 1",
"row 2",
"row 3",
"row 4"]],
1614 [[
"x",
"y",
"z"], [
"i",
"j",
"k",
"l"]],
1617 x.setColumnValueLists(names[i] +
"C", columnData[i])
1623 Demonstrates how to save a demo SDDS file using `sddsdata` commands directly.
1626 output (str): The output SDDS filename to save the demo data.
1628 This function shows how to use `sddsdata` module functions directly to create and save an SDDS file.
1634 if sddsdata.InitializeOutput(x.index, x.SDDS_BINARY, 1,
"",
"", output) != 1:
1635 raise ValueError(
"Failed to initialize SDDS output.")
1637 sddsdata.SetColumnMajorOrder(x.index)
1639 if sddsdata.DefineSimpleParameter(x.index,
"ParameterA",
"mm", x.SDDS_DOUBLE) != 1:
1640 raise ValueError(
"Failed to define parameter.")
1642 if sddsdata.DefineSimpleArray(x.index,
"ArrayA",
"DegC", x.SDDS_DOUBLE, 1) != 1:
1643 raise ValueError(
"Failed to define array.")
1644 if sddsdata.DefineSimpleArray(x.index,
"ArrayB",
"DegC", x.SDDS_DOUBLE, 2) != 1:
1645 raise ValueError(
"Failed to define array.")
1647 if sddsdata.DefineSimpleColumn(x.index,
"ColumnA",
"Volts", x.SDDS_DOUBLE) != 1:
1648 raise ValueError(
"Failed to define column.")
1649 if sddsdata.DefineSimpleColumn(x.index,
"ColumnB",
"Amps", x.SDDS_DOUBLE) != 1:
1650 raise ValueError(
"Failed to define column.")
1652 if sddsdata.WriteLayout(x.index) != 1:
1653 raise ValueError(
"Failed to write SDDS layout.")
1655 if sddsdata.StartPage(x.index, 100) != 1:
1656 raise ValueError(
"Failed to start SDDS page.")
1658 if sddsdata.SetParameter(x.index,
"ParameterA", 1.1) != 1:
1659 raise ValueError(
"Failed to set parameter value.")
1661 if sddsdata.SetArray(x.index,
"ArrayA", [1, 2, 3], [3]) != 1:
1662 raise ValueError(
"Failed to set array value.")
1663 if sddsdata.SetArray(x.index,
"ArrayB", [1, 2, 3, 4, 5, 6], [2, 3]) != 1:
1664 raise ValueError(
"Failed to set array value.")
1666 if sddsdata.SetColumn(x.index,
"ColumnA", [1, 2, 3]) != 1:
1667 raise ValueError(
"Failed to set column value.")
1668 if sddsdata.SetColumn(x.index,
"ColumnB", [1, 2, 3]) != 1:
1669 raise ValueError(
"Failed to set column value.")
1671 if sddsdata.WritePage(x.index) != 1:
1672 raise ValueError(
"Failed to write SDDS page.")
1674 if sddsdata.Terminate(x.index) != 1:
1675 raise ValueError(
"Failed to terminate SDDS output.")
1678 sddsdata.PrintErrors(x.SDDS_VERBOSE_PrintErrors)
1684 Demonstrates how to save a demo SDDS file using `sddsdata` commands and writing one row at a time.
1687 output (str): The output SDDS filename to save the demo data.
1689 This function shows how to write data to an SDDS file one row at a time, useful for logging applications.
1695 if sddsdata.InitializeOutput(x.index, x.SDDS_BINARY, 1,
"",
"", output) != 1:
1696 raise ValueError(
"Failed to initialize SDDS output.")
1698 sddsdata.EnableFSync(x.index)
1699 sddsdata.SetFixedRowCountMode(x.index)
1701 if sddsdata.DefineSimpleParameter(x.index,
"ParameterA",
"mm", x.SDDS_DOUBLE) != 1:
1702 raise ValueError(
"Failed to define parameter.")
1704 if sddsdata.DefineSimpleArray(x.index,
"ArrayA",
"DegC", x.SDDS_DOUBLE, 1) != 1:
1705 raise ValueError(
"Failed to define array.")
1706 if sddsdata.DefineSimpleArray(x.index,
"ArrayB",
"DegC", x.SDDS_DOUBLE, 2) != 1:
1707 raise ValueError(
"Failed to define array.")
1709 if sddsdata.DefineSimpleColumn(x.index,
"ColumnA",
"Volts", x.SDDS_DOUBLE) != 1:
1710 raise ValueError(
"Failed to define column.")
1711 if sddsdata.DefineSimpleColumn(x.index,
"ColumnB",
"Amps", x.SDDS_DOUBLE) != 1:
1712 raise ValueError(
"Failed to define column.")
1714 if sddsdata.WriteLayout(x.index) != 1:
1715 raise ValueError(
"Failed to write SDDS layout.")
1717 if sddsdata.StartPage(x.index, 2) != 1:
1718 raise ValueError(
"Failed to start SDDS page.")
1720 if sddsdata.SetParameter(x.index,
"ParameterA", 1.1) != 1:
1721 raise ValueError(
"Failed to set parameter value.")
1723 if sddsdata.SetArray(x.index,
"ArrayA", [1, 2, 3], [3]) != 1:
1724 raise ValueError(
"Failed to set array value.")
1725 if sddsdata.SetArray(x.index,
"ArrayB", [1, 2, 3, 4, 5, 6], [2, 3]) != 1:
1726 raise ValueError(
"Failed to set array value.")
1728 if sddsdata.SetRowValues(x.index, 0, [
"ColumnA", 1,
"ColumnB", 1]) != 1:
1729 raise ValueError(
"Failed to set row values.")
1730 if sddsdata.SetRowValues(x.index, 1, [
"ColumnA", 2,
"ColumnB", 2]) != 1:
1731 raise ValueError(
"Failed to set row values.")
1733 if sddsdata.UpdatePage(x.index, x.SDDS_FLUSH_TABLE) != 1:
1734 raise ValueError(
"Failed to update SDDS page.")
1736 if sddsdata.SetRowValues(x.index, 2, [
"ColumnA", 3,
"ColumnB", 3]) != 1:
1737 raise ValueError(
"Failed to set row values.")
1739 if sddsdata.UpdatePage(x.index, x.SDDS_FLUSH_TABLE) != 1:
1740 raise ValueError(
"Failed to update SDDS page.")
1742 if sddsdata.Terminate(x.index) != 1:
1743 raise ValueError(
"Failed to terminate SDDS output.")
1746 sddsdata.PrintErrors(x.SDDS_VERBOSE_PrintErrors)
1752 Demonstrates how to open an existing SDDS file and add rows to the last page without loading the whole file into memory.
1755 output (str): The output SDDS filename to append data.
1757 This function shows how to append data to an existing SDDS file efficiently.
1763 rows = sddsdata.InitializeAppendToPage(x.index, output, 100)
1765 raise ValueError(
"Failed to initialize appending to SDDS page.")
1767 if sddsdata.SetRowValues(x.index, rows, [
"ColumnA", 4,
"ColumnB", 4]) != 1:
1768 raise ValueError(
"Failed to set row values.")
1769 if sddsdata.SetRowValues(x.index, rows + 1, [
"ColumnA", 5,
"ColumnB", 5]) != 1:
1770 raise ValueError(
"Failed to set row values.")
1771 if sddsdata.SetRowValues(x.index, rows + 2, [
"ColumnA", 6,
"ColumnB", 6]) != 1:
1772 raise ValueError(
"Failed to set row values.")
1774 if sddsdata.UpdatePage(x.index, x.SDDS_FLUSH_TABLE) != 1:
1775 raise ValueError(
"Failed to update SDDS page.")
1777 if sddsdata.Terminate(x.index) != 1:
1778 raise ValueError(
"Failed to terminate SDDS output.")
1781 sddsdata.PrintErrors(x.SDDS_VERBOSE_PrintErrors)
1787 Demonstrates how to open an existing SDDS file and add a new page.
1790 output (str): The output SDDS filename to append data.
1792 This function shows how to append a new page to an existing SDDS file.
1798 if sddsdata.InitializeAppend(x.index, output) != 1:
1799 raise ValueError(
"Failed to initialize appending to SDDS file.")
1801 if sddsdata.StartPage(x.index, 100) != 1:
1802 raise ValueError(
"Failed to start SDDS page.")
1804 if sddsdata.SetParameter(x.index,
"ParameterA", 1.1) != 1:
1805 raise ValueError(
"Failed to set parameter value.")
1807 if sddsdata.SetArray(x.index,
"ArrayA", [1, 2, 3], [3]) != 1:
1808 raise ValueError(
"Failed to set array value.")
1809 if sddsdata.SetArray(x.index,
"ArrayB", [1, 2, 3, 4, 5, 6], [2, 3]) != 1:
1810 raise ValueError(
"Failed to set array value.")
1812 if sddsdata.SetRowValues(x.index, 0, [
"ColumnA", 7,
"ColumnB", 7]) != 1:
1813 raise ValueError(
"Failed to set row values.")
1814 if sddsdata.SetRowValues(x.index, 1, [
"ColumnA", 8,
"ColumnB", 8]) != 1:
1815 raise ValueError(
"Failed to set row values.")
1816 if sddsdata.SetRowValues(x.index, 2, [
"ColumnA", 9,
"ColumnB", 9]) != 1:
1817 raise ValueError(
"Failed to set row values.")
1819 if sddsdata.WritePage(x.index) != 1:
1820 raise ValueError(
"Failed to write SDDS page.")
1822 if sddsdata.Terminate(x.index) != 1:
1823 raise ValueError(
"Failed to terminate SDDS output.")
1826 sddsdata.PrintErrors(x.SDDS_VERBOSE_PrintErrors)
1831 text: Optional[str] =
None
1832 contents: Optional[str] =
None
1837 symbol: Optional[Any] =
None
1838 units: Optional[Any] =
None
1839 description: Optional[Any] =
None
1840 format_string: Optional[Any] =
None
1841 fixed_value: Optional[str] =
None
1846 symbol: Optional[Any] =
None
1847 units: Optional[Any] =
None
1848 description: Optional[Any] =
None
1849 format_string: Optional[Any] =
None
1850 group_name: Optional[Any] =
None
1851 field_length: Optional[Any] =
None
1852 dimensions: Optional[Any] =
None
1857 symbol: Optional[Any] =
None
1858 units: Optional[Any] =
None
1859 description: Optional[Any] =
None
1860 format_string: Optional[Any] =
None
1861 field_length: Optional[Any] =
None
1870def read(input_file) -> SddsFile:
1872 Mostly backward compatible with the PyLHC sdds module read() function.
1873 Unlike the PyLHC version, this function reads all the SDDS pages and works with column data.
1874 The data is returned in a structured dictionary.
1877 input_file (str): The input SDDS file to be read.
1880 dict: A dictionary with parameters, arrays, and columns data.
1885 "definitions": {name: {"type:" string, "units": string, "description": string},
1886 "values": {parameter_name: {[Page1Value, Page2Value, ...]},
1887 {array_name: {[Page1List, Page2List, ...]},
1888 {column_name: {[Page1List, Page2List, ...]},
1889 "values": {array_name: {[page1DimList, Page2DimList, ...]}
1897 sdds_obj.load(input_file)
1898 except Exception
as e:
1899 raise ValueError(f
"Failed to load the SDDS file: {e}")
1905 if sdds_obj.mode == SDDS.SDDS_BINARY:
1906 sdds_data.binary =
True
1908 sdds_data.binary =
False
1911 text = sdds_obj.description[0]
if sdds_obj.description[0] !=
"" else None
1912 contents = sdds_obj.description[1]
if sdds_obj.description[1] !=
"" else None
1913 description_instance =
Description(text=text, contents=contents)
1914 sdds_data.description = description_instance
1917 sdds_data.pages = sdds_obj.loaded_pages
1920 if sdds_obj.parameterName:
1921 for i, definition
in enumerate(sdds_obj.parameterDefinition):
1922 name = sdds_obj.parameterName[i]
1923 symbol = definition[0]
if definition[0] !=
'' else None
1924 units = definition[1]
if definition[1] !=
'' else None
1925 description = definition[2]
if definition[2] !=
'' else None
1926 formatString = definition[3]
if definition[3] !=
'' else None
1927 datatype = sdds_data_type_to_short_string(definition[4])
1928 fixedValue = definition[5]
if definition[5] !=
'' else None
1929 parameter_instance =
Parameter(name=name, type=datatype, symbol=symbol, units=units, description=description, format_string=formatString, fixed_value=fixedValue)
1930 sdds_data.definitions.update({name: parameter_instance})
1931 sdds_data.values.update({name: sdds_obj.parameterData[i]})
1934 if sdds_obj.arrayName:
1935 for i, definition
in enumerate(sdds_obj.arrayDefinition):
1936 name = sdds_obj.arrayName[i]
1937 symbol = definition[0]
if definition[0] !=
'' else None
1938 units = definition[1]
if definition[1] !=
'' else None
1939 description = definition[2]
if definition[2] !=
'' else None
1940 formatString = definition[3]
if definition[3] !=
'' else None
1941 group_name = definition[4]
if definition[4] !=
'' else None
1942 datatype = sdds_data_type_to_short_string(definition[5])
1943 fieldLength = definition[6]
if definition[6] != 0
else None
1944 dimensions = definition[7]
if definition[7] !=
'' else None
1945 array_instance =
Array(name=name, type=datatype, symbol=symbol, units=units, description=description, format_string=formatString, group_name=group_name, field_length=fieldLength, dimensions=dimensions)
1946 sdds_data.definitions.update({name: array_instance})
1947 sdds_data.values.update({name: sdds_obj.arrayData[i]})
1948 sdds_data.array_dims.update({name: sdds_obj.arrayDimensions[i]})
1951 if sdds_obj.columnName:
1952 for i, definition
in enumerate(sdds_obj.columnDefinition):
1953 name = sdds_obj.columnName[i]
1954 symbol = definition[0]
if definition[0] !=
'' else None
1955 units = definition[1]
if definition[1] !=
'' else None
1956 description = definition[2]
if definition[2] !=
'' else None
1957 formatString = definition[3]
if definition[3] !=
'' else None
1958 datatype = sdds_data_type_to_short_string(definition[4])
1959 fieldLength = definition[5]
if definition[5] != 0
else None
1960 column_instance =
Column(name=name, type=datatype, symbol=symbol, units=units, description=description, format_string=formatString, field_length=fieldLength)
1961 sdds_data.definitions.update({name: column_instance})
1962 sdds_data.values.update({name: sdds_obj.columnData[i]})
1967def write(sdds_file: SddsFile, output_file):
1969 Mostly backward compatible with the PyLHC sdds module write() function.
1970 Unlike the PyLHC version, this function writes all the SDDS pages and works with column data.
1971 The data is expected to be in a structured dictionary like that returned from the read() function.
1974 output_file (str): The output SDDS file to be written to.
1980 if hasattr(sdds_file,
'binary'):
1981 if sdds_file.binary:
1982 sdds_obj.mode = SDDS.SDDS_BINARY
1984 sdds_obj.mode = SDDS.SDDS_ASCII
1987 if hasattr(sdds_file,
'description'):
1988 text = sdds_file.description.text
if sdds_file.description.text !=
None else ''
1989 contents = sdds_file.description.contents
if sdds_file.description.contents !=
None else ''
1990 sdds_obj.setDescription(text, contents)
1992 for name
in sdds_file.definitions:
1993 if isinstance(sdds_file.definitions[name], Parameter):
1995 parameter_instance = sdds_file.definitions[name]
1996 symbol = parameter_instance.symbol
if parameter_instance.symbol !=
None else ""
1997 units = parameter_instance.units
if parameter_instance.units !=
None else ""
1998 description = parameter_instance.description
if parameter_instance.description !=
None else ""
1999 formatString = parameter_instance.format_string
if parameter_instance.format_string !=
None else ""
2000 datatype = sdds_short_string_to_data_type(parameter_instance.type)
2001 fixedValue = parameter_instance.fixed_value
if parameter_instance.fixed_value !=
None else ""
2002 sdds_obj.defineParameter(name, symbol=symbol, units=units, description=description,
2003 formatString=formatString, type=datatype, fixedValue=fixedValue)
2004 sdds_obj.setParameterValueList(name, sdds_file.values[name])
2005 elif isinstance(sdds_file.definitions[name], Array):
2007 array_instance = sdds_file.definitions[name]
2008 symbol = array_instance.symbol
if array_instance.symbol !=
None else ""
2009 units = array_instance.units
if array_instance.units !=
None else ""
2010 description = array_instance.description
if array_instance.description !=
None else ""
2011 formatString = array_instance.format_string
if array_instance.format_string !=
None else ""
2012 group_name = array_instance.group_name
if array_instance.group_name !=
None else ""
2013 datatype = sdds_short_string_to_data_type(array_instance.type)
2014 fieldLength = array_instance.field_length
if array_instance.field_length !=
None else 0
2015 dimensions = array_instance.dimensions
if array_instance.dimensions !=
None else 1
2016 sdds_obj.defineArray(name, symbol=symbol, units=units, description=description,
2017 formatString=formatString, group_name=group_name, type=datatype,
2018 fieldLength=fieldLength, dimensions=dimensions)
2019 sdds_obj.setArrayValueLists(name, sdds_file.values[name], sdds_file.array_dims[name])
2020 elif isinstance(sdds_file.definitions[name], Column):
2022 column_instance = sdds_file.definitions[name]
2023 symbol = column_instance.symbol
if column_instance.symbol !=
None else ""
2024 units = column_instance.units
if column_instance.units !=
None else ""
2025 description = column_instance.description
if column_instance.description !=
None else ""
2026 formatString = column_instance.format_string
if column_instance.format_string !=
None else ""
2027 datatype = sdds_short_string_to_data_type(column_instance.type)
2028 fieldLength = column_instance.field_length
if column_instance.field_length !=
None else 0
2029 sdds_obj.defineColumn(name, symbol=symbol, units=units, description=description,
2030 formatString=formatString, type=datatype, fieldLength=fieldLength)
2031 sdds_obj.setColumnValueLists(name, sdds_file.values[name])
2034 sdds_obj.save(output_file)
A class to represent and manipulate SDDS datasets.
getColumnValueLists(self, name)
Gets the nested list of column values for a single column.
defineSimpleParameter(self, name, type)
Defines a simple parameter with minimal information.
setArrayValueLists(self, name, valueList, dimensionList)
Sets the nested list of array values and dimensions for a single array.
defineArray(self, name, symbol="", units="", description="", formatString="", group_name="", type=SDDS_DOUBLE, fieldLength=0, dimensions=1)
Defines an array for the SDDS object.
defineSimpleColumn(self, name, type)
Defines a simple column with minimal information.
getColumnValueList(self, name, page=1)
Gets a single column value list at a specific page.
loadSparse(self, input, interval, offset)
Loads an SDDS file into the SDDS object with sparse data reading.
getArrayCount(self)
Retrieves the number of arrays.
getArrayDatatype(self, name)
Retrieves the data type of a array.
load(self, input)
Loads an SDDS file into the SDDS object.
getArrayValueLists(self, name)
Gets the nested list of array values for a single array.
setParameterValue(self, name, value, page=1)
Sets a single parameter value at a specific page.
__init__(self, index=None)
Initializes a new SDDS object.
getColumnCount(self)
Retrieves the number of columns.
getColumnValue(self, name, page=1, row=1)
Gets a single column value at a specific page and row.
setParameterValueList(self, name, valueList)
Sets the list of parameter values for a parameter.
getParameterValue(self, name, page=1)
Gets a single parameter value at a specific page.
__del__(self)
Destructor to release the index when the object is deleted.
getParameterValueList(self, name)
Gets the list of parameter values for a parameter.
getArrayNames(self)
Retrieves a list of all array names.
defineParameter(self, name, symbol="", units="", description="", formatString="", type=SDDS_DOUBLE, fixedValue="")
Defines a parameter for the SDDS object.
defineColumn(self, name, symbol="", units="", description="", formatString="", type=SDDS_DOUBLE, fieldLength=0)
Defines a column for the SDDS object.
getParameterNames(self)
Retrieves a list of all parameter names.
getColumnDatatype(self, name)
Retrieves the data type of a column.
pageCount(self)
Retrieves the number or loaded pages.
setColumnValue(self, name, value, page=1, row=1)
Sets a single column value at a specific page and row.
getArrayDimensionLists(self, name)
Gets the nested list of array dimensions for a single array.
defineSimpleArray(self, name, type, dimensions)
Defines a simple array with minimal information.
getParameterCount(self)
Retrieves the number of parameters.
setArrayValueList(self, name, valueList, dimensionList, page=1)
Sets a single array value and dimension at a specific page.
int SDDS_VERBOSE_PrintErrors
getParameterUnits(self, name)
Retrieves the units of a parameter.
setDescription(self, text, contents)
Sets the description for the SDDS object.
loadLastRows(self, input, lastrows)
Loads an SDDS file into the SDDS object, reading only the last few rows.
getArrayValueList(self, name, page=1)
Gets a single array value at a specific page.
getParameterDatatype(self, name)
Retrieves the data type of a parameter.
getArrayDimensionList(self, name, page=1)
Gets a single array dimension at a specific page.
save(self, output)
Saves the SDDS object's data to an SDDS file.
setColumnValueList(self, name, valueList, page=1)
Sets a single column value list at a specific page.
getColumnNames(self)
Retrieves a list of all column names.
setColumnValueLists(self, name, valueList)
Sets the nested list of column values for a single column.