Read/write vectors of correlated data from/to a csv file.
Project description
correldata
Read/write vectors of correlated data from/to a csv file.
These data are stored in a dictionary, whose values are numpy arrays with elements which may be strings, floats, or floats with associated uncertainties as defined in the uncertainties library.
When reading data from a csv file, column names are interpreted in the following way:
- In most cases, each columns is converted to a dict value, with the corresponding dict key being the column's label.
- Columns whose label starts with
SE
are interpreted as specifying the standard error for the latest preceding data column. - Columns whose label starts with
correl
are interpreted as specifying the correlation matrix for the latest preceding data column. In that case, column labels are ignored for the rest of the columns belonging to this matrix. - Columns whose label starts with
covar
are interpreted as specifying the covariance matrix for the latest preceding data column. In that case, column labels are ignored for the rest of the columns belonging to this matrix. SE
,correl
, andcovar
may be specified for any arbitrary variable other than the latest preceding data column, by adding an underscore followed by the variable's label (ex:SE_foo
,correl_bar
,covar_baz
).correl
, andcovar
may also be specified for any pair of variable, by adding an underscore followed by the two variable labels, joined by a second underscore (ex:correl_foo_bar
,covar_X_Y
). The elements of the first and second variables correspond, respectively, to the lines and columns of this matrix.- Exceptions will be raised, for any given variable:
- when specifying both
covar
and any combination of (SE
,correl
) - when specifying
correl
withoutSE
- when specifying both
Example
import correldata
data = '''
Sample, Tacid, D47, SE, correl,,, D48, covar,,, correl_D47_D48
FOO, 90., .245, .005, 1, 0.5, 0.5, .145, 4e-4, 1e-4, 1e-4, 0.5, 0.0, 0.0
BAR, 90., .246, .005, 0.5, 1, 0.5, .146, 1e-4, 4e-4, 1e-4, 0.0, 0.5, 0.0
BAZ, 90., .247, .005, 0.5, 0.5, 1, .147, 1e-4, 1e-4, 4e-4, 0.0, 0.0, 0.5
'''[1:-1]
print(correldata.read_data(data))
# yields:
#
# {
# 'Sample': array(['FOO', 'BAR', 'BAZ'], dtype='<U3'),
# 'Tacid': array([90., 90., 90.]),
# 'D47': uarray([0.245+/-0.004999999999999998, 0.246+/-0.004999999999999997, 0.247+/-0.005], dtype=object),
# 'D48': uarray([0.145+/-0.019999999999999993, 0.146+/-0.019999999999999993, 0.147+/-0.019999999999999997], dtype=object),
# }
print(correldata.data_string(
correldata.read_data(data),
correl_format = '.2f',
))
# yields:
#
# Sample, Tacid, D47, SE_D47, correl_D47, , , D48, SE_D48, correl_D48, , , correl_D47_D48, ,
# FOO, 90, 0.245, 0.005, 1.00, 0.50, 0.50, 0.145, 0.02, 1.00, 0.25, 0.25, 0.50, -0.00, -0.00
# BAR, 90, 0.246, 0.005, 0.50, 1.00, 0.50, 0.146, 0.02, 0.25, 1.00, 0.25, 0.00, 0.50, -0.00
# BAZ, 90, 0.247, 0.005, 0.50, 0.50, 1.00, 0.147, 0.02, 0.25, 0.25, 1.00, -0.00, 0.00, 0.50
Documentation / API
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
correldata-1.6.0.tar.gz
(58.7 kB
view details)
Built Distribution
File details
Details for the file correldata-1.6.0.tar.gz
.
File metadata
- Download URL: correldata-1.6.0.tar.gz
- Upload date:
- Size: 58.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 160bccd4fe9de9af7c97f677f899adb65289734763742f4dbb1152919638168c |
|
MD5 | b1479f7d61b157bc37337cf10f23018b |
|
BLAKE2b-256 | 4d69e8b07326688adc1a602031b8f2a02b7dc34297efbe9e6770c5242c895ae3 |
File details
Details for the file correldata-1.6.0-py3-none-any.whl
.
File metadata
- Download URL: correldata-1.6.0-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9de98a8930121bda8598d96dde96c97a985a7a32da0b52b7c39f60d5fb0d4736 |
|
MD5 | abd28c1a0ad9214695bd7ef647b85665 |
|
BLAKE2b-256 | 0a30cbafb139e0c62d6b350443dc6cf2783f6c26d6734b7a7b2ca4599ef713c0 |