Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit checking in EPhys parameters #241

Open
lkoelman opened this issue Feb 9, 2018 · 1 comment
Open

Unit checking in EPhys parameters #241

lkoelman opened this issue Feb 9, 2018 · 1 comment

Comments

@lkoelman
Copy link
Contributor

lkoelman commented Feb 9, 2018

Hi there,

It would be great if unit checking could be added to Ephys parameters when they are instantiated. This would be pretty easy to implement. Units of Hoc variables can be queried using h.units() (if they are defined), and Python has some great unit checking/conversion packages. I have hacked together some code that may be a good start:

import re
import pint # popular units package
from neuron import h
ureg = pint.UnitRegistry()

nrn_units = h.units(hoc_varname)
units_nodash = nrn_units.replace('-', '*') # some NEURON units are defined with dashes
units_exponents = re.sub(r'([a-zA-Z]+)(\d)',r'\1^\2', units_nodash) # adds '^' char for exponents
target_units = ureg(units_exponents)

param_quantity = ureg.Quantity(param_value, param_units_str)
try:
    converted_quantity = param_quantity.to(target_units)
except pint.errors.DimensionalityError:
    raise ValueError('incompatible units')

setattr(nrn_obj, hoc_varname, converted_quantity.magnitude)

Would something like this be possible?

Cheers,
Lucas.

@wvangeit
Copy link
Contributor

Sorry for the very late reply, I lost track of this issue.
Yes, it's a good idea, but in the short term I'm afraid we won't have time to implement this from our side, but please feel free to contribute code.

@wvangeit wvangeit added this to the Longterm milestone Aug 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants