qnm.cached

Caching interface to Kerr QNMs

This is a high-level interface to the package. The global cache qnm.modes_cache (an instance of KerrSeqCache) will return instances of qnm.spinsequence.KerrSpinSeq from memory or disk. If a spin sequence is neither in memory nor on disk then it will be computed and returned.

Use download_data() to fetch a collection of precomputed spin sequences from the web.

TODO More documentation.

Functions

build_package_default_cache(ksc) Compute the standard list of modes that this package promises to have in its cache.
download_data([overwrite]) Fetch and decompress tarball of precomputed spin sequence from the web.
load_cached_mode(s, l, m, n) Read a KerrSpinSeq from disk.
mode_pickle_path(s, l, m, n) Construct the path to a pickle file for the mode (s, l, m, n)
write_mode(spin_seq[, pickle_path]) Write an instance of KerrSpinSeq to disk.

Classes

KerrSeqCache([init_schw, …]) High-level caching interface for getting precomputed spin sequences.
TqdmUpTo([iterable, desc, total, leave, …]) Provides update_to(n) which uses tqdm.update(delta_n).
class qnm.cached.KerrSeqCache(init_schw=False, compute_if_not_found=True, compute_pars=None)[source]

High-level caching interface for getting precomputed spin sequences.

An instance of KerrSeqCache will return instances of qnm.spinsequence.KerrSpinSeq from memory or disk. If a spin sequence is neither in memory nor on disk then it will be computed and returned.

Use download_data() to fetch a collection of precomputed spin sequences from the web.

Parameters:
init_schw: bool, optional [default: False]

Value of init flag to pass to qnm.schwarzschild.tabulated.QNMDict. You should set this to True the first time in a session that you create a QNMDict (most likely via this class).

compute_if_not_found: bool, optional [default: True]

If a mode sequence is not found on disk, this flag controls whether to try to compute the sequence from scratch.

compute_pars: dict, optional [default: None]

A dict of parameters to pass to qnm.spinsequence.KerrSpinSeq if computing a mode sequence from scratch.

Examples

>>> import qnm
>>> # qnm.download_data() # Only need to do this once
>>> grav_220 = qnm.modes_cache(s=-2,l=2,m=2,n=0)
>>> omega, A, C = grav_220(a=0.68)
>>> print(omega)
(0.5239751042900845-0.08151262363119986j)

Methods

__call__(self, s, l, m, n[, …]) Load a qnm.spinsequence.KerrSpinSeq from the cache or from disk if available.
write_all(self) Write all of the modes in the cache to disk.
__call__(self, s, l, m, n, compute_if_not_found=None, compute_pars=None)[source]

Load a qnm.spinsequence.KerrSpinSeq from the cache or from disk if available.

If the mode sequence is not available on disk, optionally compute it from scratch. TODO maybe take param: dict of params to pass to KerrSpinSeq?

Parameters:
s: int

Spin-weight of field of interest.

l: int

Multipole number of mode. l >= angular.l_min(s, m)

m: int

Azimuthal number of mode.

n: int

Overtone number of mode.

compute_if_not_found: bool, optional [default: self.compute_if_not_found]

Whether or not to compute from scratch the spin sequence if it is not available on disk.

compute_pars: dict, optional [default: self.compute_pars]

Dict of parameters to pass to KerrSpinSeq if a mode sequence needs to be computed from scratch.

Returns:
KerrSpinSeq

The mode, if it is in the cache, on disk, or has been computed from scratch. If the mode is not available and compute_if_not_found is false, return None.

write_all(self)[source]

Write all of the modes in the cache to disk.

TODO: Take an overwrite argument which will force overwrite or not.

class qnm.cached.TqdmUpTo(iterable=None, desc=None, total=None, leave=True, file=None, ncols=None, mininterval=0.1, maxinterval=10.0, miniters=None, ascii=None, disable=False, unit='it', unit_scale=False, dynamic_ncols=False, smoothing=0.3, bar_format=None, initial=0, position=None, postfix=None, unit_divisor=1000, write_bytes=None, gui=False, **kwargs)[source]

Provides update_to(n) which uses tqdm.update(delta_n).

Attributes:
format_dict

Public API for read-only member access.

monitor

Methods

clear(self[, nolock]) Clear current bar display.
close(self) Cleanup and (if leave=False) close the progressbar.
display(self[, msg, pos]) Use self.sp to display msg in the specified pos.
ema(x[, mu, alpha]) Exponential moving average: smoothing to give progressively lower weights to older values.
external_write_mode([file, nolock]) Disable tqdm within context and refresh tqdm when exits.
format_interval(t) Formats a number of seconds as a clock time, [H:]MM:SS
format_meter(n, total, elapsed[, ncols, …]) Return a string-based progress bar given some parameters
format_num(n) Intelligent scientific notation (.3g).
format_sizeof(num[, suffix, divisor]) Formats a number (greater than unity) with SI Order of Magnitude prefixes.
get_lock() Get the global lock.
pandas(\*targs, \*\*tkwargs) Registers the given tqdm class with
refresh(self[, nolock]) Force refresh the display of this bar.
reset(self[, total]) Resets to 0 iterations for repeated use.
set_description(self[, desc, refresh]) Set/modify description of the progress bar.
set_description_str(self[, desc, refresh]) Set/modify description without ‘: ‘ appended.
set_lock(lock) Set the global lock.
set_postfix(self[, ordered_dict, refresh]) Set/modify postfix (additional stats) with automatic formatting based on datatype.
set_postfix_str(self[, s, refresh]) Postfix without dictionary expansion, similar to prefix handling.
status_printer(file) Manage the printing and in-place updating of a line of characters.
unpause(self) Restart tqdm timer from last print time.
update(self[, n]) Manually update the progress bar, useful for streams such as reading files.
update_to(self[, b, bsize, tsize]) b : int, optional
write(s[, file, end, nolock]) Print a message via tqdm (without overlap with bars).
moveto  
update_to(self, b=1, bsize=1, tsize=None)[source]
b : int, optional
Number of blocks transferred so far [default: 1].
bsize : int, optional
Size of each block (in tqdm units) [default: 1].
tsize : int, optional
Total size (in tqdm units). If [default: None] remains unchanged.
qnm.cached.build_package_default_cache(ksc)[source]

Compute the standard list of modes that this package promises to have in its cache.

This method is intended to be used for building the modes from scratch in a predictable way. If modes are available on disk then there will be no computation, simply loading all the default modes.

Parameters:
ksc: KerrSeqCache

The cache that will hold the modes we are about to compute.

Returns:
KerrSeqCache

The updated cache.

qnm.cached.download_data(overwrite=False)[source]

Fetch and decompress tarball of precomputed spin sequence from the web.

Parameters:
overwrite: bool, optional [default: False]

If there is already a tarball on disk, this flag controls whether or not it is overwritten.

qnm.cached.load_cached_mode(s, l, m, n)[source]

Read a KerrSpinSeq from disk.

Path is determined by mode_pickle_path(s, l, m, n)().

Parameters:
s: int

Spin-weight of field of interest.

l: int

Multipole number of mode. l >= angular.l_min(s, m)

m: int

Azimuthal number of mode.

n: int

Overtone number of mode.

Returns:
KerrSpinSeq

The mode, if it exists. Otherwise None.

qnm.cached.mode_pickle_path(s, l, m, n)[source]

Construct the path to a pickle file for the mode (s, l, m, n)

Parameters:
s: int

Spin-weight of field of interest.

l: int

Multipole number of mode. l >= angular.l_min(s, m)

m: int

Azimuthal number of mode.

n: int

Overtone number of mode.

Returns:
string

<dirname of this file>/data/s<s>_l<l>_m<m>_n<n>.pickle

qnm.cached.write_mode(spin_seq, pickle_path=None)[source]

Write an instance of KerrSpinSeq to disk.

Parameters:
spin_seq: KerrSpinSeq

The mode to write to disk.

pickle_path: string, optional [default: None]

Path to file to write. If None, get the path from mode_pickle_path().

Raises:
TODO