#! /bin/bash
# Last edited on 2023-11-29 11:11:51 by stolfi

# Removes some PCA components from runs of a subject

fdir="flt-runs-B"             # Directory where the filtered runs live.
frameset="all_phase_frames"   # What set of frames are we analyzing.

# Image basis for electrode influence
bpref="imgbasis/450_630_e128"  # Prefix for electrode image basis files.
btype="voronoi"                # Type of electrode image basis.

???

echo "removing the first two PCAs..." 1>&2

# runs=( 00103 00229 00425 00829 )
runs=( 00229 )
for rid in ${runs[@]} ; do
  ppref=${fdir}/s${sid}
  rpref=${fdir}/s${sid}/r${rid}
  rfile="${rpref}.txt"

  nmeeg_comp_analysis \
    -pattern BL0 ${ppref}_${frameset}_P000_eig.txt \
    -pattern H10 ${ppref}_${frameset}_P001_eig.txt \
    -normalize \
    -writeComp BL0 ${rpref}_BL0.txt = BL0 \
    -writeComp H10 ${rpref}_H10.txt = H10 \
    -writeComp BLH ${rpref}_BLH.txt = BL0 H10 \
    -delete BL0 H10 \
    < ${rpref}.txt \
    > ${rpref}_RES.txt

  vmax=160
  display -title '%d/%f' ${rpref}.png
  nmeeg_plot_channels.sh SHOW ${rpref}_BL0 0 ${vmax} 0 9999  0 0  1400 500 

  vmax=160
  nmeeg_plot_channels.sh SHOW ${rpref}_H10 0 ${vmax} 0 9999  0 0  1400 500 
  plot_run_spectrum.sh SHOW ${rpref}_H10 0 127  50  500

  vmax=160
  nmeeg_plot_channels.sh SHOW ${rpref}_BLH 0 ${vmax} 0 9999  0 0  1400 500 

  vmax=160
  nmeeg_plot_channels.sh SHOW ${rpref}_RES 0 ${vmax} 0 9999  0 0  1400 500 
  plot_run_spectrum.sh SHOW ${rpref}_RES 0 127  50  500

done

