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.
19 A class to represent and manipulate SDDS datasets.
21 This class provides methods to load, manipulate, and save SDDS data.
22 It supports ASCII and binary formats and facilitates operations on parameters, arrays, and columns.
25 - Each SDDS object must be initialized with a unique index ranging
26 from 0 to 19. This index is required to manage the internal SDDS
27 library resources and ensure no conflicts between multiple SDDS
28 objects in the same program.
29 - Ensure that the index is released (if necessary) before reusing it.
32 index (int): The index of the SDDS dataset (integer from 0 to 19).
33 description (list): List containing the description text and contents of the SDDS file.
34 parameterName (list): List of parameter names.
35 arrayName (list): List of array names.
36 columnName (list): List of column names.
37 parameterDefinition (list): List of parameter definitions.
38 arrayDefinition (list): List of array definitions.
39 arrayDimensions (list): List of array dimensions.
40 columnDefinition (list): List of column definitions.
41 parameterData (list): List of parameter data values.
42 arrayData (list): List of array data values.
43 columnData (list): List of column data values.
44 mode (int): The data storage mode (`SDDS_ASCII` or `SDDS_BINARY`).
48 SDDS_VERBOSE_PrintErrors = 1
49 SDDS_EXIT_PrintErrors = 2
53 SDDS_CHECK_NONEXISTENT = 1
54 SDDS_CHECK_WRONGTYPE = 2
55 SDDS_CHECK_WRONGUNITS = 3
86 Initializes a new SDDS object.
89 index (int): Integer index of the SDDS object. Must be between 0 and 19 inclusive.
91 The attributes are initialized to their default values.
114 Loads an SDDS file into the SDDS object.
117 input (str): The input SDDS filename to load.
120 Exception: If unable to read the SDDS data.
122 This method reads the SDDS file specified by `input`, and populates the object's data structures
123 with the parameters, arrays, columns, and their respective data.
127 if sddsdata.InitializeInput(self.
index, input) != 1:
129 if sddsdata.InitializeInput(self.
index, input) != 1:
130 raise ValueError(
"Failed to initialize SDDS input.")
161 self.
arrayData = [[]
for _
in range(numberOfArrays)]
162 self.
columnData = [[]
for _
in range(numberOfColumns)]
166 page = sddsdata.ReadPage(self.
index)
168 raise Exception(
"Unable to read SDDS data for the first page")
171 for i
in range(numberOfParameters):
173 for i
in range(numberOfArrays):
176 rows = sddsdata.RowCount(self.
index)
178 for i
in range(numberOfColumns):
181 for i
in range(numberOfColumns):
183 page = sddsdata.ReadPage(self.
index)
186 if sddsdata.Terminate(self.
index) != 1:
187 raise ValueError(
"Failed to terminate SDDS input.")
195 Loads an SDDS file into the SDDS object with sparse data reading.
198 input (str): The input SDDS filename to load.
199 interval (int): Interval between pages to read.
200 offset (int): Offset to start reading from.
203 Exception: If unable to read the SDDS data.
205 This method reads every `interval` pages from the SDDS file, starting from the page at `offset`.
209 if sddsdata.InitializeInput(self.
index, input) != 1:
211 if sddsdata.InitializeInput(self.
index, input) != 1:
212 raise ValueError(
"Failed to initialize SDDS input.")
243 self.
arrayData = [[]
for _
in range(numberOfArrays)]
244 self.
columnData = [[]
for _
in range(numberOfColumns)]
248 page = sddsdata.ReadPageSparse(self.
index, interval, offset)
250 raise Exception(
"Unable to read SDDS data for the first page")
252 for i
in range(numberOfParameters):
254 for i
in range(numberOfArrays):
257 rows = sddsdata.RowCount(self.
index)
259 for i
in range(numberOfColumns):
262 for i
in range(numberOfColumns):
264 page = sddsdata.ReadPageSparse(self.
index, interval, offset)
267 if sddsdata.Terminate(self.
index) != 1:
268 raise ValueError(
"Failed to terminate SDDS input.")
276 Loads an SDDS file into the SDDS object, reading only the last few rows.
279 input (str): The input SDDS filename to load.
280 lastrows (int): Number of last rows to read.
283 Exception: If unable to read the SDDS data.
285 This method reads only the last `lastrows` rows from each page of the SDDS file.
289 if sddsdata.InitializeInput(self.
index, input) != 1:
291 if sddsdata.InitializeInput(self.
index, input) != 1:
292 raise ValueError(
"Failed to initialize SDDS input.")
323 self.
arrayData = [[]
for _
in range(numberOfArrays)]
324 self.
columnData = [[]
for _
in range(numberOfColumns)]
328 page = sddsdata.ReadPageLastRows(self.
index, lastrows)
330 raise Exception(
"Unable to read SDDS data for the first page")
332 for i
in range(numberOfParameters):
334 for i
in range(numberOfArrays):
337 rows = sddsdata.RowCount(self.
index)
339 for i
in range(numberOfColumns):
342 for i
in range(numberOfColumns):
344 page = sddsdata.ReadPageLastRows(self.
index, lastrows)
347 if sddsdata.Terminate(self.
index) != 1:
348 raise ValueError(
"Failed to terminate SDDS input.")
356 Saves the SDDS object's data to an SDDS file.
359 output (str): The output SDDS filename to save the data.
362 Exception: If unable to write the SDDS data.
364 This method writes the data stored in the SDDS object to the specified file, including the
365 parameters, arrays, columns, and their data.
375 raise Exception(
"Unmatched parameterName and parameterData")
376 if numberOfArrays != len(self.
arrayData):
377 raise Exception(
"Unmatched arrayName and arrayData")
379 raise Exception(
"Unmatched columnName and columnData")
381 raise Exception(
"Unmatched parameterName and parameterDefinition")
383 raise Exception(
"Unmatched arrayName and arrayDefinition")
385 raise Exception(
"Unmatched columnName and columnDefinition")
387 if numberOfParameters > 0:
389 elif numberOfColumns > 0:
391 elif numberOfArrays > 0:
394 for i
in range(numberOfParameters):
396 raise Exception(
"Unequal number of pages in parameter data")
397 for i
in range(numberOfArrays):
399 raise Exception(
"Unequal number of pages in array data")
401 raise Exception(
"Unequal number of pages in array dimension data")
402 for i
in range(numberOfColumns):
404 raise Exception(
"Unequal number of pages in column data")
405 for page
in range(pages):
407 if numberOfColumns > 0:
409 for i
in range(numberOfColumns):
411 raise Exception(
"Unequal number of rows in column data")
415 raise ValueError(
"Failed to initialize SDDS output.")
418 for i
in range(numberOfParameters):
419 if sddsdata.DefineParameter(
429 raise ValueError(
"Failed to define parameter.")
431 for i
in range(numberOfArrays):
432 if sddsdata.DefineArray(
444 raise ValueError(
"Failed to define array.")
446 for i
in range(numberOfColumns):
447 if sddsdata.DefineColumn(
457 raise ValueError(
"Failed to define column.")
460 if sddsdata.WriteLayout(self.
index) != 1:
461 raise ValueError(
"Failed to write SDDS layout.")
464 for page
in range(pages):
466 if numberOfColumns > 0:
468 if sddsdata.StartPage(self.
index, rows) != 1:
469 raise ValueError(
"Failed to start SDDS page.")
470 for i
in range(numberOfParameters):
472 raise ValueError(
"Failed to set parameter value.")
473 for i
in range(numberOfArrays):
474 if sddsdata.SetArray(
477 raise ValueError(
"Failed to set array value.")
478 for i
in range(numberOfColumns):
480 raise ValueError(
"Failed to set column value.")
481 if sddsdata.WritePage(self.
index) != 1:
482 raise ValueError(
"Failed to write SDDS page.")
485 if sddsdata.Terminate(self.
index) != 1:
486 raise ValueError(
"Failed to terminate SDDS output.")
493 Sets the description for the SDDS object.
496 text (str): Description text.
497 contents (str): Description contents.
501 def defineParameter(self, name, symbol="", units="", description="", formatString="", type=SDDS_DOUBLE, fixedValue=""):
503 Defines a parameter for the SDDS object.
506 name (str): Parameter name.
507 symbol (str, optional): Parameter symbol.
508 units (str, optional): Parameter units.
509 description (str, optional): Parameter description.
510 formatString (str, optional): Format string for the parameter.
511 type (int, optional): Data type of the parameter. Defaults to SDDS_DOUBLE. Valid options include:
512 - SDDS_SHORT: 16-bit signed integer.
513 - SDDS_USHORT: 16-bit unsigned integer.
514 - SDDS_LONG: 32-bit signed integer.
515 - SDDS_ULONG: 32-bit unsigned integer.
516 - SDDS_LONG64: 64-bit signed integer.
517 - SDDS_ULONG64: 64-bit unsigned integer.
518 - SDDS_FLOAT: Single-precision floating-point number.
519 - SDDS_DOUBLE: Double-precision floating-point number.
520 - SDDS_LONGDOUBLE: Long double-precision floating-point number.
521 - SDDS_STRING: String (textual data).
522 - SDDS_CHARACTER: Single character.
523 fixedValue (str, optional): Fixed value of the parameter.
525 This method adds a parameter definition to the SDDS object.
529 [symbol, units, description, formatString, type, fixedValue]
535 Defines a simple parameter with minimal information.
538 name (str): Parameter name.
539 type (int): Data type of the parameter. Valid options include:
540 - SDDS_SHORT: 16-bit signed integer.
541 - SDDS_USHORT: 16-bit unsigned integer.
542 - SDDS_LONG: 32-bit signed integer.
543 - SDDS_ULONG: 32-bit unsigned integer.
544 - SDDS_LONG64: 64-bit signed integer.
545 - SDDS_ULONG64: 64-bit unsigned integer.
546 - SDDS_FLOAT: Single-precision floating-point number.
547 - SDDS_DOUBLE: Double-precision floating-point number.
548 - SDDS_LONGDOUBLE: Long double-precision floating-point number.
549 - SDDS_STRING: String (textual data).
550 - SDDS_CHARACTER: Single character.
552 This method adds a parameter definition with default attributes.
558 def defineArray(self, name, symbol="", units="", description="", formatString="", group_name="", type=SDDS_DOUBLE, fieldLength=0, dimensions=1):
560 Defines an array for the SDDS object.
563 name (str): Array name.
564 symbol (str, optional): Array symbol.
565 units (str, optional): Array units.
566 description (str, optional): Array description.
567 formatString (str, optional): Format string for the array.
568 group_name (str, optional): Group name for the array.
569 type (int, optional): Data type of the array. Defaults to SDDS_DOUBLE, Valid options include:
570 - SDDS_SHORT: 16-bit signed integer.
571 - SDDS_USHORT: 16-bit unsigned integer.
572 - SDDS_LONG: 32-bit signed integer.
573 - SDDS_ULONG: 32-bit unsigned integer.
574 - SDDS_LONG64: 64-bit signed integer.
575 - SDDS_ULONG64: 64-bit unsigned integer.
576 - SDDS_FLOAT: Single-precision floating-point number.
577 - SDDS_DOUBLE: Double-precision floating-point number.
578 - SDDS_LONGDOUBLE: Long double-precision floating-point number.
579 - SDDS_STRING: String (textual data).
580 - SDDS_CHARACTER: Single character.
581 fieldLength (int, optional): Field length for the array.
582 dimensions (int, optional): Number of dimensions of the array. Defaults to 1
584 This method adds an array definition to the SDDS object.
588 [symbol, units, description, formatString, group_name, type, fieldLength, dimensions]
595 Defines a simple array with minimal information.
598 name (str): Array name.
599 type (int): Data type of the array. Valid options include:
600 - SDDS_SHORT: 16-bit signed integer.
601 - SDDS_USHORT: 16-bit unsigned integer.
602 - SDDS_LONG: 32-bit signed integer.
603 - SDDS_ULONG: 32-bit unsigned integer.
604 - SDDS_LONG64: 64-bit signed integer.
605 - SDDS_ULONG64: 64-bit unsigned integer.
606 - SDDS_FLOAT: Single-precision floating-point number.
607 - SDDS_DOUBLE: Double-precision floating-point number.
608 - SDDS_LONGDOUBLE: Long double-precision floating-point number.
609 - SDDS_STRING: String (textual data).
610 - SDDS_CHARACTER: Single character.
611 dimensions (int): Number of dimensions of the array.
613 This method adds an array definition with default attributes.
620 def defineColumn(self, name, symbol="", units="", description="", formatString="", type=SDDS_DOUBLE, fieldLength=0):
622 Defines a column for the SDDS object.
625 name (str): Column name.
626 symbol (str, optional): Column symbol.
627 units (str, optional): Column units.
628 description (str, optional): Column description.
629 formatString (str, optional): Format string for the column.
630 type (int, optional): Data type of the column. Defaults to SDDS_DOUBLE. Valid options include:
631 - SDDS_SHORT: 16-bit signed integer.
632 - SDDS_USHORT: 16-bit unsigned integer.
633 - SDDS_LONG: 32-bit signed integer.
634 - SDDS_ULONG: 32-bit unsigned integer.
635 - SDDS_LONG64: 64-bit signed integer.
636 - SDDS_ULONG64: 64-bit unsigned integer.
637 - SDDS_FLOAT: Single-precision floating-point number.
638 - SDDS_DOUBLE: Double-precision floating-point number.
639 - SDDS_LONGDOUBLE: Long double-precision floating-point number.
640 - SDDS_STRING: String (textual data).
641 - SDDS_CHARACTER: Single character.
642 fieldLength (int, optional): Field length for the column.
644 This method adds a column definition to the SDDS object.
648 [symbol, units, description, formatString, type, fieldLength]
654 Defines a simple column with minimal information.
657 name (str): Column name.
658 type (int): Data type of the column. Valid options include:
659 - SDDS_SHORT: 16-bit signed integer.
660 - SDDS_USHORT: 16-bit unsigned integer.
661 - SDDS_LONG: 32-bit signed integer.
662 - SDDS_ULONG: 32-bit unsigned integer.
663 - SDDS_LONG64: 64-bit signed integer.
664 - SDDS_ULONG64: 64-bit unsigned integer.
665 - SDDS_FLOAT: Single-precision floating-point number.
666 - SDDS_DOUBLE: Double-precision floating-point number.
667 - SDDS_LONGDOUBLE: Long double-precision floating-point number.
668 - SDDS_STRING: String (textual data).
669 - SDDS_CHARACTER: Single character.
671 This method adds a column definition with default attributes.
679 Sets the list of parameter values for a parameter. This can be used to set values for multiple pages at once.
682 name (str): Parameter name.
683 valueList (list): List of values for the parameter.
686 Exception: If the parameter name is invalid.
688 This method assigns a list of values to a parameter across pages.
694 msg =
"Invalid parameter name " + name
699 Gets the list of parameter values for a parameter. This can be used to get values for multiple pages at once.
702 name (str): Parameter name.
705 list: List of values for the parameter.
708 Exception: If the parameter name is invalid.
715 msg =
"Invalid parameter name " + name
720 Sets a single parameter value at a specific page.
723 name (str): Parameter name.
724 value: Parameter value.
725 page (int, optional): Page number (1-based index, defaults to 1).
728 Exception: If the parameter name or page is invalid.
730 This method sets the parameter value at the specified page.
739 msg =
"Invalid page " + str(page + 1)
744 msg =
"Invalid parameter name " + name
749 Gets a single parameter value at a specific page.
752 name (str): Parameter name.
753 page (int, optional): Page number (1-based index, defaults to 1).
756 value: Parameter value.
759 Exception: If the parameter name or page is invalid.
768 msg =
"Invalid page " + str(page + 1)
773 msg =
"Invalid parameter name " + name
778 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.
781 name (str): Array name.
782 valueList (list): Nested list of array values.
783 dimensionList (list): Nested list of array dimensions.
786 Exception: If the array name is invalid.
788 This method assigns values and dimensions to an array across pages.
796 msg =
"Invalid array name " + name
801 Gets the nested list of array values for a single array. This can be used to get values for multiple pages at once.
804 name (str): Array name.
807 list: Nested list of array values.
810 Exception: If the array name is invalid.
816 msg =
"Invalid array name " + name
821 Gets the nested list of array dimensions for a single array. This can be used to get dimensions for multiple pages at once.
824 name (str): Array name.
827 list: Nested list of array dimensions.
830 Exception: If the array name is invalid.
836 msg =
"Invalid array name " + name
841 Sets a single array value and dimension at a specific page.
844 name (str): Array name.
845 valueList (list): Array values.
846 dimensionList (list): Array dimensions.
847 page (int, optional): Page number (1-based index, defaults to 1).
850 Exception: If the array name or page is invalid.
852 This method sets the array values and dimensions at the specified page.
861 elif len(self.
arrayData[i]) < page
or page < 0:
862 msg =
"Invalid page " + str(page + 1)
868 msg =
"Invalid array name " + name
873 Gets a single array value at a specific page.
876 name (str): Array name.
877 page (int, optional): Page number (1-based index, defaults to 1).
883 Exception: If the array name or page is invalid.
891 elif len(self.
arrayData[i]) < page
or page < 0:
892 msg =
"Invalid page " + str(page + 1)
897 msg =
"Invalid array name " + name
902 Gets a single array dimension at a specific page.
905 name (str): Array name.
906 page (int, optional): Page number (1-based index, defaults to 1).
909 list: Array dimension.
912 Exception: If the array name or page is invalid.
920 elif len(self.
arrayData[i]) < page
or page < 0:
921 msg =
"Invalid page " + str(page + 1)
926 msg =
"Invalid array name " + name
931 Sets the nested list of column values for a single column. This can be used to set values for multiple pages at once.
934 name (str): Column name.
935 valueList (list): Nested list of column values.
938 Exception: If the column name is invalid.
940 This method assigns a list of values to a column across pages.
946 msg =
"Invalid column name " + name
951 Gets the nested list of column values for a single column. This can be used to get values for multiple pages at once.
954 name (str): Column name.
957 list: Nested list of column values.
960 Exception: If the column name is invalid.
966 msg =
"Invalid column name " + name
971 Sets a single column value list at a specific page.
974 name (str): Column name.
975 valueList (list): Column values.
976 page (int, optional): Page number (1-based index, defaults to 1).
979 Exception: If the column name or page is invalid.
981 This method sets the column values at the specified page.
988 elif len(self.
columnData[i]) < page
or page < 0:
989 msg =
"Invalid page " + str(page + 1)
994 msg =
"Invalid column name " + name
999 Gets a single column value list at a specific page.
1002 name (str): Column name.
1003 page (int, optional): Page number (1-based index, defaults to 1).
1006 list: Column values.
1009 Exception: If the column name or page is invalid.
1017 elif len(self.
columnData[i]) < page
or page < 0:
1018 msg =
"Invalid page " + str(page + 1)
1019 raise Exception(msg)
1023 msg =
"Invalid column name " + name
1024 raise Exception(msg)
1028 Sets a single column value at a specific page and row.
1031 name (str): Column name.
1032 value: Column value.
1033 page (int, optional): Page number (1-based index, defaults to 1).
1034 row (int, optional): Row number (1-based index, defaults to 1).
1037 Exception: If the column name, page, or row is invalid.
1039 This method sets the column value at the specified page and row.
1050 msg =
"Invalid row " + str(row + 1)
1051 raise Exception(msg)
1052 elif len(self.
columnData[i]) < page
or page < 0:
1053 msg =
"Invalid page " + str(page + 1)
1054 raise Exception(msg)
1058 elif len(self.
columnData[i][page]) < row
or row < 0:
1059 msg =
"Invalid row " + str(row + 1)
1060 raise Exception(msg)
1064 msg =
"Invalid column name " + name
1065 raise Exception(msg)
1069 Gets a single column value at a specific page and row.
1072 name (str): Column name.
1073 page (int, optional): Page number (1-based index, defaults to 1).
1074 row (int, optional): Row number (1-based index, defaults to 1).
1077 value: Column value.
1080 Exception: If the column name, page, or row is invalid.
1091 msg =
"Invalid row " + str(row + 1)
1092 raise Exception(msg)
1093 elif len(self.
columnData[i]) < page
or page < 0:
1094 msg =
"Invalid page " + str(page + 1)
1095 raise Exception(msg)
1099 elif len(self.
columnData[i][page]) < row
or row < 0:
1100 msg =
"Invalid row " + str(row + 1)
1101 raise Exception(msg)
1105 msg =
"Invalid column name " + name
1106 raise Exception(msg)
1110 Retrieves the number of parameters.
1113 int: The number of parameters.
1119 Retrieves the number of arrays.
1122 int: The number of arrays.
1128 Retrieves the number of columns.
1131 int: The number of columns.
1137 Retrieves a list of all parameter names.
1140 list: A list of parameter names as strings, or an empty list.
1146 Retrieves a list of all array names.
1149 list: A list of array names as strings, or an empty list.
1155 Retrieves a list of all column names.
1158 list: A list of column names as strings, or an empty list.
1164 Retrieves the data type of a parameter.
1167 name (str): Parameter name.
1170 int: Number representing the data type of the parameter.
1175 msg =
"Invalid parameter name " + name
1176 raise Exception(msg)
1180 Retrieves the data type of a array.
1183 name (str): Array name.
1186 int: Number representing the data type of the array.
1191 msg =
"Invalid array name " + name
1192 raise Exception(msg)
1196 Retrieves the data type of a column.
1199 name (str): Column name.
1202 int: Number representing the data type of the column.
1207 msg =
"Invalid column name " + name
1208 raise Exception(msg)
1212 Retrieves the units of a parameter.
1215 name (str): Parameter name.
1218 str: Units of the parameter.
1223 msg =
"Invalid parameter name " + name
1224 raise Exception(msg)
1228 Retrieves the units of a array.
1231 name (str): Array name.
1234 str: Units of the array.
1239 msg =
"Invalid array name " + name
1240 raise Exception(msg)
1244 Retrieves the units of a column.
1247 name (str): Column name.
1250 str: Units of the column.
1255 msg =
"Invalid column name " + name
1256 raise Exception(msg)
1260 Retrieves the number or loaded pages
1263 int: Number or loaded pages
1270SDDS_VERBOSE_PrintErrors = SDDS.SDDS_VERBOSE_PrintErrors
1271SDDS_EXIT_PrintErrors = SDDS.SDDS_EXIT_PrintErrors
1272SDDS_CHECK_OKAY = SDDS.SDDS_CHECK_OKAY
1273SDDS_CHECK_NONEXISTENT = SDDS.SDDS_CHECK_NONEXISTENT
1274SDDS_CHECK_WRONGTYPE = SDDS.SDDS_CHECK_WRONGTYPE
1275SDDS_CHECK_WRONGUNITS = SDDS.SDDS_CHECK_WRONGUNITS
1276SDDS_LONGDOUBLE = SDDS.SDDS_LONGDOUBLE
1277SDDS_DOUBLE = SDDS.SDDS_DOUBLE
1278SDDS_REAL64 = SDDS.SDDS_REAL64
1279SDDS_FLOAT = SDDS.SDDS_FLOAT
1280SDDS_REAL32 = SDDS.SDDS_REAL32
1281SDDS_LONG64 = SDDS.SDDS_LONG64
1282SDDS_INT64 = SDDS.SDDS_INT64
1283SDDS_ULONG64 = SDDS.SDDS_ULONG64
1284SDDS_UINT64 = SDDS.SDDS_UINT64
1285SDDS_LONG = SDDS.SDDS_LONG
1286SDDS_INT32 = SDDS.SDDS_INT32
1287SDDS_ULONG = SDDS.SDDS_ULONG
1288SDDS_UINT32 = SDDS.SDDS_UINT32
1289SDDS_SHORT = SDDS.SDDS_SHORT
1290SDDS_INT16 = SDDS.SDDS_INT16
1291SDDS_USHORT = SDDS.SDDS_USHORT
1292SDDS_UINT16 = SDDS.SDDS_UINT16
1293SDDS_STRING = SDDS.SDDS_STRING
1294SDDS_CHARACTER = SDDS.SDDS_CHARACTER
1295SDDS_NUM_TYPES = SDDS.SDDS_NUM_TYPES
1296SDDS_BINARY = SDDS.SDDS_BINARY
1297SDDS_ASCII = SDDS.SDDS_ASCII
1298SDDS_FLUSH_TABLE = SDDS.SDDS_FLUSH_TABLE
1300def sdds_data_type_to_string(data_type_code):
1302 Converts a numeric SDDS data type code to its string representation.
1305 data_type_code (int): Numeric code of the SDDS data type.
1308 str: String representation of the SDDS data type.
1312 1:
"SDDS_LONGDOUBLE",
1322 11:
"SDDS_CHARACTER",
1324 return data_type_map.get(data_type_code,
"Unknown Data Type")
1328 Demonstrates how to save a demo SDDS file using the SDDS class.
1331 output (str): The output SDDS filename to save the demo data.
1333 This function creates an SDDS object, populates it with sample data, and saves it to the specified output file.
1336 x.description[0] =
"text"
1337 x.description[1] =
"contents"
1338 x.parameterName = [
"ShortP",
"LongP",
"FloatP",
"DoubleP",
"StringP",
"CharacterP"]
1339 x.parameterData = [[1, 6], [2, 7], [3.3, 8.8], [4.4, 9.8], [
"five",
"ten"], [
"a",
"b"]]
1340 x.parameterDefinition = [
1341 [
"",
"",
"",
"", x.SDDS_SHORT,
""],
1342 [
"",
"",
"",
"", x.SDDS_LONG,
""],
1343 [
"",
"",
"",
"", x.SDDS_FLOAT,
""],
1344 [
"",
"",
"",
"", x.SDDS_DOUBLE,
""],
1345 [
"",
"",
"",
"", x.SDDS_STRING,
""],
1346 [
"",
"",
"",
"", x.SDDS_CHARACTER,
""],
1349 x.arrayName = [
"ShortA",
"LongA",
"FloatA",
"DoubleA",
"StringA",
"CharacterA"]
1350 x.arrayDefinition = [
1351 [
"",
"",
"",
"",
"", x.SDDS_SHORT, 0, 1],
1352 [
"",
"",
"",
"",
"", x.SDDS_LONG, 0, 1],
1353 [
"",
"",
"",
"",
"", x.SDDS_FLOAT, 0, 2],
1354 [
"",
"",
"",
"",
"", x.SDDS_DOUBLE, 0, 1],
1355 [
"",
"",
"",
"",
"", x.SDDS_STRING, 0, 1],
1356 [
"",
"",
"",
"",
"", x.SDDS_CHARACTER, 0, 1],
1358 x.arrayDimensions = [
1367 [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6, 7, 8]],
1368 [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 6, 7]],
1369 [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6, 7, 8]],
1370 [[1, 2, 3, 4], [1, 2, 3, 4, 5]],
1371 [[
"one",
"two",
"three",
"four"], [
"five",
"six",
"seven",
"eight",
"nine"]],
1372 [[
"a",
"b",
"c",
"d"], [
"e",
"f",
"g",
"h",
"i"]],
1375 x.columnName = [
"ShortC",
"LongC",
"FloatC",
"DoubleC",
"StringC",
"CharacterC"]
1377 [[1, 2, 3], [-1, -2, -3, -4]],
1378 [[1, 2, 3], [-1, -2, -3, -4]],
1379 [[1, 2, 3], [-1, -2, -3.6, -4.4]],
1380 [[1, 2, 3], [-1, -2, -3.6, -4.4]],
1381 [[
"row 1",
"row 2",
"row 3"], [
"row 1",
"row 2",
"row 3",
"row 4"]],
1382 [[
"x",
"y",
"z"], [
"i",
"j",
"k",
"l"]],
1384 x.columnDefinition = [
1385 [
"",
"",
"",
"", x.SDDS_SHORT, 0],
1386 [
"",
"",
"",
"", x.SDDS_LONG, 0],
1387 [
"",
"",
"",
"", x.SDDS_FLOAT, 0],
1388 [
"",
"",
"",
"", x.SDDS_DOUBLE, 0],
1389 [
"",
"",
"",
"", x.SDDS_STRING, 0],
1390 [
"",
"",
"",
"", x.SDDS_CHARACTER, 0],
1399 Demonstrates how to save a demo SDDS file using the SDDS class with simplified definitions.
1402 output (str): The output SDDS filename to save the demo data.
1404 This function shows how to use simplified methods to define parameters, arrays, and columns.
1407 x.setDescription(
"text",
"contents")
1408 names = [
"Short",
"Long",
"Float",
"Double",
"String",
"Character"]
1409 types = [x.SDDS_SHORT, x.SDDS_LONG, x.SDDS_FLOAT, x.SDDS_DOUBLE, x.SDDS_STRING, x.SDDS_CHARACTER]
1411 x.defineSimpleParameter(names[i] +
"P", types[i])
1412 if types[i] == x.SDDS_FLOAT:
1413 x.defineSimpleArray(names[i] +
"A", types[i], 2)
1415 x.defineSimpleArray(names[i] +
"A", types[i], 1)
1416 x.defineSimpleColumn(names[i] +
"C", types[i])
1417 parameterData = [[1, 6], [2, 7], [3.3, 8.8], [4.4, 9.8], [
"five",
"ten"], [
"a",
"b"]]
1419 x.setParameterValueList(names[i] +
"P", parameterData[i])
1430 [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6, 7, 8]],
1431 [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 6, 7]],
1432 [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6, 7, 8]],
1433 [[1, 2, 3, 4], [1, 2, 3, 4, 5]],
1434 [[
"one",
"two",
"three",
"four"], [
"five",
"six",
"seven",
"eight",
"nine"]],
1435 [[
"a",
"b",
"c",
"d"], [
"e",
"f",
"g",
"h",
"i"]],
1438 x.setArrayValueLists(names[i] +
"A", arrayData[i], arrayDimensions[i])
1441 [[1, 2, 3], [-1, -2, -3, -4]],
1442 [[1, 2, 3], [-1, -2, -3, -4]],
1443 [[1, 2, 3], [-1, -2, -3.6, -4.4]],
1444 [[1, 2, 3], [-1, -2, -3.6, -4.4]],
1445 [[
"row 1",
"row 2",
"row 3"], [
"row 1",
"row 2",
"row 3",
"row 4"]],
1446 [[
"x",
"y",
"z"], [
"i",
"j",
"k",
"l"]],
1449 x.setColumnValueLists(names[i] +
"C", columnData[i])
1455 Demonstrates how to save a demo SDDS file using `sddsdata` commands directly.
1458 output (str): The output SDDS filename to save the demo data.
1460 This function shows how to use `sddsdata` module functions directly to create and save an SDDS file.
1466 if sddsdata.InitializeOutput(x.index, x.SDDS_BINARY, 1,
"",
"", output) != 1:
1467 raise ValueError(
"Failed to initialize SDDS output.")
1469 sddsdata.SetColumnMajorOrder(x.index)
1471 if sddsdata.DefineSimpleParameter(x.index,
"ParameterA",
"mm", x.SDDS_DOUBLE) != 1:
1472 raise ValueError(
"Failed to define parameter.")
1474 if sddsdata.DefineSimpleArray(x.index,
"ArrayA",
"DegC", x.SDDS_DOUBLE, 1) != 1:
1475 raise ValueError(
"Failed to define array.")
1476 if sddsdata.DefineSimpleArray(x.index,
"ArrayB",
"DegC", x.SDDS_DOUBLE, 2) != 1:
1477 raise ValueError(
"Failed to define array.")
1479 if sddsdata.DefineSimpleColumn(x.index,
"ColumnA",
"Volts", x.SDDS_DOUBLE) != 1:
1480 raise ValueError(
"Failed to define column.")
1481 if sddsdata.DefineSimpleColumn(x.index,
"ColumnB",
"Amps", x.SDDS_DOUBLE) != 1:
1482 raise ValueError(
"Failed to define column.")
1484 if sddsdata.WriteLayout(x.index) != 1:
1485 raise ValueError(
"Failed to write SDDS layout.")
1487 if sddsdata.StartPage(x.index, 100) != 1:
1488 raise ValueError(
"Failed to start SDDS page.")
1490 if sddsdata.SetParameter(x.index,
"ParameterA", 1.1) != 1:
1491 raise ValueError(
"Failed to set parameter value.")
1493 if sddsdata.SetArray(x.index,
"ArrayA", [1, 2, 3], [3]) != 1:
1494 raise ValueError(
"Failed to set array value.")
1495 if sddsdata.SetArray(x.index,
"ArrayB", [1, 2, 3, 4, 5, 6], [2, 3]) != 1:
1496 raise ValueError(
"Failed to set array value.")
1498 if sddsdata.SetColumn(x.index,
"ColumnA", [1, 2, 3]) != 1:
1499 raise ValueError(
"Failed to set column value.")
1500 if sddsdata.SetColumn(x.index,
"ColumnB", [1, 2, 3]) != 1:
1501 raise ValueError(
"Failed to set column value.")
1503 if sddsdata.WritePage(x.index) != 1:
1504 raise ValueError(
"Failed to write SDDS page.")
1506 if sddsdata.Terminate(x.index) != 1:
1507 raise ValueError(
"Failed to terminate SDDS output.")
1510 sddsdata.PrintErrors(x.SDDS_VERBOSE_PrintErrors)
1516 Demonstrates how to save a demo SDDS file using `sddsdata` commands and writing one row at a time.
1519 output (str): The output SDDS filename to save the demo data.
1521 This function shows how to write data to an SDDS file one row at a time, useful for logging applications.
1527 if sddsdata.InitializeOutput(x.index, x.SDDS_BINARY, 1,
"",
"", output) != 1:
1528 raise ValueError(
"Failed to initialize SDDS output.")
1530 sddsdata.EnableFSync(x.index)
1531 sddsdata.SetFixedRowCountMode(x.index)
1533 if sddsdata.DefineSimpleParameter(x.index,
"ParameterA",
"mm", x.SDDS_DOUBLE) != 1:
1534 raise ValueError(
"Failed to define parameter.")
1536 if sddsdata.DefineSimpleArray(x.index,
"ArrayA",
"DegC", x.SDDS_DOUBLE, 1) != 1:
1537 raise ValueError(
"Failed to define array.")
1538 if sddsdata.DefineSimpleArray(x.index,
"ArrayB",
"DegC", x.SDDS_DOUBLE, 2) != 1:
1539 raise ValueError(
"Failed to define array.")
1541 if sddsdata.DefineSimpleColumn(x.index,
"ColumnA",
"Volts", x.SDDS_DOUBLE) != 1:
1542 raise ValueError(
"Failed to define column.")
1543 if sddsdata.DefineSimpleColumn(x.index,
"ColumnB",
"Amps", x.SDDS_DOUBLE) != 1:
1544 raise ValueError(
"Failed to define column.")
1546 if sddsdata.WriteLayout(x.index) != 1:
1547 raise ValueError(
"Failed to write SDDS layout.")
1549 if sddsdata.StartPage(x.index, 2) != 1:
1550 raise ValueError(
"Failed to start SDDS page.")
1552 if sddsdata.SetParameter(x.index,
"ParameterA", 1.1) != 1:
1553 raise ValueError(
"Failed to set parameter value.")
1555 if sddsdata.SetArray(x.index,
"ArrayA", [1, 2, 3], [3]) != 1:
1556 raise ValueError(
"Failed to set array value.")
1557 if sddsdata.SetArray(x.index,
"ArrayB", [1, 2, 3, 4, 5, 6], [2, 3]) != 1:
1558 raise ValueError(
"Failed to set array value.")
1560 if sddsdata.SetRowValues(x.index, 0, [
"ColumnA", 1,
"ColumnB", 1]) != 1:
1561 raise ValueError(
"Failed to set row values.")
1562 if sddsdata.SetRowValues(x.index, 1, [
"ColumnA", 2,
"ColumnB", 2]) != 1:
1563 raise ValueError(
"Failed to set row values.")
1565 if sddsdata.UpdatePage(x.index, x.SDDS_FLUSH_TABLE) != 1:
1566 raise ValueError(
"Failed to update SDDS page.")
1568 if sddsdata.SetRowValues(x.index, 2, [
"ColumnA", 3,
"ColumnB", 3]) != 1:
1569 raise ValueError(
"Failed to set row values.")
1571 if sddsdata.UpdatePage(x.index, x.SDDS_FLUSH_TABLE) != 1:
1572 raise ValueError(
"Failed to update SDDS page.")
1574 if sddsdata.Terminate(x.index) != 1:
1575 raise ValueError(
"Failed to terminate SDDS output.")
1578 sddsdata.PrintErrors(x.SDDS_VERBOSE_PrintErrors)
1584 Demonstrates how to open an existing SDDS file and add rows to the last page without loading the whole file into memory.
1587 output (str): The output SDDS filename to append data.
1589 This function shows how to append data to an existing SDDS file efficiently.
1595 rows = sddsdata.InitializeAppendToPage(x.index, output, 100)
1597 raise ValueError(
"Failed to initialize appending to SDDS page.")
1599 if sddsdata.SetRowValues(x.index, rows, [
"ColumnA", 4,
"ColumnB", 4]) != 1:
1600 raise ValueError(
"Failed to set row values.")
1601 if sddsdata.SetRowValues(x.index, rows + 1, [
"ColumnA", 5,
"ColumnB", 5]) != 1:
1602 raise ValueError(
"Failed to set row values.")
1603 if sddsdata.SetRowValues(x.index, rows + 2, [
"ColumnA", 6,
"ColumnB", 6]) != 1:
1604 raise ValueError(
"Failed to set row values.")
1606 if sddsdata.UpdatePage(x.index, x.SDDS_FLUSH_TABLE) != 1:
1607 raise ValueError(
"Failed to update SDDS page.")
1609 if sddsdata.Terminate(x.index) != 1:
1610 raise ValueError(
"Failed to terminate SDDS output.")
1613 sddsdata.PrintErrors(x.SDDS_VERBOSE_PrintErrors)
1619 Demonstrates how to open an existing SDDS file and add a new page.
1622 output (str): The output SDDS filename to append data.
1624 This function shows how to append a new page to an existing SDDS file.
1630 if sddsdata.InitializeAppend(x.index, output) != 1:
1631 raise ValueError(
"Failed to initialize appending to SDDS file.")
1633 if sddsdata.StartPage(x.index, 100) != 1:
1634 raise ValueError(
"Failed to start SDDS page.")
1636 if sddsdata.SetParameter(x.index,
"ParameterA", 1.1) != 1:
1637 raise ValueError(
"Failed to set parameter value.")
1639 if sddsdata.SetArray(x.index,
"ArrayA", [1, 2, 3], [3]) != 1:
1640 raise ValueError(
"Failed to set array value.")
1641 if sddsdata.SetArray(x.index,
"ArrayB", [1, 2, 3, 4, 5, 6], [2, 3]) != 1:
1642 raise ValueError(
"Failed to set array value.")
1644 if sddsdata.SetRowValues(x.index, 0, [
"ColumnA", 7,
"ColumnB", 7]) != 1:
1645 raise ValueError(
"Failed to set row values.")
1646 if sddsdata.SetRowValues(x.index, 1, [
"ColumnA", 8,
"ColumnB", 8]) != 1:
1647 raise ValueError(
"Failed to set row values.")
1648 if sddsdata.SetRowValues(x.index, 2, [
"ColumnA", 9,
"ColumnB", 9]) != 1:
1649 raise ValueError(
"Failed to set row values.")
1651 if sddsdata.WritePage(x.index) != 1:
1652 raise ValueError(
"Failed to write SDDS page.")
1654 if sddsdata.Terminate(x.index) != 1:
1655 raise ValueError(
"Failed to terminate SDDS output.")
1658 sddsdata.PrintErrors(x.SDDS_VERBOSE_PrintErrors)
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.
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.
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.
__init__(self, index)
Initializes a new 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.