ism3d.utils.misc.human_unit¶
-
ism3d.utils.misc.
human_unit
(quantity, return_unit=False, base_index=0, scale_range=None)[source]¶ Sugguest a better unit for the quantity and make it more human readable e.g. 1200 m/s -> 1.2 km/s
- return_unit:
False: return the input quantity in a suggested unit True: just return a suggested unit
- base_index:
the index of the unitbase which we examine its prefix possibility.
For time: try built-in astropy.utils.console.human_time() For file size: one may also use astropy.utils.concolse.human_file_size()
reference: https://docs.astropy.org/en/stable/_modules/astropy/units/core.html
have tried the functions below,they work similar for PrefixUnit, but they dont work well with composited units (e.g. u.km/u.s)
get_current_unit_registry().get_units_with_physical_type(unit) unit.find_equivalent_units(include_prefix_units=True) unit.compose(include_prefix_units=True) might work but the results can be unexpected
- note:
get_units_with_same_physical_type() is a private method, since end users should be encouraged to use the more powerful compose and find_equivalent_units methods (which use this under the hood).
help find the best human readable unit then you can do q.to_string(unit=’*’)