Bladeren bron

Illustrate how to override setup values

Andrej 2 maanden geleden
bovenliggende
commit
4fcc25636c
1 gewijzigde bestanden met toevoegingen van 23 en 2 verwijderingen
  1. 23 2
      pythonScripts/cDiazepam.ipynb

+ 23 - 2
pythonScripts/cDiazepam.ipynb

@@ -61,7 +61,23 @@
     "    #copy last for settings\n",
     "    for v in ['lut','lutSE','setup','model','parameters','qt','sOut']:\n",
     "        out[v]=seq[-1][v]\n",
-    "    return out    "
+    "    return out \n",
+    "\n",
+    "def updateSetup(job):\n",
+    "    setupFileSrc=job['setupFile']\n",
+    "    setupFile=os.path.join(job['jobDir'],'setupInput.json')\n",
+    "\n",
+    "    with open(setupFileSrc,'r') as f:\n",
+    "        setup=json.load(f)\n",
+    "    try:\n",
+    "        setup.update(job['setupUpdates'])\n",
+    "    except KeyError:\n",
+    "        pass\n",
+    "    \n",
+    "    with open(setupFile,'w+') as f:\n",
+    "        f.write(json.dumps(setup))\n",
+    "    return setupFile\n",
+    "        "
    ]
   },
   {
@@ -191,6 +207,7 @@
     "d['modelFile']=os.path.join(fh,'software','src','PBPK','models','cDiazepam.json')\n",
     "d['parameterFile']=os.path.join(fh,'software','src','PBPK','models','cDiazepam_parameters3.json')\n",
     "d['setupFile']=os.path.join(fh,'software','src','PBPK','setup','setupHours.json')\n",
+    "#d['setupUpdates']={'mode':'solveMatrix','method':'separately'}\n",
     "d['srcDir']='NONE'\n",
     "d['doCalculate']=True\n",
     "#data['cDiazepamB']=[d]\n",
@@ -204,7 +221,11 @@
     "    \n",
     "        if not os.path.isdir(job['jobDir']):\n",
     "            os.mkdir(job['jobDir'])\n",
-    "        runSolver.main([job['setupFile'],job['modelFile'],job['parameterFile']],job['jobDir'],job['srcDir'])\n",
+    "            \n",
+    "        #adjust local setup file with ad-hoc modifications\n",
+    "        setupFile=updateSetup(job)\n",
+    "        \n",
+    "        runSolver.main([setupFile,job['modelFile'],job['parameterFile']],job['jobDir'],job['srcDir'])\n",
     "    \n",
     "\n",
     "#t0,y0,S1,lut,lutSE=runSolver.getStartPoint(setup)\n"