rapidtide 3.0.5__py3-none-any.whl → 3.0.7__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.
Files changed (45) hide show
  1. rapidtide/RapidtideDataset.py +17 -0
  2. rapidtide/_version.py +3 -3
  3. rapidtide/calccoherence.py +51 -73
  4. rapidtide/calcnullsimfunc.py +65 -111
  5. rapidtide/calcsimfunc.py +73 -91
  6. rapidtide/correlate.py +25 -6
  7. rapidtide/data/examples/src/testatlasaverage +22 -0
  8. rapidtide/data/examples/src/testfmri +16 -1
  9. rapidtide/data/examples/src/testhappy +57 -60
  10. rapidtide/data/examples/src/testsimdata +45 -28
  11. rapidtide/genericmultiproc.py +122 -0
  12. rapidtide/happy_supportfuncs.py +608 -107
  13. rapidtide/linfitfiltpass.py +8 -1
  14. rapidtide/makelaggedtcs.py +49 -78
  15. rapidtide/multiproc.py +5 -17
  16. rapidtide/refineregressor.py +59 -81
  17. rapidtide/resample.py +24 -14
  18. rapidtide/tests/.coveragerc +9 -0
  19. rapidtide/tests/test_congrid.py +68 -79
  20. rapidtide/tests/test_externaltools.py +69 -0
  21. rapidtide/tests/test_fastresampler.py +1 -0
  22. rapidtide/tests/test_fullrunrapidtide_v2.py +1 -0
  23. rapidtide/tests/test_nullcorr.py +2 -5
  24. rapidtide/tests/test_parserfuncs.py +46 -15
  25. rapidtide/tests/test_zRapidtideDataset.py +2 -2
  26. rapidtide/voxelData.py +17 -3
  27. rapidtide/workflows/ccorrica.py +1 -2
  28. rapidtide/workflows/cleanregressor.py +3 -2
  29. rapidtide/workflows/happy.py +62 -3
  30. rapidtide/workflows/happy_parser.py +36 -0
  31. rapidtide/workflows/rapidtide.py +18 -13
  32. rapidtide/workflows/rapidtide_parser.py +8 -1
  33. rapidtide/workflows/regressfrommaps.py +0 -2
  34. rapidtide/workflows/showarbcorr.py +19 -6
  35. rapidtide/workflows/showxcorrx.py +4 -8
  36. rapidtide/workflows/simdata.py +149 -65
  37. {rapidtide-3.0.5.dist-info → rapidtide-3.0.7.dist-info}/METADATA +1 -1
  38. {rapidtide-3.0.5.dist-info → rapidtide-3.0.7.dist-info}/RECORD +42 -43
  39. {rapidtide-3.0.5.dist-info → rapidtide-3.0.7.dist-info}/WHEEL +1 -1
  40. rapidtide/DerivativeDelay.py +0 -209
  41. rapidtide/calcandfitcorrpairs.py +0 -262
  42. rapidtide/transformerdlfilter.py +0 -126
  43. {rapidtide-3.0.5.dist-info → rapidtide-3.0.7.dist-info}/entry_points.txt +0 -0
  44. {rapidtide-3.0.5.dist-info → rapidtide-3.0.7.dist-info}/licenses/LICENSE +0 -0
  45. {rapidtide-3.0.5.dist-info → rapidtide-3.0.7.dist-info}/top_level.txt +0 -0
@@ -106,6 +106,12 @@ def linfitfiltpass(
106
106
  print(f"{fmri_data.shape=}")
107
107
  print(f"{threshval=}")
108
108
  print(f"{theevs.shape=}")
109
+ if procbyvoxel:
110
+ indexaxis = 0
111
+ procunit = "voxels"
112
+ else:
113
+ indexaxis = 1
114
+ procunit = "timepoints"
109
115
  if threshval is None:
110
116
  themask = None
111
117
  else:
@@ -187,7 +193,8 @@ def linfitfiltpass(
187
193
  themask,
188
194
  verbose=verbose,
189
195
  nprocs=nprocs,
190
- procbyvoxel=procbyvoxel,
196
+ indexaxis=indexaxis,
197
+ procunit=procunit,
191
198
  showprogressbar=showprogressbar,
192
199
  chunksize=mp_chunksize,
193
200
  )
@@ -17,32 +17,47 @@
17
17
  #
18
18
  #
19
19
  import gc
20
- import logging
21
20
 
22
21
  import numpy as np
23
- from tqdm import tqdm
24
22
 
25
- import rapidtide.multiproc as tide_multiproc
23
+ import rapidtide.genericmultiproc as tide_genericmultiproc
26
24
 
27
25
 
28
26
  def _procOneVoxelMakelagtc(
29
27
  vox,
30
- lagtcgenerator,
31
- maxlag,
32
- timeaxis,
33
- rt_floatset=np.float64,
34
- rt_floattype="float64",
28
+ voxelargs,
29
+ **kwargs,
35
30
  ):
31
+ # unpack arguments
32
+ options = {
33
+ "rt_floatset": np.float64,
34
+ "debug": False,
35
+ }
36
+ options.update(kwargs)
37
+ rt_floatset = options["rt_floatset"]
38
+ debug = options["debug"]
39
+ (lagtcgenerator, thelag, timeaxis) = voxelargs
40
+ if debug:
41
+ print(f"{vox=}, {thelag=}, {timeaxis=}")
42
+
36
43
  # question - should maxlag be added or subtracted? As of 10/18, it is subtracted
37
44
  # potential answer - tried adding, results are terrible.
38
- thelagtc = rt_floatset(lagtcgenerator.yfromx(timeaxis - maxlag))
45
+ thelagtc = rt_floatset(lagtcgenerator.yfromx(timeaxis - thelag))
39
46
 
40
47
  return (
41
48
  vox,
42
- thelagtc,
49
+ (thelagtc),
43
50
  )
44
51
 
45
52
 
53
+ def _packvoxeldata(voxnum, voxelargs):
54
+ return [voxelargs[0], (voxelargs[1])[voxnum], voxelargs[2]]
55
+
56
+
57
+ def _unpackvoxeldata(retvals, voxelproducts):
58
+ (voxelproducts[0])[retvals[0], :] = retvals[1]
59
+
60
+
46
61
  def makelaggedtcs(
47
62
  lagtcgenerator,
48
63
  timeaxis,
@@ -58,75 +73,31 @@ def makelaggedtcs(
58
73
  rt_floattype="float64",
59
74
  ):
60
75
  inputshape = lagtc.shape
61
- if nprocs > 1 or alwaysmultiproc:
62
- # define the consumer function here so it inherits most of the arguments
63
- def makelagtc_consumer(inQ, outQ):
64
- while True:
65
- try:
66
- # get a new message
67
- val = inQ.get()
68
-
69
- # this is the 'TERM' signal
70
- if val is None:
71
- break
72
-
73
- # process and send the data
74
- outQ.put(
75
- _procOneVoxelMakelagtc(
76
- val,
77
- lagtcgenerator,
78
- lagtimes[val],
79
- timeaxis,
80
- rt_floatset=rt_floatset,
81
- rt_floattype=rt_floattype,
82
- )
83
- )
84
- except Exception as e:
85
- print("error!", e)
86
- break
87
-
88
- data_out = tide_multiproc.run_multiproc(
89
- makelagtc_consumer,
90
- inputshape,
91
- lagmask,
92
- verbose=(LGR is not None),
93
- nprocs=nprocs,
94
- showprogressbar=showprogressbar,
95
- chunksize=chunksize,
96
- )
97
-
98
- # unpack the data
99
- volumetotal = 0
100
- for voxel in data_out:
101
- volumetotal += 1
102
- lagtc[voxel[0], :] = voxel[1]
103
- del data_out
104
- else:
105
- volumetotal = 0
106
- for vox in tqdm(
107
- range(0, inputshape[0]),
108
- desc="Voxel",
109
- unit="voxels",
110
- disable=(not showprogressbar),
111
- ):
112
- if lagmask[vox] > 0:
113
- dothisone = True
114
- else:
115
- dothisone = False
116
- if dothisone:
117
- (
118
- dummy,
119
- lagtc[vox, :],
120
- ) = _procOneVoxelMakelagtc(
121
- vox,
122
- lagtcgenerator,
123
- lagtimes[vox],
124
- timeaxis,
125
- rt_floatset=rt_floatset,
126
- rt_floattype=rt_floattype,
127
- )
128
- volumetotal += 1
76
+ voxelargs = [
77
+ lagtcgenerator,
78
+ lagtimes,
79
+ timeaxis,
80
+ ]
81
+ voxelfunc = _procOneVoxelMakelagtc
82
+ packfunc = _packvoxeldata
83
+ unpackfunc = _unpackvoxeldata
84
+ voxeltargets = [lagtc]
129
85
 
86
+ volumetotal = tide_genericmultiproc.run_multiproc(
87
+ voxelfunc,
88
+ packfunc,
89
+ unpackfunc,
90
+ voxelargs,
91
+ voxeltargets,
92
+ inputshape,
93
+ lagmask,
94
+ LGR,
95
+ nprocs,
96
+ alwaysmultiproc,
97
+ showprogressbar,
98
+ chunksize,
99
+ rt_floatset=rt_floatset,
100
+ )
130
101
  if LGR is not None:
131
102
  LGR.info(f"\nLagged timecourses created for {volumetotal} voxels")
132
103
 
rapidtide/multiproc.py CHANGED
@@ -36,7 +36,7 @@ def maxcpus(reservecpu=True):
36
36
  return mp.cpu_count()
37
37
 
38
38
 
39
- def _process_data(data_in, inQ, outQ, showprogressbar=True, reportstep=1000, chunksize=10000):
39
+ def _process_data(data_in, inQ, outQ, showprogressbar=True, chunksize=10000):
40
40
  # send pos/data to workers
41
41
  data_out = []
42
42
  totalnum = len(data_in)
@@ -89,7 +89,8 @@ def run_multiproc(
89
89
  maskarray,
90
90
  nprocs=1,
91
91
  verbose=True,
92
- procbyvoxel=True,
92
+ indexaxis=0,
93
+ procunit="voxels",
93
94
  showprogressbar=True,
94
95
  chunksize=1000,
95
96
  ):
@@ -113,13 +114,6 @@ def run_multiproc(
113
114
  for i, w in enumerate(workers):
114
115
  w.start()
115
116
 
116
- if procbyvoxel:
117
- indexaxis = 0
118
- procunit = "voxels"
119
- else:
120
- indexaxis = 1
121
- procunit = "timepoints"
122
-
123
117
  # check that the mask array matches the index dimension
124
118
  if maskarray is not None:
125
119
  if inputshape[indexaxis] != len(maskarray):
@@ -159,7 +153,8 @@ def run_multithread(
159
153
  maskarray,
160
154
  verbose=True,
161
155
  nprocs=1,
162
- procbyvoxel=True,
156
+ indexaxis=0,
157
+ procunit="voxels",
163
158
  showprogressbar=True,
164
159
  chunksize=1000,
165
160
  ):
@@ -171,13 +166,6 @@ def run_multithread(
171
166
  for i, w in enumerate(workers):
172
167
  w.start()
173
168
 
174
- if procbyvoxel:
175
- indexaxis = 0
176
- procunit = "voxels"
177
- else:
178
- indexaxis = 1
179
- procunit = "timepoints"
180
-
181
169
  # check that the mask array matches the index dimension
182
170
  if maskarray is not None:
183
171
  if inputshape[indexaxis] != len(maskarray):
@@ -23,12 +23,11 @@ import sys
23
23
  import numpy as np
24
24
  from scipy.stats import pearsonr
25
25
  from sklearn.decomposition import PCA, FastICA
26
- from tqdm import tqdm
27
26
 
28
27
  import rapidtide.fit as tide_fit
28
+ import rapidtide.genericmultiproc as tide_genericmultiproc
29
29
  import rapidtide.io as tide_io
30
30
  import rapidtide.miscmath as tide_math
31
- import rapidtide.multiproc as tide_multiproc
32
31
  import rapidtide.resample as tide_resample
33
32
  import rapidtide.stats as tide_stats
34
33
 
@@ -37,15 +36,26 @@ LGR = logging.getLogger("GENERAL")
37
36
 
38
37
  def _procOneVoxelTimeShift(
39
38
  vox,
40
- fmritc,
41
- lagtime,
42
- padtrs,
43
- fmritr,
44
- detrendorder=1,
45
- offsettime=0.0,
46
- rt_floatset=np.float64,
47
- rt_floattype="float64",
39
+ voxelargs,
40
+ **kwargs,
48
41
  ):
42
+ options = {
43
+ "detrendorder": 1,
44
+ "offsettime": 0.0,
45
+ "debug": False,
46
+ }
47
+ options.update(kwargs)
48
+ detrendorder = options["detrendorder"]
49
+ offsettime = options["offsettime"]
50
+ debug = options["debug"]
51
+ if debug:
52
+ print(f"{detrendorder=} {offsettime=}")
53
+ (
54
+ fmritc,
55
+ lagtime,
56
+ padtrs,
57
+ fmritr,
58
+ ) = voxelargs
49
59
  if detrendorder > 0:
50
60
  normtc = tide_fit.detrend(fmritc, order=detrendorder, demean=True)
51
61
  else:
@@ -57,6 +67,17 @@ def _procOneVoxelTimeShift(
57
67
  return vox, shiftedtc, weights, paddedshiftedtc, paddedweights
58
68
 
59
69
 
70
+ def _packvoxeldata(voxnum, voxelargs):
71
+ return [(voxelargs[0])[voxnum, :], (voxelargs[1])[voxnum], voxelargs[2], voxelargs[3]]
72
+
73
+
74
+ def _unpackvoxeldata(retvals, voxelproducts):
75
+ (voxelproducts[0])[retvals[0], :] = retvals[1]
76
+ (voxelproducts[1])[retvals[0], :] = retvals[2]
77
+ (voxelproducts[2])[retvals[0], :] = retvals[3]
78
+ (voxelproducts[3])[retvals[0], :] = retvals[4]
79
+
80
+
60
81
  def alignvoxels(
61
82
  fmridata,
62
83
  fmritr,
@@ -150,83 +171,40 @@ def alignvoxels(
150
171
  Mask of voxels used for refinement
151
172
  """
152
173
  inputshape = np.shape(fmridata)
153
- volumetotal = np.sum(lagmask)
174
+ voxelargs = [fmridata, lagtimes, padtrs, fmritr]
175
+ voxelfunc = _procOneVoxelTimeShift
176
+ packfunc = _packvoxeldata
177
+ unpackfunc = _unpackvoxeldata
178
+ voxeltargets = [
179
+ shiftedtcs,
180
+ weights,
181
+ paddedshiftedtcs,
182
+ paddedweights,
183
+ ]
154
184
  if debug:
155
185
  print("alignvoxels: {inputshape}")
156
186
  print("volumetotal: {volumetotal}")
157
187
 
158
188
  # timeshift the valid voxels
159
- if nprocs > 1 or alwaysmultiproc:
160
- # define the consumer function here so it inherits most of the arguments
161
- def timeshift_consumer(inQ, outQ):
162
- while True:
163
- try:
164
- # get a new message
165
- val = inQ.get()
166
-
167
- # this is the 'TERM' signal
168
- if val is None:
169
- break
170
-
171
- # process and send the data
172
- outQ.put(
173
- _procOneVoxelTimeShift(
174
- val,
175
- fmridata[val, :],
176
- lagtimes[val],
177
- padtrs,
178
- fmritr,
179
- detrendorder=detrendorder,
180
- offsettime=offsettime,
181
- rt_floatset=rt_floatset,
182
- rt_floattype=rt_floattype,
183
- )
184
- )
185
-
186
- except Exception as e:
187
- print("error!", e)
188
- break
189
-
190
- data_out = tide_multiproc.run_multiproc(
191
- timeshift_consumer,
192
- inputshape,
193
- lagmask,
194
- nprocs=nprocs,
195
- showprogressbar=showprogressbar,
196
- chunksize=chunksize,
197
- )
198
-
199
- # unpack the data
200
- for voxel in data_out:
201
- shiftedtcs[voxel[0], :] = voxel[1]
202
- weights[voxel[0], :] = voxel[2]
203
- paddedshiftedtcs[voxel[0], :] = voxel[3]
204
- paddedweights[voxel[0], :] = voxel[4]
205
- del data_out
189
+ # NOTE need to figure out how to use kwargs to pass extra arguments
190
+ volumetotal = tide_genericmultiproc.run_multiproc(
191
+ voxelfunc,
192
+ packfunc,
193
+ unpackfunc,
194
+ voxelargs,
195
+ voxeltargets,
196
+ inputshape,
197
+ lagmask,
198
+ LGR,
199
+ nprocs,
200
+ alwaysmultiproc,
201
+ showprogressbar,
202
+ chunksize,
203
+ detrendorder=detrendorder,
204
+ offsettime=offsettime,
205
+ debug=debug,
206
+ )
206
207
 
207
- else:
208
- for vox in tqdm(
209
- range(0, inputshape[0]),
210
- desc="Voxel timeshifts",
211
- unit="voxels",
212
- disable=(not showprogressbar),
213
- ):
214
- if lagmask[vox] > 0.5:
215
- retvals = _procOneVoxelTimeShift(
216
- vox,
217
- fmridata[vox, :],
218
- lagtimes[vox],
219
- padtrs,
220
- fmritr,
221
- detrendorder=detrendorder,
222
- offsettime=offsettime,
223
- rt_floatset=rt_floatset,
224
- rt_floattype=rt_floattype,
225
- )
226
- shiftedtcs[retvals[0], :] = retvals[1]
227
- weights[retvals[0], :] = retvals[2]
228
- paddedshiftedtcs[retvals[0], :] = retvals[3]
229
- paddedweights[retvals[0], :] = retvals[4]
230
208
  LGR.info(
231
209
  "Timeshift applied to " + str(int(volumetotal)) + " voxels",
232
210
  )
rapidtide/resample.py CHANGED
@@ -124,7 +124,17 @@ congridyvals["kernel"] = "kaiser"
124
124
  congridyvals["width"] = 3.0
125
125
 
126
126
 
127
- def congrid(xaxis, loc, val, width, kernel="kaiser", cyclic=True, debug=False):
127
+ def congrid(
128
+ xaxis,
129
+ loc,
130
+ val,
131
+ width,
132
+ kernel="kaiser",
133
+ cache=True,
134
+ cyclic=True,
135
+ debug=False,
136
+ onlykeynotices=True,
137
+ ):
128
138
  """
129
139
  Perform a convolution gridding operation with a Kaiser-Bessel or Gaussian kernel of width 'width'. Grid
130
140
  parameters are cached for performance.
@@ -164,10 +174,10 @@ def congrid(xaxis, loc, val, width, kernel="kaiser", cyclic=True, debug=False):
164
174
 
165
175
  if (congridyvals["kernel"] != kernel) or (congridyvals["width"] != width):
166
176
  if congridyvals["kernel"] != kernel:
167
- if debug:
177
+ if debug and not onlykeynotices:
168
178
  print(congridyvals["kernel"], "!=", kernel)
169
179
  if congridyvals["width"] != width:
170
- if debug:
180
+ if debug and not onlykeynotices:
171
181
  print(congridyvals["width"], "!=", width)
172
182
  if debug:
173
183
  print("(re)initializing congridyvals")
@@ -191,7 +201,7 @@ def congrid(xaxis, loc, val, width, kernel="kaiser", cyclic=True, debug=False):
191
201
 
192
202
  # find the closest grid point to the target location, calculate relative offsets from this point
193
203
  center = tide_util.valtoindex(xaxis, loc)
194
- offset = np.fmod(np.round((loc - xaxis[center]) / xstep, 3), 1.0) # will vary from -0.5 to 0.5
204
+ offset = np.fmod(np.round((loc - xaxis[center]) / xstep, 4), 1.0) # will vary from -0.5 to 0.5
195
205
  if cyclic:
196
206
  if center == len(xaxis) - 1 and offset > 0.5:
197
207
  center = 0
@@ -224,12 +234,13 @@ def congrid(xaxis, loc, val, width, kernel="kaiser", cyclic=True, debug=False):
224
234
  )
225
235
  + offset
226
236
  )
227
- congridyvals[offsetkey] = tide_fit.gauss_eval(xvals, np.array([1.0, 0.0, width]))
228
- yvals = congridyvals[offsetkey]
237
+ yvals = tide_fit.gauss_eval(xvals, np.array([1.0, 0.0, width]))
238
+ if cache:
239
+ congridyvals[offsetkey] = 1.0 * yvals
229
240
  startpt = int(center - widthinpts // 2)
230
241
  indices = range(startpt, startpt + widthinpts)
231
242
  indices = np.remainder(indices, len(xaxis))
232
- if debug:
243
+ if debug and not onlykeynotices:
233
244
  print("center, offset, indices, yvals", center, offset, indices, yvals)
234
245
  return val * yvals, yvals, indices
235
246
  else:
@@ -245,19 +256,18 @@ def congrid(xaxis, loc, val, width, kernel="kaiser", cyclic=True, debug=False):
245
256
  xvals = indices - center + offset
246
257
  if kernel == "gauss":
247
258
  sigma = optsigma[kernelindex]
248
- congridyvals[offsetkey] = tide_fit.gauss_eval(xvals, np.array([1.0, 0.0, sigma]))
259
+ yvals = tide_fit.gauss_eval(xvals, np.array([1.0, 0.0, sigma]))
249
260
  elif kernel == "kaiser":
250
261
  beta = optbeta[kernelindex]
251
- congridyvals[offsetkey] = tide_fit.kaiserbessel_eval(
252
- xvals, np.array([beta, width / 2.0])
253
- )
262
+ yvals = tide_fit.kaiserbessel_eval(xvals, np.array([beta, width / 2.0]))
254
263
  else:
255
264
  print("illegal kernel value in congrid - exiting")
256
265
  sys.exit()
257
- yvals = congridyvals[offsetkey]
258
- if debug:
266
+ if cache:
267
+ congridyvals[offsetkey] = 1.0 * yvals
268
+ if debug and not onlykeynotices:
259
269
  print("xvals, yvals", xvals, yvals)
260
- if debug:
270
+ if debug and not onlykeynotices:
261
271
  print("center, offset, indices, yvals", center, offset, indices, yvals)
262
272
  return val * yvals, yvals, indices
263
273
 
@@ -11,13 +11,22 @@ omit =
11
11
  ../OrthoImageItem.py
12
12
  ../wiener2.py
13
13
  ../tidepoolTemplate.py
14
+ ../tidepoolTemplate_qt6.py
14
15
  ../tidepoolTemplate_alt.py
16
+ ../tidepoolTemplate_alt_qt6.py
17
+ ../tidepoolTemplate_big.py
18
+ ../tidepoolTemplate_big_qt6.py
19
+ ../notreadyforprimetime/*
15
20
 
16
21
  [report]
17
22
  exclude_lines =
18
23
  # Don't complain if non-runnable code isn't run:
19
24
  if displayplots:
25
+ if doplot:
20
26
  if args.displayplots:
21
27
  if debug:
28
+ if self.debug:
22
29
  if False:
23
30
  if __name__ == .__main__.:
31
+ except np.lib.RankWarning:
32
+ except IndexError:
@@ -21,6 +21,7 @@ import matplotlib.pyplot as plt
21
21
  import numpy as np
22
22
 
23
23
  from rapidtide.resample import congrid
24
+ from rapidtide.happy_supportfuncs import preloadcongrid
24
25
  from rapidtide.tests.utils import mse
25
26
 
26
27
 
@@ -74,86 +75,74 @@ def test_congrid(debug=False, displayplots=False):
74
75
  weights = np.zeros((gridlen), dtype=float)
75
76
  griddeddata = np.zeros((gridlen), dtype=float)
76
77
 
77
- for gridkernel in kernellist:
78
- for congridbins in binslist:
79
- print("about to grid")
80
-
81
- # reinitialize grid outputs
82
- weights *= 0.0
83
- griddeddata *= 0.0
84
-
85
- for i in range(numsamples):
86
- thevals, theweights, theindices = congrid(
87
- gridaxis,
88
- testvals[i],
89
- funcvalue2(testvals[i], frequency=cycles),
90
- congridbins,
91
- kernel=gridkernel,
92
- debug=False,
93
- )
94
- for i in range(len(theindices)):
95
- weights[theindices[i]] += theweights[i]
96
- griddeddata[theindices[i]] += thevals[i]
97
-
98
- griddeddata = np.where(weights > 0.0, griddeddata / weights, 0.0)
99
-
100
- target = np.float64(gridaxis * 0.0)
101
- for i in range(len(gridaxis)):
102
- target[i] = funcvalue2(gridaxis[i], frequency=cycles)
103
-
104
- print("gridding done")
105
- print("debug:", debug)
106
-
107
- # plot if we are doing that
108
- if displayplots:
109
- offset = 0.0
110
- legend = []
111
- plt.plot(sourceaxis, timecoursein)
112
- legend.append("Original")
113
- # offset += 1.0
114
- plt.plot(gridaxis, target + offset)
115
- legend.append("Target")
116
- # offset += 1.0
117
- plt.plot(gridaxis, griddeddata + offset)
118
- legend.append("Gridded")
119
- plt.plot(gridaxis, weights)
120
- legend.append("Weights")
121
- plt.legend(legend)
122
- plt.show()
123
-
124
- # do the tests
125
- msethresh = 6.0e-2
126
- themse = mse(target, griddeddata)
127
- if debug:
128
- if themse >= msethresh:
129
- extra = "FAIL"
130
- else:
131
- extra = ""
132
- print(
133
- "mse for",
134
- cycles,
135
- "cycles:",
136
- gridkernel,
137
- str(congridbins),
138
- ":",
139
- themse,
140
- extra,
141
- )
142
- outputlines.append(
143
- " ".join(
144
- [
145
- "mse for",
146
- str(cycles),
147
- "cycles:",
148
- gridkernel,
149
- str(congridbins),
150
- ":",
151
- str(themse),
152
- ]
78
+ for prefill in [True, False]:
79
+ for gridkernel in kernellist:
80
+ for congridbins in binslist:
81
+ print("about to grid")
82
+
83
+ # reinitialize grid outputs
84
+ weights *= 0.0
85
+ griddeddata *= 0.0
86
+
87
+ if prefill:
88
+ preloadcongrid(
89
+ gridaxis, congridbins, gridkernel=gridkernel, cyclic=True, debug=False
90
+ )
91
+ for i in range(numsamples):
92
+ thevals, theweights, theindices = congrid(
93
+ gridaxis,
94
+ testvals[i],
95
+ funcvalue2(testvals[i], frequency=cycles),
96
+ congridbins,
97
+ kernel=gridkernel,
98
+ debug=False,
99
+ )
100
+ for i in range(len(theindices)):
101
+ weights[theindices[i]] += theweights[i]
102
+ griddeddata[theindices[i]] += thevals[i]
103
+
104
+ griddeddata = np.where(weights > 0.0, griddeddata / weights, 0.0)
105
+
106
+ target = np.float64(gridaxis * 0.0)
107
+ for i in range(len(gridaxis)):
108
+ target[i] = funcvalue2(gridaxis[i], frequency=cycles)
109
+
110
+ print("gridding done")
111
+ print("debug:", debug)
112
+
113
+ # plot if we are doing that
114
+ if displayplots:
115
+ offset = 0.0
116
+ legend = []
117
+ plt.plot(sourceaxis, timecoursein)
118
+ legend.append("Original")
119
+ # offset += 1.0
120
+ plt.plot(gridaxis, target + offset)
121
+ legend.append("Target")
122
+ # offset += 1.0
123
+ plt.plot(gridaxis, griddeddata + offset)
124
+ legend.append("Gridded")
125
+ plt.plot(gridaxis, weights)
126
+ legend.append("Weights")
127
+ plt.legend(legend)
128
+ plt.show()
129
+
130
+ # do the tests
131
+ msethresh = 6.0e-2
132
+ themse = mse(target, griddeddata)
133
+ if debug:
134
+ if themse >= msethresh:
135
+ extra = "FAIL"
136
+ else:
137
+ extra = ""
138
+ print(
139
+ f"mse for {cycles} cycles: {prefill=}, {gridkernel} {congridbins}: {themse} {extra}"
140
+ )
141
+ outputlines.append(
142
+ f"mse for {cycles} cycles: {prefill=}, {gridkernel} {congridbins}: {themse}"
153
143
  )
154
- )
155
- if not debug:
156
- assert themse < msethresh
144
+ if not debug:
145
+ assert themse < msethresh
157
146
  if debug:
158
147
  for theline in outputlines:
159
148
  print(theline)