Custom units
Function to convert back and forth between a custom defined unit system and SI.
- unitconvert.custom.checksystem(ls)
Check if the user defined unit system can be transformed to and from SI units.
- Args :
ls (list) : a list of astropy quantities belonging to the custom unit system
want_details (boolean) : if True returns details about the passed custom-unit system
- Returns :
None : default details (dictionary) : if want_details is set to True, inferred details about the passed custom-unit system
- Example :
>>> from unitconvert.unitsystem import checksystem >>> from astropy import units as u >>> from astropy import constants as c >>> checksystem([c.c]) # c.c = speed of light <Error message> >>> checksystem([c.c,u.m]) Custom-unit system looks good ! :)
- unitconvert.custom.create_units(constants, units, save=None, name=None, overwrite='no', labels=[])
Creates a new unit system and saves them in current working directory or inside a global directory. This saved system can be accessed later. The target custom unit system has two parts. 1) List of constants or units that needs to be set to 1 2) List of Remaining units
- Args :
constants (list) : A list of astropy quantities that is a part of the custom unit that needs to be set to 1.
units (list) : A list of astropy quantities corresponding to the remanining units.
name (str) The name of the unit system
save (str) : ‘local’ to save the unit system in the current working directory ‘global’ to save it in a global directory in the home of the user
overwrite (str) : ‘yes’ to overwrite the existing unit system with a given name if it exists ‘no’ to not to overwrite the existing unit system
labels (list) : A list of strings corresponding to each physical constant that serves as a symbol for that constant. It is useful when one uses not the inbuilt astropy constants but defines ones own constants.
- Returns :
None
- unitconvert.custom.load_units(name, save='global')
Loading saved unit system
- Args :
name (str) : The name of the unit system that has to be loaded
save (str) : ‘local’ : to load the unit system saved in the current working directory ‘global’ : to load the unit system saved in the global directory (home directory of the user)
- Returns :
The function returns three functions with three functionalities
1) function that converts from SI to the New unit system
2) function that converts from the New unit system to SI
3) function to returns the conversion factor