Skip to content

Instantly share code, notes, and snippets.

@tritemio
Last active August 29, 2015 13:57
Show Gist options
  • Save tritemio/9825928 to your computer and use it in GitHub Desktop.
Save tritemio/9825928 to your computer and use it in GitHub Desktop.
An IPython Notebook that shows how to decode .set files from Becker & Hickl boards.
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#nsALEX - BH parameters from .set files"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##Extract parameters:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"file_name = \"try6_100uw_green_100uw_red_30pm.set\""
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Find the full file name:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"dir_ = r\"C:\\Data\\Eitan/\"\n",
"fname = dir_+file_name\n",
"fname"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 2,
"text": [
"'C:\\\\Data\\\\Eitan/try6_100uw_green_100uw_red_30pm.set'"
]
}
],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"f = open(fname, 'rb')"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"## Make a dictionary of system parameters\n",
"start = False\n",
"sys_para = {}\n",
"for line in f.readlines():\n",
" line = line.strip()\n",
" if line == 'SYS_PARA_BEGIN:':\n",
" start = True\n",
" continue\n",
" if line == 'SYS_PARA_END:':\n",
" break\n",
" if start and line.startswith('#'):\n",
" fields = line[5:-1].split(',')\n",
" \n",
" if fields[1] == 'B':\n",
" value = bool(fields[2])\n",
" elif fields[1] in ['I', 'U', 'L']:\n",
" value = int(fields[2])\n",
" elif fields[1] == 'F':\n",
" value = float(fields[2])\n",
" elif fields[1] == 'S':\n",
" value = fields[2]\n",
" else:\n",
" value = fields[1:]\n",
" \n",
" sys_para[fields[0]] = value"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def deco(s):\n",
" s = s.replace('SP_', '')\n",
" s = s.replace('_ZC', ' ZC Thresh.')\n",
" s = s.replace('_LL', ' Limit Low')\n",
" s = s.replace('_LH', ' Limit High')\n",
" s = s.replace('_FD', ' Freq. Div.')\n",
" s = s.replace('_OF', ' Offset')\n",
" s = s.replace('_HF', ' Holdoff')\n",
" s = s.replace('_G', ' Gain')\n",
" s = s.replace('_R', ' Range')\n",
" s = s.replace('_TC', ' Time/Chan')\n",
" s = s.replace('_TD', ' Time/Div')\n",
" s = s.replace('_FQ', ' Threshold')\n",
" return s"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 13
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print fname\n",
"for k, v in sys_para.iteritems():\n",
" if 'TAC' in k: print '%s\\t %f' % (deco(k), v)\n",
"print\n",
"for k, v in sys_para.iteritems():\n",
" if 'CFD' in k: print '%s\\t %f' % (deco(k), v)\n",
"print\n",
"for k, v in sys_para.iteritems():\n",
" if 'SYN' in k: print '%s\\t %f' % (deco(k), v)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"C:\\Data\\Eitan/try6_100uw_green_100uw_red_30pm.set\n",
"TAC Gain\t 1.000000\n",
"TAC Range\t 0.000000\n",
"TAC Limit High\t 90.588234\n",
"TAC Limit Low\t 15.294118\n",
"TAC_EH\t 10.000000\n",
"TAC Time/Chan\t 0.000000\n",
"TAC Time/Div\t 0.000000\n",
"TAC Offset\t 0.000000\n",
"\n",
"CFD Limit Low\t -200.000000\n",
"CFD Limit High\t 5.019608\n",
"CFD Holdoff\t 5.000000\n",
"CFD ZC Thresh.\t 0.000000\n",
"\n",
"SYN ZC Thresh.\t 0.000000\n",
"SYN Holdoff\t 4.000000\n",
"SYN Freq. Div.\t 2.000000\n",
"SYN Threshold\t -500.000000\n"
]
}
],
"prompt_number": 14
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 35
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 35
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 37
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 37
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from IPython.core.display import HTML\n",
"HTML(open(\"./styles/custom2.css\", \"r\").read())"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<script src=\"http://use.edgefonts.net/source-code-pro.js\"></script>\n",
"\n",
"<style>\n",
"\t/* Import the \"Computer Modern\" font */\n",
" @font-face {\n",
" font-family: \"Computer Modern\";\n",
" src: url('http://mirrors.ctan.org/fonts/cm-unicode/fonts/otf/cmunss.otf');\n",
" }\n",
"\t\n",
"\t/* Style for all the cells */\n",
"\t/*div.cell{\n",
" width:900px;\n",
" margin-left:8% !important;\n",
" margin-right:auto;\n",
" }*/\n",
"\n",
"\t/* Text in markdown cells */\n",
" div.text_cell_render{\n",
" font-family: Computer Modern, Liberation Sans, Arial, Helvetica, sans-serif;\n",
" line-height: 130%;\n",
" font-size: 120%;\n",
" /* width:800px;\n",
" margin-left:auto;\n",
" margin-right:auto;*/\n",
" }\n",
"\n",
"\t/* Quoted text in markdown cells */\n",
"\t/*blockquote p {\n",
"\tmargin: 1em 2em;\n",
"\tline-height: 140%;\n",
" }*/\n",
"\n",
"\t/* Input and output prompt (In[1], Out[1], ...) */\n",
"\tdiv.prompt{\n",
"\t\tfont-family: \"Source Code Pro\", source-code-pro, Computer Modern, Consolas, monospace;\n",
"\t}\n",
"\n",
"\t/* Output text (i.e. output of print or text display) */\n",
"\tdiv.output_area pre{\n",
"\t\tfont-family: \"Source Code Pro\", source-code-pro, Computer Modern, Consolas, monospace;\n",
"\t}\n",
"\n",
"\t/* Text in code markup, within markdown cells */\n",
" .rendered_html code {\n",
"\tfont-family: \"Source Code Pro\", source-code-pro, Computer Modern, Consolas, monospace;\n",
"\tbackground-color: #f7f7f7;\n",
"\tborder: 1px solid #dddddd;\n",
"\tcolor: black;\n",
"\tline-height: 1.1em;\n",
"\tpadding: 0.15em;\n",
"\tfont-size: 80%;\n",
" }\n",
"\n",
"\t/* Text in code cells */\n",
" .CodeMirror{\n",
" font-family: \"Source Code Pro\", source-code-pro, Consolas, monospace;\n",
" }\n",
"\t\n",
" /* Whether to displays In[] and Out[] prompt */\n",
"\t/*.prompt{\n",
" display: None;\n",
" }*/\n",
" \n",
"</style>\n"
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 224,
"text": [
"<IPython.core.display.HTML at 0xddc95c0>"
]
}
],
"prompt_number": 224
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment