gemdat.utils
This module connects generally useful utilties.
bfill(arr, fill_val=-1, axis=-1)
Backward fill values equal to val with upcoming values.
See ffill for options.
Source code in src/gemdat/utils.py
173 174 175 176 177 178 179 180 181 182 183 184 | |
cartesian_to_spherical(cart_coords, *, degrees=True)
Trajectory from cartesian coordinates to spherical coordinates.
Parameters:
-
cart_coords(ndarray) –Trajectory of the unit vectors in cartesian setting
-
degrees(bool, default:True) –If true, return angles in degrees
Returns:
-
spherical_coords(ndarray) –Trajectory of the unit vectors in spherical coordinates
Source code in src/gemdat/utils.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
ffill(arr, fill_val=-1, axis=-1)
Forward fill values equal to val with most recent values.
Parameters:
-
arr(ndarray) –Input array with 2 dimensions
-
fill_val(int, default:-1) –Value to fill
-
axis(int, default:-1) –Axis along which to operate
Returns:
-
out(ndarray) –Output array with all values
Source code in src/gemdat/utils.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
fft_autocorrelation(coords)
Compute the autocorrelation of the given coordinates using FFT.
Parameters:
-
coords(ndarray) –The input signal in direct cartesian coordinates. It is expected to have shape (n_times, n_particles, n_coordinates)
Returns:
-
autocorrelation(array) –The autocorrelation of the input signal, with shape (n_particles, n_times)
Source code in src/gemdat/utils.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
integer_remap(a, key, palette=None)
Map integers in array a from palette -> key
Parameters:
-
a(ndarray) –Input array with values to be
-
key(ndarray) –The key gives the new values that the palette will be mapped to
-
palette(ndarray | None, default:None) –Input values, must be given in sorted order. If None, use sorted unique values in
a
Returns:
-
ndarray–
Source code in src/gemdat/utils.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
is_lattice_similar(a, b, length_tol=0.5, angle_tol=1.0)
Return True if lattices are similar within given tolerance.
Parameters:
-
a(Lattice | Structure) –Input lattices or structures
-
b(Lattice | Structure) –Input lattices or structures
-
length_tol(float, default:0.5) –Length tolerance in Angstrom
-
angle_tol(float, default:1.0) –Angle tolerance in degrees
Returns:
-
bool–Return True if lattices are similar
Source code in src/gemdat/utils.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
meanfreq(x, fs=1.0)
Estimates the mean frequency in terms of the sample rate, fs.
Vectorized version of https://stackoverflow.com/a/56487241
Parameters:
-
x(ndarray[i, j]) –Time series of measurement values. The mean frequency is computed along the last axis (-1).
-
fs(float, default:1.0) –Sampling frequency of the
xtime series. Defaults to 1.0.
Returns:
-
mnfreq(ndarray) –Array of mean frequencies.
Source code in src/gemdat/utils.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
nearest_structure_reference(structure)
Find distance and index of the nearest site of the structure for each voxel using a KD-tree.
Parameters:
-
structure(Structure) –Structure of the material to use as reference for nearest site
Returns:
-
kd_tree(cKDTree) –KD-tree of the structure
-
periodic_ids(list[int]) –List of ids corresponding to the closest site of the structure
Source code in src/gemdat/utils.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
remove_partial_occupancies_from_structure(structure)
Reset partial occupancies to 1 in input structure.
Parameters:
-
structure(Structure) –Input structure
Returns:
-
new_structure(Structure) –Output structure with partial occupancies set to 1
Source code in src/gemdat/utils.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
require_constant_lattice(func)
Reject calls that operate on a variable (non-constant) lattice.
Analyses that pin a single lattice -- site distances, voxel grids, the
cartesian frame of a whole trajectory -- are only defined for a constant
cell. Without this guard they fail deep inside with a
get_lattice() ValueError
asking for a frame index the caller has no way to supply.
The lattice is read from a constant_lattice argument if there is one,
else from the first argument that holds a trajectory -- including self,
or a jumps/transitions argument.
Apply below classmethod, but above weak_lru_cache -- under the cache
the guard would be skipped on a cache hit.
@classmethod
@require_constant_lattice
def from_given_radius(cls, *, trajectory, ...): ...
@require_constant_lattice
@weak_lru_cache()
def jump_diffusivity(self, dimensions): ...
Raises:
-
NotImplementedError–If the lattice is not constant.
Source code in src/gemdat/utils.py
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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
warn_lattice_not_close(a, b)
Raises a userwarning if lattices are not close.
Source code in src/gemdat/utils.py
287 288 289 290 291 292 293 | |