{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import quantities as pq\n", "import sciunit\n", "from sciunit.errors import ObservationError, ParametersError" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from neuronunit.tests import APWidthTest" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'dt': {'type': 'time', 'required': False},\n", " 'tmax': {'type': 'time', 'min': 0, 'required': False}}" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Display the parameters schema for this test\n", "APWidthTest.params_schema" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'params': [{'3.0 mV': ['Must have dimensions of time.']}]}\n" ] } ], "source": [ "# Try to instantiate the test using a parameter (tmax) that has the wrong units. \n", "# This should show an error message\n", "try:\n", " test = APWidthTest({'mean':3.2*pq.ms, 'std':1.4*pq.ms}, name=\"My Test\", tmax=3*pq.mV) # Should fail due to incorrect units\n", " raise Exception(\"Test should not have been allowed with incorrect parameter units\")\n", "except ParametersError as e:\n", " print(e)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "# Now do it correctly. There should be no error message. \n", "try:\n", " test = APWidthTest({'mean':3.2*pq.ms, 'std':1.4*pq.ms}, name=\"My Test\", tmax=3*pq.s) # Should validate successfully\n", "except ParametersError as e:\n", " print(e)\n", " raise Exception(\"Test should have been allowed with correct parameter units\")" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "from sciunit.validators import ParametersValidator" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'s'" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Get the units type (e.g. \"time\") from the parameters schema \n", "units_type = APWidthTest.params_schema['dt']['type']\n", "\n", "# Get the actual units for this units type\n", "ParametersValidator.units_map[units_type]" ] } ], "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.6.7" } }, "nbformat": 4, "nbformat_minor": 2 }