watertap.tools.oli_api package
Subpackages
Submodules
watertap.tools.oli_api.client module
- class watertap.tools.oli_api.client.OLIApi(credential_manager, interactive_mode=True, debug_level='INFO')[source]
Bases:
object
A class to wrap OLI Cloud API calls and access functions for interfacing with WaterTAP.
- __init__(credential_manager, interactive_mode=True, debug_level='INFO')[source]
Construct all necessary attributes for OLIApi class.
- Parameters:
credential_manager_class – class used to manage credentials
interactive_mode – enables direct interaction with user through prompts
debug_level – string defining level of logging activity
- call(flash_method=None, dbs_file_id=None, input_params=None, poll_time=0.5, max_request=100, **kwargs)[source]
Make a call to the OLI Cloud API.
- Parameters:
flash_method – string indicating flash method
dbs_file_id – string indicating DBS file
input_params – dictionary for flash calculation inputs
poll_time – seconds between each poll
max_request – maximum number of times to try request before failure
- Return result:
dictionary for JSON output result
- dbs_file_cleanup(dbs_file_ids=None)[source]
Delete all (or specified) DBS files on OLI Cloud.
- Parameters:
dbs_file_ids – list of DBS file IDs to delete
- generate_dbs_file(inflows, thermo_framework=None, model_name=None, phases=None, databanks=None, keep_file=False)[source]
Generate a DBS file on OLI Cloud given chemistry inputs.
- Parameters:
inflows – dictionary with inflows and optional custom parameters
thermo_framework – string name of thermodynamic databank to use
model_name – string name of model OLI will use
phases – container dict for chemistry model parameters
databanks – list of databanks to include in DBS file
keep_file – bool to remove (default) or ignore DBS file during session cleanup
- Return dbs_file_id:
string name for DBS file ID
- get_corrosion_contact_surfaces(dbs_file_id)[source]
Get list of valid contact surfaces for corrosion analysis, given a DBS file ID.
- Parameters:
dbs_file_id – string name for DBS file ID
- Return contact_surfaces:
JSON results from OLI Cloud
- get_dbs_file_summary(dbs_file_id)[source]
Get chemistry info and flash history for a DBS file.
- Parameters:
dbs_file_id – string name for DBS file ID
- Return dbs_file_summary:
dictionary containing JSON results from OLI Cloud
- get_user_dbs_file_ids()[source]
Get all DBS files on user’s cloud.
- Return user_dbs_file_ids:
list of user DBS files saved on OLI Cloud
watertap.tools.oli_api.conftest module
watertap.tools.oli_api.credentials module
- class watertap.tools.oli_api.credentials.CredentialManager(username='', password='', root_url='', auth_url='', config_file='./credentials.txt', encryption_key='', access_keys=[], test=False, interactive_mode=True)[source]
Bases:
object
A class to handle credentials for OLI Cloud.
- __init__(username='', password='', root_url='', auth_url='', config_file='./credentials.txt', encryption_key='', access_keys=[], test=False, interactive_mode=True)[source]
Manages credentials for OLIApi authentication requests.
- Parameters:
username – user’s username
password – user’s password
root_url – root url
auth_url – authorization url
config_file – existing/desired path (absolute, or relative to the working directory) to encrypted oli_config_file
encryption_key – fernet key generated by credential manager object
access_keys – list of access keys generated by user
test – bool switch for automation during tests
interactive_mode – bool to switch level of logging display from info to debug only
- auth_status(body, req_result=None)[source]
Posts authorization request to OLI Cloud.
- Parameters:
body – dictionary containing authorization data
- Return bool:
bool indicating success or failure
- delete_oliapi_access_key(api_key)[source]
Delete an access key for OLI Cloud.
- Parameters:
api_key – The access key to delete
- Return string:
Response text containing the success message or an error message
- generate_oliapi_access_key(key_lifetime=365)[source]
Generate an access key for OLI Cloud.
- Parameters:
key_lifetime – integer number of days key will be valid
- Return string:
Response text containing the access key information or an error message
watertap.tools.oli_api.flash module
- class watertap.tools.oli_api.flash.Flash(optional_properties={'electricalConductivity': True, 'viscosity': True, 'selfDiffusivityAndMobility': True, 'heatCapacity': True, 'thermalConductivity': True, 'surfaceTension': True, 'interfacialTension': True, 'volumeStdConditions': True, 'prescalingTendenciesEstimated': False, 'prescalingIndexEstimated': False, 'prescalingTendenciesRigorous': True, 'prescalingIndexRigorous': True, 'scalingTendencies': True, 'scalingIndex': True, 'hardness': True, 'ionicStrengthXBased': True, 'ionicStrengthMBased': True, 'totalDissolvedSolids': True, 'vaporToInflowMoleFraction': True, 'partialPressure': True, 'vaporDiffusivityMatrix': True, 'entropyStream': True, 'entropySpecies': True, 'entropyStreamStandardState': True, 'entropySpeciesStandardState': True, 'gibbsEnergyStream': True, 'gibbsEnergySpecies': True, 'gibbsEnergyStreamStandardState': True, 'gibbsEnergySpeciesStandardState': True, 'activityCoefficientsXBased': True, 'activityCoefficientsMBased': True, 'fugacityCoefficients': True, 'vaporFugacity': True, 'kValuesXBased': True, 'kValuesMBased': True, 'MBGComposition': True, 'materialBalanceGroup': True}, input_unit_set={'inflows': {'oli_unit': 'mg/L', 'pyomo_unit': <pyomo.core.expr.numeric_expr.NPV_DivisionExpression object>}, 'molecularConcentration': {'oli_unit': 'mg/L', 'pyomo_unit': <pyomo.core.expr.numeric_expr.NPV_DivisionExpression object>}, 'mass': {'oli_unit': 'mg', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'temperature': {'oli_unit': 'K', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'pressure': {'oli_unit': 'Pa', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'enthalpy': {'oli_unit': 'J', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'vaporAmountMoles': {'oli_unit': 'mol', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'vaporMolFrac': {'oli_unit': 'mol/mol', 'pyomo_unit': <pyomo.core.expr.numeric_expr.NPV_DivisionExpression object>}, 'totalVolume': {'oli_unit': 'L', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'pipeDiameter': {'oli_unit': 'm', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'pipeFlowVelocity': {'oli_unit': 'm/s', 'pyomo_unit': <pyomo.core.expr.numeric_expr.NPV_DivisionExpression object>}, 'diskDiameter': {'oli_unit': 'm', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'diskRotatingSpeed': {'oli_unit': 'cycle/s', 'pyomo_unit': <pyomo.core.expr.numeric_expr.NPV_DivisionExpression object>}, 'rotorDiameter': {'oli_unit': 'm', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'rotorRotation': {'oli_unit': 'cycle/s', 'pyomo_unit': <pyomo.core.expr.numeric_expr.NPV_DivisionExpression object>}, 'shearStress': {'oli_unit': 'Pa', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'pipeRoughness': {'oli_unit': 'm', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'liquidFlowInPipe': {'oli_unit': 'L/s', 'pyomo_unit': <pyomo.core.expr.numeric_expr.NPV_DivisionExpression object>}, 'gasFlowInPipe': {'oli_unit': 'L/s', 'pyomo_unit': <pyomo.core.expr.numeric_expr.NPV_DivisionExpression object>}, 'viscAbs2ndLiq': {'oli_unit': 'Pa-s', 'pyomo_unit': <pyomo.core.expr.numeric_expr.NPV_ProductExpression object>}, 'alkalinity': {'oli_unit': 'mg HCO3/L', 'pyomo_unit': <pyomo.core.expr.numeric_expr.NPV_DivisionExpression object>}, 'TIC': {'oli_unit': 'mol C/L', 'pyomo_unit': <pyomo.core.expr.numeric_expr.NPV_DivisionExpression object>}, 'CO2GasFraction': {'oli_unit': 'mol/mol', 'pyomo_unit': <pyomo.core.expr.numeric_expr.NPV_DivisionExpression object>}}, output_unit_set={'enthalpy': {'oli_unit': 'J', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'mass': {'oli_unit': 'mg', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'pt': {'oli_unit': 'Pa', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'total': {'oli_unit': 'mg', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'liq1_phs_comp': {'oli_unit': 'mg', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'solid_phs_comp': {'oli_unit': 'mg', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'vapor_phs_comp': {'oli_unit': 'mg', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'liq2_phs_comp': {'oli_unit': 'mg', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'combined_phs_comp': {'oli_unit': 'mg', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'molecularConcentration': {'oli_unit': 'mg/L', 'pyomo_unit': <pyomo.core.expr.numeric_expr.NPV_DivisionExpression object>}}, relative_inflows=True, debug_level='INFO')[source]
Bases:
object
A class to execute OLI Cloud flash calculations.
- Parameters:
optional_properties – dictionary for optional properties to attach to OLI calls, all True by default
input_unit_set – dictionary for conversions between OLI and Pyomo unit names
output_unit_set – dictionary for preferred output units
relative_inflows – bool switch for surveys - true to add specified value to initial value, false to replace initial value with specified value
debug_level – string defining level of logging activity
- __init__(optional_properties={'electricalConductivity': True, 'viscosity': True, 'selfDiffusivityAndMobility': True, 'heatCapacity': True, 'thermalConductivity': True, 'surfaceTension': True, 'interfacialTension': True, 'volumeStdConditions': True, 'prescalingTendenciesEstimated': False, 'prescalingIndexEstimated': False, 'prescalingTendenciesRigorous': True, 'prescalingIndexRigorous': True, 'scalingTendencies': True, 'scalingIndex': True, 'hardness': True, 'ionicStrengthXBased': True, 'ionicStrengthMBased': True, 'totalDissolvedSolids': True, 'vaporToInflowMoleFraction': True, 'partialPressure': True, 'vaporDiffusivityMatrix': True, 'entropyStream': True, 'entropySpecies': True, 'entropyStreamStandardState': True, 'entropySpeciesStandardState': True, 'gibbsEnergyStream': True, 'gibbsEnergySpecies': True, 'gibbsEnergyStreamStandardState': True, 'gibbsEnergySpeciesStandardState': True, 'activityCoefficientsXBased': True, 'activityCoefficientsMBased': True, 'fugacityCoefficients': True, 'vaporFugacity': True, 'kValuesXBased': True, 'kValuesMBased': True, 'MBGComposition': True, 'materialBalanceGroup': True}, input_unit_set={'inflows': {'oli_unit': 'mg/L', 'pyomo_unit': <pyomo.core.expr.numeric_expr.NPV_DivisionExpression object>}, 'molecularConcentration': {'oli_unit': 'mg/L', 'pyomo_unit': <pyomo.core.expr.numeric_expr.NPV_DivisionExpression object>}, 'mass': {'oli_unit': 'mg', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'temperature': {'oli_unit': 'K', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'pressure': {'oli_unit': 'Pa', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'enthalpy': {'oli_unit': 'J', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'vaporAmountMoles': {'oli_unit': 'mol', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'vaporMolFrac': {'oli_unit': 'mol/mol', 'pyomo_unit': <pyomo.core.expr.numeric_expr.NPV_DivisionExpression object>}, 'totalVolume': {'oli_unit': 'L', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'pipeDiameter': {'oli_unit': 'm', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'pipeFlowVelocity': {'oli_unit': 'm/s', 'pyomo_unit': <pyomo.core.expr.numeric_expr.NPV_DivisionExpression object>}, 'diskDiameter': {'oli_unit': 'm', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'diskRotatingSpeed': {'oli_unit': 'cycle/s', 'pyomo_unit': <pyomo.core.expr.numeric_expr.NPV_DivisionExpression object>}, 'rotorDiameter': {'oli_unit': 'm', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'rotorRotation': {'oli_unit': 'cycle/s', 'pyomo_unit': <pyomo.core.expr.numeric_expr.NPV_DivisionExpression object>}, 'shearStress': {'oli_unit': 'Pa', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'pipeRoughness': {'oli_unit': 'm', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'liquidFlowInPipe': {'oli_unit': 'L/s', 'pyomo_unit': <pyomo.core.expr.numeric_expr.NPV_DivisionExpression object>}, 'gasFlowInPipe': {'oli_unit': 'L/s', 'pyomo_unit': <pyomo.core.expr.numeric_expr.NPV_DivisionExpression object>}, 'viscAbs2ndLiq': {'oli_unit': 'Pa-s', 'pyomo_unit': <pyomo.core.expr.numeric_expr.NPV_ProductExpression object>}, 'alkalinity': {'oli_unit': 'mg HCO3/L', 'pyomo_unit': <pyomo.core.expr.numeric_expr.NPV_DivisionExpression object>}, 'TIC': {'oli_unit': 'mol C/L', 'pyomo_unit': <pyomo.core.expr.numeric_expr.NPV_DivisionExpression object>}, 'CO2GasFraction': {'oli_unit': 'mol/mol', 'pyomo_unit': <pyomo.core.expr.numeric_expr.NPV_DivisionExpression object>}}, output_unit_set={'enthalpy': {'oli_unit': 'J', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'mass': {'oli_unit': 'mg', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'pt': {'oli_unit': 'Pa', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'total': {'oli_unit': 'mg', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'liq1_phs_comp': {'oli_unit': 'mg', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'solid_phs_comp': {'oli_unit': 'mg', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'vapor_phs_comp': {'oli_unit': 'mg', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'liq2_phs_comp': {'oli_unit': 'mg', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'combined_phs_comp': {'oli_unit': 'mg', 'pyomo_unit': <pyomo.core.base.units_container._PyomoUnit object>}, 'molecularConcentration': {'oli_unit': 'mg/L', 'pyomo_unit': <pyomo.core.expr.numeric_expr.NPV_DivisionExpression object>}}, relative_inflows=True, debug_level='INFO')[source]
- configure_flash_analysis(inflows=None, flash_method=None, temperature=None, pressure=None, calculated_variable=None, enthalpy=None, vapor_amount=None, vapor_fraction=None, volume=None, ph=None, acid_titrant=None, base_titrant=None, formed_solid=None, precipitant_inflow=None, included_solids=None, excluded_solids=None, contact_surface=None, flow_type=None, diameter=None, liq_velocity=None, gas_velocity=None, rot_velocity=None, shear_stress=None, roughness=None, nonaqueous_visc=None, water_cut_inversion=None, relative_visc_inversion=None, use_scaling_rigorous=True, file_name=None)[source]
Configure Flash Analysis JSON input.
- Parameters:
inflows – dictionary of solutes, of the form {“unit”: unit, “values”: {solute_name: concentration_value}}; otherwise, {solute_name: concentration_value}
flash_method – string for flash calculation name
temperature – float for temperature in Kelvins
pressure – float for pressure in Pascals
calculated_variable – string for variable to calculate, such as temperature or pressure, used in ‘bubblepoint’, ‘dewpoint’, ‘vapor-amount’, ‘vapor-fraction’, and ‘isochoric’ flashes
enthalpy – float for total enthalpy in Joules, used in ‘isenthalpic’ flash
vapor_amount – float for vapor phase Moles, used in ‘vapor-amount’ flash
vapor_fraction – float for vapor phase in Mole %, used in ‘vapor-fraction’ flash
volume – float for total volume in Cubic Meters, used in ‘isochoric’ flash
ph – float for target pH, used in ‘setph’ flash
acid_titrant – string for acidification titrant, used in ‘setph’ flash
base_titrant – string for basification titrant, used in ‘setph’ flash
formed_solid – string for solid species to precipitate based on inflow sweep, used in ‘precipitation-point’
precipitant_inflow – string for inflow species to sweep, used in ‘precipitation-point’
included_solids – list of solids to include in analysis
excluded_solids – list of solids to exclude from analysis
contact_surface – string for contact surface metal name
flow_type – string for flow configuration
diameter – float for diameter of surface (i.e., pipe or rotor)
liq_velocity – float for velocity of liquid flow
gas_velocity – float for velocity of vapor flow, used in ‘approximateMultiPhaseFlow’
rot_velocity – float for rotational velocity
shear_stress – float for defined shear stress, used in ‘definedShearStress’
roughness – float for pipe roughness, used in ‘approximateMultiPhaseFlow’
nonaqueous_visc – float for absolute viscosity of nonaqueous phase, used in ‘approximateMultiPhaseFlow’
water_cut_inversion – float for water cut at point of dispersion inversion, used in ‘approximateMultiPhaseFlow’
relative_visc_inversion – float for maximum relative viscosity of dispersion at inversion, used in ‘approximateMultiPhaseFlow’
use_scaling_rigorous – bool to switch between Rigorous (default) and Estimated scaling computations
file_name – string for file to write, if any
- Return json_input:
JSON for Water Analysis
- configure_water_analysis(inflows=None, temperature=None, pressure=None, reconciliation=None, electroneutrality=None, makeup_ion=None, ph=None, acid_titrant=None, base_titrant=None, alkalinity=None, alkalinity_ph=None, alkalinity_titrant=None, tic=None, allow_solids=False, included_solids=None, excluded_solids=None, calc_alkalinity=False, use_scaling_rigorous=True, file_name=None)[source]
Configure Water Analysis JSON input.
- Parameters:
inflows – dictionary of solutes
temperature – float for temperature in Kelvins
pressure – float for pressure in Pascals
reconciliation – string for method of reconciliation: “EquilCalcOnly” (default), “ReconcilePh”, “ReconcilePhAndAlkalinity”, or “ReconcilePhAndAlkalinityAndTic”; “ReconcileCo2Gas” not supported currently.
electroneutrality – string for method of electroneutrality calculation: “DominantIon”, “ProrateCations”, “ProrateAnions”, “Prorate”, “AutoNACL”, or “MakeupIon” are supported
makeup_ion – string for ion to use for electroneutrality balance, if “MakeupIon,
ph – float for pH to reconcile solution to, required for pH based reconciliation
acid_titrant – string for acidification titrant, used in pH based reconciliation
base_titrant – string for basification titrant, used in pH based reconciliation
alkalinity – float for alkalinity to reconcile solution to, required for Alk based reconciliation
alkalinity_ph – float for alkalinity endpoint ph, used in Alk based reconciliation
alkalinity_titrant – string for alkalinity titration species, used in Alk based reconciliation
tic – float for total inorganic carbon concentration to reconcile solution to, required for TIC based reconcilation
allow_solids – bool to enable solid phase formation
included_solids – list of solids to include in analysis
excluded_solids – list of solids to exclude from analysis
calc_alkalinity – bool to calculate alkalinity of solution
use_scaling_rigorous – bool to switch between Rigorous (default) and Estimated scaling computations
file_name – string for file to write, if any
mesh_grid – if True (default) the input array will be combined to generate combination of all possible samples if False, the direct values in survey_arrays will be used
- Return json_input:
JSON for Water Analysis
- get_apparent_species_from_true(true_species_json, oliapi_instance, dbs_file_id, phase=None, file_name=None)[source]
Run Water Analysis to get apparent species.
- Parameters:
true_species_json – JSON generated from true species
oliapi_instance – instance of OLI Cloud API to call
dbs_file_id – string ID of DBS file
phase – string for inflows phase
file_name – string for file to write, if any
- Return apparent_species:
dictionary for molecular concentrations
- get_clone(flash_method, json_input, index, survey=None)[source]
Iterate over a survey to create a modified clone from JSON input.
- Parameters:
flash_method – string for flash calculation name
json_input – JSON input for flash calculation
index – integer for index of incoming data
survey – dictionary containing names and input values to modify in JSON
- Return clone:
dictionary containing modified state variables and survey index
- run_flash(flash_method, oliapi_instance, dbs_file_id, json_input, survey=None, file_name=None)[source]
Conduct single point analysis with initial JSON input, or conduct a survey on that input.
- Parameters:
flash_method – string for flash calculation name
oliapi_instance – instance of OLI Cloud API
dbs_file_id – string ID of DBS file
json_input – JSON input for flash calculation
survey – dictionary containing names and input values to modify in JSON
file_name – string for file to write, if any
- Return processed_requests:
results from processed OLI flash requests
- watertap.tools.oli_api.flash.build_survey(survey_arrays, get_oli_names=False, file_name=None, mesh_grid=True)[source]
Build a dictionary for modifying flash calculation parameters.
- Parameters:
survey_arrays – dictionary for variables and values to survey
get_oli_names – bool switch to convert name into OLI name
file_name – string for file to write, if any
mesh_grid – if True (default) the input array will be combined to generate combination of all possible samples if False, the direct values in survey_arrays will be used
- Return survey:
dictionary for product of survey variables and values
- watertap.tools.oli_api.flash.get_survey_sample_conditions(survey, sample_points)[source]
Return survey parameter values for one or more sample points.
- Parameters:
survey – dictionary for product of survey conditions and values
sample_points – list of indices to get parameter values from
- Return sample_conditions:
dictionary for parameter values for given samples