Table¤
Suppose you have a variable named table
(which is an instance of Table) that represents the following information in an equipment register for equipment that measures spectral irradiance
<table comment="Spectral">
<type> int , double , double </type>
<unit> nm , W/m^2 , W/m^2 </unit>
<header> Wavelength, Irradiance, u(Irradiance) </header>
<data> 250 , 0.01818, 0.02033
300 , 0.18478, 0.01755
350 , 0.80845, 0.01606
400 , 2.21355, 0.01405
450 , 4.49004, 0.01250
500 , 7.45135, 0.01200
550 , 10.75753, 0.01152
600 , 14.03809, 0.01102
650 , 16.99469, 0.01103
700 , 19.44093, 0.01077
</data>
</table>
The table
instance is a numpy structured array that has the header values as the field name of each column
>>> table.header
array(['Wavelength', 'Irradiance', 'u(Irradiance)'], dtype='<U13')
>>> table["Wavelength"]
Table([250, 300, 350, 400, 450, 500, 550, 600, 650, 700])
>>> table.types["Irradiance"]
array(dtype('float64'), dtype=object)
>>> assert table.units["u(Irradiance)"] == "W/m^2"
Since table
is a numpy array, you can index it
>>> print(table[0])
(250, 0.01818, 0.02033)
>>> sliced=table[:3]
>>> print(sliced)
[(250, 0.01818, 0.02033) (300, 0.18478, 0.01755) (350, 0.80845, 0.01606)]
and since sliced
is another Table instance, the attributes of the original table
are available
>>> sliced.comment
'Spectral'
>>> sliced.header
array(['Wavelength', 'Irradiance', 'u(Irradiance)'], dtype='<U13')
You can also perform mathematical operations and call numpy functions directly with the table
instance
>>> np.cos(1 + table["Irradiance"])
Table([ 0.52491592, 0.37650087, -0.2354229 , -0.99741219, 0.70160756,
-0.56246854, 0.6903377 , -0.78390036, 0.65631968, -0.0205763 ])
Suppose you wanted to get all Irradiance values in the table that are for UV light (i.e., wavelengths < 400 nm)
>>> table["Irradiance"][ table["Wavelength"] < 400 ]
Table([0.01818, 0.18478, 0.80845])
If you prefer to work with unstructured data, you can convert the table
by calling the unstructured method
>>> unstructured = table.unstructured()
>>> unstructured
Table([[2.500000e+02, 1.818000e-02, 2.033000e-02],
[3.000000e+02, 1.847800e-01, 1.755000e-02],
[3.500000e+02, 8.084500e-01, 1.606000e-02],
[4.000000e+02, 2.213550e+00, 1.405000e-02],
[4.500000e+02, 4.490040e+00, 1.250000e-02],
[5.000000e+02, 7.451350e+00, 1.200000e-02],
[5.500000e+02, 1.075753e+01, 1.152000e-02],
[6.000000e+02, 1.403809e+01, 1.102000e-02],
[6.500000e+02, 1.699469e+01, 1.103000e-02],
[7.000000e+02, 1.944093e+01, 1.077000e-02]])
>>> print(unstructured[0, 0])
250.0
Table
¤
Bases: ndarray
Represents the table element in an equipment register.
comment
class-attribute
instance-attribute
¤
comment: str = ''
A comment that is associated with the table.
header
class-attribute
instance-attribute
¤
The header value of each column.
types
class-attribute
instance-attribute
¤
The data type of each column.
units
class-attribute
instance-attribute
¤
The unit of each column.
from_xml
classmethod
¤
Convert an XML element into a Table instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
element
|
Element[str]
|
A table XML element from an equipment register. |
required |
Returns:
Type | Description |
---|---|
Table
|
A Table is an subclass of a numpy
structured array, where the |
Source code in src/msl/equipment/schema.py
1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 |
|
to_xml
¤
Convert the Table class into an XML element.
Returns:
Type | Description |
---|---|
Element[str]
|
The Table as an XML element. |
Source code in src/msl/equipment/schema.py
1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 |
|
unstructured
¤
unstructured(
*,
dtype: DTypeLike = None,
copy: bool = False,
casting: Literal[
"no", "equiv", "safe", "same_kind", "unsafe"
] = "unsafe"
) -> NDArray[Any]
Converts the structured array into an unstructured array.
See structured_to_unstructured for more details.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype
|
DTypeLike
|
The dtype of the output unstructured array. |
None
|
copy
|
bool
|
If |
False
|
casting
|
Literal['no', 'equiv', 'safe', 'same_kind', 'unsafe']
|
Controls what kind of data casting may occur. See the casting argument of astype for more details. |
'unsafe'
|
Returns:
Type | Description |
---|---|
NDArray[Any]
|
Source code in src/msl/equipment/schema.py
1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 |
|