Google Drive Downloads str, target_path: str, chunk_size=32768) → None

Download a file via a public Google Drive url.

Example usage:

  • url (str) – Google Drive url.

  • target_path (str) – Destination to write to. str, url: str) → str

Return a local path to a file from Google Drive. Downloads the file if it doesn’t exist yet locally.

By default, cached files live in ~/.cache/fannypack-drive-files/. It often makes sense to move this directory (eg to an NFS): see

  • name (str) – Name of path, eg secret_key.pem.

  • url (str) – URL, eg


str – Local path to file. str)

Set the cache location for


_cache_path (str) – New location for cached files. Defaults to ~/.cache/fannypack-drive-files/.

HDF5 for Trajectories

class str, convert_doubles: bool = True, read_only: bool = True, compress: bool = True, verbose: bool = True)

Bases: Iterable

An interface for reading/writing trajectories via h5py.

Each TrajectoriesFile represents an iterable list of trajectories, where trajectores are stored as dictionaries that map str keys to np.ndarray contents.

Example usage (read):

with TrajectoriesFile('test.hdf5') as traj_file:

    for traj in traj_file:
        print(traj.keys()) # list of keys
        print(traj['some-key-name']) # numpy array

Example usage (write):

traj_file = TrajectoriesFile('test.hdf5', read_only=False)

traj_file.add_meta({'label': 5})
traj_file.add_timestep({'a': 1, 'b': 2})
traj_file.add_timestep({'a': 3, 'b': 4})

with traj_file:

print(len(traj_file)) # 1 trajectory!

with traj_file:
    print(traj_file[0]['label']) # 5
    print(traj_file[0]['a']) # [1, 3]
    print(traj_file[0]['b']) # [2, 4]

Note that some operations – ones that require interfacing with the filesytem – need to be called within a with statement.

  • path (str) – File path for this trajectory file.

  • convert_doubles (bool) – Convert doubles to floats to shrink files.

  • read_only (bool, optional) – Open file in read-only mode.

  • compress (bool, optional) – Reduce filesize w/ gzip.

  • verbose (bool, optional) – Enable debug prints.

abandon_trajectory() → None

Abandon the current trajectory.

add_meta(content: Dict[str, numpy.ndarray]) → None

Add some metadata to the current trajectory.


content (dict) – Map from metadata keys (str) to values (np.ndarray).

add_timestep(content: Dict[str, numpy.ndarray]) → None

Add a timestep to the current trajectory.


content (dict) – Map from timestep keys (str) to values (np.ndarray).

clear() → None

Clear the contents of the TrajectoriesFile.

complete_trajectory() → None

Write the current trajectory to disk, and mark the start of a new trajectory. Must be called with the TrajectoriesFile object in a with statement.

The next call to add_timestep() will be time 0 of the next trajectory.

get_all(key: str) → list

Get contents associated with a key from all trajectories.


key (str) – Content identifier.


list – List of contents. First index is trajectory #.

resize(count: int)

Expand or contract our TrajectoriesFile.