bucky.util.util

Generic utility functions/classes used in the model.

Module Contents

Classes

TqdmLoggingHandler

Logging handler that is friendly with tqdm.

dotdict

dot.notation access to dictionary attributes.

Functions

_banner()

A banner for the CLI.

bin_age_csv(filename, out_filename)

Group ages in the Census csv to match the bins used by Prem et al.

date_to_t_int(dates, start_date)

Find the indices of a list of dates internally used by time indexed arrays in the modeli.

estimate_IFR(age)

Estimate the best fit IFR for a given age.

map_np_array(a, d)

Function similar to pandas map but for np arrays.

remove_chars(seq)

Remove all non digit characters from a string, but cleanly passthrough non strs.

class bucky.util.util.TqdmLoggingHandler(level=logging.NOTSET)[source]

Bases: logging.Handler

Logging handler that is friendly with tqdm.

See https://stackoverflow.com/questions/38543506/change-logging-print-function-to-tqdm-write-so-logging-doesnt-interfere-wit

emit(self, record)[source]

Emit message.

class bucky.util.util.dotdict[source]

Bases: dict

dot.notation access to dictionary attributes.

__delattr__[source]
__getattr__[source]
__setattr__[source]
__deepcopy__(self, memo=None)[source]

Return a deepcopy of the dict.

bucky.util.util._banner()[source]

A banner for the CLI.

bucky.util.util.bin_age_csv(filename, out_filename)[source]

Group ages in the Census csv to match the bins used by Prem et al.

Parameters
  • filename (str) – Location of Census CSV

  • out_filename (str) – Output filename for binned data

bucky.util.util.date_to_t_int(dates, start_date)[source]

Find the indices of a list of dates internally used by time indexed arrays in the modeli.

bucky.util.util.estimate_IFR(age)[source]

Estimate the best fit IFR for a given age.

See https://www.medrxiv.org/content/10.1101/2020.07.23.20160895v4.full.pdf for the fit

Parameters

age (numpy.ndarray or cupy.ndarray if using CuPy) – Array of ages to calculate IFR for

Returns

ifr – The calculated best fit IFR

Return type

numpy.ndarray or cupy.ndarray if using CuPy

bucky.util.util.map_np_array(a, d)[source]

Function similar to pandas map but for np arrays.

Deprecated since version 0.8.0.

bucky.util.util.remove_chars(seq)[source]

Remove all non digit characters from a string, but cleanly passthrough non strs.

Parameters

seq (Any) – Strings will be modified, any other type is directly returned

Returns

The original sequence, minus non-digit characters if input was a string

Return type

Any