{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# The Location Formatter\n", "\n", "The Location Formatter controls the format of the location to which data are saved.\n", "\n", "This notebook shows some examples of setting different location formats." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Magic only supported for Python version 3.6 and up\n" ] } ], "source": [ "%matplotlib nbagg\n", "import matplotlib.pyplot as plt\n", "import time\n", "import numpy as np\n", "\n", "import qcodes as qc" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# First we set up some mock experiment\n", "from qcodes.tests.instrument_mocks import DummyInstrument\n", "\n", "gates = DummyInstrument('some_gates', gates=['plunger', 'left', 'topo'])\n", "meter = DummyInstrument('meter', gates=['voltage', 'current'])\n", "\n", "station = qc.Station(gates, meter)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## The formatter in action\n", "\n", "Now let's run some loops to get datasets and see where they end up.\n", "\n", "When writing the location format, some fields are automatically filled out.\n", "\n", "That is the fields '{date}', '{time}', and '{counter}'.\n", "All other fields must have their values provided via the record dict." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Started at 2017-12-15 11:09:08\n", "DataSet:\n", " location = '2017-12-15/#005_unicorn_2017-12-15_11-09-08'\n", " | | | \n", " Setpoint | some_gates_plunger_set | plunger | (25,)\n", " Measured | meter_voltage | voltage | (25,)\n", "Finished at 2017-12-15 11:09:08\n" ] } ], "source": [ "loc_fmt='{date}/#{counter}_{name}_{date}_{time}' # set the desired location format\n", "rcd={'name': 'unicorn'} # provide a value for 'name'\n", "loc_provider = qc.FormatLocation(fmt=loc_fmt, record=rcd) # create a location provider using that format\n", "\n", "loop = qc.Loop(gates.plunger.sweep(0, 1, num=25), 0).each(meter.voltage)\n", "data2 = loop.run(location=loc_provider)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Started at 2017-12-15 11:09:09\n", "DataSet:\n", " location = 'my_custom_folder/#011_randomnumber_69_2017-12-15_11-09-09'\n", " | | | \n", " Setpoint | some_gates_plunger_set | plunger | (25,)\n", " Measured | meter_voltage | voltage | (25,)\n", "Finished at 2017-12-15 11:09:09\n" ] } ], "source": [ "# Now let's do that a few times with different formats\n", "\n", "import numpy as np\n", "\n", "loc_fmt='my_custom_folder/#{counter}_randomnumber_{name}_{date}_{time}'\n", "rcd = {'name': str(np.random.randint(1, 100))}\n", "loc_provider = qc.FormatLocation(fmt=loc_fmt, record=rcd)\n", "\n", "loop = qc.Loop(gates.plunger.sweep(0, 1, num=25), 0).each(meter.voltage)\n", "data2 = loop.run(location=loc_provider)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Started at 2017-12-15 11:09:09\n", "DataSet:\n", " location = '2017-12-15/#006_{name}_2017-12-15_hammer_time'\n", " | | | \n", " Setpoint | some_gates_plunger_set | plunger | (25,)\n", " Measured | meter_voltage | voltage | (25,)\n", "Finished at 2017-12-15 11:09:09\n" ] } ], "source": [ "# You can also overwrite the custom fields\n", "\n", "loc_fmt='{date}/#{counter}_{name}_{date}_{time}'\n", "rcd = {'time': 'hammer_time'}\n", "loc_provider = qc.FormatLocation(fmt=loc_fmt, record=rcd)\n", "\n", "loop = qc.Loop(gates.plunger.sweep(0, 1, num=25), 0).each(meter.voltage)\n", "data2 = loop.run(location=loc_provider)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.3" } }, "nbformat": 4, "nbformat_minor": 1 }