Skip to content

Commit

Permalink
Added some tuning parameters, trying out a potential speedup
Browse files Browse the repository at this point in the history
  • Loading branch information
bbfrederick committed Oct 1, 2024
1 parent 21908ff commit 4460069
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 10 deletions.
6 changes: 3 additions & 3 deletions rapidtide/data/examples/src/testfmri
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ rapidtide \
--simcalcrange 50 -1 \
--outputlevel max \
sub-RAPIDTIDETEST.nii.gz \
../dst/sub-RAPIDTIDETEST_0deriv
../dst/sub-RAPIDTIDETEST

rapidtide \
--spatialfilt 2 \
--nprocs -1 \
--passes 3 \
--simcalcrange 50 -1 \
--padtype constant \
--outputlevel max \
--glmderivs 1 \
sub-RAPIDTIDETEST.nii.gz \
../dst/sub-RAPIDTIDETEST_1deriv
../dst/sub-RAPIDTIDETEST_constantpad

#rapidtide \
# --spatialfilt 2 \
Expand Down
29 changes: 23 additions & 6 deletions rapidtide/helper_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def __init__(
reftc=None,
reftcstart=0.0,
detrendorder=1,
filterinputdata=True,
debug=False,
):
self.Fs = Fs
Expand All @@ -172,25 +173,41 @@ def __init__(
self.negativegradient = negativegradient
self.reftc = reftc
self.detrendorder = detrendorder
self.filterinputdata = filterinputdata
self.debug = debug
if self.reftc is not None:
self.setreftc(self.reftc)
self.reftcstart = reftcstart

def preptc(self, thetc, isreftc=False):
# prepare timecourse by filtering, normalizing, detrending, and applying a window function
if isreftc or (not self.negativegradient):
if isreftc:
thenormtc = tide_math.corrnormalize(
self.ncprefilter.apply(self.Fs, thetc),
detrendorder=self.detrendorder,
windowfunc=self.windowfunc,
)
else:
thenormtc = tide_math.corrnormalize(
-np.gradient(self.ncprefilter.apply(self.Fs, thetc)),
detrendorder=self.detrendorder,
windowfunc=self.windowfunc,
)
if self.negativegradient:
thenormtc = tide_math.corrnormalize(
-np.gradient(self.ncprefilter.apply(self.Fs, thetc)),
detrendorder=self.detrendorder,
windowfunc=self.windowfunc,
)
else:
if self.filterinputdata:
thenormtc = tide_math.corrnormalize(
self.ncprefilter.apply(self.Fs, thetc),
detrendorder=self.detrendorder,
windowfunc=self.windowfunc,
)
else:
thenormtc = tide_math.corrnormalize(
thetc,
detrendorder=self.detrendorder,
windowfunc=self.windowfunc,
)

return thenormtc

def trim(self, vector):
Expand Down
23 changes: 22 additions & 1 deletion rapidtide/workflows/parser_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def is_valid_tag(parser, arg):

DEFAULT_FILTER_ORDER = 6
DEFAULT_PAD_SECONDS = 30.0
DEFAULT_PREFILTERPADTYPE = "reflect"
DEFAULT_PERMUTATIONMETHOD = "shuffle"
DEFAULT_NORMTYPE = "stddev"
DEFAULT_FILTERBAND = "lfo"
Expand Down Expand Up @@ -395,11 +396,24 @@ def addfilteropts(
metavar="SECONDS",
help=(
"The number of seconds of padding to add to each end of a "
"filtered timecourse "
"timecourse to be filtered "
f"to reduce end effects. Default is {DEFAULT_PAD_SECONDS}."
),
default=DEFAULT_PAD_SECONDS,
)
filt_opts.add_argument(
"--padtype",
dest="ncfiltpadtype",
action="store",
type=str,
choices=["reflect", "zero", "constant"],
help=(
f"The type of padding at each end of a "
"timecourse to be filtered "
f'to reduce end effects. Default is "{DEFAULT_PREFILTERPADTYPE}".'
),
default=DEFAULT_PREFILTERPADTYPE,
)


def postprocesssamplerateopts(args, debug=False):
Expand Down Expand Up @@ -428,6 +442,10 @@ def postprocessfilteropts(args, debug=False):
thepadseconds = args.padseconds
except AttributeError:
args.padseconds = DEFAULT_PAD_SECONDS
try:
prefilterpadtype = args.prefilterpadtype
except AttributeError:
args.prefilterpadtype = DEFAULT_PREFILTERPADTYPE

# if passvec, or passvec and stopvec, are set, we are going set up an arbpass filter
args.arbvec = None
Expand Down Expand Up @@ -456,13 +474,16 @@ def postprocessfilteropts(args, debug=False):
theprefilter = tide_filt.NoncausalFilter(
"arb",
transferfunc=args.filtertype,
padtime=args.padseconds,
padtype=args.prefilterpadtype,
)
theprefilter.setfreqs(args.arbvec[2], args.arbvec[0], args.arbvec[1], args.arbvec[3])
else:
theprefilter = tide_filt.NoncausalFilter(
args.filterband,
transferfunc=args.filtertype,
padtime=args.padseconds,
padtype=args.prefilterpadtype,
)

# set the butterworth order
Expand Down
2 changes: 2 additions & 0 deletions rapidtide/workflows/rapidtide.py
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,7 @@ def rapidtide_main(argparsingfunc):
ncprefilter=theprefilter,
negativegradient=optiondict["negativegradient"],
detrendorder=optiondict["detrendorder"],
filterinputdata=optiondict["filterinputdata"],
windowfunc=optiondict["windowfunc"],
corrweighting=optiondict["corrweighting"],
corrpadding=optiondict["corrpadding"],
Expand Down Expand Up @@ -1499,6 +1500,7 @@ def rapidtide_main(argparsingfunc):
ncprefilter=theprefilter,
negativegradient=optiondict["negativegradient"],
detrendorder=optiondict["detrendorder"],
filterinputdata=optiondict["filterinputdata"],
windowfunc=optiondict["windowfunc"],
madnorm=False,
lagmininpts=lagmininpts,
Expand Down
9 changes: 9 additions & 0 deletions rapidtide/workflows/rapidtide_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,15 @@ def _get_parser():
),
default=False,
)
experimental.add_argument(
"--donotfilterinputdata",
dest="filterinputdata",
action="store_false",
help=(
"Do not filter input data prior to similarity calculation. May make processing faster."
),
default=True,
)
experimental.add_argument(
"--dispersioncalc",
dest="dodispersioncalc",
Expand Down

0 comments on commit 4460069

Please sign in to comment.