rapidtide 3.0.9__py3-none-any.whl → 3.0.11__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
rapidtide/filter.py CHANGED
@@ -73,10 +73,11 @@ def disablenumba():
73
73
 
74
74
 
75
75
  @conditionaljit()
76
- def padvec(inputdata, padlen=20, avlen=20, cyclic=False, padtype="reflect", debug=False):
76
+ def padvec(inputdata, padlen=20, avlen=20, padtype="reflect", debug=False):
77
77
  r"""Returns a padded copy of the input data; padlen points of
78
- reflected data are prepended and appended to the input data to reduce
79
- end effects when the data is then filtered.
78
+ filled data are prepended and appended to the input data to reduce
79
+ end effects when the data is then filtered. Filling can be "zero", "reflect", "cyclic", "constant",
80
+ or "constant+".
80
81
 
81
82
  Parameters
82
83
  ----------
@@ -85,15 +86,15 @@ def padvec(inputdata, padlen=20, avlen=20, cyclic=False, padtype="reflect", debu
85
86
  :param inputdata:
86
87
 
87
88
  padlen : int, optional
88
- The number of points to remove from each end. Default is 20.
89
+ The number of points to add to each end. Default is 20.
89
90
  :param padlen:
90
-
91
- cyclic : bool, optional
92
- If True, pad by wrapping the data in a cyclic manner rather than reflecting at the ends
93
- :param cyclic:
91
+
92
+ avlen : int, optional
93
+ The number of points to average when doing "constant+" padding. Default is 20.
94
94
 
95
95
  padtype : str, optional
96
- If True, pad by wrapping the data in a cyclic manner rather than reflecting at the ends
96
+ Method for padding data on the ends of the vector. Options are "reflect", "zero", "cyclic",
97
+ "constant", or "constant+". Default is "reflect".
97
98
  :param padtype:
98
99
 
99
100
  Returns
@@ -103,66 +104,48 @@ def padvec(inputdata, padlen=20, avlen=20, cyclic=False, padtype="reflect", debu
103
104
 
104
105
  """
105
106
  if debug:
106
- print(
107
- "padvec: padlen=",
108
- padlen,
109
- "avlen=",
110
- avlen,
111
- ", cyclic=",
112
- cyclic,
113
- ", padtype=",
114
- padtype,
115
- ", len(inputdata)=",
116
- len(inputdata),
117
- )
107
+ print("padvec: padlen=", padlen, ", avlen=", avlen, ", padtype=", padtype, "len(inputdata)=", len(inputdata))
118
108
  if padlen > len(inputdata):
119
- raise RuntimeError(
120
- "ERROR: padlen (",
121
- padlen,
122
- ") is greater than input data length (",
123
- len(inputdata),
124
- ")",
125
- )
109
+ raise RuntimeError(f"ERROR: padlen ({padlen}) is greater than input data length ({len(inputdata)})")
126
110
  if avlen > padlen:
127
111
  avlen = padlen
128
112
 
129
113
  inputdtype = inputdata.dtype
130
114
  if padlen > 0:
131
- if cyclic:
132
- return np.concatenate((inputdata[-padlen:], inputdata, inputdata[0:padlen]))
133
- else:
134
- if padtype == "reflect":
135
- return np.concatenate(
136
- (inputdata[::-1][-padlen:], inputdata, inputdata[::-1][0:padlen])
137
- )
138
- elif padtype == "zero":
139
- return np.concatenate(
140
- (
141
- np.zeros((padlen), dtype=inputdtype),
142
- inputdata,
143
- np.zeros((padlen), dtype=inputdtype),
144
- )
115
+ if padtype == "reflect":
116
+ return np.concatenate(
117
+ (inputdata[::-1][-padlen:], inputdata, inputdata[::-1][0:padlen])
118
+ )
119
+ elif padtype == "zero":
120
+ return np.concatenate(
121
+ (
122
+ np.zeros((padlen), dtype=inputdtype),
123
+ inputdata,
124
+ np.zeros((padlen), dtype=inputdtype),
145
125
  )
146
- elif padtype == "constant":
147
- return np.concatenate(
148
- (
149
- inputdata[0] * np.ones((padlen), dtype=inputdtype),
150
- inputdata,
151
- inputdata[-1] * np.ones((padlen), dtype=inputdtype),
152
- )
126
+ )
127
+ elif padtype == "cyclic":
128
+ return np.concatenate((inputdata[-padlen:], inputdata, inputdata[0:padlen]))
129
+ elif padtype == "constant":
130
+ return np.concatenate(
131
+ (
132
+ inputdata[0] * np.ones((padlen), dtype=inputdtype),
133
+ inputdata,
134
+ inputdata[-1] * np.ones((padlen), dtype=inputdtype),
153
135
  )
154
- elif padtype == "constant+":
155
- startval = np.mean(inputdata[0:avlen])
156
- endval = np.mean(inputdata[-avlen:])
157
- return np.concatenate(
158
- (
159
- (startval * np.ones((padlen), dtype=inputdtype)).astype(inputdtype),
160
- inputdata,
161
- (endval * np.ones((padlen), dtype=inputdtype)).astype(inputdtype),
162
- )
136
+ )
137
+ elif padtype == "constant+":
138
+ startval = np.mean(inputdata[0:avlen])
139
+ endval = np.mean(inputdata[-avlen:])
140
+ return np.concatenate(
141
+ (
142
+ (startval * np.ones((padlen), dtype=inputdtype)).astype(inputdtype),
143
+ inputdata,
144
+ (endval * np.ones((padlen), dtype=inputdtype)).astype(inputdtype),
163
145
  )
164
- else:
165
- raise ValueError("Padtype must be one of 'reflect', 'zero', or 'constant'")
146
+ )
147
+ else:
148
+ raise ValueError("Padtype must be one of 'reflect', 'zero', 'cyclic', 'constant', or 'constant+'.")
166
149
  else:
167
150
  return inputdata
168
151
 
@@ -237,7 +220,6 @@ def dolpfiltfilt(
237
220
  order,
238
221
  padlen=20,
239
222
  avlen=20,
240
- cyclic=False,
241
223
  padtype="reflect",
242
224
  debug=False,
243
225
  ):
@@ -296,7 +278,7 @@ def dolpfiltfilt(
296
278
  b,
297
279
  a,
298
280
  padvec(
299
- inputdata, padlen=padlen, avlen=avlen, cyclic=cyclic, padtype=padtype, debug=debug
281
+ inputdata, padlen=padlen, avlen=avlen, padtype=padtype, debug=debug
300
282
  ),
301
283
  ).real,
302
284
  padlen=padlen,
@@ -311,7 +293,6 @@ def dohpfiltfilt(
311
293
  order,
312
294
  padlen=20,
313
295
  avlen=20,
314
- cyclic=False,
315
296
  padtype="reflect",
316
297
  debug=False,
317
298
  ):
@@ -369,7 +350,7 @@ def dohpfiltfilt(
369
350
  b,
370
351
  a,
371
352
  padvec(
372
- inputdata, padlen=padlen, avlen=avlen, cyclic=cyclic, padtype=padtype, debug=debug
353
+ inputdata, padlen=padlen, avlen=avlen, padtype=padtype, debug=debug
373
354
  ),
374
355
  ).real,
375
356
  padlen=padlen,
@@ -385,7 +366,6 @@ def dobpfiltfilt(
385
366
  order,
386
367
  padlen=20,
387
368
  avlen=20,
388
- cyclic=False,
389
369
  padtype="reflect",
390
370
  debug=False,
391
371
  ):
@@ -450,7 +430,7 @@ def dobpfiltfilt(
450
430
  b,
451
431
  a,
452
432
  padvec(
453
- inputdata, padlen=padlen, avlen=avlen, cyclic=cyclic, padtype=padtype, debug=debug
433
+ inputdata, padlen=padlen, avlen=avlen, padtype=padtype, debug=debug
454
434
  ),
455
435
  ).real,
456
436
  padlen=padlen,
@@ -522,7 +502,7 @@ def getlpfftfunc(Fs, upperpass, inputdata, debug=False):
522
502
 
523
503
  # @conditionaljit()
524
504
  def dolpfftfilt(
525
- Fs, upperpass, inputdata, padlen=20, avlen=20, cyclic=False, padtype="reflect", debug=False
505
+ Fs, upperpass, inputdata, padlen=20, avlen=20, padtype="reflect", debug=False
526
506
  ):
527
507
  r"""Performs an FFT brickwall lowpass filter on an input vector
528
508
  and returns the result. Ends are padded to reduce transients.
@@ -559,7 +539,7 @@ def dolpfftfilt(
559
539
  The filtered data
560
540
  """
561
541
  padinputdata = padvec(
562
- inputdata, padlen=padlen, avlen=avlen, cyclic=cyclic, padtype=padtype, debug=debug
542
+ inputdata, padlen=padlen, avlen=avlen, padtype=padtype, debug=debug
563
543
  )
564
544
  inputdata_trans = fftpack.fft(padinputdata)
565
545
  transferfunc = getlpfftfunc(Fs, upperpass, padinputdata, debug=debug)
@@ -569,7 +549,7 @@ def dolpfftfilt(
569
549
 
570
550
  # @conditionaljit()
571
551
  def dohpfftfilt(
572
- Fs, lowerpass, inputdata, padlen=20, avlen=20, cyclic=False, padtype="reflect", debug=False
552
+ Fs, lowerpass, inputdata, padlen=20, avlen=20, padtype="reflect", debug=False
573
553
  ):
574
554
  r"""Performs an FFT brickwall highpass filter on an input vector
575
555
  and returns the result. Ends are padded to reduce transients.
@@ -606,7 +586,7 @@ def dohpfftfilt(
606
586
  The filtered data
607
587
  """
608
588
  padinputdata = padvec(
609
- inputdata, padlen=padlen, avlen=avlen, cyclic=cyclic, padtype=padtype, debug=debug
589
+ inputdata, padlen=padlen, avlen=avlen, padtype=padtype, debug=debug
610
590
  )
611
591
  inputdata_trans = fftpack.fft(padinputdata)
612
592
  transferfunc = 1.0 - getlpfftfunc(Fs, lowerpass, padinputdata, debug=debug)
@@ -622,7 +602,6 @@ def dobpfftfilt(
622
602
  inputdata,
623
603
  padlen=20,
624
604
  avlen=20,
625
- cyclic=False,
626
605
  padtype="reflect",
627
606
  debug=False,
628
607
  ):
@@ -665,7 +644,7 @@ def dobpfftfilt(
665
644
  The filtered data
666
645
  """
667
646
  padinputdata = padvec(
668
- inputdata, padlen=padlen, avlen=avlen, cyclic=cyclic, padtype=padtype, debug=debug
647
+ inputdata, padlen=padlen, avlen=avlen, padtype=padtype, debug=debug
669
648
  )
670
649
  inputdata_trans = fftpack.fft(padinputdata)
671
650
  transferfunc = getlpfftfunc(Fs, upperpass, padinputdata, debug=debug) * (
@@ -823,7 +802,6 @@ def dolptransfuncfilt(
823
802
  type="brickwall",
824
803
  padlen=20,
825
804
  avlen=20,
826
- cyclic=False,
827
805
  padtype="reflect",
828
806
  debug=False,
829
807
  ):
@@ -862,7 +840,7 @@ def dolptransfuncfilt(
862
840
  The filtered data
863
841
  """
864
842
  padinputdata = padvec(
865
- inputdata, padlen=padlen, avlen=avlen, cyclic=cyclic, padtype=padtype, debug=debug
843
+ inputdata, padlen=padlen, avlen=avlen, padtype=padtype, debug=debug
866
844
  )
867
845
  inputdata_trans = fftpack.fft(padinputdata)
868
846
  transferfunc = getlptransfunc(
@@ -891,7 +869,6 @@ def dohptransfuncfilt(
891
869
  type="brickwall",
892
870
  padlen=20,
893
871
  avlen=20,
894
- cyclic=False,
895
872
  padtype="reflect",
896
873
  debug=False,
897
874
  ):
@@ -936,7 +913,7 @@ def dohptransfuncfilt(
936
913
  if lowerstop is None:
937
914
  lowerstop = lowerpass * (1.0 / 1.05)
938
915
  padinputdata = padvec(
939
- inputdata, padlen=padlen, avlen=avlen, cyclic=cyclic, padtype=padtype, debug=debug
916
+ inputdata, padlen=padlen, avlen=avlen, padtype=padtype, debug=debug
940
917
  )
941
918
  inputdata_trans = fftpack.fft(padinputdata)
942
919
  transferfunc = getlptransfunc(
@@ -967,7 +944,6 @@ def dobptransfuncfilt(
967
944
  type="brickwall",
968
945
  padlen=20,
969
946
  avlen=20,
970
- cyclic=False,
971
947
  padtype="reflect",
972
948
  debug=False,
973
949
  ):
@@ -1012,7 +988,7 @@ def dobptransfuncfilt(
1012
988
  if lowerstop is None:
1013
989
  lowerstop = lowerpass * (1.0 / 1.05)
1014
990
  padinputdata = padvec(
1015
- inputdata, padlen=padlen, avlen=avlen, cyclic=cyclic, padtype=padtype, debug=debug
991
+ inputdata, padlen=padlen, avlen=avlen, padtype=padtype, debug=debug
1016
992
  )
1017
993
  inputdata_trans = fftpack.fft(padinputdata)
1018
994
  transferfunc = getlptransfunc(
@@ -1049,7 +1025,6 @@ def dolptrapfftfilt(
1049
1025
  inputdata,
1050
1026
  padlen=20,
1051
1027
  avlen=20,
1052
- cyclic=False,
1053
1028
  padtype="reflect",
1054
1029
  debug=False,
1055
1030
  ):
@@ -1092,7 +1067,7 @@ def dolptrapfftfilt(
1092
1067
  The filtered data
1093
1068
  """
1094
1069
  padinputdata = padvec(
1095
- inputdata, padlen=padlen, avlen=avlen, cyclic=cyclic, padtype=padtype, debug=debug
1070
+ inputdata, padlen=padlen, avlen=avlen, padtype=padtype, debug=debug
1096
1071
  )
1097
1072
  inputdata_trans = fftpack.fft(padinputdata)
1098
1073
  transferfunc = getlptrapfftfunc(Fs, upperpass, upperstop, padinputdata, debug=debug)
@@ -1108,7 +1083,6 @@ def dohptrapfftfilt(
1108
1083
  inputdata,
1109
1084
  padlen=20,
1110
1085
  avlen=20,
1111
- cyclic=False,
1112
1086
  padtype="reflect",
1113
1087
  debug=False,
1114
1088
  ):
@@ -1151,7 +1125,7 @@ def dohptrapfftfilt(
1151
1125
  The filtered data
1152
1126
  """
1153
1127
  padinputdata = padvec(
1154
- inputdata, padlen=padlen, avlen=avlen, cyclic=cyclic, padtype=padtype, debug=debug
1128
+ inputdata, padlen=padlen, avlen=avlen, padtype=padtype, debug=debug
1155
1129
  )
1156
1130
  inputdata_trans = fftpack.fft(padinputdata)
1157
1131
  transferfunc = 1.0 - getlptrapfftfunc(Fs, lowerstop, lowerpass, padinputdata, debug=debug)
@@ -1169,7 +1143,6 @@ def dobptrapfftfilt(
1169
1143
  inputdata,
1170
1144
  padlen=20,
1171
1145
  avlen=20,
1172
- cyclic=False,
1173
1146
  padtype="reflect",
1174
1147
  debug=False,
1175
1148
  ):
@@ -1220,7 +1193,7 @@ def dobptrapfftfilt(
1220
1193
  The filtered data
1221
1194
  """
1222
1195
  padinputdata = padvec(
1223
- inputdata, padlen=padlen, avlen=avlen, cyclic=cyclic, padtype=padtype, debug=debug
1196
+ inputdata, padlen=padlen, avlen=avlen, padtype=padtype, debug=debug
1224
1197
  )
1225
1198
  inputdata_trans = fftpack.fft(padinputdata)
1226
1199
  if debug:
@@ -1425,7 +1398,7 @@ def savgolsmooth(data, smoothlen=101, polyorder=3):
1425
1398
 
1426
1399
 
1427
1400
  def csdfilter(
1428
- obsdata, commondata, padlen=20, avlen=20, cyclic=False, padtype="reflect", debug=False
1401
+ obsdata, commondata, padlen=20, avlen=20, padtype="reflect", debug=False
1429
1402
  ):
1430
1403
  r"""Cross spectral density filter - makes a filter transfer function that preserves common frequencies.
1431
1404
 
@@ -1453,10 +1426,10 @@ def csdfilter(
1453
1426
 
1454
1427
  """
1455
1428
  padobsdata = padvec(
1456
- obsdata, padlen=padlen, avlen=avlen, cyclic=cyclic, padtype=padtype, debug=debug
1429
+ obsdata, padlen=padlen, avlen=avlen, padtype=padtype, debug=debug
1457
1430
  )
1458
1431
  padcommondata = padvec(
1459
- commondata, padlen=padlen, avlen=avlen, cyclic=cyclic, padtype=padtype, debug=debug
1432
+ commondata, padlen=padlen, avlen=avlen, padtype=padtype, debug=debug
1460
1433
  )
1461
1434
  obsdata_trans = fftpack.fft(padobsdata)
1462
1435
  transferfunc = np.sqrt(np.abs(fftpack.fft(padobsdata) * np.conj(fftpack.fft(padcommondata))))
@@ -1476,7 +1449,6 @@ def arb_pass(
1476
1449
  butterorder=6,
1477
1450
  padlen=20,
1478
1451
  avlen=20,
1479
- cyclic=False,
1480
1452
  padtype="reflect",
1481
1453
  debug=False,
1482
1454
  ):
@@ -1542,7 +1514,6 @@ def arb_pass(
1542
1514
  butterorder,
1543
1515
  padlen=padlen,
1544
1516
  avlen=avlen,
1545
- cyclic=False,
1546
1517
  padtype=padtype,
1547
1518
  debug=debug,
1548
1519
  )
@@ -1556,7 +1527,6 @@ def arb_pass(
1556
1527
  type=transferfunc,
1557
1528
  padlen=padlen,
1558
1529
  avlen=avlen,
1559
- cyclic=cyclic,
1560
1530
  padtype=padtype,
1561
1531
  debug=debug,
1562
1532
  )
@@ -1570,7 +1540,6 @@ def arb_pass(
1570
1540
  butterorder,
1571
1541
  padlen=padlen,
1572
1542
  avlen=avlen,
1573
- cyclic=False,
1574
1543
  padtype=padtype,
1575
1544
  debug=debug,
1576
1545
  )
@@ -1583,7 +1552,6 @@ def arb_pass(
1583
1552
  type=transferfunc,
1584
1553
  padlen=padlen,
1585
1554
  avlen=avlen,
1586
- cyclic=cyclic,
1587
1555
  padtype=padtype,
1588
1556
  debug=debug,
1589
1557
  )
@@ -1600,14 +1568,12 @@ def arb_pass(
1600
1568
  butterorder,
1601
1569
  padlen=padlen,
1602
1570
  avlen=avlen,
1603
- cyclic=False,
1604
1571
  padtype=padtype,
1605
1572
  debug=debug,
1606
1573
  ),
1607
1574
  butterorder,
1608
1575
  padlen=padlen,
1609
1576
  avlen=avlen,
1610
- cyclic=False,
1611
1577
  padtype=padtype,
1612
1578
  debug=debug,
1613
1579
  )
@@ -1622,7 +1588,6 @@ def arb_pass(
1622
1588
  type=transferfunc,
1623
1589
  padlen=padlen,
1624
1590
  avlen=avlen,
1625
- cyclic=cyclic,
1626
1591
  padtype=padtype,
1627
1592
  debug=debug,
1628
1593
  )
@@ -1732,7 +1697,6 @@ class NoncausalFilter:
1732
1697
  butterworthorder=6,
1733
1698
  correctfreq=True,
1734
1699
  padtime=30.0,
1735
- cyclic=False,
1736
1700
  padtype="reflect",
1737
1701
  debug=False,
1738
1702
  ):
@@ -1748,8 +1712,6 @@ class NoncausalFilter:
1748
1712
  Fix pass frequencies that are impossible. Default is True.
1749
1713
  padtime: float, optional
1750
1714
  Amount of time to end pad to reduce edge effects. Default is 30.0 seconds
1751
- cyclic : boolean, optional
1752
- If True, pad vectors cyclicly rather than reflecting data around the ends
1753
1715
  padtype : str, optional
1754
1716
  Choice of "reflect", "zero", or "constant". Default is "reflect".
1755
1717
  debug: boolean, optional
@@ -1802,7 +1764,6 @@ class NoncausalFilter:
1802
1764
  self.butterworthorder = butterworthorder
1803
1765
  self.correctfreq = correctfreq
1804
1766
  self.padtime = padtime
1805
- self.cyclic = cyclic
1806
1767
  self.padtype = padtype
1807
1768
  self.debug = debug
1808
1769
 
@@ -1880,12 +1841,6 @@ class NoncausalFilter:
1880
1841
  def getpadtime(self):
1881
1842
  return self.padtime
1882
1843
 
1883
- def setcyclic(self, cyclic):
1884
- self.cyclic = cyclic
1885
-
1886
- def getcyclic(self):
1887
- return self.cyclic
1888
-
1889
1844
  def setpadtype(self, padtype):
1890
1845
  self.padtype = padtype
1891
1846
 
@@ -2056,7 +2011,6 @@ class NoncausalFilter:
2056
2011
  print("padtime=", self.padtime)
2057
2012
  print("padlen=", padlen)
2058
2013
  print("avlen=", avlen)
2059
- print("cyclic=", self.cyclic)
2060
2014
  print("padtype=", self.padtype)
2061
2015
 
2062
2016
  # now do the actual filtering
@@ -2073,7 +2027,6 @@ class NoncausalFilter:
2073
2027
  transferfunc=self.transferfunc,
2074
2028
  butterorder=self.butterworthorder,
2075
2029
  padlen=padlen,
2076
- cyclic=self.cyclic,
2077
2030
  padtype=self.padtype,
2078
2031
  debug=self.debug,
2079
2032
  )
@@ -2101,7 +2054,6 @@ class NoncausalFilter:
2101
2054
  butterorder=self.butterworthorder,
2102
2055
  padlen=padlen,
2103
2056
  avlen=avlen,
2104
- cyclic=self.cyclic,
2105
2057
  padtype=self.padtype,
2106
2058
  debug=self.debug,
2107
2059
  )
@@ -2129,7 +2081,6 @@ class NoncausalFilter:
2129
2081
  butterorder=self.butterworthorder,
2130
2082
  padlen=padlen,
2131
2083
  avlen=avlen,
2132
- cyclic=self.cyclic,
2133
2084
  padtype=self.padtype,
2134
2085
  debug=self.debug,
2135
2086
  )
@@ -2145,7 +2096,6 @@ class NoncausalFilter:
2145
2096
  butterorder=self.butterworthorder,
2146
2097
  padlen=padlen,
2147
2098
  avlen=avlen,
2148
- cyclic=self.cyclic,
2149
2099
  padtype=self.padtype,
2150
2100
  debug=self.debug,
2151
2101
  )
@@ -2161,7 +2111,6 @@ class NoncausalFilter:
2161
2111
  butterorder=self.butterworthorder,
2162
2112
  padlen=padlen,
2163
2113
  avlen=avlen,
2164
- cyclic=self.cyclic,
2165
2114
  padtype=self.padtype,
2166
2115
  debug=self.debug,
2167
2116
  )