File¤
Suppose you have a variable named file (which is an instance of File) that represents the following information in an equipment register for data that is stored in a Spreadsheet
<file comment="FEL T647">
<url sheet="2024-May" cells="A1:C11">tests\resources\irradiance.xlsx</url>
<sha256>7a91267cfb529388a99762b891ee4b7a12463e83b5d55809f76a0c8e76c71886</sha256>
</file>
You can access sha256 and comment as attributes of file
>>> file.sha256
'7a91267cfb529388a99762b891ee4b7a12463e83b5d55809f76a0c8e76c71886'
>>> file.comment
'FEL T647'
The url and attributes attributes of file can be used with the read_table function of msl-io to read the Spreadsheet data
>>> from msl.io import read_table
>>> table = read_table(file.url, **file.attributes)
>>> print(table.metadata.header)
['Wavelength' 'Irradiance' 'u(Irradiance)']
>>> table
<Dataset 'irradiance.xlsx' shape=(10, 3) dtype='<f8' (1 metadata)>
>>> print(table)
array([[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]])
Note
Passing **file.attributes to read_table works as expected provided that the XML attributes of the <url> element are valid keyword arguments to read_table. See Read a table for more examples from msl-io, in particular, specifying dtype="header" will return a structured dataset which would behave similar to the Table example in msl-equipment (i.e., accessing columns by header name).
File
dataclass
¤
Represents the file element in an equipment register.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The location of the file. The syntax follows RFC 1738
|
required |
sha256
|
str
|
The SHA-256 checksum of the file. |
required |
attributes
|
dict[str, str]
|
XML attributes associated with the |
dict()
|
comment
|
str
|
A comment to associate with the file. |
''
|
attributes
class-attribute
instance-attribute
¤
XML attributes associated with the <url> element.
from_xml
classmethod
¤
Convert an XML element into a File instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
Element[str]
|
A file XML element from an equipment register. |
required |
Returns:
| Type | Description |
|---|---|
File
|
The File instance. |
Source code in src/msl/equipment/schema.py
907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 | |
to_xml
¤
Convert the File class into an XML element.
Returns:
| Type | Description |
|---|---|
Element[str]
|
The File as an XML element. |
Source code in src/msl/equipment/schema.py
935 936 937 938 939 940 941 942 943 944 945 946 947 | |