Skip to content

Commit

Permalink
made measurementw waveforms rst
Browse files Browse the repository at this point in the history
  • Loading branch information
ElPsyKurisu committed Feb 26, 2025
1 parent a278858 commit 424cfb5
Show file tree
Hide file tree
Showing 4 changed files with 263 additions and 92 deletions.
14 changes: 14 additions & 0 deletions docs/source/piec.measurement_waveforms.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
piec.measurement_waveforms package
==========================

Submodules
----------

piec.measurement_waveforms module
------------------------------
.. automodule:: piec.measurement_waveforms
:members:
:undoc-members:
:show-inheritance:


131 changes: 51 additions & 80 deletions notebooks/Big_Magnet.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
{
"data": {
"text/plain": [
"('GPIB0::9::INSTR',)"
"('GPIB0::10::INSTR',)"
]
},
"execution_count": 2,
Expand Down Expand Up @@ -71,16 +71,16 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'ID?\\r\\n001'"
"'ID?\\r\\n000'"
]
},
"execution_count": 5,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -94,87 +94,27 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def set_output(self, value, mode=\"voltage\"):\n",
" \"\"\"\n",
" Formats a current or voltage value into an 8-character string for instrument control.\n",
" Automatically determines the appropriate range.\n",
"\n",
" Args:\n",
" value (float or int): The value to send to the instrument.\n",
" mode (str, optional): \"voltage\" or \"current\". Defaults to \"voltage\".\n",
"\n",
" Returns:\n",
" str: An 8-character command string, or None if input is invalid or value is out of range.\n",
" \"\"\"\n",
"\n",
" if mode not in (\"voltage\", \"current\"):\n",
" return None\n",
"\n",
" if value == 0:\n",
" return \"00000000\"\n",
"\n",
" polarity = \"+\" if value > 0 else \"-\"\n",
" abs_value = abs(value)\n",
"\n",
" if mode == \"voltage\":\n",
" ranges = [0.1, 10, 100, 1000]\n",
" range_chars = \"0123\"\n",
" max_values = [0.9999999, 10, 100, 1000] # Slightly higher max values\n",
" elif mode == \"current\":\n",
" ranges = [0.01, 0.1]\n",
" range_chars = \"45\"\n",
" max_values = [0.00999999, 0.1] # Slightly higher max values\n",
" else:\n",
" return None\n",
"\n",
" for i, r in enumerate(ranges):\n",
" if abs_value <= max_values[i]: # Check against max value for the range\n",
" scaled = abs_value / r\n",
" best_range_index = i\n",
" scaled_value = scaled\n",
" break\n",
" else: # No suitable range was found\n",
" return None\n",
"\n",
" digits_str = \"{:06.0f}\".format(scaled_value * 1000000)\n",
"\n",
" # J handling:\n",
" if best_range_index == 1 and scaled_value == 10: # Exactly 10V\n",
" digits_str = \"J00000\"\n",
" elif best_range_index == 1 and 1 <= scaled_value < 10: # 1V to 9.99999V in 10V range\n",
" digits = []\n",
" for digit in str(int(scaled_value * 1000000)):\n",
" if digit == '1':\n",
" digits.append('J')\n",
" else:\n",
" digits.append(digit)\n",
" digits_str = \"\".join(digits).zfill(6)\n",
" command = f\"{polarity}{digits_str}{range_chars[best_range_index]}\"\n",
" print(command)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+0100001\n"
"ename": "TypeError",
"evalue": "'>' not supported between instances of 'str' and 'int'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn[7], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mvoltage_program\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mset_output\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m69\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmode\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mcrowbar\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n",
"File \u001b[1;32mc:\\Users\\geofr\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages\\piec\\drivers\\edc522\\core.py:53\u001b[0m, in \u001b[0;36mEDC522.set_output\u001b[1;34m(self, value, mode, opt)\u001b[0m\n\u001b[0;32m 50\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39minstrument\u001b[38;5;241m.\u001b[39mwrite(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m-0000000\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;66;03m#negative negative mode\u001b[39;00m\n\u001b[0;32m 51\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m\n\u001b[1;32m---> 53\u001b[0m polarity \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m+\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[43mvalue\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m>\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m0\u001b[39;49m \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m-\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 54\u001b[0m abs_value \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mabs\u001b[39m(value)\n\u001b[0;32m 56\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m mode \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mvoltage\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n",
"\u001b[1;31mTypeError\u001b[0m: '>' not supported between instances of 'str' and 'int'"
]
}
],
"source": [
"set_output('bet', 1)"
"voltage_program.set_output()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 16,
"metadata": {},
"outputs": [
{
Expand All @@ -183,13 +123,13 @@
"10"
]
},
"execution_count": 8,
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"voltage_program.instrument.write(\"+1000001\")"
"voltage_program.instrument.write(\"00000000\")"
]
},
{
Expand All @@ -203,13 +143,44 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"'NDCV-0000.003E+0\\r\\n'"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"voltage_out = Keithley193a()\n",
"voltage_out = Keithley193a(\"GPIB0::10::INSTR\")\n",
"voltage_out.idn() # This will print the IDN of the instrument"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'-0000.005E+0'"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"voltage_out.read_voltage()"
]
}
],
"metadata": {
Expand Down
4 changes: 2 additions & 2 deletions notebooks/Single_Pulse_Out.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "base",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -223,7 +223,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
"version": "3.13.1"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 424cfb5

Please sign in to comment.