You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
importreimportpint# popular units packagefromneuronimporthureg=pint.UnitRegistry()
nrn_units=h.units(hoc_varname)
units_nodash=nrn_units.replace('-', '*') # some NEURON units are defined with dashesunits_exponents=re.sub(r'([a-zA-Z]+)(\d)',r'\1^\2', units_nodash) # adds '^' char for exponentstarget_units=ureg(units_exponents)
param_quantity=ureg.Quantity(param_value, param_units_str)
try:
converted_quantity=param_quantity.to(target_units)
exceptpint.errors.DimensionalityError:
raiseValueError('incompatible units')
setattr(nrn_obj, hoc_varname, converted_quantity.magnitude)
Would something like this be possible?
Cheers,
Lucas.
The text was updated successfully, but these errors were encountered:
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.
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:Would something like this be possible?
Cheers,
Lucas.
The text was updated successfully, but these errors were encountered: