Guest User

Untitled

a guest
Mar 18th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.97 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 1,
  6. "metadata": {
  7. "collapsed": true
  8. },
  9. "outputs": [],
  10. "source": [
  11. "import sys \n",
  12. "sys.path.append(r\"D:\\Code\\broadbean\")\n",
  13. "import broadbean as bb\n",
  14. "import numpy as np\n",
  15. "import re \n",
  16. "import functools\n",
  17. "import matplotlib.pyplot as plt\n",
  18. "import matplotlib as mpl\n",
  19. "mpl.rcParams['figure.figsize'] = (8, 3)\n",
  20. "mpl.rcParams['figure.subplot.bottom'] = 0.15 \n",
  21. "\n",
  22. "sys.path.append(r\"D:\\Code\\Qcodes\")\n",
  23. "import qcodes.instrument_drivers.tektronix.AWG5014 as awg \n",
  24. "from qcodes.instrument_drivers.tektronix.AWGFileParser import parse_awg_file \n",
  25. "\n",
  26. "from qcodes.instrument_drivers.AlazarTech.ATS9373 import AlazarTech_ATS9373\n",
  27. "from qcodes.instrument_drivers.AlazarTech.ATS import AcquisitionController"
  28. ]
  29. },
  30. {
  31. "cell_type": "code",
  32. "execution_count": 2,
  33. "metadata": {},
  34. "outputs": [
  35. {
  36. "name": "stdout",
  37. "output_type": "stream",
  38. "text": [
  39. "Connected to: TEKTRONIX AWG5014C (serial:B051389, firmware:SCPI:99.0 FW:4.6.0.7) in 0.17s\n"
  40. ]
  41. }
  42. ],
  43. "source": [
  44. "awg = awg.Tektronix_AWG5014('AWG1', 'TCPIP0::145.94.39.154::inst0::INSTR', timeout=40)\n",
  45. "alazar = AlazarTech_ATS9373(\"alazar\")"
  46. ]
  47. },
  48. {
  49. "cell_type": "markdown",
  50. "metadata": {},
  51. "source": [
  52. "```python\n",
  53. "player1 = sine(freq, ampl, phase, offset)\n",
  54. "player2 = sine(freq, ampl, phase + np.pi/2, offset)\n",
  55. "\n",
  56. "awg_controller.ch1 = player1\n",
  57. "awg_controller.ch2 = player2\n",
  58. "\n",
  59. "awg_controller.play()\n",
  60. "```"
  61. ]
  62. },
  63. {
  64. "cell_type": "code",
  65. "execution_count": 8,
  66. "metadata": {
  67. "collapsed": true
  68. },
  69. "outputs": [],
  70. "source": [
  71. "class AWGController:\n",
  72. " def __init__(self, awg): \n",
  73. " self._awg = awg \n",
  74. " self._channel_blueprints = {k: [] for k in range(awg.num_channels)}\n",
  75. " \n",
  76. " def __getattr__(self, att): \n",
  77. " match = re.match(\"ch(\\d)$\", att)\n",
  78. " if match is not None: \n",
  79. " chnum = int(match.groups()[0])\n",
  80. " return functools.partial(self._set_channel_blueprint, chnum)\n",
  81. " else:\n",
  82. " raise AttributeError(f\"AWGController has no attribute {att}\")\n",
  83. " \n",
  84. " def _set_channel_blueprint(self, chnum, blue_prints):\n",
  85. " self._channel_blueprints[chnum] = blue_prints\n",
  86. " \n",
  87. " def _compile_package(self): \n",
  88. " element = bb.Element()\n",
  89. " \n",
  90. " for chnum, blueprints in self._channel_blueprints.items():\n",
  91. " for blueprint in blueprints:\n",
  92. " element.addBluePrint(chnum, blueprint)\n",
  93. " \n",
  94. " sequence = bb.Sequence()\n",
  95. " sequence.addElement(1, element) \n",
  96. " sequence.setSR(element.SR)\n",
  97. " sequence.checkConsistency() \n",
  98. " \n",
  99. " for chnum in self._channel_blueprints.keys():\n",
  100. " sequence.setChannelAmplitude(chnum, 1) # We work in volts!\n",
  101. " sequence.setChannelOffset (chnum, 0)\n",
  102. " \n",
  103. " sequence.setSequenceSettings(1, 0, 1, 0, 1) # We want to loop the sequence\n",
  104. " package = sequence.outputForAWGFile()\n",
  105. " \n",
  106. " return package\n",
  107. " \n",
  108. " def _set_channel_states(self, value): \n",
  109. " \n",
  110. " for chnum, blueprints in self._channel_blueprints.items():\n",
  111. " if len(blueprints): \n",
  112. " ch_state = getattr(self._awg, f\"ch{chnum}_state\")\n",
  113. " ch_state(1)\n",
  114. " \n",
  115. " def play(self): \n",
  116. " package = self._compile_package()\n",
  117. " self._awg.delete_all_waveforms_from_list()\n",
  118. " self._awg.make_send_and_load_awg_file(*package[:])\n",
  119. " \n",
  120. " #self._set_channel_states(1)\n",
  121. " #awg.run()\n",
  122. " \n",
  123. " def stop(self):\n",
  124. " awg.stop()\n",
  125. " self._set_channel_states(0)"
  126. ]
  127. },
  128. {
  129. "cell_type": "code",
  130. "execution_count": 17,
  131. "metadata": {
  132. "collapsed": true
  133. },
  134. "outputs": [],
  135. "source": [
  136. "def sine(freq, ampl, off, phase): \n",
  137. " \"\"\"\n",
  138. " Args: \n",
  139. " freq: in Hz \n",
  140. " ampl: In volt\n",
  141. " off: In Volt\n",
  142. " phase: In radians \n",
  143. " \"\"\"\n",
  144. " \n",
  145. " def sine_function(freq, ampl, off, phase, SR, npts):\n",
  146. " time = np.linspace(0, npts/SR, npts)\n",
  147. " return ampl * np.sin(2 * np.pi * freq * time + phase) + off\n",
  148. "\n",
  149. " bp_sine = bb.BluePrint()\n",
  150. " bp_sine.setSR(1e9)\n",
  151. " bp_sine.insertSegment(0, sine_function , (freq, ampl, off, phase), dur=300e-9)\n",
  152. " \n",
  153. " return [bp_sine]"
  154. ]
  155. },
  156. {
  157. "cell_type": "code",
  158. "execution_count": 18,
  159. "metadata": {
  160. "collapsed": true
  161. },
  162. "outputs": [],
  163. "source": [
  164. "awg_controller = AWGController(awg)"
  165. ]
  166. },
  167. {
  168. "cell_type": "code",
  169. "execution_count": 22,
  170. "metadata": {},
  171. "outputs": [],
  172. "source": [
  173. "awg_controller.ch1(sine(3.333e6, 0.3, 0, 0))\n",
  174. "awg_controller.ch2(sine(2*3.333e6, 0.3, 0, np.pi/2))"
  175. ]
  176. },
  177. {
  178. "cell_type": "code",
  179. "execution_count": 23,
  180. "metadata": {},
  181. "outputs": [
  182. {
  183. "name": "stderr",
  184. "output_type": "stream",
  185. "text": [
  186. "D:\\Code\\broadbean\\broadbean\\broadbean.py:1323: UserWarning: Deprecation warning. This function is only compatible with AWG5014 output and will be removed. Please use the specific setSequencingXXX methods.\n",
  187. " warnings.warn('Deprecation warning. This function is only compatible '\n",
  188. "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:11: DeprecationWarning: object of type <class 'numpy.float64'> cannot be safely interpreted as an integer.\n",
  189. " # This is added back by InteractiveShellApp.init_path()\n"
  190. ]
  191. }
  192. ],
  193. "source": [
  194. "awg_controller.play()"
  195. ]
  196. },
  197. {
  198. "cell_type": "code",
  199. "execution_count": 48,
  200. "metadata": {},
  201. "outputs": [
  202. {
  203. "data": {
  204. "text/plain": [
  205. "AttributeError"
  206. ]
  207. },
  208. "execution_count": 48,
  209. "metadata": {},
  210. "output_type": "execute_result"
  211. }
  212. ],
  213. "source": [
  214. "AttributeError"
  215. ]
  216. },
  217. {
  218. "cell_type": "code",
  219. "execution_count": null,
  220. "metadata": {
  221. "collapsed": true
  222. },
  223. "outputs": [],
  224. "source": []
  225. }
  226. ],
  227. "metadata": {
  228. "kernelspec": {
  229. "display_name": "Python 3",
  230. "language": "python",
  231. "name": "python3"
  232. },
  233. "language_info": {
  234. "codemirror_mode": {
  235. "name": "ipython",
  236. "version": 3
  237. },
  238. "file_extension": ".py",
  239. "mimetype": "text/x-python",
  240. "name": "python",
  241. "nbconvert_exporter": "python",
  242. "pygments_lexer": "ipython3",
  243. "version": "3.6.3"
  244. }
  245. },
  246. "nbformat": 4,
  247. "nbformat_minor": 2
  248. }
Add Comment
Please, Sign In to add comment