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
{{ message }}
Repository navigation
Rescaling of units from a list of preferred units #172
I am interested in having the ability to rescale to a preferred set of units (e.g. MKS), without specifying those units in each call. For example, say that I prefer mV, pA, and fC as my units of voltage, current, and charge. I might define a preferred set of units in a downstream package:
I would then like to change Quantity.rescale() to make the desired units optional, like:
def rescale(self, units=None):
if units is None:
unit_str = str(self.simplified.dimensionality)
if unit_str in pq.preferred and unit_str is not None:
new_units = pq.preferred[unit_str]
return self.rescale(new_units)
such that, if not specified, my desired units are looked up in pq.preferred, where I can keep my preferred set of units project-wide. I think it is simplest do this in rescale but if there are serious concerns about mucking with the signature of rescale then I could implement it in a new method rescale_preferred.
OK, now I see that there are only a limited set of fundamental dimensions to pick from (currency, current, temperature, etc.) so I cannot set default voltage or charge units, for example. And I don't think I can extend unit_quantity.py to include those (UnitVoltage, etc.) and update set_default_units to include them as keyword arguments, because then there could be conflicts for units which are derivable from each other (e.g. the preferred units for time and charge may be different than for current, which would cause a conflict). So I think there is still a need for a default rescaling option that can support arbitrary units including compound units.
Activity
rgerkin commentedon Jan 21, 2020
I just discovered
set_default_unitsin unit_quantity.py. This acts on thesimplifiedproperty, but that might be a good enough.rgerkin commentedon Jan 21, 2020
OK, now I see that there are only a limited set of fundamental dimensions to pick from (currency, current, temperature, etc.) so I cannot set default voltage or charge units, for example. And I don't think I can extend
unit_quantity.pyto include those (UnitVoltage, etc.) and updateset_default_unitsto include them as keyword arguments, because then there could be conflicts for units which are derivable from each other (e.g. the preferred units for time and charge may be different than for current, which would cause a conflict). So I think there is still a need for a default rescaling option that can support arbitrary units including compound units.rgerkin commentedon Jan 28, 2020
Implemented in #173. See demo here. Note that errors in the notebook are raised deliberately to illustrate expected failures.