{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "1b84bf02",
   "metadata": {},
   "source": [
    "# Reproduce this analysis\n",
    "\n",
    "Run from inside the analysis folder. Every table below is read from this folder's own CSVs; `scripts/` is the exact code that produced them. `python -m scripts run --params params.yaml --input input --out .` re-runs the whole analysis in place."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f3bcc4b6",
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys, pandas as pd\n",
    "sys.path.insert(0, '.')\n",
    "from scripts import csvmeta, params, split, figures\n",
    "P = params.load(\"params.yaml\")\n",
    "somas, meta = csvmeta.read_csv(\"somas_filtered.csv\")\n",
    "subjects, _ = csvmeta.read_csv(\"subjects.csv\")\n",
    "qc, _ = csvmeta.read_csv(\"qc_stacks.csv\")\n",
    "print(meta['analysis_id'], meta['created'], meta['code_version'])\n",
    "subjects"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "586929ba",
   "metadata": {},
   "outputs": [],
   "source": [
    "METRICS = ['syn_per_um2', 'syn_per_um3', 'n_synapse', 'n_synapse_maxplane']\n",
    "sp = split.run_split(somas, METRICS, P)\n",
    "sp.skipped_reason or sp.assignments"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ade2ca6e",
   "metadata": {},
   "outputs": [],
   "source": [
    "files, errors = figures.make_all(somas, subjects, qc, sp, METRICS, \"figures_notebook\", (\"png\",), P.analysis_id)\n",
    "from IPython.display import Image, display\n",
    "for name in sorted(files):\n",
    "    display(Image(f\"figures_notebook/{files[name][0]}\"))\n",
    "errors"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
