SDDS ToolKit Programs and Libraries for C and Python
Loading...
Searching...
No Matches
sdds Namespace Reference

Classes

class  Array
 
class  Column
 
class  Description
 
class  Parameter
 
class  SDDS
 A class to represent and manipulate SDDS datasets. More...
 
class  SddsFile
 

Functions

 sdds_data_type_to_string (data_type_code)
 Converts a numeric SDDS data type code to its string representation.
 
 sdds_data_type_to_short_string (data_type_code)
 Converts a numeric SDDS data type code to its short string representation.
 
 sdds_short_string_to_data_type (data_type_code)
 Converts a numeric SDDS data type code to its short string representation.
 
 demo1 (output)
 Demonstrates how to save a demo SDDS file using the SDDS class.
 
 demo2 (output)
 Demonstrates how to save a demo SDDS file using the SDDS class with simplified definitions.
 
 demo3 (output)
 Demonstrates how to save a demo SDDS file using sddsdata commands directly.
 
 demo4 (output)
 Demonstrates how to save a demo SDDS file using sddsdata commands and writing one row at a time.
 
 demo5 (output)
 Demonstrates how to open an existing SDDS file and add rows to the last page without loading the whole file into memory.
 
 demo6 (output)
 Demonstrates how to open an existing SDDS file and add a new page.
 
SddsFile read (input_file)
 Mostly backward compatible with the PyLHC sdds module read() function.
 
 write (SddsFile sdds_file, output_file)
 Mostly backward compatible with the PyLHC sdds module write() function.
 

Variables

 SDDS_VERBOSE_PrintErrors = SDDS.SDDS_VERBOSE_PrintErrors
 
 SDDS_EXIT_PrintErrors = SDDS.SDDS_EXIT_PrintErrors
 
 SDDS_CHECK_OKAY = SDDS.SDDS_CHECK_OKAY
 
 SDDS_CHECK_NONEXISTENT = SDDS.SDDS_CHECK_NONEXISTENT
 
 SDDS_CHECK_WRONGTYPE = SDDS.SDDS_CHECK_WRONGTYPE
 
 SDDS_CHECK_WRONGUNITS = SDDS.SDDS_CHECK_WRONGUNITS
 
 SDDS_LONGDOUBLE = SDDS.SDDS_LONGDOUBLE
 
 SDDS_DOUBLE = SDDS.SDDS_DOUBLE
 
 SDDS_REAL64 = SDDS.SDDS_REAL64
 
 SDDS_FLOAT = SDDS.SDDS_FLOAT
 
 SDDS_REAL32 = SDDS.SDDS_REAL32
 
 SDDS_LONG64 = SDDS.SDDS_LONG64
 
 SDDS_INT64 = SDDS.SDDS_INT64
 
 SDDS_ULONG64 = SDDS.SDDS_ULONG64
 
 SDDS_UINT64 = SDDS.SDDS_UINT64
 
 SDDS_LONG = SDDS.SDDS_LONG
 
 SDDS_INT32 = SDDS.SDDS_INT32
 
 SDDS_ULONG = SDDS.SDDS_ULONG
 
 SDDS_UINT32 = SDDS.SDDS_UINT32
 
 SDDS_SHORT = SDDS.SDDS_SHORT
 
 SDDS_INT16 = SDDS.SDDS_INT16
 
 SDDS_USHORT = SDDS.SDDS_USHORT
 
 SDDS_UINT16 = SDDS.SDDS_UINT16
 
 SDDS_STRING = SDDS.SDDS_STRING
 
 SDDS_CHARACTER = SDDS.SDDS_CHARACTER
 
 SDDS_NUM_TYPES = SDDS.SDDS_NUM_TYPES
 
 SDDS_BINARY = SDDS.SDDS_BINARY
 
 SDDS_ASCII = SDDS.SDDS_ASCII
 
 SDDS_FLUSH_TABLE = SDDS.SDDS_FLUSH_TABLE
 

Function Documentation

◆ demo1()

sdds.demo1 ( output)

Demonstrates how to save a demo SDDS file using the SDDS class.

Args: output (str): The output SDDS filename to save the demo data.

This function creates an SDDS object, populates it with sample data, and saves it to the specified output file.

Definition at line 1383 of file sdds.py.

1383def demo1(output):
1384 """
1385 Demonstrates how to save a demo SDDS file using the SDDS class.
1386
1387 Args:
1388 output (str): The output SDDS filename to save the demo data.
1389
1390 This function creates an SDDS object, populates it with sample data, and saves it to the specified output file.
1391 """
1392 x = SDDS(0)
1393 x.description[0] = "text"
1394 x.description[1] = "contents"
1395 x.parameterName = ["ShortP", "LongP", "FloatP", "DoubleP", "StringP", "CharacterP"]
1396 x.parameterData = [[1, 6], [2, 7], [3.3, 8.8], [4.4, 9.8], ["five", "ten"], ["a", "b"]]
1397 x.parameterDefinition = [
1398 ["", "", "", "", x.SDDS_SHORT, ""],
1399 ["", "", "", "", x.SDDS_LONG, ""],
1400 ["", "", "", "", x.SDDS_FLOAT, ""],
1401 ["", "", "", "", x.SDDS_DOUBLE, ""],
1402 ["", "", "", "", x.SDDS_STRING, ""],
1403 ["", "", "", "", x.SDDS_CHARACTER, ""],
1404 ]
1405
1406 x.arrayName = ["ShortA", "LongA", "FloatA", "DoubleA", "StringA", "CharacterA"]
1407 x.arrayDefinition = [
1408 ["", "", "", "", "", x.SDDS_SHORT, 0, 1],
1409 ["", "", "", "", "", x.SDDS_LONG, 0, 1],
1410 ["", "", "", "", "", x.SDDS_FLOAT, 0, 2],
1411 ["", "", "", "", "", x.SDDS_DOUBLE, 0, 1],
1412 ["", "", "", "", "", x.SDDS_STRING, 0, 1],
1413 ["", "", "", "", "", x.SDDS_CHARACTER, 0, 1],
1414 ]
1415 x.arrayDimensions = [
1416 [[6], [8]],
1417 [[5], [7]],
1418 [[2, 3], [2, 4]],
1419 [[4], [5]],
1420 [[4], [5]],
1421 [[4], [5]],
1422 ]
1423 x.arrayData = [
1424 [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6, 7, 8]],
1425 [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 6, 7]],
1426 [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6, 7, 8]],
1427 [[1, 2, 3, 4], [1, 2, 3, 4, 5]],
1428 [["one", "two", "three", "four"], ["five", "six", "seven", "eight", "nine"]],
1429 [["a", "b", "c", "d"], ["e", "f", "g", "h", "i"]],
1430 ]
1431
1432 x.columnName = ["ShortC", "LongC", "FloatC", "DoubleC", "StringC", "CharacterC"]
1433 x.columnData = [
1434 [[1, 2, 3], [-1, -2, -3, -4]],
1435 [[1, 2, 3], [-1, -2, -3, -4]],
1436 [[1, 2, 3], [-1, -2, -3.6, -4.4]],
1437 [[1, 2, 3], [-1, -2, -3.6, -4.4]],
1438 [["row 1", "row 2", "row 3"], ["row 1", "row 2", "row 3", "row 4"]],
1439 [["x", "y", "z"], ["i", "j", "k", "l"]],
1440 ]
1441 x.columnDefinition = [
1442 ["", "", "", "", x.SDDS_SHORT, 0],
1443 ["", "", "", "", x.SDDS_LONG, 0],
1444 ["", "", "", "", x.SDDS_FLOAT, 0],
1445 ["", "", "", "", x.SDDS_DOUBLE, 0],
1446 ["", "", "", "", x.SDDS_STRING, 0],
1447 ["", "", "", "", x.SDDS_CHARACTER, 0],
1448 ]
1449
1450 x.save(output)
1451 del x
1452
1453

◆ demo2()

sdds.demo2 ( output)

Demonstrates how to save a demo SDDS file using the SDDS class with simplified definitions.

Args: output (str): The output SDDS filename to save the demo data.

This function shows how to use simplified methods to define parameters, arrays, and columns.

Definition at line 1454 of file sdds.py.

1454def demo2(output):
1455 """
1456 Demonstrates how to save a demo SDDS file using the SDDS class with simplified definitions.
1457
1458 Args:
1459 output (str): The output SDDS filename to save the demo data.
1460
1461 This function shows how to use simplified methods to define parameters, arrays, and columns.
1462 """
1463 x = SDDS(0)
1464 x.setDescription("text", "contents")
1465 names = ["Short", "Long", "Float", "Double", "String", "Character"]
1466 types = [x.SDDS_SHORT, x.SDDS_LONG, x.SDDS_FLOAT, x.SDDS_DOUBLE, x.SDDS_STRING, x.SDDS_CHARACTER]
1467 for i in range(6):
1468 x.defineSimpleParameter(names[i] + "P", types[i])
1469 if types[i] == x.SDDS_FLOAT:
1470 x.defineSimpleArray(names[i] + "A", types[i], 2)
1471 else:
1472 x.defineSimpleArray(names[i] + "A", types[i], 1)
1473 x.defineSimpleColumn(names[i] + "C", types[i])
1474 parameterData = [[1, 6], [2, 7], [3.3, 8.8], [4.4, 9.8], ["five", "ten"], ["a", "b"]]
1475 for i in range(6):
1476 x.setParameterValueList(names[i] + "P", parameterData[i])
1477
1478 arrayDimensions = [
1479 [[6], [8]],
1480 [[5], [7]],
1481 [[2, 3], [2, 4]],
1482 [[4], [5]],
1483 [[4], [5]],
1484 [[4], [5]],
1485 ]
1486 arrayData = [
1487 [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6, 7, 8]],
1488 [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 6, 7]],
1489 [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6, 7, 8]],
1490 [[1, 2, 3, 4], [1, 2, 3, 4, 5]],
1491 [["one", "two", "three", "four"], ["five", "six", "seven", "eight", "nine"]],
1492 [["a", "b", "c", "d"], ["e", "f", "g", "h", "i"]],
1493 ]
1494 for i in range(6):
1495 x.setArrayValueLists(names[i] + "A", arrayData[i], arrayDimensions[i])
1496
1497 columnData = [
1498 [[1, 2, 3], [-1, -2, -3, -4]],
1499 [[1, 2, 3], [-1, -2, -3, -4]],
1500 [[1, 2, 3], [-1, -2, -3.6, -4.4]],
1501 [[1, 2, 3], [-1, -2, -3.6, -4.4]],
1502 [["row 1", "row 2", "row 3"], ["row 1", "row 2", "row 3", "row 4"]],
1503 [["x", "y", "z"], ["i", "j", "k", "l"]],
1504 ]
1505 for i in range(6):
1506 x.setColumnValueLists(names[i] + "C", columnData[i])
1507 x.save(output)
1508
1509

◆ demo3()

sdds.demo3 ( output)

Demonstrates how to save a demo SDDS file using sddsdata commands directly.

Args: output (str): The output SDDS filename to save the demo data.

This function shows how to use sddsdata module functions directly to create and save an SDDS file.

Definition at line 1510 of file sdds.py.

1510def demo3(output):
1511 """
1512 Demonstrates how to save a demo SDDS file using `sddsdata` commands directly.
1513
1514 Args:
1515 output (str): The output SDDS filename to save the demo data.
1516
1517 This function shows how to use `sddsdata` module functions directly to create and save an SDDS file.
1518 """
1519 x = SDDS(0)
1520
1521 try:
1522 # Open SDDS output file
1523 if sddsdata.InitializeOutput(x.index, x.SDDS_BINARY, 1, "", "", output) != 1:
1524 raise ValueError("Failed to initialize SDDS output.")
1525 # Setting column_major to true. Only use this if you are going to write whole columns and not one row at a time.
1526 sddsdata.SetColumnMajorOrder(x.index)
1527 # Define parameters
1528 if sddsdata.DefineSimpleParameter(x.index, "ParameterA", "mm", x.SDDS_DOUBLE) != 1:
1529 raise ValueError("Failed to define parameter.")
1530 # Define arrays
1531 if sddsdata.DefineSimpleArray(x.index, "ArrayA", "DegC", x.SDDS_DOUBLE, 1) != 1:
1532 raise ValueError("Failed to define array.")
1533 if sddsdata.DefineSimpleArray(x.index, "ArrayB", "DegC", x.SDDS_DOUBLE, 2) != 1:
1534 raise ValueError("Failed to define array.")
1535 # Define columns
1536 if sddsdata.DefineSimpleColumn(x.index, "ColumnA", "Volts", x.SDDS_DOUBLE) != 1:
1537 raise ValueError("Failed to define column.")
1538 if sddsdata.DefineSimpleColumn(x.index, "ColumnB", "Amps", x.SDDS_DOUBLE) != 1:
1539 raise ValueError("Failed to define column.")
1540 # Write SDDS header
1541 if sddsdata.WriteLayout(x.index) != 1:
1542 raise ValueError("Failed to write SDDS layout.")
1543 # Start SDDS page. Allocate 100 rows.
1544 if sddsdata.StartPage(x.index, 100) != 1:
1545 raise ValueError("Failed to start SDDS page.")
1546 # Set parameter values
1547 if sddsdata.SetParameter(x.index, "ParameterA", 1.1) != 1:
1548 raise ValueError("Failed to set parameter value.")
1549 # Set array values
1550 if sddsdata.SetArray(x.index, "ArrayA", [1, 2, 3], [3]) != 1:
1551 raise ValueError("Failed to set array value.")
1552 if sddsdata.SetArray(x.index, "ArrayB", [1, 2, 3, 4, 5, 6], [2, 3]) != 1:
1553 raise ValueError("Failed to set array value.")
1554 # Set column values
1555 if sddsdata.SetColumn(x.index, "ColumnA", [1, 2, 3]) != 1:
1556 raise ValueError("Failed to set column value.")
1557 if sddsdata.SetColumn(x.index, "ColumnB", [1, 2, 3]) != 1:
1558 raise ValueError("Failed to set column value.")
1559 # Write page to disk
1560 if sddsdata.WritePage(x.index) != 1:
1561 raise ValueError("Failed to write SDDS page.")
1562 # Close SDDS output file
1563 if sddsdata.Terminate(x.index) != 1:
1564 raise ValueError("Failed to terminate SDDS output.")
1565
1566 except:
1567 sddsdata.PrintErrors(x.SDDS_VERBOSE_PrintErrors)
1568 raise
1569
1570

◆ demo4()

sdds.demo4 ( output)

Demonstrates how to save a demo SDDS file using sddsdata commands and writing one row at a time.

Args: output (str): The output SDDS filename to save the demo data.

This function shows how to write data to an SDDS file one row at a time, useful for logging applications.

Definition at line 1571 of file sdds.py.

1571def demo4(output):
1572 """
1573 Demonstrates how to save a demo SDDS file using `sddsdata` commands and writing one row at a time.
1574
1575 Args:
1576 output (str): The output SDDS filename to save the demo data.
1577
1578 This function shows how to write data to an SDDS file one row at a time, useful for logging applications.
1579 """
1580 x = SDDS(0)
1581
1582 try:
1583 # Open SDDS output file
1584 if sddsdata.InitializeOutput(x.index, x.SDDS_BINARY, 1, "", "", output) != 1:
1585 raise ValueError("Failed to initialize SDDS output.")
1586 # Turning on fsync mode and fixed rows count mode. These are useful for loggers.
1587 sddsdata.EnableFSync(x.index)
1588 sddsdata.SetFixedRowCountMode(x.index)
1589 # Define parameters
1590 if sddsdata.DefineSimpleParameter(x.index, "ParameterA", "mm", x.SDDS_DOUBLE) != 1:
1591 raise ValueError("Failed to define parameter.")
1592 # Define arrays
1593 if sddsdata.DefineSimpleArray(x.index, "ArrayA", "DegC", x.SDDS_DOUBLE, 1) != 1:
1594 raise ValueError("Failed to define array.")
1595 if sddsdata.DefineSimpleArray(x.index, "ArrayB", "DegC", x.SDDS_DOUBLE, 2) != 1:
1596 raise ValueError("Failed to define array.")
1597 # Define columns
1598 if sddsdata.DefineSimpleColumn(x.index, "ColumnA", "Volts", x.SDDS_DOUBLE) != 1:
1599 raise ValueError("Failed to define column.")
1600 if sddsdata.DefineSimpleColumn(x.index, "ColumnB", "Amps", x.SDDS_DOUBLE) != 1:
1601 raise ValueError("Failed to define column.")
1602 # Write SDDS header
1603 if sddsdata.WriteLayout(x.index) != 1:
1604 raise ValueError("Failed to write SDDS layout.")
1605 # Start SDDS page, allocate 2 rows.
1606 if sddsdata.StartPage(x.index, 2) != 1:
1607 raise ValueError("Failed to start SDDS page.")
1608 # Set parameter values
1609 if sddsdata.SetParameter(x.index, "ParameterA", 1.1) != 1:
1610 raise ValueError("Failed to set parameter value.")
1611 # Set array values
1612 if sddsdata.SetArray(x.index, "ArrayA", [1, 2, 3], [3]) != 1:
1613 raise ValueError("Failed to set array value.")
1614 if sddsdata.SetArray(x.index, "ArrayB", [1, 2, 3, 4, 5, 6], [2, 3]) != 1:
1615 raise ValueError("Failed to set array value.")
1616 # Set all columns, one row at a time
1617 if sddsdata.SetRowValues(x.index, 0, ["ColumnA", 1, "ColumnB", 1]) != 1:
1618 raise ValueError("Failed to set row values.")
1619 if sddsdata.SetRowValues(x.index, 1, ["ColumnA", 2, "ColumnB", 2]) != 1:
1620 raise ValueError("Failed to set row values.")
1621 # Update page because we reached the row allocation limit set in the StartPage command
1622 if sddsdata.UpdatePage(x.index, x.SDDS_FLUSH_TABLE) != 1:
1623 raise ValueError("Failed to update SDDS page.")
1624 # Set more rows
1625 if sddsdata.SetRowValues(x.index, 2, ["ColumnA", 3, "ColumnB", 3]) != 1:
1626 raise ValueError("Failed to set row values.")
1627 # Update page
1628 if sddsdata.UpdatePage(x.index, x.SDDS_FLUSH_TABLE) != 1:
1629 raise ValueError("Failed to update SDDS page.")
1630 # Close SDDS output file
1631 if sddsdata.Terminate(x.index) != 1:
1632 raise ValueError("Failed to terminate SDDS output.")
1633
1634 except:
1635 sddsdata.PrintErrors(x.SDDS_VERBOSE_PrintErrors)
1636 raise
1637
1638

◆ demo5()

sdds.demo5 ( output)

Demonstrates how to open an existing SDDS file and add rows to the last page without loading the whole file into memory.

Args: output (str): The output SDDS filename to append data.

This function shows how to append data to an existing SDDS file efficiently.

Definition at line 1639 of file sdds.py.

1639def demo5(output):
1640 """
1641 Demonstrates how to open an existing SDDS file and add rows to the last page without loading the whole file into memory.
1642
1643 Args:
1644 output (str): The output SDDS filename to append data.
1645
1646 This function shows how to append data to an existing SDDS file efficiently.
1647 """
1648 x = SDDS(0)
1649
1650 try:
1651 # Open SDDS output file
1652 rows = sddsdata.InitializeAppendToPage(x.index, output, 100)
1653 if rows == 0:
1654 raise ValueError("Failed to initialize appending to SDDS page.")
1655 # Set all columns, one row at a time
1656 if sddsdata.SetRowValues(x.index, rows, ["ColumnA", 4, "ColumnB", 4]) != 1:
1657 raise ValueError("Failed to set row values.")
1658 if sddsdata.SetRowValues(x.index, rows + 1, ["ColumnA", 5, "ColumnB", 5]) != 1:
1659 raise ValueError("Failed to set row values.")
1660 if sddsdata.SetRowValues(x.index, rows + 2, ["ColumnA", 6, "ColumnB", 6]) != 1:
1661 raise ValueError("Failed to set row values.")
1662 # Update page
1663 if sddsdata.UpdatePage(x.index, x.SDDS_FLUSH_TABLE) != 1:
1664 raise ValueError("Failed to update SDDS page.")
1665 # Close SDDS output file
1666 if sddsdata.Terminate(x.index) != 1:
1667 raise ValueError("Failed to terminate SDDS output.")
1668
1669 except:
1670 sddsdata.PrintErrors(x.SDDS_VERBOSE_PrintErrors)
1671 raise
1672
1673

◆ demo6()

sdds.demo6 ( output)

Demonstrates how to open an existing SDDS file and add a new page.

Args: output (str): The output SDDS filename to append data.

This function shows how to append a new page to an existing SDDS file.

Definition at line 1674 of file sdds.py.

1674def demo6(output):
1675 """
1676 Demonstrates how to open an existing SDDS file and add a new page.
1677
1678 Args:
1679 output (str): The output SDDS filename to append data.
1680
1681 This function shows how to append a new page to an existing SDDS file.
1682 """
1683 x = SDDS(0)
1684
1685 try:
1686 # Open SDDS output file
1687 if sddsdata.InitializeAppend(x.index, output) != 1:
1688 raise ValueError("Failed to initialize appending to SDDS file.")
1689 # Allocate rows
1690 if sddsdata.StartPage(x.index, 100) != 1:
1691 raise ValueError("Failed to start SDDS page.")
1692 # Set parameter values
1693 if sddsdata.SetParameter(x.index, "ParameterA", 1.1) != 1:
1694 raise ValueError("Failed to set parameter value.")
1695 # Set array values
1696 if sddsdata.SetArray(x.index, "ArrayA", [1, 2, 3], [3]) != 1:
1697 raise ValueError("Failed to set array value.")
1698 if sddsdata.SetArray(x.index, "ArrayB", [1, 2, 3, 4, 5, 6], [2, 3]) != 1:
1699 raise ValueError("Failed to set array value.")
1700 # Set all columns, one row at a time
1701 if sddsdata.SetRowValues(x.index, 0, ["ColumnA", 7, "ColumnB", 7]) != 1:
1702 raise ValueError("Failed to set row values.")
1703 if sddsdata.SetRowValues(x.index, 1, ["ColumnA", 8, "ColumnB", 8]) != 1:
1704 raise ValueError("Failed to set row values.")
1705 if sddsdata.SetRowValues(x.index, 2, ["ColumnA", 9, "ColumnB", 9]) != 1:
1706 raise ValueError("Failed to set row values.")
1707 # Write page
1708 if sddsdata.WritePage(x.index) != 1:
1709 raise ValueError("Failed to write SDDS page.")
1710 # Close SDDS output file
1711 if sddsdata.Terminate(x.index) != 1:
1712 raise ValueError("Failed to terminate SDDS output.")
1713
1714 except:
1715 sddsdata.PrintErrors(x.SDDS_VERBOSE_PrintErrors)
1716 raise
1717
1718@dataclass

◆ read()

SddsFile sdds.read ( input_file)

Mostly backward compatible with the PyLHC sdds module read() function.

Unlike the PyLHC version, this function reads all the SDDS pages and works with column data. The data is returned in a structured dictionary.

Args: input_file (str): The input SDDS file to be read.

Returns: dict: A dictionary with parameters, arrays, and columns data. Example structure: { pages = {integer}, binary = {boolean}, "definitions": {name: {"type:" string, "units": string, "description": string}, "values": {parameter_name: {[Page1Value, Page2Value, ...]}, {array_name: {[Page1List, Page2List, ...]}, {column_name: {[Page1List, Page2List, ...]}, "values": {array_name: {[page1DimList, Page2DimList, ...]} }

Definition at line 1759 of file sdds.py.

1759def read(input_file) -> SddsFile:
1760 """
1761 Mostly backward compatible with the PyLHC sdds module read() function.
1762 Unlike the PyLHC version, this function reads all the SDDS pages and works with column data.
1763 The data is returned in a structured dictionary.
1764
1765 Args:
1766 input_file (str): The input SDDS file to be read.
1767
1768 Returns:
1769 dict: A dictionary with parameters, arrays, and columns data.
1770 Example structure:
1771 {
1772 pages = {integer},
1773 binary = {boolean},
1774 "definitions": {name: {"type:" string, "units": string, "description": string},
1775 "values": {parameter_name: {[Page1Value, Page2Value, ...]},
1776 {array_name: {[Page1List, Page2List, ...]},
1777 {column_name: {[Page1List, Page2List, ...]},
1778 "values": {array_name: {[page1DimList, Page2DimList, ...]}
1779 }
1780 """
1781 # Initialize an SDDS object
1782 sdds_obj = SDDS(0)
1783
1784 # Load the file
1785 try:
1786 sdds_obj.load(input_file)
1787 except Exception as e:
1788 raise ValueError(f"Failed to load the SDDS file: {e}")
1789
1790 # Initialize the output dictionary
1791 sdds_data = SddsFile()
1792
1793 # Store the data mode (ascii or binary)
1794 if sdds_obj.mode == SDDS.SDDS_BINARY:
1795 sdds_data.binary = True
1796 else:
1797 sdds_data.binary = False
1798
1799 # Store description data
1800 text = sdds_obj.description[0] if sdds_obj.description[0] != "" else None
1801 contents = sdds_obj.description[1] if sdds_obj.description[1] != "" else None
1802 description_instance = Description(text=text, contents=contents)
1803 sdds_data.description = description_instance
1804
1805 # Store number of pages
1806 sdds_data.pages = sdds_obj.loaded_pages
1807
1808 # Store parameter data
1809 if sdds_obj.parameterName:
1810 for i, definition in enumerate(sdds_obj.parameterDefinition):
1811 name = sdds_obj.parameterName[i]
1812 symbol = definition[0] if definition[0] != '' else None
1813 units = definition[1] if definition[1] != '' else None
1814 description = definition[2] if definition[2] != '' else None
1815 formatString = definition[3] if definition[3] != '' else None
1816 datatype = sdds_data_type_to_short_string(definition[4])
1817 fixedValue = definition[5] if definition[5] != '' else None
1818 parameter_instance = Parameter(name=name, type=datatype, symbol=symbol, units=units, description=description, format_string=formatString, fixed_value=fixedValue)
1819 sdds_data.definitions.update({name: parameter_instance})
1820 sdds_data.values.update({name: sdds_obj.parameterData[i]})
1821
1822 # Store array data
1823 if sdds_obj.arrayName:
1824 for i, definition in enumerate(sdds_obj.arrayDefinition):
1825 name = sdds_obj.arrayName[i]
1826 symbol = definition[0] if definition[0] != '' else None
1827 units = definition[1] if definition[1] != '' else None
1828 description = definition[2] if definition[2] != '' else None
1829 formatString = definition[3] if definition[3] != '' else None
1830 group_name = definition[4] if definition[4] != '' else None
1831 datatype = sdds_data_type_to_short_string(definition[5])
1832 fieldLength = definition[6] if definition[6] != 0 else None
1833 dimensions = definition[7] if definition[7] != '' else None
1834 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)
1835 sdds_data.definitions.update({name: array_instance})
1836 sdds_data.values.update({name: sdds_obj.arrayData[i]})
1837 sdds_data.array_dims.update({name: sdds_obj.arrayDimensions[i]})
1838
1839 # Store column data
1840 if sdds_obj.columnName:
1841 for i, definition in enumerate(sdds_obj.columnDefinition):
1842 name = sdds_obj.columnName[i]
1843 symbol = definition[0] if definition[0] != '' else None
1844 units = definition[1] if definition[1] != '' else None
1845 description = definition[2] if definition[2] != '' else None
1846 formatString = definition[3] if definition[3] != '' else None
1847 datatype = sdds_data_type_to_short_string(definition[4])
1848 fieldLength = definition[5] if definition[5] != 0 else None
1849 column_instance = Column(name=name, type=datatype, symbol=symbol, units=units, description=description, format_string=formatString, field_length=fieldLength)
1850 sdds_data.definitions.update({name: column_instance})
1851 sdds_data.values.update({name: sdds_obj.columnData[i]})
1852
1853 # Return the dictionary
1854 return sdds_data
1855

◆ sdds_data_type_to_short_string()

sdds.sdds_data_type_to_short_string ( data_type_code)

Converts a numeric SDDS data type code to its short string representation.

Args: data_type_code (int): Numeric code of the SDDS data type.

Returns: str: String representation of the SDDS data type.

Definition at line 1331 of file sdds.py.

1331def sdds_data_type_to_short_string(data_type_code):
1332 """
1333 Converts a numeric SDDS data type code to its short string representation.
1334
1335 Args:
1336 data_type_code (int): Numeric code of the SDDS data type.
1337
1338 Returns:
1339 str: String representation of the SDDS data type.
1340 """
1341 # Mapping of SDDS numeric data type codes to string representations
1342 data_type_map = {
1343 1: "longdouble",
1344 2: "double",
1345 3: "float",
1346 4: "long64",
1347 5: "ulong64",
1348 6: "long",
1349 7: "ulong",
1350 8: "short",
1351 9: "ushort",
1352 10: "string",
1353 11: "character",
1354 }
1355 return data_type_map.get(data_type_code, "Unknown Data Type")
1356

◆ sdds_data_type_to_string()

sdds.sdds_data_type_to_string ( data_type_code)

Converts a numeric SDDS data type code to its string representation.

Args: data_type_code (int): Numeric code of the SDDS data type.

Returns: str: String representation of the SDDS data type.

Definition at line 1305 of file sdds.py.

1305def sdds_data_type_to_string(data_type_code):
1306 """
1307 Converts a numeric SDDS data type code to its string representation.
1308
1309 Args:
1310 data_type_code (int): Numeric code of the SDDS data type.
1311
1312 Returns:
1313 str: String representation of the SDDS data type.
1314 """
1315 # Mapping of SDDS numeric data type codes to string representations
1316 data_type_map = {
1317 1: "SDDS_LONGDOUBLE",
1318 2: "SDDS_DOUBLE",
1319 3: "SDDS_FLOAT",
1320 4: "SDDS_LONG64",
1321 5: "SDDS_ULONG64",
1322 6: "SDDS_LONG",
1323 7: "SDDS_ULONG",
1324 8: "SDDS_SHORT",
1325 9: "SDDS_USHORT",
1326 10: "SDDS_STRING",
1327 11: "SDDS_CHARACTER",
1328 }
1329 return data_type_map.get(data_type_code, "Unknown Data Type")
1330

◆ sdds_short_string_to_data_type()

sdds.sdds_short_string_to_data_type ( data_type_code)

Converts a numeric SDDS data type code to its short string representation.

Args: data_type_code (string): String representation of the SDDS data type.

Returns: int: Numeric code of the SDDS data type.

Definition at line 1357 of file sdds.py.

1357def sdds_short_string_to_data_type(data_type_code):
1358 """
1359 Converts a numeric SDDS data type code to its short string representation.
1360
1361 Args:
1362 data_type_code (string): String representation of the SDDS data type.
1363
1364 Returns:
1365 int: Numeric code of the SDDS data type.
1366 """
1367 # Mapping of SDDS numeric data type codes to string representations
1368 data_type_map = {
1369 "longdouble": 1,
1370 "double": 2,
1371 "float": 3,
1372 "long64": 4,
1373 "ulong64": 5,
1374 "long": 6,
1375 "ulong": 7,
1376 "short": 8,
1377 "ushort": 9,
1378 "string": 10,
1379 "character": 11,
1380 }
1381 return data_type_map.get(data_type_code, "Unknown Data Type")
1382

◆ write()

sdds.write ( SddsFile sdds_file,
output_file )

Mostly backward compatible with the PyLHC sdds module write() function.

Unlike the PyLHC version, this function writes all the SDDS pages and works with column data. The data is expected to be in a structured dictionary like that returned from the read() function.

Args: output_file (str): The output SDDS file to be written to.

Definition at line 1856 of file sdds.py.

1856def write(sdds_file: SddsFile, output_file):
1857 """
1858 Mostly backward compatible with the PyLHC sdds module write() function.
1859 Unlike the PyLHC version, this function writes all the SDDS pages and works with column data.
1860 The data is expected to be in a structured dictionary like that returned from the read() function.
1861
1862 Args:
1863 output_file (str): The output SDDS file to be written to.
1864 """
1865 # Initialize an SDDS object
1866 sdds_obj = SDDS(0)
1867
1868 # Set the data mode (ascii or binary)
1869 if hasattr(sdds_file, 'binary'):
1870 if sdds_file.binary:
1871 sdds_obj.mode = SDDS.SDDS_BINARY
1872 else:
1873 sdds_obj.mode = SDDS.SDDS_ASCII
1874
1875 # Set description data
1876 if hasattr(sdds_file, 'description'):
1877 text = sdds_file.description.text if sdds_file.description.text != None else ''
1878 contents = sdds_file.description.contents if sdds_file.description.contents != None else ''
1879 sdds_obj.setDescription(text, contents)
1880
1881 for name in sdds_file.definitions:
1882 if isinstance(sdds_file.definitions[name], Parameter):
1883 # Set parameter data
1884 parameter_instance = sdds_file.definitions[name]
1885 symbol = parameter_instance.symbol if parameter_instance.symbol != None else ""
1886 units = parameter_instance.units if parameter_instance.units != None else ""
1887 description = parameter_instance.description if parameter_instance.description != None else ""
1888 formatString = parameter_instance.format_string if parameter_instance.format_string != None else ""
1889 datatype = sdds_short_string_to_data_type(parameter_instance.type)
1890 fixedValue = parameter_instance.fixed_value if parameter_instance.fixed_value != None else ""
1891 sdds_obj.defineParameter(name, symbol=symbol, units=units, description=description,
1892 formatString=formatString, type=datatype, fixedValue=fixedValue)
1893 sdds_obj.setParameterValueList(name, sdds_file.values[name])
1894 elif isinstance(sdds_file.definitions[name], Array):
1895 # Set array data
1896 array_instance = sdds_file.definitions[name]
1897 symbol = array_instance.symbol if array_instance.symbol != None else ""
1898 units = array_instance.units if array_instance.units != None else ""
1899 description = array_instance.description if array_instance.description != None else ""
1900 formatString = array_instance.format_string if array_instance.format_string != None else ""
1901 group_name = array_instance.group_name if array_instance.group_name != None else ""
1902 datatype = sdds_short_string_to_data_type(array_instance.type)
1903 fieldLength = array_instance.field_length if array_instance.field_length != None else 0
1904 dimensions = array_instance.dimensions if array_instance.dimensions != None else 1
1905 sdds_obj.defineArray(name, symbol=symbol, units=units, description=description,
1906 formatString=formatString, group_name=group_name, type=datatype,
1907 fieldLength=fieldLength, dimensions=dimensions)
1908 sdds_obj.setArrayValueLists(name, sdds_file.values[name], sdds_file.array_dims[name])
1909 elif isinstance(sdds_file.definitions[name], Column):
1910 # Set column data
1911 column_instance = sdds_file.definitions[name]
1912 symbol = column_instance.symbol if column_instance.symbol != None else ""
1913 units = column_instance.units if column_instance.units != None else ""
1914 description = column_instance.description if column_instance.description != None else ""
1915 formatString = column_instance.format_string if column_instance.format_string != None else ""
1916 datatype = sdds_short_string_to_data_type(column_instance.type)
1917 fieldLength = column_instance.field_length if column_instance.field_length != None else 0
1918 sdds_obj.defineColumn(name, symbol=symbol, units=units, description=description,
1919 formatString=formatString, type=datatype, fieldLength=fieldLength)
1920 sdds_obj.setColumnValueLists(name, sdds_file.values[name])
1921
1922 # Set the data to the output file
1923 sdds_obj.save(output_file)

Variable Documentation

◆ SDDS_ASCII

sdds.SDDS_ASCII = SDDS.SDDS_ASCII

Definition at line 1302 of file sdds.py.

◆ SDDS_BINARY

sdds.SDDS_BINARY = SDDS.SDDS_BINARY

Definition at line 1301 of file sdds.py.

◆ SDDS_CHARACTER

sdds.SDDS_CHARACTER = SDDS.SDDS_CHARACTER

Definition at line 1299 of file sdds.py.

◆ SDDS_CHECK_NONEXISTENT

sdds.SDDS_CHECK_NONEXISTENT = SDDS.SDDS_CHECK_NONEXISTENT

Definition at line 1278 of file sdds.py.

◆ SDDS_CHECK_OKAY

sdds.SDDS_CHECK_OKAY = SDDS.SDDS_CHECK_OKAY

Definition at line 1277 of file sdds.py.

◆ SDDS_CHECK_WRONGTYPE

sdds.SDDS_CHECK_WRONGTYPE = SDDS.SDDS_CHECK_WRONGTYPE

Definition at line 1279 of file sdds.py.

◆ SDDS_CHECK_WRONGUNITS

sdds.SDDS_CHECK_WRONGUNITS = SDDS.SDDS_CHECK_WRONGUNITS

Definition at line 1280 of file sdds.py.

◆ SDDS_DOUBLE

sdds.SDDS_DOUBLE = SDDS.SDDS_DOUBLE

Definition at line 1282 of file sdds.py.

◆ SDDS_EXIT_PrintErrors

sdds.SDDS_EXIT_PrintErrors = SDDS.SDDS_EXIT_PrintErrors

Definition at line 1276 of file sdds.py.

◆ SDDS_FLOAT

sdds.SDDS_FLOAT = SDDS.SDDS_FLOAT

Definition at line 1284 of file sdds.py.

◆ SDDS_FLUSH_TABLE

sdds.SDDS_FLUSH_TABLE = SDDS.SDDS_FLUSH_TABLE

Definition at line 1303 of file sdds.py.

◆ SDDS_INT16

sdds.SDDS_INT16 = SDDS.SDDS_INT16

Definition at line 1295 of file sdds.py.

◆ SDDS_INT32

sdds.SDDS_INT32 = SDDS.SDDS_INT32

Definition at line 1291 of file sdds.py.

◆ SDDS_INT64

sdds.SDDS_INT64 = SDDS.SDDS_INT64

Definition at line 1287 of file sdds.py.

◆ SDDS_LONG

sdds.SDDS_LONG = SDDS.SDDS_LONG

Definition at line 1290 of file sdds.py.

◆ SDDS_LONG64

sdds.SDDS_LONG64 = SDDS.SDDS_LONG64

Definition at line 1286 of file sdds.py.

◆ SDDS_LONGDOUBLE

sdds.SDDS_LONGDOUBLE = SDDS.SDDS_LONGDOUBLE

Definition at line 1281 of file sdds.py.

◆ SDDS_NUM_TYPES

sdds.SDDS_NUM_TYPES = SDDS.SDDS_NUM_TYPES

Definition at line 1300 of file sdds.py.

◆ SDDS_REAL32

sdds.SDDS_REAL32 = SDDS.SDDS_REAL32

Definition at line 1285 of file sdds.py.

◆ SDDS_REAL64

sdds.SDDS_REAL64 = SDDS.SDDS_REAL64

Definition at line 1283 of file sdds.py.

◆ SDDS_SHORT

sdds.SDDS_SHORT = SDDS.SDDS_SHORT

Definition at line 1294 of file sdds.py.

◆ SDDS_STRING

sdds.SDDS_STRING = SDDS.SDDS_STRING

Definition at line 1298 of file sdds.py.

◆ SDDS_UINT16

sdds.SDDS_UINT16 = SDDS.SDDS_UINT16

Definition at line 1297 of file sdds.py.

◆ SDDS_UINT32

sdds.SDDS_UINT32 = SDDS.SDDS_UINT32

Definition at line 1293 of file sdds.py.

◆ SDDS_UINT64

sdds.SDDS_UINT64 = SDDS.SDDS_UINT64

Definition at line 1289 of file sdds.py.

◆ SDDS_ULONG

sdds.SDDS_ULONG = SDDS.SDDS_ULONG

Definition at line 1292 of file sdds.py.

◆ SDDS_ULONG64

sdds.SDDS_ULONG64 = SDDS.SDDS_ULONG64

Definition at line 1288 of file sdds.py.

◆ SDDS_USHORT

sdds.SDDS_USHORT = SDDS.SDDS_USHORT

Definition at line 1296 of file sdds.py.

◆ SDDS_VERBOSE_PrintErrors

sdds.SDDS_VERBOSE_PrintErrors = SDDS.SDDS_VERBOSE_PrintErrors

Definition at line 1275 of file sdds.py.