razorback.utils module
high level functions to compute transfer function estimates
- razorback.utils.compute_prefilter(data, freq, prefilter, remote=None, fourier_opts=None)
- razorback.utils.impedance(data, l_freq, weights=(None,), prefilter=None, fourier_opts=None, remote=None, remote_weights=None, remote_prefilter=None, tag_elec='E', tag_mag='B', mest_opts=None, real_pb=False, silent_fail=True, keep_invalid_times=False)
Uses razorback.mestimator.transfer_error() for error estimation.
TODO
- data: SignalSet
- tags:
‘E’ -> local elec ‘B’ -> local magn other -> remote
prefilter: None or function(outputs[i], inputs) -> invalid_idx
[TODO: section outdated] remote: str or dict
if str then it is the same as {‘name’: remote_tag}. if dict then keys are ‘name’, ‘weights’ and ‘prefilter’. ‘name’ : the str tag of remote fields in data ‘weights’ : the weighting function to use on stage 1
if missing, weights is used instead
- ‘prefilter’the prefilter to use on stage 1
if missing, prefilter is used instead
fourier_opts defaults : dict(Nper=8, overlap=.71, window=slepian_window(4))
- razorback.utils.tags_from_path(names, pattern, *tag_tpls)
yield (name, tags) for each name in names
name is skiped if it does not match the pattern. tags is a list of strings formed from tag_tpls by using the matching fields in name
fields are marked with curly brackets by ‘{identifier}’, identifier must be a valid identifier in python grammar.
Some special characters are available:
‘*’ matches everything in one directory path level
‘**’ matches everything across directory path level
‘?’ matches any single character
[seq] matches any character in seq
[!seq] matches any character not in seq
Examples:
>>> g = tags_from_path(['rep/A/X.txt', 'rep/B/Y.txt'], 'rep/{a}/{x}.txt', '{a}_{x}') >>> list(g) [('rep/A/X.txt', ['A_X']), ('rep/B/Y.txt', ['B_Y'])]
more complex patterns are possible, like:
>>> g = tags_from_path(names, 'path_{a}/to_{b}/my_{c}/file_{d}.txt', '{a}_{b}_{c}_{d}') >>> g = tags_from_path(names, 'path_{a}/to_{b}/my_{c}/file_{d}.txt', '{a}_{d}') >>> g = tags_from_path(names, 'path_{a}/*/*/file_{d}.txt', '{a}_{d}') >>> g = tags_from_path(names, 'path_{a}/**/file_{d}.txt', '{a}_{d}') >>> g = tags_from_path(names, '**_{d}.txt', '{d}')
using tags_from_path() to build an inventory from a directory tree:
>>> root = 'the/main/directory/' >>> pattern = '**/Set?/site{site}/{type}/meas*/*_T{channel}_BL*.ats' >>> tag_tpl = 'site{site}_{channel}_{type}' >>> files = (os.path.join(r, f) for r, _, fs in os.walk(root) if fs for f in fs) >>> inv = Inventory( ... SignalSet({tag:0 for tag in tags}, rb.io.ats.load_ats([name], calibrations=None)) ... for name, tags in tags_from_path(files, pattern, tag_tpl) ... )