App
all_units(reference=None)
Get all available units in the reference
Parameters
reference : str, optional The reference name such as 'PRESSURE', 'TEMPERATURE', ...
Returns
List[str] A list of all available units
Raises
Exception If getting all units fails
Source code in pycuc/app.py
check_reference(reference, dataframe=True)
Shows reference unit table
Parameters
reference : str reference name such as pressure, temperature, custom dataframe : bool, optional If True, then return a dataframe, otherwise return a dict
Returns
reference : dict | dataframe reference details
Notes
- The reference can be set to 'PRESSURE', 'TEMPERATURE', 'CUSTOM'
Examples
! pressure
print(pycuc.check_reference('pressure'))
! temperature
print(pycuc.check_reference('temperature'))
! custom
print(pycuc.check_reference('custom'))
Source code in pycuc/app.py
check_version()
convert_from_to(value, from_unit, to_unit, reference=None)
Convert a value from one unit to another
Parameters
value : float The value to be converted from_unit : str The unit of the value to_unit : str The unit to convert to reference : str, optional The reference name such as 'PRESSURE', 'TEMPERATURE', 'CUSTOM'
Returns
float The converted value
Notes
- The reference can be set to 'PRESSURE', 'TEMPERATURE', 'CUSTOM'
- If reference is None, then automatically set a value
Examples
! pressure
print(pycuc.convert_from_to(1, 'MPa', 'Pa'))
! temperature
print(pycuc.convert_from_to(358, 'K', 'C')) print(pycuc.convert_from_to(25, 'C', 'K'))
Source code in pycuc/app.py
create_cuc(value, unit)
Define a CustomUnitConverter object
Parameters
value : float The value to be converted unit : str The unit of the value
Returns
CustomUnitConverter A CustomUnitConverter object
Examples
! pressure
my_cuc_1 = pycuc.create_cuc(1, 'MPa')
convert to Pa
print(my_cuc_1.convert('Pa'))
print(my_cuc_1.convert('bar'))
print(my_cuc_1.convert('kPa'))
! temperature
my_cuc_2 = pycuc.create_cuc(358, 'K')
convert to K
print(my_cuc_2.convert('C'))
print(my_cuc_2.convert('F'))
print(my_cuc_2.convert('R'))
! heat capacity unit: J/mol.K
my_cuc_3 = pycuc.create_cuc(25, 'J/mol.K')
add custom
my_cuc_3.add_custom_unit('J/mol.K', 1) my_cuc_3.add_custom_unit('kJ/mol.K', 1000)
conversion
print(my_cuc_3.convert('J/mol.K')) print(my_cuc_3.convert('kJ/mol.K'))
Source code in pycuc/app.py
go(reference_file=None)
Initializes app with/without external yml file
Parameters
reference_file : str, optional The path to the yml reference file
Returns
cucx : CustomUnitConverterX A CustomUnitConverterX object
Notes
- The reference can be set to 'PRESSURE', 'TEMPERATURE', 'CUSTOM'
- If reference_file is not None, then the app will load the yml file
yml reference file format is as:
CUSTOM-UNIT
HEAT-CAPACITY: J/mol.K : 1 kJ/mol.K : 0.001 J/kmol.K : 1000 ENERGY: J/mol : 1 kJ/mol : 0.001 J/kmol : 1000 kcal/mol: 0.000239006 cal/mol: 0.239006
Source code in pycuc/app.py
is_unit_available(unit, reference=None)
Check if a unit is available in the reference
Parameters
unit : str The unit to check reference : str, optional The reference name such as 'PRESSURE', 'TEMPERATURE', ...
Returns
bool True if the unit is available, False otherwise
Raises
Exception If checking unit availability fails
Source code in pycuc/app.py
to(value, unit_conversion_block, reference=None)
Convert a value from one unit to another using unit conversion block
Parameters
value : float
The value to be converted
unit_conversion_block : str
The block shows (from_unit => to_unit) such as (MPa => Pa), (K => C)
reference : str, optional
The reference name such as 'PRESSURE', 'TEMPERATURE', 'CUSTOM'
Returns
float The converted value
Notes
- The reference can be set to 'PRESSURE', 'TEMPERATURE', 'CUSTOM'
- If reference is None, then automatically set a value
Examples
! pressure
print(pycuc.to(1, 'MPa => Pa'))
! temperature
print(pycuc.to(358, 'K => C')) print(pycuc.to(25, 'C => K'))