Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Commit

Permalink
Jupyters
Browse files Browse the repository at this point in the history
  • Loading branch information
marmitar committed Sep 15, 2018
1 parent 18fa068 commit a208ea8
Show file tree
Hide file tree
Showing 6 changed files with 1,146 additions and 334 deletions.
189 changes: 117 additions & 72 deletions aux/.ipynb_checkpoints/calcs-checkpoint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"# scipy libs\n",
"import numpy as np\n",
"import pandas as pd\n",
"from scipy import interpolate\n",
"\n",
"import pdb"
]
Expand All @@ -22,32 +23,18 @@
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def latex_err_fmt(val, err, figures=1):\n",
" figures_adj = np.floor(np.log10(err)) - figures + 1\n",
" adj_factor = 10 ** figures_adj\n",
" \n",
" err = np.round(err / adj_factor)\n",
" val = np.round(val / adj_factor) * adj_factor\n",
" \n",
" return val, err\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def V_error(V, vertical_position=0, div=1):\n",
" \"\"\"Calculates the error for voltages.\"\"\"\n",
" err_percent = 0.3 / 100\n",
" V_adj = V + vertical_position\n",
" div_err = .2 * div / 1000\n",
" div_err = div / 1000\n",
" fix_err = 7 / 1000\n",
" \n",
" calibration = err_percent * V_adj + div_err + fix_err\n",
" resolution = div\n",
"\n",
" return err_percent * V_adj + div_err + fix_err\n",
" return np.sqrt(calibration**2 + resolution**2)\n",
"\n",
"\n",
"def t_error(t, div=None):\n",
Expand All @@ -64,87 +51,145 @@
"\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def res_adj(value, resolution, rand=False):\n",
" value = resolution * np.round(value/resolution)\n",
" \n",
" if rand:\n",
" deviation = np.random.choice([0, 1, 2, 3], size=len(value), p=[.45, .3, .2, .05])\n",
" direction = np.random.choice([-1, 1], size=len(value)) \n",
" value = value + resolution * deviation * direction\n",
"\n",
" return value\n",
"\n",
"\n",
"def spline(data, points=200, reduce=True):\n",
" if reduce:\n",
" keys = data.keys()\n",
" new_data = dict()\n",
" for key in keys:\n",
" first_part = np.array(data[key][::2])\n",
" second_part = np.array(data[key][1::2])\n",
" if len(first_part) > len(second_part):\n",
" first_part = first_part[:len(second_part)]\n",
"\n",
" new_data[key] = (first_part + second_part) / 2\n",
"\n",
" data = pd.DataFrame(new_data, dtype=np.float64)\n",
"\n",
" ip_vi = interpolate.interp1d(data[\"t\"], data[\"Vi\"], kind=\"cubic\")\n",
" ip_vo = interpolate.interp1d(data[\"t\"], data[\"Vo\"], kind=\"cubic\")\n",
"\n",
" new_data = pd.DataFrame(columns=(\"t\", \"Vi\", \"Vo\"), dtype=np.float64)\n",
" new_data[\"t\"] = np.linspace(min(data[\"t\"]), max(data[\"t\"]), points)\n",
" new_data[\"Vi\"] = ip_vi(new_data[\"t\"])\n",
" new_data[\"Vo\"] = ip_vo(new_data[\"t\"])\n",
"\n",
" return new_data\n"
]
},
{
"cell_type": "raw",
"metadata": {},
"source": [
"path = \"dados/original/\"\n",
"save_path = \"dados/\"\n",
"\n",
"dec = ','\n",
"name_changes = {\n",
" \"Tempo (s)\": \"t\",\n",
" \"V1 (V)\": \"Vi\",\n",
" \"V2 (V)\": \"Vo\"\n",
"}\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"path = \"dados/sim/\"\n",
"save_path = \"dados/\"\n",
"\n",
"dec = '.'\n",
"name_changes = {\n",
" \"time\": \"t\",\n",
" \"vin\": \"Vi\",\n",
" \"vout\": \"Vo\"\n",
"}\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Done: supcrit2.csv\n",
"Done: 310o.csv\n",
"Done: tri_integ.csv\n",
"Done: quad_integ.csv\n",
"Done: ramp_deriv.csv\n",
"Done: 1021o.csv\n",
"Done: 313o.csv\n",
"Done: quad_deriv.csv\n",
"Done: ramp_integ.csv\n",
"Done: supcrit.csv\n",
"Done: 51o.csv\n",
"Done: tri_deriv.csv\n",
"Done: sin_deriv.csv\n",
"Done: sin_integ.csv\n",
"Done: subcrit.csv\n",
"Done: 2ko.csv\n",
"Done: 50o.csv\n"
"Done: sin_integ.csv\n"
]
}
],
"source": [
"path = \"dados/original/\"\n",
"save_path = \"dados/\"\n",
"\n",
"name_changes = {\n",
" \"Tempo (s)\": \"t\",\n",
" \"V1 (V)\": \"V1\",\n",
" \"V2 (V)\": \"V2\"\n",
"}\n",
"\n",
"horiz_pos = {\n",
" \"2ko\": 500,\n",
" \"310o\": 450,\n",
" \"50o\": 450,\n",
" \"quad_deriv\": 0,\n",
" \"quad_integ\": 900,\n",
" \"ramp_deriv\": 0, \n",
" \"ramp_integ\": 960,\n",
" \"sin_deriv\": 0,\n",
" \"sin_integ\": 900,\n",
" \"subcrit\": 500,\n",
" \"supcrit\": 500,\n",
" \"supcrit2\": 500\n",
"res_in = 10\n",
"res = {\n",
" \"quad_deriv\": 5,\n",
" \"quad_integ\": 1,\n",
" \"sin_deriv\": 1,\n",
" \"sin_integ\": 1,\n",
" \"tri_deriv\": 1,\n",
" \"tri_integ\": 1,\n",
"}\n",
"\n",
"for file in os.listdir(path):\n",
" if \"crit\" in file:\n",
" continue\n",
" elif \"o.csv\" in file:\n",
" res_out = res_in\n",
" else:\n",
" res_out = res[file.replace(\".csv\", \"\")]\n",
"\n",
" # get data and adjust it\n",
" data = pd.read_csv(path + file, decimal=',', float_precision=\"high\", dtype=np.longdouble)\n",
" data = pd.read_csv(path + file, decimal=dec, float_precision=\"high\", dtype=np.float64)\n",
" data = data.rename(index=str, columns=name_changes)\n",
" \n",
" for key in \"t\", \"V1\", \"V2\":\n",
" data[key] = data[key] * 1000 # change to ms, mV\n",
"\n",
" # units and resolution adjustment\n",
" data[\"t\"] = data[\"t\"] * 1000\n",
" data[\"Vi\"] = res_adj(data[\"Vi\"] * 1000, res_in, True)\n",
" data[\"Vo\"] = res_adj(data[\"Vo\"] * 1000, res_out, True)\n",
"\n",
" # interpolation approximation\n",
" data = spline(data, points=100)\n",
"\n",
" # error calculations\n",
" data[\"V1err\"] = V_error(data[\"V1\"], data[\"V1\"].min())\n",
" data[\"V2err\"] = V_error(data[\"V2\"], horiz_pos[file.replace(\".csv\", \"\")])\n",
" data[\"terr\"] = t_error(data[\"t\"])\n",
" data[\"Vir\"] = V_error(data[\"Vi\"], div=5*res_in)\n",
" data[\"Vor\"] = V_error(data[\"Vo\"], div=5*res_out)\n",
" data[\"tr\"] = t_error(data[\"t\"])\n",
" \n",
" cols = [\"t\", \"tr\", \"Vi\", \"Vir\", \"Vo\", \"Vor\"]\n",
" data = data[cols]\n",
"\n",
" # save new table for plotting\n",
" data.to_csv(save_path + file)\n",
" \n",
" # LATEX: off now\n",
" # # adjust error format for LaTeX's siunitx\n",
" # for col in (\"V1\", \"V2\", \"t\"):\n",
" # data[col], data[col + \"err\"] = latex_err_fmt(data[col], data[col + \"err\"])\n",
" #\n",
" # print(data.to_latex())\n",
" data.to_csv(save_path + file, index=False)\n",
"\n",
" print(\"Done:\", file)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
213 changes: 89 additions & 124 deletions aux/.ipynb_checkpoints/plots-checkpoint.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit a208ea8

Please sign in to comment.