Repository navigation
🚀 Mapper Input Data
🚀 Mapper: mapper.py
We’ve added a new example script, mapper.py, to help users understand and utilize the mapping and reference-checking features of PyCUC! Here’s what’s included:
🧩 Reference Checking
Easily check for reference types, available units, and unit availability using PyCUC’s built-in functions:
# Check if a reference exists
print(pycuc.check_reference('PRESSURE'))
# List all units for a reference
print(pycuc.all_units('PRESSURE'))
# List all available reference units
print(pycuc.all_units())
# Check if a unit is available for a reference
print(pycuc.is_unit_available('bar', 'PRESSURE'))
print(pycuc.is_unit_available('C', 'TEMPERATURE'))
print(pycuc.is_unit_available('kg/m3'))These functions help you validate and explore the supported references and units in your application.
🔄 Mapping Inputs to References
Map your input data to a reference schema, handling unit conversions and symbol mapping automatically:
from pycuc.utils.tools import map_to_reference
inputs = {
'Tc': {'value': 0, 'unit': 'K', 'symbol': 'Tc'},
'T': {'value': None, 'unit': 'K', 'symbol': 'T'}
}
reference = {
'Tc': {'name': 'critical temperature', 'symbol': 'Tc', 'unit': 'C'},
'T': {'name': 'temperature', 'symbol': 'T', 'unit': 'F'}
}
print(map_to_reference(inputs=inputs, reference=reference, verbose=True))
# Output:
{'Tc': {'value': -273.15, 'symbol': 'Tc', 'unit': 'C'}, 'T': {'value': None, 'symbol': 'T', 'unit': 'F'}}This example shows how to align your input data with a reference definition, including unit conversion and symbol matching, with detailed output when verbose=True.
📚 Usage Guide
- The script is well-commented and structured for easy understanding.
- Use it as a template to integrate PyCUC’s mapping and reference utilities into your own projects.