Skip to content

Commit

Permalink
Back-fill, then forward-fill, NaNs in external regressors (#1163)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo authored Jan 14, 2025
1 parent fbbe233 commit f84cbbc
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tedana/metrics/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,20 @@ def expand_regress_regex(regressor_templates, external_regressor_names, err_msg)
f"external regressor model: {sorted(extra_names)}"
)

nan_columns = []
for column in external_regressor_names:
if external_regressors[column].isna().values.any():
nan_columns.append(column)

if nan_columns:
LGR.warning(
f"External regressors include columns with NaN values: {sorted(nan_columns)}. "
"These will be backfilled with the nearest non-NaN value."
)
external_regressors = external_regressors.bfill(axis=0)
# Also ffill just in case there are NaNs at the end of the time series
external_regressors = external_regressors.ffill(axis=0)

# If a model includes specifications for partial regressors, expand them
for config_idx in range(len(external_regressor_config)):
if "partial_models" in external_regressor_config[config_idx].keys():
Expand Down

0 comments on commit f84cbbc

Please sign in to comment.