io
Input and Output Text Files¶
This submodule contains all methods related to reading data from text files and writing data to text files, including helpful header comments.
FileError
¶
Bases: Exception
An exception for wrongly formated input files.
opentxt(file_name, comment='#', nrows=None, **kwargs)
¶
Open a text file.
This method can load an nxm array of floats from an ascii file. It uses either pandas read_csv for a single comment or as fallback the slower np.loadtxt for multiple comments.
Warning
In contrast to pandas the order of usecols will be used. So if
using data = opentxt(..., uscols=[1, 0])
you access the first column
by data[:, 0]
and the second one by data[:, 1]
.
Parameters:
-
file_name
(string
) –Name of file to be opened.
-
comment
(str or array of str
, default:'#'
) –Characters with which a comment starts.
-
nrows
(int
, default:None
) –The maximum number of lines to be read
-
usecols
(int - array
) –Columns to be read from the file (zero indexed).
-
skiprows
(int
) –The number of leading rows which will be skipped.
-
dtype
(data - type
) –Data-type of the resulting array. Default: float.
Returns:
-
array
(ndarray
) –Data read from the text file.
Source code in src/msmhelper/io.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
savetxt(file_name, array, header=None, fmt='%.5f')
¶
Save nxm array of floats to a text file.
It uses numpys savetxt method and extends the header with information of execution.
Parameters:
-
file_name
(string
) –File name to store data.
-
array
(ndarray
) –Data to be stored.
-
header
(str
, default:None
) –Comment written into the header of the output file.
-
fmt
(str or sequence of strs
, default:'%.5f'
) –See numpy.savetxt.
Source code in src/msmhelper/io.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
opentxt_limits(file_name, limits_file=None, **kwargs)
¶
Load file and split according to limit file.
If limits_file is not provided it will return [traj]
.
Parameters:
-
file_name
(string
) –Name of file to be opened.
-
limits_file
(str
, default:None
) –File name of limit file. Should be single column ascii file.
-
**kwargs
–See parameters defined in opentxt
Returns:
-
traj
(ndarray
) –Return array of subtrajectories.
Source code in src/msmhelper/io.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
openmicrostates(file_name, limits_file=None, **kwargs)
¶
Load 1d file and split according to limit file.
Both, the limit file and the trajectory file needs to be a single column file. If limits_file is not provided it will return [traj]. The trajectory will of dtype np.int16, so the states needs to be smaller than 32767.
Parameters:
-
file_name
(string
) –Name of file to be opened.
-
limits_file
(str
, default:None
) –File name of limit file. Should be single column ascii file.
-
**kwargs
–See parameters defined in opentxt
Returns:
-
traj
(ndarray
) –Return array of subtrajectories.
Source code in src/msmhelper/io.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
open_limits(data_length, limits_file=None)
¶
Load and check limit file.
The limits give the length of each single trajectory. So e.g. [5, 5, 5] for 3 equally-sized subtrajectories of length 5.
Parameters:
-
data_length
(int
) –Length of data read.
-
limits_file
(str
, default:None
) –File name of limit file. Should be single column ascii file.
Returns:
-
limits
(ndarray
) –Return cumsum of limits.
Source code in src/msmhelper/io.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|