# Path: lems/base/util.py
# def validate_lems(file_name):
# 
#     from lxml import etree
# 
#     try:
#         from urllib2 import urlopen  # Python 2
#     except:
#         from urllib.request import urlopen  # Python 3
# 
#     schema_file = urlopen(__schema_location__)
#     xmlschema = etree.XMLSchema(etree.parse(schema_file))
#     print("Validating {0} against {1}".format(file_name, schema_file.geturl()))
#     xmlschema.assertValid(etree.parse(file_name))
#     print("It's valid!")


import lems.api as lems
from lems.base.util import validate_lems
#! /usr/bin/python


model = lems.Model()

model.add(lems.Include("test.xml"))

model.add(lems.Dimension("voltage", m=1, l=3, t=-3, i=-1))
model.add(lems.Dimension("time", t=1))
model.add(lems.Dimension("capacitance", m=-1, l=-2, t=4, i=2))

model.add(lems.Unit("milliVolt", "mV", "voltage", -3))
model.add(lems.Unit("milliSecond", "ms", "time", -3))
model.add(lems.Unit("microFarad", "uF", "capacitance", -12))

iaf1 = lems.ComponentType("iaf1")
model.add(iaf1)

iaf1.add(lems.Parameter("threshold", "voltage"))
iaf1.add(lems.Parameter("reset", "voltage"))
iaf1.add(lems.Parameter("refractoryPeriod", "time"))

# Path: lems/base/util.py
# def validate_lems(file_name):
# 
#     from lxml import etree
# 
#     try:
#         from urllib2 import urlopen  # Python 2
#     except:
#         from urllib.request import urlopen  # Python 3
# 
#     schema_file = urlopen(__schema_location__)
#     xmlschema = etree.XMLSchema(etree.parse(schema_file))
#     print("Validating {0} against {1}".format(file_name, schema_file.geturl()))
#     xmlschema.assertValid(etree.parse(file_name))
#     print("It's valid!")


# Path: examples/apitest3.py
import lems.api as lems
from lems.base.util import validate_lems

#! /usr/bin/python


model = lems.Model()

model.add(lems.Include("test.xml"))

model.add(lems.Dimension("voltage", m=1, l=3, t=-3, i=-1))
model.add(lems.Dimension("time", t=1))
model.add(lems.Dimension("capacitance", m=-1, l=-2, t=4, i=2))

model.add(lems.Unit("milliVolt", "mV", "voltage", -3))
model.add(lems.Unit("milliSecond", "ms", "time", -3))
model.add(lems.Unit("microFarad", "uF", "capacitance", -12))

iaf1 = lems.ComponentType("iaf1")
model.add(iaf1)

iaf1.add(lems.Parameter("threshold", "voltage"))
iaf1.add(lems.Parameter("reset", "voltage"))
iaf1.add(lems.Parameter("refractoryPeriod", "time"))

iaf1.add(lems.Parameter("capacitance", "capacitance"))