File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -201,7 +201,9 @@ def units(self, units):
201
201
202
202
def rescale (self , units = None ):
203
203
"""
204
- Return a copy of the quantity converted to the specified units
204
+ Return a copy of the quantity converted to the specified units.
205
+ If `units` is `None`, an attempt will be made to rescale the quantity
206
+ to preferred units (see `rescale_preferred`).
205
207
"""
206
208
if units is None :
207
209
try :
@@ -223,6 +225,18 @@ def rescale(self, units=None):
223
225
return Quantity (cf * self .magnitude , to_u )
224
226
225
227
def rescale_preferred (self ):
228
+ """
229
+ Return a copy of the quantity converted to the preferred units and scale.
230
+ These will be identified from among the compatible units specified in the
231
+ list PREFERRED in this module. For example, a voltage quantity might be
232
+ converted to `mV`:
233
+ ```
234
+ import quantities as pq
235
+ pq.quantity.PREFERRED = [pq.mV, pq.pA]
236
+ old = 3.1415 * pq.V
237
+ new = old.rescale_preferred() # `new` will be 3141.5 mV.
238
+ ```
239
+ """
226
240
units_str = str (self .simplified .dimensionality )
227
241
for preferred in PREFERRED :
228
242
if units_str == str (preferred .simplified .dimensionality ):
You can’t perform that action at this time.
0 commit comments