|
@@ 102-158 (lines=57) @@
|
| 99 |
|
return np.mean(udcf[msk]) |
| 100 |
|
|
| 101 |
|
|
| 102 |
|
def welsh_ab(t1, d1, t2, d2, t, dt): |
| 103 |
|
"""Welsh (1999) correlation with adaptative binning. |
| 104 |
|
|
| 105 |
|
This function implements the correlation function proposed |
| 106 |
|
by Welsh (1999), which allows for the computation of the correlation |
| 107 |
|
for -discrete- signals non-uniformly sampled in time. |
| 108 |
|
|
| 109 |
|
Parameters |
| 110 |
|
---------- |
| 111 |
|
t1 : :class:`~numpy.ndarray` |
| 112 |
|
Times corresponding to the first signal. |
| 113 |
|
d1 : :class:`~numpy.ndarray` |
| 114 |
|
Values of the first signal. |
| 115 |
|
t2 : :class:`~numpy.ndarray` |
| 116 |
|
Times corresponding to the second signal. |
| 117 |
|
d2 : :class:`~numpy.ndarray` |
| 118 |
|
Values of the second signal. |
| 119 |
|
t : :class:`~numpy.ndarray` |
| 120 |
|
Times on which to compute the correlation (binning). |
| 121 |
|
dt : :class:`~numpy.ndarray` |
| 122 |
|
Size of the bins on which to compute the correlation. |
| 123 |
|
|
| 124 |
|
Returns |
| 125 |
|
------- |
| 126 |
|
res : :class:`~numpy.ndarray` (size `len(t)`) |
| 127 |
|
Values of the correlation at the times `t`. |
| 128 |
|
|
| 129 |
|
Examples |
| 130 |
|
-------- |
| 131 |
|
An example of raw usage would be: |
| 132 |
|
|
| 133 |
|
>>> import numpy as np |
| 134 |
|
>>> from mutis.lib.correlation import welsh_ab |
| 135 |
|
>>> t1 = np.linspace(1, 10, 100); s1 = np.sin(t1) |
| 136 |
|
>>> t2 = np.linspace(1, 10, 100); s2 = np.cos(t2) |
| 137 |
|
>>> t = np.linspace(1, 10, 100); dt = np.full(t.shape, 0.1) |
| 138 |
|
>>> welsh_ab_p(t1, d1, t2, d2, t, dt) |
| 139 |
|
|
| 140 |
|
However, it is recommended to be used as expalined in the |
| 141 |
|
standard MUTIS' workflow notebook. |
| 142 |
|
""" |
| 143 |
|
|
| 144 |
|
if t.size != dt.size: |
| 145 |
|
log.error("Error, t and dt not the same size") |
| 146 |
|
return False |
| 147 |
|
if t1.size != d1.size: |
| 148 |
|
log.error("Error, t1 and d1 not the same size") |
| 149 |
|
return False |
| 150 |
|
if t2.size != d2.size: |
| 151 |
|
log.error("Error, t2 and d2 not the same size") |
| 152 |
|
return False |
| 153 |
|
|
| 154 |
|
# res = np.array([]) |
| 155 |
|
res = np.empty(t.size) |
| 156 |
|
for i in range(t.size): |
| 157 |
|
res[i] = welsh_ab_p(t1, d1, t2, d2, t[i], dt[i]) |
| 158 |
|
return res |
| 159 |
|
|
| 160 |
|
|
| 161 |
|
|
|
@@ 29-85 (lines=57) @@
|
| 26 |
|
return np.mean(udcf[mask]) |
| 27 |
|
|
| 28 |
|
|
| 29 |
|
def kroedel_ab(t1, d1, t2, d2, t, dt): |
| 30 |
|
"""Krolik & Edelson (1988) correlation with adaptative binning. |
| 31 |
|
|
| 32 |
|
This function implements the correlation function proposed by |
| 33 |
|
Krolik & Edelson (1988), which allows for the computation of |
| 34 |
|
the correlation for -discrete- signals non-uniformly sampled |
| 35 |
|
in time. |
| 36 |
|
|
| 37 |
|
Parameters |
| 38 |
|
---------- |
| 39 |
|
t1 : :class:`~numpy.ndarray` |
| 40 |
|
Times corresponding to the first signal. |
| 41 |
|
d1 : :class:`~numpy.ndarray` |
| 42 |
|
Values of the first signal. |
| 43 |
|
t2 : :class:`~numpy.ndarray` |
| 44 |
|
Times corresponding to the second signal. |
| 45 |
|
d2 : :class:`~numpy.ndarray` |
| 46 |
|
Values of the second signal. |
| 47 |
|
t : :class:`~numpy.ndarray` |
| 48 |
|
Times on which to compute the correlation (binning). |
| 49 |
|
dt : :class:`~numpy.ndarray` |
| 50 |
|
Size of the bins on which to compute the correlation. |
| 51 |
|
|
| 52 |
|
Returns |
| 53 |
|
------- |
| 54 |
|
res : :class:`~numpy.ndarray` (size `len(t)`) |
| 55 |
|
Values of the correlation at the times `t`. |
| 56 |
|
|
| 57 |
|
Examples |
| 58 |
|
-------- |
| 59 |
|
An example of raw usage would be: |
| 60 |
|
|
| 61 |
|
>>> import numpy as np |
| 62 |
|
>>> from mutis.lib.correlation import kroedel_ab |
| 63 |
|
>>> t1 = np.linspace(1, 10, 100); s1 = np.sin(t1) |
| 64 |
|
>>> t2 = np.linspace(1, 10, 100); s2 = np.cos(t2) |
| 65 |
|
>>> t = np.linspace(1, 10, 100); dt = np.full(t.shape, 0.1) |
| 66 |
|
>>> kroedel_ab_p(t1, d1, t2, d2, t, dt) |
| 67 |
|
|
| 68 |
|
However, it is recommended to be used as expalined in the |
| 69 |
|
standard MUTIS' workflow notebook. |
| 70 |
|
""" |
| 71 |
|
|
| 72 |
|
if t.size != dt.size: |
| 73 |
|
log.error("Error, t and dt not the same size") |
| 74 |
|
return False |
| 75 |
|
if t1.size != d1.size: |
| 76 |
|
log.error("Error, t1 and d1 not the same size") |
| 77 |
|
return False |
| 78 |
|
if t2.size != d2.size: |
| 79 |
|
log.error("Error, t2 and d2 not the same size") |
| 80 |
|
return False |
| 81 |
|
|
| 82 |
|
res = np.empty(t.size) |
| 83 |
|
for i in range(t.size): |
| 84 |
|
res[i] = kroedel_ab_p(t1, d1, t2, d2, t[i], dt[i]) |
| 85 |
|
return res |
| 86 |
|
|
| 87 |
|
|
| 88 |
|
|