def pyprf_opt_brute(strCsvCnfg, objNspc, lgcTest=False, strPathHrf=None,<EOL>varRat=None):
<EOL>print('<STR_LIT>')<EOL>varTme01 = time.time()<EOL>dicCnfg = load_config(strCsvCnfg, lgcTest=lgcTest)<EOL>cfg = cls_set_config(dicCnfg)<EOL>if cfg.strVersion == '<STR_LIT>':<EOL><INDENT>from pyprf_feature.analysis.find_prf_gpu import find_prf_gpu<EOL><DEDENT>if ((cfg.strVersion == '<STR_LIT>') or (cfg.strVersion == '<STR_LIT>')):<EOL><INDENT>from pyprf_feature.analysis.find_prf_cpu import find_prf_cpu<EOL><DEDENT>cfg.varSdSmthTmp = np.divide(cfg.varSdSmthTmp, cfg.varTr)<EOL>aryLgcMsk, aryLgcVar, hdrMsk, aryAff, aryFunc, tplNiiShp = prep_func(<EOL>cfg.strPathNiiMask, cfg.lstPathNiiFunc, varAvgThr=-<NUM_LIT>)<EOL>hdrMsk.set_data_dtype(np.float32)<EOL>print('<STR_LIT>' +<EOL>str(np.sum(aryLgcVar)))<EOL>if cfg.strVersion == '<STR_LIT>':<EOL><INDENT>strErrMsg = '<STR_LIT>' +'<STR_LIT>' +'<STR_LIT>'<EOL>assert cfg.varNumXval == <NUM_LIT:1>, strErrMsg<EOL><DEDENT>if cfg.strVersion == '<STR_LIT>':<EOL><INDENT>cfg.varPar = <NUM_LIT:1><EOL><DEDENT>if np.greater(cfg.varNumXval, <NUM_LIT:1>):<EOL><INDENT>cfg.lgcXval = True<EOL><DEDENT>elif np.equal(cfg.varNumXval, <NUM_LIT:1>):<EOL><INDENT>cfg.lgcXval = False<EOL><DEDENT>strErrMsg = '<STR_LIT>' +'<STR_LIT>'<EOL>assert np.greater_equal(cfg.varNumXval, <NUM_LIT:1>), strErrMsg<EOL>if varRat is not None:<EOL><INDENT>varNumFtr = int(<NUM_LIT:2>*cfg.switchHrfSet)    <EOL><DEDENT>else:<EOL><INDENT>varNumFtr = cfg.switchHrfSet<EOL><DEDENT>print('<STR_LIT>')<EOL>print(objNspc.strPthPrior)<EOL>lstWnrPrm = [objNspc.strPthPrior + '<STR_LIT>',<EOL>objNspc.strPthPrior + '<STR_LIT>',<EOL>objNspc.strPthPrior + '<STR_LIT>',<EOL>objNspc.strPthPrior + '<STR_LIT>']<EOL>lstPrmInt, objHdr, aryAff = load_res_prm(lstWnrPrm,<EOL>lstFlsMsk=[cfg.strPathNiiMask])<EOL>assert len(lstPrmInt) == <NUM_LIT:1><EOL>aryIntGssPrm = lstPrmInt[<NUM_LIT:0>]<EOL>del(lstPrmInt)<EOL>aryIntGssPrm = aryIntGssPrm[aryLgcVar, :]<EOL>aryPlrAng = np.arctan2(aryIntGssPrm[:, <NUM_LIT:1>], aryIntGssPrm[:, <NUM_LIT:0>])<EOL>aryUnqPlrAng = np.linspace(<NUM_LIT:0.0>, <NUM_LIT:2>*np.pi, objNspc.varNumOpt2,<EOL>endpoint=False)<EOL>aryPlrAng = (aryPlrAng + <NUM_LIT:2> * np.pi) % (<NUM_LIT:2> * np.pi)<EOL>aryUnqPlrAngInd, aryDstPlrAng = find_near_pol_ang(aryPlrAng, aryUnqPlrAng)<EOL>assert np.max(aryDstPlrAng) < np.divide(<NUM_LIT:2>*np.pi, objNspc.varNumOpt2)<EOL>aryUnqPlrAng = aryUnqPlrAng[np.unique(aryUnqPlrAngInd)]<EOL>aryUnqPlrAngInd, aryDstPlrAng = find_near_pol_ang(aryPlrAng, aryUnqPlrAng)<EOL>lstLgcUnqPlrAng = []<EOL>for indPlrAng in range(len(aryUnqPlrAng)):<EOL><INDENT>lstLgcUnqPlrAng.append([aryUnqPlrAngInd == indPlrAng][<NUM_LIT:0>])<EOL><DEDENT>print('<STR_LIT>' +<EOL>str(objNspc.varNumOpt1))<EOL>print('<STR_LIT>' +<EOL>str(objNspc.varNumOpt2))<EOL>print('<STR_LIT>' +<EOL>str(len(aryUnqPlrAng)))<EOL>print('<STR_LIT>' +<EOL>str(objNspc.varNumOpt3))<EOL>print('<STR_LIT>' +<EOL>str(objNspc.lgcRstrCentre))<EOL>aryBstXpos = np.zeros((aryPlrAng.shape[<NUM_LIT:0>]))<EOL>aryBstYpos = np.zeros((aryPlrAng.shape[<NUM_LIT:0>]))<EOL>aryBstSd = np.zeros((aryPlrAng.shape[<NUM_LIT:0>]))<EOL>aryBstR2 = np.zeros((aryPlrAng.shape[<NUM_LIT:0>]))<EOL>aryBstBts = np.zeros((aryPlrAng.shape[<NUM_LIT:0>], varNumFtr))<EOL>if np.greater(cfg.varNumXval, <NUM_LIT:1>):<EOL><INDENT>aryBstR2Single = np.zeros((aryPlrAng.shape[<NUM_LIT:0>],<EOL>len(cfg.lstPathNiiFunc)))<EOL><DEDENT>for indPlrAng in range(len(aryUnqPlrAng)):<EOL><INDENT>print('<STR_LIT>' + str(indPlrAng+<NUM_LIT:1>) + '<STR_LIT>' +<EOL>str(len(aryUnqPlrAng)))<EOL>varPlrAng = np.array(aryUnqPlrAng[indPlrAng])<EOL>lgcUnqPlrAng = lstLgcUnqPlrAng[indPlrAng]<EOL>vecPrrEcc = aryIntGssPrm[lgcUnqPlrAng, <NUM_LIT:3>]<EOL>print('<STR_LIT>' +<EOL>str(np.sum(lgcUnqPlrAng)))<EOL>vecRad = np.linspace(<NUM_LIT:0.0>, cfg.varExtXmax, objNspc.varNumOpt1,<EOL>endpoint=True)<EOL>aryRad, aryTht = np.meshgrid(vecRad, varPlrAng, indexing='<STR_LIT>')<EOL>vecRad = aryRad.flatten()<EOL>vecTht = aryTht.flatten()<EOL>vecX, vecY = map_pol_to_crt(vecTht, vecRad)<EOL>vecPrfSd = np.linspace(cfg.varPrfStdMin, cfg.varPrfStdMax,<EOL>cfg.varNumPrfSizes, endpoint=True)<EOL>varNumMdls = len(vecX) * len(vecPrfSd)<EOL>aryMdlParams = np.zeros((varNumMdls, <NUM_LIT:3>), dtype=np.float32)<EOL>varCntMdlPrms = <NUM_LIT:0><EOL>for idxXY in range(<NUM_LIT:0>, len(vecX)):<EOL><INDENT>for idxSd in range(<NUM_LIT:0>, len(vecPrfSd)):<EOL><INDENT>aryMdlParams[varCntMdlPrms, <NUM_LIT:0>] = vecX[idxXY]<EOL>aryMdlParams[varCntMdlPrms, <NUM_LIT:1>] = vecY[idxXY]<EOL>aryMdlParams[varCntMdlPrms, <NUM_LIT:2>] = vecPrfSd[idxSd]<EOL>varCntMdlPrms += <NUM_LIT:1><EOL><DEDENT><DEDENT>vecIntX, vecIntY, vecIntSd = rmp_deg_pixel_xys(aryMdlParams[:, <NUM_LIT:0>],<EOL>aryMdlParams[:, <NUM_LIT:1>],<EOL>aryMdlParams[:, <NUM_LIT:2>],<EOL>cfg.tplVslSpcSze,<EOL>cfg.varExtXmin,<EOL>cfg.varExtXmax,<EOL>cfg.varExtYmin,<EOL>cfg.varExtYmax)<EOL>aryMdlParamsPxl = np.column_stack((vecIntX, vecIntY, vecIntSd))<EOL>if objNspc.lgcRstrCentre:<EOL><INDENT>arySptExpInf = np.load(cfg.strSptExpInf)<EOL>arySptExpInf = np.rot90(arySptExpInf, k=<NUM_LIT:3>)<EOL>aryStimArea = np.sum(arySptExpInf, axis=-<NUM_LIT:1>).astype(np.bool)<EOL>lgcMdlInc = aryStimArea[aryMdlParamsPxl[:, <NUM_LIT:0>].astype(np.int32),<EOL>aryMdlParamsPxl[:, <NUM_LIT:1>].astype(np.int32)]<EOL>aryMdlParams = aryMdlParams[lgcMdlInc, :]<EOL>aryMdlParamsPxl = aryMdlParamsPxl[lgcMdlInc, :]<EOL><DEDENT>aryPrfTc = model_creation_opt(dicCnfg, aryMdlParamsPxl,<EOL>strPathHrf=strPathHrf, varRat=varRat,<EOL>lgcPrint=False)<EOL>aryPrfTc = prep_models(aryPrfTc, varSdSmthTmp=cfg.varSdSmthTmp,<EOL>lgcPrint=False)<EOL>if objNspc.varNumOpt3 is not None:<EOL><INDENT>vecMdlEcc = np.sqrt(np.add(np.square(aryMdlParams[:, <NUM_LIT:0>]),<EOL>np.square(aryMdlParams[:, <NUM_LIT:1>])))<EOL>vecPrrEccGrd, vecMdlEccGrd = np.meshgrid(vecPrrEcc, vecMdlEcc,<EOL>indexing='<STR_LIT>')<EOL>lgcRstr = np.logical_and(np.less_equal(vecMdlEccGrd,<EOL>np.add(vecPrrEccGrd,<EOL>objNspc.varNumOpt3)),<EOL>np.greater(vecMdlEccGrd,<EOL>np.subtract(vecPrrEccGrd,<EOL>objNspc.varNumOpt3)<EOL>)<EOL>)<EOL><DEDENT>else:<EOL><INDENT>lgcRstr = np.ones((np.sum(lgcUnqPlrAng),<EOL>aryMdlParams.shape[<NUM_LIT:0>]), dtype=np.bool)<EOL><DEDENT>lgcMdlPerVxl = np.greater(np.sum(lgcRstr, axis=<NUM_LIT:1>), <NUM_LIT:0>)<EOL>print('<STR_LIT>' + str(np.sum(lgcMdlPerVxl)))<EOL>lgcUnqPlrAng[lgcUnqPlrAng] = lgcMdlPerVxl<EOL>lgcRstr = lgcRstr[lgcMdlPerVxl, :]<EOL>if np.any(lgcUnqPlrAng):<EOL><INDENT>lstPrfRes = [None] * cfg.varPar<EOL>lstPrcs = [None] * cfg.varPar<EOL>queOut = mp.Queue()<EOL>lstRst = np.array_split(lgcRstr, cfg.varPar)<EOL>del(lgcRstr)<EOL>lstFunc = np.array_split(aryFunc[lgcUnqPlrAng, :], cfg.varPar)<EOL>if ((cfg.strVersion == '<STR_LIT>') or (cfg.strVersion == '<STR_LIT>')):<EOL><INDENT>for idxPrc in range(<NUM_LIT:0>, cfg.varPar):<EOL><INDENT>lstPrcs[idxPrc] = mp.Process(target=find_prf_cpu,<EOL>args=(idxPrc,<EOL>lstFunc[idxPrc],<EOL>aryPrfTc,<EOL>aryMdlParams,<EOL>cfg.strVersion,<EOL>cfg.lgcXval,<EOL>cfg.varNumXval,<EOL>queOut),<EOL>kwargs={'<STR_LIT>':<EOL>lstRst[idxPrc],<EOL>'<STR_LIT>': False},<EOL>)<EOL>lstPrcs[idxPrc].Daemon = True<EOL><DEDENT><DEDENT>elif cfg.strVersion == '<STR_LIT>':<EOL><INDENT>for idxPrc in range(<NUM_LIT:0>, cfg.varPar):<EOL><INDENT>lstPrcs[idxPrc] = mp.Process(target=find_prf_gpu,<EOL>args=(idxPrc,<EOL>aryMdlParams,<EOL>lstFunc[idxPrc],<EOL>aryPrfTc,<EOL>queOut),<EOL>kwargs={'<STR_LIT>':<EOL>lstRst[idxPrc],<EOL>'<STR_LIT>': False},<EOL>)<EOL>lstPrcs[idxPrc].Daemon = True<EOL><DEDENT><DEDENT>for idxPrc in range(<NUM_LIT:0>, cfg.varPar):<EOL><INDENT>lstPrcs[idxPrc].start()<EOL><DEDENT>del(lstFunc)<EOL>for idxPrc in range(<NUM_LIT:0>, cfg.varPar):<EOL><INDENT>lstPrfRes[idxPrc] = queOut.get(True)<EOL><DEDENT>for idxPrc in range(<NUM_LIT:0>, cfg.varPar):<EOL><INDENT>lstPrcs[idxPrc].join()<EOL><DEDENT>lstPrfRes = sorted(lstPrfRes)<EOL>aryBstTmpXpos = joinRes(lstPrfRes, cfg.varPar, <NUM_LIT:1>, inFormat='<STR_LIT>')<EOL>aryBstTmpYpos = joinRes(lstPrfRes, cfg.varPar, <NUM_LIT:2>, inFormat='<STR_LIT>')<EOL>aryBstTmpSd = joinRes(lstPrfRes, cfg.varPar, <NUM_LIT:3>, inFormat='<STR_LIT>')<EOL>aryBstTmpR2 = joinRes(lstPrfRes, cfg.varPar, <NUM_LIT:4>, inFormat='<STR_LIT>')<EOL>aryBstTmpBts = joinRes(lstPrfRes, cfg.varPar, <NUM_LIT:5>, inFormat='<STR_LIT>')<EOL>if np.greater(cfg.varNumXval, <NUM_LIT:1>):<EOL><INDENT>aryTmpBstR2Single = joinRes(lstPrfRes, cfg.varPar, <NUM_LIT:6>,<EOL>inFormat='<STR_LIT>')<EOL><DEDENT>del(lstPrfRes)<EOL>aryBstXpos[lgcUnqPlrAng] = aryBstTmpXpos<EOL>aryBstYpos[lgcUnqPlrAng] = aryBstTmpYpos<EOL>aryBstSd[lgcUnqPlrAng] = aryBstTmpSd<EOL>aryBstR2[lgcUnqPlrAng] = aryBstTmpR2<EOL>aryBstBts[lgcUnqPlrAng, :] = aryBstTmpBts<EOL>if np.greater(cfg.varNumXval, <NUM_LIT:1>):<EOL><INDENT>aryBstR2Single[lgcUnqPlrAng, :] = aryTmpBstR2Single<EOL><DEDENT><DEDENT><DEDENT>aryPlrAng = np.arctan2(aryBstYpos, aryBstXpos)<EOL>aryEcc = np.sqrt(np.add(np.square(aryBstXpos),<EOL>np.square(aryBstYpos)))<EOL>lgcMvdOrgn = np.logical_and(aryBstXpos == <NUM_LIT:0.0>, aryBstYpos == <NUM_LIT:0.0>)<EOL>lgcMvdOrgn = np.logical_and(lgcMvdOrgn, aryBstSd > <NUM_LIT:0>)<EOL>aryIntPlrAng = np.arctan2(aryIntGssPrm[:, <NUM_LIT:1>], aryIntGssPrm[:, <NUM_LIT:0>])<EOL>aryPlrAng[lgcMvdOrgn] = np.copy(aryIntPlrAng[lgcMvdOrgn])<EOL>print('<STR_LIT>')<EOL>if strPathHrf is not None:<EOL><INDENT>cfg.strPathOut = cfg.strPathOut + '<STR_LIT>'<EOL><DEDENT>aryBstMaps = np.stack([aryBstXpos, aryBstYpos, aryBstSd, aryBstR2,<EOL>aryPlrAng, aryEcc], axis=<NUM_LIT:1>)<EOL>lstNiiNames = ['<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>']<EOL>if varRat is not None:<EOL><INDENT>lstNiiNames = [strNii + '<STR_LIT:_>' + str(varRat) for strNii in lstNiiNames]<EOL><DEDENT>lstNiiNames = [cfg.strPathOut + strNii + '<STR_LIT>' for strNii in<EOL>lstNiiNames]<EOL>export_nii(aryBstMaps, lstNiiNames, aryLgcMsk, aryLgcVar, tplNiiShp,<EOL>aryAff, hdrMsk, outFormat='<STR_LIT>')<EOL>lstNiiNames = ['<STR_LIT>']<EOL>if varRat is not None:<EOL><INDENT>lstNiiNames = [strNii + '<STR_LIT:_>' + str(varRat) for strNii in lstNiiNames]<EOL><DEDENT>lstNiiNames = [cfg.strPathOut + strNii + '<STR_LIT>' for strNii in<EOL>lstNiiNames]<EOL>export_nii(aryBstBts, lstNiiNames, aryLgcMsk, aryLgcVar, tplNiiShp,<EOL>aryAff, hdrMsk, outFormat='<STR_LIT>')<EOL>if np.greater(cfg.varNumXval, <NUM_LIT:1>):<EOL><INDENT>aryBstR2Single[np.where(np.less_equal(aryBstR2Single, -<NUM_LIT:1.0>))] = -<NUM_LIT:1.0><EOL>lstNiiNames = ['<STR_LIT>']<EOL>if varRat is not None:<EOL><INDENT>lstNiiNames = [strNii + '<STR_LIT:_>' + str(varRat) for strNii in<EOL>lstNiiNames]<EOL><DEDENT>lstNiiNames = [cfg.strPathOut + strNii + '<STR_LIT>' for strNii in<EOL>lstNiiNames]<EOL>export_nii(aryBstR2Single, lstNiiNames, aryLgcMsk, aryLgcVar,<EOL>tplNiiShp, aryAff, hdrMsk, outFormat='<STR_LIT>')<EOL><DEDENT>varTme02 = time.time()<EOL>varTme03 = varTme02 - varTme01<EOL>print('<STR_LIT>' + str(varTme03) + '<STR_LIT>')<EOL>print('<STR_LIT>')<EOL>
Function for optimizing given pRF paramaters using brute-force grid search.

Parameters
----------
strCsvCnfg : str
    Absolute file path of config file.
objNspc : object
    Name space from command line arguments.
lgcTest : Boolean
    Whether this is a test (pytest). If yes, absolute path of pyprf libary
    will be prepended to config file paths.
strPathHrf : str or None:
    Path to npy file with custom hrf parameters. If None, default
    parameters will be used.
varRat : float, default None
    Ratio of size suppressive surround to size of center pRF